Correctly cancel any sync triggers after starting a sync with a shared function that removes timers and idle observers.
authorEdward Lee <edilee@mozilla.com>
Thu, 24 Sep 2009 19:04:06 -0700
changeset 45772 a93c07f52847f55208eb3ead2bdd601ca0c84953
parent 45771 09fe5a0ab1fcb4a4854114be02070586b2439cbf
child 45773 fe15302520bb81050e29cd0d9b58aeb93c3397e4
push id14033
push useredward.lee@engineering.uiuc.edu
push dateWed, 23 Jun 2010 22:21:35 +0000
treeherdermozilla-central@227db4ad8cdf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
Correctly cancel any sync triggers after starting a sync with a shared function that removes timers and idle observers.
services/sync/modules/service.js
--- a/services/sync/modules/service.js
+++ b/services/sync/modules/service.js
@@ -981,32 +981,41 @@ WeaveSvc.prototype = {
       reason = kSyncNotScheduled;
     else if (this.status.minimumNextSync > Date.now())
       reason = kSyncBackoffNotMet;
 
     return reason;
   },
 
   /**
+   * Remove any timers/observers that might trigger a sync
+   */
+  _clearSyncTriggers: function _clearSyncTriggers() {
+    // Clear out any scheduled syncs
+    if (this._syncTimer) {
+      this._syncTimer.cancel();
+      this._syncTimer = null;
+    }
+
+    // Clear out a sync that's just waiting for idle if we happen to have one
+    try {
+      Svc.Idle.removeIdleObserver(this, IDLE_TIME);
+    }
+    catch(ex) {}
+  },
+
+  /**
    * Check if we should be syncing and schedule the next sync, if it's not scheduled
    */
   _checkSyncStatus: function WeaveSvc__checkSyncStatus() {
     // Should we be syncing now, if not, cancel any sync timers and return
     // if we're in backoff, we'll schedule the next sync
     let reason = this._checkSync();
     if (reason && reason != kSyncBackoffNotMet) {
-      if (this._syncTimer) {
-        this._syncTimer.cancel();
-        this._syncTimer = null;
-      }
-
-      try {
-        Svc.Idle.removeIdleObserver(this, IDLE_TIME);
-      } catch(e) {} // this throws if there isn't an observer, but that's fine
-
+      this._clearSyncTriggers();
       this.status.service = STATUS_DISABLED;
       return;
     }
 
     // otherwise, schedule the sync
     this._scheduleNextSync();
   },
 
@@ -1088,20 +1097,18 @@ WeaveSvc.prototype = {
     let reason = this._checkSync();
     if (reason && (useThresh || reason != kSyncNotScheduled)) {
       // this is a purposeful abort rather than a failure, so don't set
       // any status bits
       reason = "Can't sync: " + reason;
       throw reason;
     }
 
-    if (this._autoConnectTimer) {
-      this._autoConnectTimer.cancel();
-      this._autoConnectTimer = null;
-    }
+    // Clear out any potentially pending syncs now that we're syncing
+    this._clearSyncTriggers();
 
     if (!(this._remoteSetup()))
       throw "aborting sync, remote setup failed";
 
     // Figure out what the last modified time is for each collection
     let info = new Resource(this.infoURL).get();
     if (!info.success)
       throw "aborting sync, failed to get collections";