Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/bootstrap_xpcom.js

Issue 10233013: Crawler, second version (Closed)
Patch Set: Created April 12, 2013, 1:38 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/application.js ('k') | lib/browser.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This Source Code is subject to the terms of the Mozilla Public License
3 * version 2.0 (the "License"). You can obtain a copy of the License at
4 * http://mozilla.org/MPL/2.0/.
5 */
6
7
8 //Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService)
9
10 var Bootstrap_XPCOM_Base_class = function()
11 {
12 };
13
14 Bootstrap_XPCOM_Base_class.prototype = {
15 registrar: Components.manager.QueryInterface( Ci.nsIComponentRegistrar ),
16 category_manager: Cc["@mozilla.org/categorymanager;1"].getService( Ci.nsICateg oryManager ),
17 observer_service: Cc["@mozilla.org/observer-service;1"].getService( Ci.nsIObse rverService )
18 };
19
20 Bootstrap_XPCOM_Base_class.prototype.add_observation_topic = function( topic )
21 {
22 /*
23 * Third argument 'false' means to make a strong reference. This class (right now) supports singletons at
24 * file scope, which have the lifetime of the application.
25 */
26 this.observer_service.addObserver( this, topic, false );
27 };
28
29 Bootstrap_XPCOM_Base_class.prototype.remove_observation_topic = function( topic )
30 {
31 this.observer_service.removeObserver( this, topic );
32 };
33
34 //------------------------------------------------------------------------------ -----------
35 // Singleton_class
36 //------------------------------------------------------------------------------ -----------
37 /**
38 *
39 * @param {string} class_description
40 * Human-readable description of the class.
41 * @param class_ID
42 * Class ID for this component.
43 * @param contract_ID
44 * The contract ID that this component uses. It's only a single ID for this r elatively-simple class.
45 * @param {Array} interfaces
46 * An array of interfaces that this class supports. Used to initialize QueryI nterface.
47 * @param {Array} category_entries
48 * An array of arguments for addCategoryEntry().
49 * @constructor
50 */
51 var Singleton_class = function( class_description, class_ID, contract_ID, interf aces, category_entries )
52 {
53 this.class_description = class_description;
54 this.class_ID = class_ID;
55 this.contract_ID = contract_ID;
56 this._xpcom_categories = category_entries;
57
58 /**
59 * Standard QI function from the XPCOM utility module.
60 * @type {Function}
61 */
62 this.QueryInterface = XPCOMUtils.generateQI( interfaces );
63 };
64 Singleton_class.prototype = new Bootstrap_XPCOM_Base_class();
65
66 /**
67 * Initialization
68 * @private
69 */
70 Singleton_class.prototype.init = function()
71 {
72 this.registrar.registerFactory( this.class_ID, this.class_description, this.co ntract_ID, this );
73 for ( let c of this._xpcom_categories )
74 {
75 //noinspection JSUnusedAssignment
76 this.category_manager.addCategoryEntry( c.category, c.entry, this.contract_I D, false, true );
77 }
78 onShutdown.add( Singleton_class._deinit.bind( this ) );
79 };
80
81 /**
82 * De-initialization function, run at shutdown time.
83 *
84 * This is a separate function to avoid using a closure for registering the shut down hook.
85 *
86 * @private
87 */
88 Singleton_class._deinit = function()
89 {
90 for ( let c of this._xpcom_categories )
91 {
92 //noinspection JSUnusedAssignment
93 this.category_manager.deleteCategoryEntry( c.category, c.entry, false );
94 }
95
96 this.registrar.unregisterFactory( this.class_ID, this );
97 };
98
99 /**
100 * Standard createInstance implementation for a singleton, returning 'this' rath er than a new object.
101 */
102 Singleton_class.prototype.createInstance = function( outer, iid )
103 {
104 if ( outer )
105 throw Cr.NS_ERROR_NO_AGGREGATION;
106 return this.QueryInterface( iid );
107 };
108
109
110 //------------------------------------------------------------------------------ -----------
111 // exports
112 //------------------------------------------------------------------------------ -----------
113
114 var Bootstrap_XPCOM = {
115 Singleton_class: Singleton_class
116 };
117 exports.Bootstrap_XPCOM = Bootstrap_XPCOM;
OLDNEW
« no previous file with comments | « lib/application.js ('k') | lib/browser.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld