Index: lib/sync.js |
=================================================================== |
--- a/lib/sync.js |
+++ b/lib/sync.js |
@@ -12,27 +12,25 @@ Cu.import("resource://gre/modules/XPCOMU |
Cu.import("resource://gre/modules/Services.jsm"); |
let {FilterStorage} = require("filterStorage"); |
let {FilterNotifier} = require("filterNotifier"); |
let {Synchronizer} = require("synchronizer"); |
let {Subscription, SpecialSubscription, DownloadableSubscription, ExternalSubscription} = require("subscriptionClasses"); |
let {Filter, ActiveFilter} = require("filterClasses"); |
+// Firefox Sync classes are set later in initEngine() |
+let Service, Engines, SyncEngine, Store, Tracker; |
+ |
/** |
* ID of the only record stored |
* @type String |
*/ |
let filtersRecordID = "6fad6286-8207-46b6-aa39-8e0ce0bd7c49"; |
-/** |
- * Weave tracker class (is set when Weave is initialized). |
- */ |
-let Tracker = null; |
- |
let Sync = exports.Sync = |
{ |
/** |
* Will be set to true if/when Weave starts up. |
* @type Boolean |
*/ |
initialized: false, |
@@ -44,17 +42,17 @@ let Sync = exports.Sync = |
/** |
* Returns Adblock Plus sync engine. |
* @result Engine |
*/ |
getEngine: function() |
{ |
if (this.initialized) |
- return Weave.Engines.get("adblockplus"); |
+ return Engines.get("adblockplus"); |
else |
return null; |
} |
}; |
/** |
* Listens to notifications from Sync service. |
*/ |
@@ -88,27 +86,31 @@ let SyncServiceObserver = |
} catch (e) {} |
Services.obs.removeObserver(this, "weave:engine:start-tracking"); |
Services.obs.removeObserver(this, "weave:engine:stop-tracking"); |
}.bind(this)); |
}, |
initEngine: function() |
{ |
- Cu.import("resource://services-sync/main.js"); |
+ ({Engines, SyncEngine, Store, Tracker} = Cu.import("resource://services-sync/engines.js")); |
Felix Dahlke
2012/10/30 17:44:12
Why surround this with parentheses?
Wladimir Palant
2012/10/30 18:53:49
Because otherwise {...} is a block statement and y
|
+ if (typeof Engines == "undefined") |
+ { |
+ ({Service} = Cu.import("resource://services-sync/service.js")); |
Felix Dahlke
2012/10/30 17:44:12
Same here, are those parentheses necessary?
|
+ Engines = Service.engineManager; |
+ } |
- Tracker = Weave.SyncEngine.prototype._trackerObj; |
- ABPEngine.prototype.__proto__ = Weave.SyncEngine.prototype; |
- ABPStore.prototype.__proto__ = Weave.Store.prototype; |
+ ABPEngine.prototype.__proto__ = SyncEngine.prototype; |
+ ABPStore.prototype.__proto__ = Store.prototype; |
ABPTracker.prototype.__proto__ = Tracker.prototype; |
- Weave.Engines.register(ABPEngine); |
+ Engines.register(ABPEngine); |
onShutdown.add(function() |
{ |
- Weave.Engines.unregister("adblockplus"); |
+ Engines.unregister("adblockplus"); |
}); |
}, |
observe: function(subject, topic, data) |
{ |
switch (topic) |
{ |
case "weave:service:ready": |
@@ -131,34 +133,34 @@ let SyncServiceObserver = |
} |
}, |
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakReference]), |
}; |
function ABPEngine() |
{ |
- Weave.SyncEngine.call(this, "AdblockPlus"); |
+ SyncEngine.call(this, "AdblockPlus", Service); |
} |
ABPEngine.prototype = |
{ |
_storeObj: ABPStore, |
_trackerObj: ABPTracker, |
version: 1, |
_reconcile: function(item) |
{ |
// Always process server data, we will do the merging ourselves |
return true; |
} |
}; |
-function ABPStore(name) |
+function ABPStore(name, engine) |
{ |
- Weave.Store.call(this, name); |
+ Store.call(this, name, engine); |
} |
ABPStore.prototype = |
{ |
getAllIDs: function() |
{ |
let result = {} |
result[filtersRecordID] = true; |
return result; |
@@ -351,21 +353,21 @@ ABPStore.prototype = |
} |
}; |
/** |
* Hack to allow store to use the tracker - store tracker pointer globally. |
*/ |
let trackerInstance = null; |
-function ABPTracker(name) |
+function ABPTracker(name, engine) |
{ |
- Tracker.call(this, name); |
+ Tracker.call(this, name, engine); |
- this.privateTracker = new Tracker(name + ".private"); |
+ this.privateTracker = new Tracker(name + ".private", engine); |
trackerInstance = this; |
this.onChange = this.onChange.bind(this); |
if (Sync.trackingEnabled) |
this.startTracking(); |
} |
ABPTracker.prototype = |