Bug 1369539 - Sync UI startup performance improvements. r?florian, markh draft
authorEdouard Oger <eoger@fastmail.com>
Tue, 04 Jul 2017 14:23:33 -0400
changeset 606987 479f60d4880c866d9bad11e527438cd5b89ce0f3
parent 606958 6fec4855b5345eb63fef57089e61829b88f5f4eb
child 636907 0e364edadcd2f3b0b3b45ecd7fcef85a8eeb0609
push id67854
push userbmo:eoger@fastmail.com
push dateTue, 11 Jul 2017 18:04:32 +0000
reviewersflorian, markh
bugs1369539
milestone56.0a1
Bug 1369539 - Sync UI startup performance improvements. r?florian, markh MozReview-Commit-ID: 7ibJokJttLh
browser/base/content/browser.js
browser/base/content/test/performance/browser_startup.js
services/sync/modules/UIState.jsm
services/sync/tests/unit/test_uistate.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -1633,17 +1633,19 @@ var gBrowserInit = {
     FullScreen.init();
     PointerLock.init();
 
     if (AppConstants.isPlatformAndVersionAtLeast("win", "10")) {
       ContextMenuTouchModeObserver.init();
     }
 
     // initialize the sync UI
-    gSync.init();
+    requestIdleCallback(() => {
+      gSync.init();
+    }, {timeout: 1000 * 5});
 
     if (AppConstants.MOZ_DATA_REPORTING)
       gDataNotificationInfoBar.init();
 
     gBrowserThumbnails.init();
 
     gExtensionsNotifications.init();
 
--- a/browser/base/content/test/performance/browser_startup.js
+++ b/browser/base/content/test/performance/browser_startup.js
@@ -87,16 +87,18 @@ const startupPhases = {
     ])
   }},
 
   // We are at this phase once we are ready to handle user events.
   // Anything loaded at this phase or before gets in the way of the user
   // interacting with the first browser window.
   "before handling user events": {blacklist: {
     modules: new Set([
+      "resource://gre/modules/FxAccounts.jsm",
+      "resource://gre/modules/FxAccountsStorage.jsm",
       "resource://gre/modules/LoginManagerContextMenu.jsm",
       "resource://gre/modules/Task.jsm",
     ]),
   }},
 };
 
 function test() {
   if (!AppConstants.NIGHTLY_BUILD && !AppConstants.DEBUG) {
--- a/services/sync/modules/UIState.jsm
+++ b/services/sync/modules/UIState.jsm
@@ -67,16 +67,19 @@ const UIStateInternal = {
       this.init();
       return false;
     }
     return true;
   },
 
   init() {
     this._initialized = true;
+    if (!Services.prefs.prefHasUserValue("services.sync.username")) {
+      return;
+    }
     // Refresh the state in the background.
     this.refreshState().catch(e => {
       Cu.reportError(e);
     });
   },
 
   // Used for testing.
   reset() {
--- a/services/sync/tests/unit/test_uistate.js
+++ b/services/sync/tests/unit/test_uistate.js
@@ -2,21 +2,40 @@
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 Cu.import("resource://services-sync/UIState.jsm");
 
 const UIStateInternal = UIState._internal;
 
-add_task(async function test_isReady() {
+add_task(async function test_isReady_unconfigured() {
   UIState.reset();
 
   let refreshState = sinon.spy(UIStateInternal, "refreshState");
 
+  // On the first call, returns false
+  // Does not trigger a refresh of the state since services.sync.username is undefined
+  ok(!UIState.isReady());
+  ok(!refreshState.called);
+  refreshState.reset();
+
+  // On subsequent calls, only return true
+  ok(UIState.isReady());
+  ok(!refreshState.called);
+
+  refreshState.restore();
+});
+
+add_task(async function test_isReady_signedin() {
+  UIState.reset();
+  Services.prefs.setCharPref("services.sync.username", "foo");
+
+  let refreshState = sinon.spy(UIStateInternal, "refreshState");
+
   // On the first call, returns false and triggers a refresh of the state
   ok(!UIState.isReady());
   ok(refreshState.calledOnce);
   refreshState.reset();
 
   // On subsequent calls, only return true
   ok(UIState.isReady());
   ok(!refreshState.called);