Bug 979034 - [Australis] Make CustomizationTabPreloader kick-off when the user opens the menu panel. r=ttaubert, a=gavin.
authorMike Conley <mconley@mozilla.com>
Tue, 11 Mar 2014 19:38:51 -0400
changeset 183263 8fbd4f92ca4ef9bba2e9e6b2224e80969692e78e
parent 183262 d40e9c054bc318f86353affab41d9eefd51f9b78
child 183264 38733824a12ab1b84bedde6f96e96f2ac55c245c
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)
reviewersttaubert, gavin
bugs979034
milestone29.0a2
Bug 979034 - [Australis] Make CustomizationTabPreloader kick-off when the user opens the menu panel. r=ttaubert, a=gavin.
browser/components/customizableui/content/panelUI.js
browser/components/customizableui/src/CustomizeMode.jsm
browser/components/nsBrowserGlue.js
browser/modules/CustomizationTabPreloader.jsm
--- a/browser/components/customizableui/content/panelUI.js
+++ b/browser/components/customizableui/content/panelUI.js
@@ -149,16 +149,20 @@ const PanelUI = {
       }
       let iconAnchor =
         document.getAnonymousElementByAttribute(anchor, "class",
                                                 "toolbarbutton-icon");
       this.panel.openPopup(iconAnchor || anchor);
 
       this.panel.addEventListener("popupshown", function onPopupShown() {
         this.removeEventListener("popupshown", onPopupShown);
+        // As an optimization for the customize mode transition, we preload
+        // about:customizing in the background once the menu panel is first
+        // shown.
+        gCustomizationTabPreloader.ensurePreloading();
         deferred.resolve();
       });
     });
 
     return deferred.promise;
   },
 
   /**
--- a/browser/components/customizableui/src/CustomizeMode.jsm
+++ b/browser/components/customizableui/src/CustomizeMode.jsm
@@ -265,16 +265,21 @@ CustomizeMode.prototype = {
       this._updateEmptyPaletteNotice();
 
       this.maybeShowTip(panelHolder);
 
       this._handler.isEnteringCustomizeMode = false;
       panelContents.removeAttribute("customize-transitioning");
 
       CustomizableUI.dispatchToolboxEvent("customizationready", {}, window);
+
+      // It's possible that we didn't enter customize mode via the menu panel,
+      // meaning we didn't kick off about:customizing preloading. If that's
+      // the case, let's kick it off for the next time we load this mode.
+      window.gCustomizationTabPreloader.ensurePreloading();
       if (!this._wantToBeInCustomizeMode) {
         this.exit();
       }
     }.bind(this)).then(null, function(e) {
       ERROR(e);
       // We should ensure this has been called, and calling it again doesn't hurt:
       window.PanelUI.endBatchUpdate();
       this._handler.isEnteringCustomizeMode = false;
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -473,17 +473,16 @@ BrowserGlue.prototype = {
     this._migrateUI();
 
     this._syncSearchEngines();
 
     webappsUI.init();
     PageThumbs.init();
     NewTabUtils.init();
     BrowserNewTabPreloader.init();
-    CustomizationTabPreloader.init();
     SignInToWebsiteUX.init();
     PdfJs.init();
 #ifdef NIGHTLY_BUILD
     ShumwayUtils.init();
 #endif
     webrtcUI.init();
     AboutHome.init();
     SessionStore.init();
--- a/browser/modules/CustomizationTabPreloader.jsm
+++ b/browser/modules/CustomizationTabPreloader.jsm
@@ -16,70 +16,55 @@ Cu.import("resource://gre/modules/Promis
 const HTML_NS = "http://www.w3.org/1999/xhtml";
 const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
 const XUL_PAGE = "data:application/vnd.mozilla.xul+xml;charset=utf-8,<window%20id='win'/>";
 const CUSTOMIZATION_URL = "about:customizing";
 
 // The interval between swapping in a preload docShell and kicking off the
 // next preload in the background.
 const PRELOADER_INTERVAL_MS = 600;
-// The initial delay before we start preloading our first customization page. The
-// timer is started after the first 'browser-delayed-startup' has been sent.
-const PRELOADER_INIT_DELAY_MS = 7000;
-
-const TOPIC_TIMER_CALLBACK = "timer-callback";
-const TOPIC_DELAYED_STARTUP = "browser-delayed-startup-finished";
 
 function createTimer(obj, delay) {
   let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
   timer.init(obj, delay, Ci.nsITimer.TYPE_ONE_SHOT);
   return timer;
 }
 
 function clearTimer(timer) {
   if (timer) {
     timer.cancel();
   }
   return null;
 }
 
 this.CustomizationTabPreloader = {
-  init: function() {
-    CustomizationTabPreloaderInternal.init();
-  },
-
   uninit: function () {
     CustomizationTabPreloaderInternal.uninit();
   },
 
   newTab: function (aTab) {
     return CustomizationTabPreloaderInternal.newTab(aTab);
   },
+
+  /**
+   * ensurePreloading starts the preloading of the about:customizing
+   * content page. This function is idempotent (until a call to uninit),
+   * so multiple calls to it are fine.
+   */
+  ensurePreloading: function() {
+    CustomizationTabPreloaderInternal.ensurePreloading();
+  },
 };
 
 Object.freeze(CustomizationTabPreloader);
 
 this.CustomizationTabPreloaderInternal = {
   _browser: null,
-  _timer: null,
-  _observing: false,
-
-  init: function () {
-    Services.obs.addObserver(this, TOPIC_DELAYED_STARTUP, false);
-    this._observing = true;
-  },
 
   uninit: function () {
-    this._timer = clearTimer(this._timer);
-
-    if (this._observing) {
-      Services.obs.removeObserver(this, TOPIC_DELAYED_STARTUP);
-      this._observing = false;
-    }
-
     HostFrame.destroy();
 
     if (this._browser) {
       this._browser.destroy();
       this._browser = null;
     }
   },
 
@@ -87,33 +72,20 @@ this.CustomizationTabPreloaderInternal =
     let win = aTab.ownerDocument.defaultView;
     if (win.gBrowser && this._browser) {
       return this._browser.swapWithNewTab(aTab);
     }
 
     return false;
   },
 
-  observe: function (aSubject, aTopic, aData) {
-    if (aTopic == TOPIC_DELAYED_STARTUP) {
-      Services.obs.removeObserver(this, TOPIC_DELAYED_STARTUP);
-      this._observing = false;
-      this._startTimer();
-    } else if (aTopic == TOPIC_TIMER_CALLBACK) {
-      this._timer = null;
-      this._startPreloader();
+  ensurePreloading: function () {
+    if (!this._browser) {
+      this._browser = new HiddenBrowser();
     }
-  },
-
-  _startTimer: function () {
-    this._timer = createTimer(this, PRELOADER_INIT_DELAY_MS);
-  },
-
-  _startPreloader: function () {
-    this._browser = new HiddenBrowser();
   }
 };
 
 function HiddenBrowser() {
   this._createBrowser();
 }
 
 HiddenBrowser.prototype = {