Bug 1369539 - Sync UI startup performance improvements. r?florian, markh
MozReview-Commit-ID: 7ibJokJttLh
--- 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);