Bug 965896 - allow a legacy sync reset to re-enable fxa accounts. r=rnewman
☠☠ backed out by cff85c90a8a3 ☠ ☠
authorMark Hammond <mhammond@skippinet.com.au>
Wed, 05 Feb 2014 14:59:19 +1100
changeset 166826 e78a7c6d9601b8c669b520d9aae02abfa5652e23
parent 166825 50c164585e255921e0f28f4e4dd929e7d94cb717
child 166827 94cbbe810eb867164f5f9a36c7de0c299376feb8
push id4843
push usermhammond@skippinet.com.au
push dateWed, 05 Feb 2014 03:59:52 +0000
treeherderfx-team@e78a7c6d9601 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs965896
milestone30.0a1
Bug 965896 - allow a legacy sync reset to re-enable fxa accounts. r=rnewman
browser/components/preferences/sync.js
services/sync/Weave.js
services/sync/modules/service.js
--- a/browser/components/preferences/sync.js
+++ b/browser/components/preferences/sync.js
@@ -80,17 +80,17 @@ let gSyncPane = {
     window.addEventListener("unload", onUnload, false);
 
     xps.ensureLoaded();
   },
 
   _init: function () {
     let topics = ["weave:service:login:error",
                   "weave:service:login:finish",
-                  "weave:service:start-over",
+                  "weave:service:start-over:finish",
                   "weave:service:setup-complete",
                   "weave:service:logout:finish",
                   FxAccountsCommon.ONVERIFIED_NOTIFICATION];
 
     // Add the observers now and remove them on unload
     //XXXzpao This should use Services.obs.* but Weave's Obs does nice handling
     //        of `this`. Fix in a followup. (bug 583347)
     topics.forEach(function (topic) {
--- a/services/sync/Weave.js
+++ b/services/sync/Weave.js
@@ -74,20 +74,20 @@ WeaveService.prototype = {
     } catch (_) {
       // That pref doesn't exist - so let's assume this is a first-run.
       // If sync already appears configured, we assume it's for the legacy
       // provider.
       let prefs = Services.prefs.getBranch(SYNC_PREFS_BRANCH);
       fxAccountsEnabled = !prefs.prefHasUserValue("username");
       Services.prefs.setBoolPref("services.sync.fxaccounts.enabled", fxAccountsEnabled);
     }
-    // Currently we don't support toggling this pref after initialization, so
-    // inject the pref value as a regular boolean.
-    delete this.fxAccountsEnabled;
-    return this.fxAccountsEnabled = fxAccountsEnabled;
+    // Currently we don't support toggling this pref after initialization -
+    // except when sync is reset - but this 1 exception is enough that we can't
+    // cache the value.
+    return fxAccountsEnabled;
   },
 
   observe: function (subject, topic, data) {
     switch (topic) {
     case "app-startup":
       let os = Cc["@mozilla.org/observer-service;1"].
                getService(Ci.nsIObserverService);
       os.addObserver(this, "final-ui-startup", true);
--- a/services/sync/modules/service.js
+++ b/services/sync/modules/service.js
@@ -884,17 +884,33 @@ Sync11Service.prototype = {
     this._ignorePrefObserver = true;
     Svc.Prefs.resetBranch("");
     this._ignorePrefObserver = false;
 
     Svc.Prefs.set("lastversion", WEAVE_VERSION);
 
     this.identity.deleteSyncCredentials();
 
-    Svc.Obs.notify("weave:service:start-over:finish");
+    // Reset the identity manager, then re-initialize it so the FxA manager is
+    // used.
+    this.identity.username = "";
+    Services.prefs.clearUserPref("services.sync.fxaccounts.enabled");
+    this.status.__authManager = null;
+    this.identity = Status._authManager;
+    this._clusterManager = this.identity.createClusterManager(this);
+
+    // Tell the new identity manager to initialize itself
+    this.identity.initialize().then(() => {
+      Svc.Obs.notify("weave:service:start-over:finish");
+    }).then(null, err => {
+      this._log.error("startOver failed to re-initialize the identity manager: " + err);
+      // Still send the observer notification so the current state is
+      // reflected in the UI.
+      Svc.Obs.notify("weave:service:start-over:finish");
+    });
   },
 
   persistLogin: function persistLogin() {
     try {
       this.identity.persistCredentials(true);
     } catch (ex) {
       this._log.info("Unable to persist credentials: " + ex);
     }