Bug 965544 - Show "now syncing" doorhanger when sync actually starts, once per login r=markh
authorTim Taubert <ttaubert@mozilla.com>
Wed, 29 Jan 2014 12:41:07 -0800
changeset 182198 cff14c66958466601695a1e5d5a1978cc19bc488
parent 182197 2d7d07a85dd05e1c60d74c8a1fc9aff9dae4b6a7
child 182199 29ba0cc9b15310799e3397ce288c295d2e4ef28e
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarkh
bugs965544
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 965544 - Show "now syncing" doorhanger when sync actually starts, once per login r=markh
browser/base/content/aboutaccounts/aboutaccounts.js
browser/base/content/browser-fxaccounts.js
services/sync/modules/browserid_identity.js
--- a/browser/base/content/aboutaccounts/aboutaccounts.js
+++ b/browser/base/content/aboutaccounts/aboutaccounts.js
@@ -5,16 +5,17 @@
 "use strict";
 
 const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/FxAccounts.jsm");
 
 const PREF_LAST_FXA_USER = "identity.fxaccounts.lastSignedInUser";
+const PREF_SYNC_SHOW_CUSTOMIZATION = "services.sync.ui.showCustomizationDialog";
 
 function log(msg) {
   //dump("FXA: " + msg + "\n");
 };
 
 function error(msg) {
   console.log("Firefox Account Error: " + msg + "\n");
 };
