Bug 1131414 (part 1) - add a pref to indicate if sync is disabled in its entirety. r=rnewman a=readinglist
authorMark Hammond <mhammond@skippinet.com.au>
Fri, 20 Mar 2015 11:08:51 -0700
changeset 258061 bf356118c79edd721906d013977d475bb6d01a5b
parent 258060 28912ec5344f23094e927e370d4504c362ab23f2
child 258062 395fa1ecf377e8f736312f2d1961094e58534632
push id4610
push userjlund@mozilla.com
push dateMon, 30 Mar 2015 18:32:55 +0000
treeherdermozilla-beta@4df54044d9ef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman, readinglist
bugs1131414
milestone38.0a2
Bug 1131414 (part 1) - add a pref to indicate if sync is disabled in its entirety. r=rnewman a=readinglist
services/sync/modules/browserid_identity.js
services/sync/modules/service.js
services/sync/services-sync.js
services/sync/tests/unit/test_service_login.js
--- a/services/sync/modules/browserid_identity.js
+++ b/services/sync/modules/browserid_identity.js
@@ -277,17 +277,17 @@ this.BrowserIDManager.prototype = {
     switch (topic) {
     case fxAccountsCommon.ONLOGIN_NOTIFICATION:
       // This should only happen if we've been initialized without a current
       // user - otherwise we'd have seen the LOGOUT notification and been
       // thrown away.
       // The exception is when we've initialized with a user that needs to
       // reauth with the server - in that case we will also get here, but
       // should have the same identity.
-      // initializeWithCurrentIdentity will throw and log if these contraints
+      // initializeWithCurrentIdentity will throw and log if these constraints
       // aren't met, so just go ahead and do the init.
       this.initializeWithCurrentIdentity(true);
       break;
 
     case fxAccountsCommon.ONLOGOUT_NOTIFICATION:
       Weave.Service.startOver();
       // startOver will cause this instance to be thrown away, so there's
       // nothing else to do.
--- a/services/sync/modules/service.js
+++ b/services/sync/modules/service.js
@@ -300,16 +300,31 @@ Sync11Service.prototype = {
 
         this._log.info("Downloaded new keys, client reset. Proceeding.");
       }
       return true;
     }
     return false;
   },
 
+  // The global "enabled" state comes from prefs, and will be set to false
+  // whenever the UI that exposes what to sync finds all Sync engines disabled.
+  get enabled() {
+    return Svc.Prefs.get("enabled");
+  },
+  set enabled(val) {
+    // There's no real reason to impose this other than to catch someone doing
+    // something we don't expect with bad consequences - all setting of this
+    // pref are in the UI code and external to this module.
+    if (val) {
+      throw new Error("Only disabling via this setter is supported");
+    }
+    Svc.Prefs.set("enabled", val);
+  },
+
   /**
    * Prepare to initialize the rest of Weave after waiting a little bit
    */
   onStartup: function onStartup() {
     this._migratePrefs();
 
     // Status is instantiated before us and is the first to grab an instance of
     // the IdentityManager. We use that instance because IdentityManager really
@@ -329,18 +344,16 @@ Sync11Service.prototype = {
     this._log.level =
       Log.Level[Svc.Prefs.get("log.logger.service.main")];
 
     this._log.info("Loading Weave " + WEAVE_VERSION);
 
     this._clusterManager = this.identity.createClusterManager(this);
     this.recordManager = new RecordManager(this);
 
-    this.enabled = true;
-
     this._registerEngines();
 
     let ua = Cc["@mozilla.org/network/protocol;1?name=http"].
       getService(Ci.nsIHttpProtocolHandler).userAgent;
     this._log.info(ua);
 
     if (!this._checkCrypto()) {
       this.enabled = false;
@@ -1237,16 +1250,20 @@ Sync11Service.prototype = {
 
     if (ignore && ignore.indexOf(reason) != -1)
       return "";
 
     return reason;
   },
 
   sync: function sync() {
+    if (!this.enabled) {
+      this._log.debug("Not syncing as Sync is disabled.");
+      return;
+    }
     let dateStr = new Date().toLocaleFormat(LOG_DATE_FORMAT);
     this._log.debug("User-Agent: " + SyncStorageRequest.prototype.userAgent);
     this._log.info("Starting sync at " + dateStr);
     this._catch(function () {
       // Make sure we're logged in.
       if (this._shouldLogin()) {
         this._log.debug("In sync: should login.");
         if (!this.login()) {
--- a/services/sync/services-sync.js
+++ b/services/sync/services-sync.js
@@ -19,16 +19,21 @@ pref("services.sync.scheduler.activeInte
 pref("services.sync.scheduler.immediateInterval",    90);    // 1.5 minutes
 pref("services.sync.scheduler.idleTime",             300);   // 5 minutes
 
 pref("services.sync.scheduler.fxa.singleDeviceInterval",     3600); // 1 hour
 pref("services.sync.scheduler.sync11.singleDeviceInterval", 86400); // 1 day
 
 pref("services.sync.errorhandler.networkFailureReportTimeout", 1209600); // 2 weeks
 
+// A "master" pref for Sync being enabled. Will be set to false if the sync
+// customization UI finds all our builtin engines disabled (and addons are
+// free to force this to true if they have their own engine)
+pref("services.sync.enabled", true);
+// Our engines.
 pref("services.sync.engine.addons", true);
 pref("services.sync.engine.bookmarks", true);
 pref("services.sync.engine.history", true);
 pref("services.sync.engine.passwords", true);
 pref("services.sync.engine.prefs", true);
 pref("services.sync.engine.tabs", true);
 pref("services.sync.engine.tabs.filteredUrls", "^(about:.*|chrome://weave/.*|wyciwyg:.*|file:.*)$");
 
--- a/services/sync/tests/unit/test_service_login.js
+++ b/services/sync/tests/unit/test_service_login.js
@@ -178,17 +178,17 @@ add_test(function test_login_on_sync() {
     // and checkSyncStatus reflects that by waiting for login.
     //
     // This process doesn't apply if your MP is still locked, so we make
     // checkSyncStatus accept a locked MP in place of being logged in.
     //
     // This test exercises these two branches.
 
     _("We're ready to sync if locked.");
-    Service.enabled = true;
+    Svc.Prefs.set("enabled", true);
     Services.io.offline = false;
     Service.scheduler.checkSyncStatus();
     do_check_true(scheduleCalled);
 
     _("... and also if we're not locked.");
     scheduleCalled = false;
     mpLocked = false;
     Service.scheduler.checkSyncStatus();