disable tracker for entire sync run. make sure tracker is re-enabled at the end
authorDan Mills <thunder@mozilla.com>
Fri, 05 Dec 2008 00:55:19 -0800
changeset 45082 53b4d5b8b9c3540028fae78efd19f74880b0f66f
parent 45081 3a765c3738ccd6262483cc9f0f7491e11a054120
child 45083 e1d3a8cfd970ec17fdf9c195ddb07e5b81c4db45
push idunknown
push userunknown
push dateunknown
disable tracker for entire sync run. make sure tracker is re-enabled at the end
services/sync/modules/engines.js
services/sync/modules/engines/bookmarks.js
--- a/services/sync/modules/engines.js
+++ b/services/sync/modules/engines.js
@@ -342,17 +342,17 @@ SyncEngine.prototype = {
   _changeRecordRefs: function SyncEngine__changeRecordRefs(oldID, newID) {
     let self = yield;
     for each (let rec in this.outgoing) {
       if (rec.parentid == oldID)
         rec.parentid = newID;
     }
   },
 
-  _changeRecordID: function SyncEngine__changeRecordID(oldID, newID) {
+  _changeItemID: function SyncEngine__changeItemID(oldID, newID) {
     let self = yield;
     throw "_changeRecordID must be overridden in a subclass";
   },
 
   _recDepth: function SyncEngine__recDepth(rec) {
     // we've calculated depth for this record already
     if (rec.depth)
       return rec.depth;
@@ -385,16 +385,18 @@ SyncEngine.prototype = {
       let cryptoSvc = Cc["@labs.mozilla.com/Weave/Crypto;1"].
         getService(Ci.IWeaveCrypto);
       let symkey = cryptoSvc.generateRandomKey();
       let pubkey = yield PubKeys.getDefaultKey(self.cb);
       meta = new CryptoMeta(this.cryptoMetaURL);
       meta.generateIV();
       yield meta.addUnwrappedKey(self.cb, pubkey, symkey);
       yield meta.put(self.cb);
+
+      this._tracker.disable();
     }
   },
 
   // Generate outgoing records
   _generateOutgoing: function SyncEngine__generateOutgoing() {
     let self = yield;
 
     this._log.debug("Calculating client changes");
@@ -517,24 +519,22 @@ SyncEngine.prototype = {
     this._incoming = this.incoming.filter(function(n) n); // removes any holes
   },
 
   // Apply incoming records
   _applyIncoming: function SyncEngine__applyIncoming() {
     let self = yield;
     if (this.incoming.length) {
       this._log.debug("Applying server changes");
-      this._tracker.disable();
       let inc;
       while ((inc = this.incoming.shift())) {
         yield this._store.applyIncoming(self.cb, inc);
         if (inc.modified > this.lastSync)
           this.lastSync = inc.modified;
       }
-      this._tracker.enable();
     }
   },
 
   // Upload outgoing records
   _uploadOutgoing: function SyncEngine__uploadOutgoing() {
     let self = yield;
     if (this.outgoing.length) {
       this._log.debug("Uploading client changes");
@@ -552,36 +552,43 @@ SyncEngine.prototype = {
   },
 
   // Any cleanup necessary.
   // Save the current snapshot so as to calculate changes at next sync
   _syncFinish: function SyncEngine__syncFinish() {
     let self = yield;
     this._log.debug("Finishing up sync");
     this._tracker.resetScore();
+    this._tracker.enable();
   },
 
   _sync: function SyncEngine__sync() {
     let self = yield;
 
-    yield this._syncStartup.async(this, self.cb);
+    try {
+      yield this._syncStartup.async(this, self.cb);
 
-    // Populate incoming and outgoing queues
-    yield this._generateOutgoing.async(this, self.cb);
-    yield this._fetchIncoming.async(this, self.cb);
+      // Populate incoming and outgoing queues
+      yield this._generateOutgoing.async(this, self.cb);
+      yield this._fetchIncoming.async(this, self.cb);
+
+      // Decrypt and sort incoming records, then reconcile
+      yield this._processIncoming.async(this, self.cb);
+      yield this._reconcile.async(this, self.cb);
 
-    // Decrypt and sort incoming records, then reconcile
-    yield this._processIncoming.async(this, self.cb);
-    yield this._reconcile.async(this, self.cb);
-
-    // Apply incoming records, upload outgoing records
-    yield this._applyIncoming.async(this, self.cb);
-    yield this._uploadOutgoing.async(this, self.cb);
-
-    yield this._syncFinish.async(this, self.cb);
+      // Apply incoming records, upload outgoing records
+      yield this._applyIncoming.async(this, self.cb);
+      yield this._uploadOutgoing.async(this, self.cb);
+    }
+    catch (e) {
+      throw e;
+    }
+    finally {
+      yield this._syncFinish.async(this, self.cb);
+    }
   },
 
   _resetServer: function SyncEngine__resetServer() {
     let self = yield;
     let all = new Resource(this.engineURL);
     yield all.delete(self.cb);
   }
 };
--- a/services/sync/modules/engines/bookmarks.js
+++ b/services/sync/modules/engines/bookmarks.js
@@ -780,19 +780,19 @@ BookmarksEngine.prototype = {
       if (rec.parentid == oldID) {
         rec.parentid = newID;
         rec.cleartext.parentid = newID;
         yield rec.encrypt(self.cb, ID.get('WeaveCryptoID').password);
       }
     }
   },
 
-  _changeRecordID: function BmkEngine__changeRecordID(oldID, newID) {
+  _changeItemID: function BmkEngine__changeRecordID(oldID, newID) {
     let self = yield;
-    yield this._store._changeRecordID.async(this._store, self.cb, oldID, newID);
+    yield this._store._changeItemID.async(this._store, self.cb, oldID, newID);
   }
 
   // XXX for sharing, will need to re-add code to get new shares before syncing,
   //     and updating incoming/outgoing shared folders after syncing
 };
 
 function BookmarksSyncCore(store) {
   this._store = store;