@@ -99,17 +100,17 @@ let wrapper = {
    * sucessful login and stores it in the fxaccounts service
    *
    * @param accountData the user's account data and credentials
    */
   onLogin: function (accountData) {
     log("Received: 'login'. Data:" + JSON.stringify(accountData));
 
     if (accountData.customizeSync) {
-      Services.prefs.setBoolPref("services.sync.needsCustomization", true);
+      Services.prefs.setBoolPref(PREF_SYNC_SHOW_CUSTOMIZATION, true);
       delete accountData.customizeSync;
     }
 
     // If the last fxa account used for sync isn't this account, we display
     // a modal dialog checking they really really want to do this...
     // (This is sync-specific, so ideally would be in sync's identity module,
     // but it's a little more seamless to do here, and sync is currently the
     // only fxa consumer, so...
--- a/browser/base/content/browser-fxaccounts.js
+++ b/browser/base/content/browser-fxaccounts.js
@@ -1,16 +1,18 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 XPCOMUtils.defineLazyGetter(this, "FxAccountsCommon", function () {
   return Cu.import("resource://gre/modules/FxAccountsCommon.js", {});
 });
 
+const PREF_SYNC_START_DOORHANGER = "services.sync.ui.showSyncStartDoorhanger";
+
 let gFxAccounts = {
 
   _initialized: false,
   _originalLabel: null,
   _inCustomizationMode: false,
 
   get weave() {
     delete this.weave;
@@ -19,33 +21,26 @@ let gFxAccounts = {
                           .wrappedJSObject;
   },
 
   get topics() {
     delete this.topics;
     return this.topics = [
       FxAccountsCommon.ONLOGIN_NOTIFICATION,
       FxAccountsCommon.ONVERIFIED_NOTIFICATION,
-      FxAccountsCommon.ONLOGOUT_NOTIFICATION
+      FxAccountsCommon.ONLOGOUT_NOTIFICATION,
+      "weave:service:sync:start"
     ];
   },
 
   get button() {
     delete this.button;
     return this.button = document.getElementById("PanelUI-fxa-status");
   },
 
-  get syncNeedsCustomization() {
-    try {
-      return Services.prefs.getBoolPref("services.sync.needsCustomization");
-    } catch (e) {
-      return false;
-    }
-  },
-
   init: function () {
     if (this._initialized) {
       return;
     }
 
     for (let topic of this.topics) {
       Services.obs.addObserver(this, topic, false);
     }
@@ -69,19 +64,38 @@ let gFxAccounts = {
     for (let topic of this.topics) {
       Services.obs.removeObserver(this, topic);
     }
 
     this._initialized = false;
   },
 
   observe: function (subject, topic) {
-    if (topic != FxAccountsCommon.ONVERIFIED_NOTIFICATION) {
-      this.updateUI();
-    } else if (!this.syncNeedsCustomization) {
+    switch (topic) {
+      case FxAccountsCommon.ONVERIFIED_NOTIFICATION:
+        Services.prefs.setBoolPref(PREF_SYNC_START_DOORHANGER, true);
+        break;
+      case "weave:service:sync:start":
+        this.onSyncStart();
+        break;
+      default:
+        this.updateUI();
+        break;
+    }
+  },
+
+  onSyncStart: function () {
+    let showDoorhanger = false;
+
+    try {
+      showDoorhanger = Services.prefs.getBoolPref(PREF_SYNC_START_DOORHANGER);
+    } catch (e) { /* The pref might not exist. */ }
+
+    if (showDoorhanger) {
+      Services.prefs.clearUserPref(PREF_SYNC_START_DOORHANGER);
       this.showSyncStartedDoorhanger();
     }
   },
 
   handleEvent: function (event) {
     this._inCustomizationMode = event.type == "customizationstarting";
     this.updateUI();
   },
--- a/services/sync/modules/browserid_identity.js
+++ b/services/sync/modules/browserid_identity.js
@@ -29,16 +29,18 @@ XPCOMUtils.defineLazyModuleGetter(this, 
                                   "resource://gre/modules/FxAccounts.jsm");
 
 XPCOMUtils.defineLazyGetter(this, 'fxAccountsCommon', function() {
   let ob = {};
   Cu.import("resource://gre/modules/FxAccountsCommon.js", ob);
   return ob;
 });
 
+const PREF_SYNC_SHOW_CUSTOMIZATION = "services.sync.ui.showCustomizationDialog";
+
 function deriveKeyBundle(kB) {
   let out = CryptoUtils.hkdf(kB, undefined,
                              "identity.mozilla.com/picl/v1/oldsync", 2*32);
   let bundle = new BulkKeyBundle();
   // [encryptionKey, hmacKey]
   bundle.keyPair = [out.slice(0, 32), out.slice(32, 64)];
   return bundle;
 }
@@ -69,17 +71,17 @@ this.BrowserIDManager.prototype = {
   get readyToAuthenticate() {
     // We are finished initializing when we *should* have a sync key bundle,
     // although we might not actually have one due to auth failures etc.
     return this._shouldHaveSyncKeyBundle;
   },
 
   get needsCustomization() {
     try {
-      return Services.prefs.getBoolPref("services.sync.needsCustomization");
+      return Services.prefs.getBoolPref(PREF_SYNC_SHOW_CUSTOMIZATION);
     } catch (e) {
       return false;
     }
   },
 
   initialize: function() {
     Services.obs.addObserver(this, fxAccountsCommon.ONVERIFIED_NOTIFICATION, false);
     Services.obs.addObserver(this, fxAccountsCommon.ONLOGOUT_NOTIFICATION, false);
@@ -108,17 +110,17 @@ this.BrowserIDManager.prototype = {
         const url = "chrome://browser/content/sync/customize.xul";
         const features = "centerscreen,chrome,modal,dialog,resizable=no";
         let win = Services.wm.getMostRecentWindow("navigator:browser");
 
         let data = {accepted: false};
         win.openDialog(url, "_blank", features, data);
 
         if (data.accepted) {
-          Services.prefs.clearUserPref("services.sync.needsCustomization");
+          Services.prefs.clearUserPref(PREF_SYNC_SHOW_CUSTOMIZATION);
         } else {
           // Log out if the user canceled the dialog.
           return fxAccounts.signOut();
         }
       }
 
       this._account = accountData.email;
       // We start a background keybundle fetch...