enable history sync (not working yet)
authorDan Mills <thunder@mozilla.com>
Tue, 09 Dec 2008 12:26:14 -0800
changeset 45092 39d5ec218f66f73f9747385bcfb4dd00965b6932
parent 45091 879687443d562fa306ee177cbb802aeb56612ff5
child 45093 24fbde38c95258387ba3d603d2c6e669e39bcd24
child 45094 45a6be7daacca547c728edc66ae9b93c3adeb5fe
push idunknown
push userunknown
push dateunknown
enable history sync (not working yet)
services/sync/modules/engines.js
services/sync/modules/engines/bookmarks.js
services/sync/modules/engines/history.js
services/sync/modules/service.js
services/sync/modules/stores.js
--- a/services/sync/modules/engines.js
+++ b/services/sync/modules/engines.js
@@ -161,17 +161,17 @@ Engine.prototype = {
   },
 
   _init: function Engine__init() {
     let levelPref = "log.logger.service.engine." + this.name;
     let level = "Debug";
     try { level = Utils.prefs.getCharPref(levelPref); }
     catch (e) { /* ignore unset prefs */ }
 
-    this._log = Log4Moz.repository.getLogger("Service." + this.logName);
+    this._log = Log4Moz.repository.getLogger("Engine." + this.logName);
     this._log.level = Log4Moz.Level[level];
     this._osPrefix = "weave:" + this.name + ":";
 
     this._tracker; // initialize tracker to load previously changed IDs
 
     this._log.debug("Engine initialized");
   },
 
--- a/services/sync/modules/engines/bookmarks.js
+++ b/services/sync/modules/engines/bookmarks.js
@@ -62,26 +62,26 @@ Cu.import("resource://weave/engines.js")
 Cu.import("resource://weave/stores.js");
 Cu.import("resource://weave/trackers.js");
 Cu.import("resource://weave/identity.js");
 Cu.import("resource://weave/notifications.js");
 Cu.import("resource://weave/resource.js");
 
 Function.prototype.async = Async.sugar;
 
-function BookmarksEngine(pbeId) {
-  this._init(pbeId);
+function BookmarksEngine() {
+  this._init();
 }
 BookmarksEngine.prototype = {
   __proto__: SyncEngine.prototype,
   get _super() SyncEngine.prototype,
 
   get name() "bookmarks",
   get displayName() "Bookmarks",
-  get logName() "BmkEngine",
+  get logName() "Bookmarks",
   get serverPrefix() "user-data/bookmarks/",
 
   get _store() {
     let store = new BookmarksStore();
     this.__defineGetter__("_store", function() store);
     return store;
   },
 
--- a/services/sync/modules/engines/history.js
+++ b/services/sync/modules/engines/history.js
@@ -6,17 +6,17 @@
  * the License. You may obtain a copy of the License at
  * http://www.mozilla.org/MPL/
  *
  * Software distributed under the License is distributed on an "AS IS" basis,
  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  * for the specific language governing rights and limitations under the
  * License.
  *
- * The Original Code is Bookmarks Sync.
+ * The Original Code is Weave
  *
  * The Initial Developer of the Original Code is Mozilla.
  * Portions created by the Initial Developer are Copyright (C) 2008
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
  *  Dan Mills <thunder@mozilla.com>
  *
@@ -45,112 +45,68 @@ Cu.import("resource://weave/util.js");
 Cu.import("resource://weave/engines.js");
 Cu.import("resource://weave/syncCores.js");
 Cu.import("resource://weave/stores.js");
 Cu.import("resource://weave/trackers.js");
 Cu.import("resource://weave/async.js");
 
 Function.prototype.async = Async.sugar;
 
-function HistoryEngine(pbeId) {
-  this._init(pbeId);
+function HistoryEngine() {
+  this._init();
 }
 HistoryEngine.prototype = {
-  __proto__: new SyncEngine(),
+  __proto__: SyncEngine.prototype,
+  get _super() SyncEngine.prototype,
 
-  get name() { return "history"; },
-  get displayName() { return "Browsing History"; },
-  get logName() { return "HistEngine"; },
-  get serverPrefix() { return "user-data/history/"; },
+  get name() "history",
+  get displayName() "History",
+  get logName() "History",
+  get serverPrefix() "user-data/history/",
 
-  __store: null,
   get _store() {
-    if (!this.__store)
-      this.__store = new HistoryStore();
-    return this.__store;
+    let store = new HistoryStore();
+    this.__defineGetter__("_store", function() store);
+    return store;
   },
 
-  __core: null,
-  get _core() {
-    if (!this.__core)
-      this.__core = new HistorySyncCore(this._store);
-    return this.__core;
-  },
-
-  __tracker: null,
   get _tracker() {
-    if (!this.__tracker)
-      this.__tracker = new HistoryTracker();
-    return this.__tracker;
+    let tracker = new HistoryTracker();
+    this.__defineGetter__("_tracker", function() tracker);
+    return tracker;
   }
 };
 
-function HistorySyncCore(store) {
-  this._store = store;
-  this._init();
-}
-HistorySyncCore.prototype = {
-  _logName: "HistSync",
-  _store: null,
-
-  _commandLike: function HSC_commandLike(a, b) {
-    // History commands never qualify for likeness.  We will always
-    // take the union of all client/server items.  We use the URL as
-    // the GUID, so the same sites will map to the same item (same
-    // GUID), without our intervention.
-    return false;
-  },
-
-  /**
-   * Determine the differences between two snapshots.  This method overrides
-   * the one in its superclass so it can ignore removes, since removes don't
-   * matter for history (and would cause deltas to grow too large too fast).
-   */
-  _detectUpdates: function HSC__detectUpdates(a, b) {
-    let self = yield;
-
-    this.__proto__.__proto__._detectUpdates.async(this, self.cb, a, b);
-    let cmds = yield;
-    cmds = cmds.filter(function (v) v.action != "remove");
-
-    self.done(cmds);
-  }
-};
-HistorySyncCore.prototype.__proto__ = new SyncCore();
-
 function HistoryStore() {
   this._init();
 }
 HistoryStore.prototype = {
+  __proto__: Store.prototype,
   _logName: "HistStore",
   _lookup: null,
 
-  __hsvc: null,
   get _hsvc() {
-    if (!this.__hsvc) {
-      this.__hsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
-                    getService(Ci.nsINavHistoryService);
-      this.__hsvc.QueryInterface(Ci.nsIGlobalHistory2);
-      this.__hsvc.QueryInterface(Ci.nsIBrowserHistory);
-    }
-    return this.__hsvc;
+    let hsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
+      getService(Ci.nsINavHistoryService);
+    hsvc.QueryInterface(Ci.nsIGlobalHistory2);
+    hsvc.QueryInterface(Ci.nsIBrowserHistory);
+    this.__defineGetter__("_hsvc", function() hsvc);
+    return hsvc;
   },
 
-  __histDB: null,
   get _histDB() {
-    if (!this.__histDB) {
-      let file = Cc["@mozilla.org/file/directory_service;1"].
-                 getService(Ci.nsIProperties).
-                 get("ProfD", Ci.nsIFile);
-      file.append("places.sqlite");
-      let stor = Cc["@mozilla.org/storage/service;1"].
-                 getService(Ci.mozIStorageService);
-      this.__histDB = stor.openDatabase(file);
-    }
-    return this.__histDB;
+    let file = Cc["@mozilla.org/file/directory_service;1"].
+      getService(Ci.nsIProperties).
+      get("ProfD", Ci.nsIFile);
+    file.append("places.sqlite");
+    let stor = Cc["@mozilla.org/storage/service;1"].
+      getService(Ci.mozIStorageService);
+    let db = stor.openDatabase(file);
+    this.__defineGetter__("_histDB", function() db);
+    return db;
   },
 
   _itemExists: function HistStore__itemExists(GUID) {
     // we don't care about already-existing items; just try to re-add them
     return false;
   },
 
   _createCommand: function HistStore__createCommand(command) {
@@ -241,24 +197,36 @@ HistoryStore.prototype = {
     this._hsvc.removeAllPages();
   },
 
   _resetGUIDs: function FormStore__resetGUIDs() {
     let self = yield;
     // Not needed.
   }
 };
-HistoryStore.prototype.__proto__ = new Store();
 
 function HistoryTracker() {
   this._init();
 }
 HistoryTracker.prototype = {
+  __proto__: Tracker.prototype,
   _logName: "HistoryTracker",
 
+  get _hsvc() {
+    let hsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
+      getService(Ci.nsINavHistoryService);
+    this.__defineGetter__("_hsvc", function() hsvc);
+    return hsvc;
+  },
+
+  _init: function HT__init() {
+    this.__proto__.__proto__._init.call(this);
+    this._hsvc.addObserver(this, false);
+  },
+
   /* We don't care about the first four */
   onBeginUpdateBatch: function HT_onBeginUpdateBatch() {
 
   },
   onEndUpdateBatch: function HT_onEndUpdateBatch() {
 
   },
   onPageChanged: function HT_onPageChanged() {
@@ -279,20 +247,10 @@ HistoryTracker.prototype = {
   onPageExpired: function HT_onPageExpired(uri, time, entry) {
     this._score += 1;
   },
   onDeleteURI: function HT_onDeleteURI(uri) {
     this._score += 1;
   },
   onClearHistory: function HT_onClearHistory() {
     this._score += 50;
-  },
-
-  _init: function HT__init() {
-    this._log = Log4Moz.Service.getLogger("Service." + this._logName);
-    this._score = 0;
-
-    Cc["@mozilla.org/browser/nav-history-service;1"].
-    getService(Ci.nsINavHistoryService).
-    addObserver(this, false);
   }
-}
-HistoryTracker.prototype.__proto__ = new Tracker();
+};
--- a/services/sync/modules/service.js
+++ b/services/sync/modules/service.js
@@ -73,23 +73,16 @@ Cu.import("resource://weave/faultToleran
 Cu.import("resource://weave/auth.js");
 Cu.import("resource://weave/resource.js");
 Cu.import("resource://weave/base_records/keys.js");
 Cu.import("resource://weave/engines.js");
 Cu.import("resource://weave/oauth.js");
 Cu.import("resource://weave/identity.js");
 Cu.import("resource://weave/async.js");
 Cu.import("resource://weave/clientData.js");
-Cu.import("resource://weave/engines/bookmarks.js");
-/*Cu.import("resource://weave/engines/cookies.js");
-Cu.import("resource://weave/engines/history.js");
-Cu.import("resource://weave/engines/passwords.js");
-Cu.import("resource://weave/engines/forms.js");
-Cu.import("resource://weave/engines/tabs.js");
-Cu.import("resource://weave/engines/input.js");*/
 
 Function.prototype.async = Async.sugar;
 
 // for export
 let Weave = {};
 Cu.import("resource://weave/constants.js", Weave);
 Cu.import("resource://weave/util.js", Weave);
 Cu.import("resource://weave/async.js", Weave);
@@ -99,24 +92,17 @@ Cu.import("resource://weave/resource.js"
 Cu.import("resource://weave/base_records/keys.js", Weave);
 Cu.import("resource://weave/notifications.js", Weave);
 Cu.import("resource://weave/identity.js", Weave);
 Cu.import("resource://weave/clientData.js", Weave);
 Cu.import("resource://weave/stores.js", Weave);
 Cu.import("resource://weave/syncCores.js", Weave);
 Cu.import("resource://weave/engines.js", Weave);
 Cu.import("resource://weave/oauth.js", Weave);
-Cu.import("resource://weave/service.js", Weave);
-Cu.import("resource://weave/engines/bookmarks.js", Weave);
-/*Cu.import("resource://weave/engines/cookies.js", Weave);
-Cu.import("resource://weave/engines/passwords.js", Weave);
-Cu.import("resource://weave/engines/history.js", Weave);
-Cu.import("resource://weave/engines/forms.js", Weave);
-Cu.import("resource://weave/engines/tabs.js", Weave);
-Cu.import("resource://weave/engines/input.js", Weave);*/
+Cu.import("resource://weave/service.js", Weave); // ??
 
 Utils.lazy(Weave, 'Service', WeaveSvc);
 
 /*
  * Service singleton
  * Main entry point into Weave's sync framework
  */
 
@@ -555,26 +541,26 @@ WeaveSvc.prototype = {
     if (!(yield this._remoteSetup.async(this, self.cb))) {
       throw "aborting sync, remote setup failed";
     }
 
     //this._log.debug("Refreshing client list");
     //yield ClientData.refresh(self.cb);
 
     let engines = Engines.getAll();
-    for (let i = 0; i < engines.length; i++) {
+    for each (let engine in engines) {
       if (this.cancelRequested)
         continue;
 
-      if (!engines[i].enabled)
+      if (!engine.enabled)
         continue;
 
-      this._log.debug("Syncing engine " + engines[i].name);
-      yield this._notify(engines[i].name + "-engine:sync", "",
-                         this._syncEngine, engines[i]).async(this, self.cb);
+      this._log.debug("Syncing engine " + engine.name);
+      yield this._notify(engine.name + "-engine:sync", "",
+                         this._syncEngine, engine).async(this, self.cb);
     }
 
     if (this._syncError) {
       this._syncError = false;
       throw "Some engines did not sync correctly";
     }
 
     this._log.debug("Sync complete");
--- a/services/sync/modules/stores.js
+++ b/services/sync/modules/stores.js
@@ -137,16 +137,20 @@ Store.prototype = {
   wrap: function Store_wrap() {
     throw "override wrap in a subclass";
   },
 
   wrapItem: function Store_wrapItem() {
     throw "override wrapItem in a subclass";
   },
 
+  changeItemID: function Store_changeItemID(oldID, newID) {
+    throw "override changeItemID in a subclass";
+  },
+
   getAllIDs: function Store_getAllIDs() {
     throw "override getAllIDs in a subclass";
   },
 
   wipe: function Store_wipe() {
     throw "override wipe in a subclass";
   }
 };