Bug 1261657 - Don't record SSTabRestored events in StartupPerformance that are the result of a remoteness flip. r?Yoric draft
authorMike Conley <mconley@mozilla.com>
Sun, 03 Apr 2016 00:30:14 -0400
changeset 347189 0b6a2132c26a8d82899318dfaa761bc2c675c27c
parent 345298 2c8a3acfb48c772cfc2f0417738590bc607ce110
child 517567 e6e2125d7332d04ed832d43e6bc8869c3a11d8e7
push id14512
push usermconley@mozilla.com
push dateSun, 03 Apr 2016 04:56:17 +0000
reviewersYoric
bugs1261657
milestone48.0a1
Bug 1261657 - Don't record SSTabRestored events in StartupPerformance that are the result of a remoteness flip. r?Yoric MozReview-Commit-ID: 2pnT2DdKPHV
browser/components/sessionstore/SessionStore.jsm
browser/components/sessionstore/StartupPerformance.jsm
browser/components/sessionstore/content/content-sessionStore.js
--- a/browser/components/sessionstore/SessionStore.jsm
+++ b/browser/components/sessionstore/SessionStore.jsm
@@ -833,17 +833,17 @@ var SessionStoreInternal = {
         // monitor the progress of network loads.
         if (gDebuggingEnabled) {
           Services.obs.notifyObservers(browser, NOTIFY_TAB_RESTORED, null);
         }
 
         SessionStoreInternal._resetLocalTabRestoringState(tab);
         SessionStoreInternal.restoreNextTab();
 
-        this._sendTabRestoredNotification(tab);
+        this._sendTabRestoredNotification(tab, data.isRemotenessUpdate);
         break;
       case "SessionStore:crashedTabRevived":
         // The browser was revived by navigating to a different page
         // manually, so we remove it from the ignored browser set.
         this._crashedBrowsers.delete(browser.permanentKey);
         break;
       case "SessionStore:error":
         this.reportInternalError(data);
@@ -3281,16 +3281,19 @@ var SessionStoreInternal = {
 
   /**
    * Kicks off restoring the given tab.
    *
    * @param aTab
    *        the tab to restore
    * @param aLoadArguments
    *        optional load arguments used for loadURI()
+   * @param aRemotenessSwitch
+   *        true if we're restoring a tab's content because we flipped
+   *        its remoteness (out-of-process) state.
    */
   restoreTabContent: function (aTab, aLoadArguments = null) {
     if (aTab.hasAttribute("customizemode")) {
       return;
     }
 
     let browser = aTab.linkedBrowser;
     let window = aTab.ownerDocument.defaultView;
@@ -3304,17 +3307,18 @@ var SessionStoreInternal = {
     }
 
     // We have to mark this tab as restoring first, otherwise
     // the "pending" attribute will be applied to the linked
     // browser, which removes it from the display list. We cannot
     // flip the remoteness of any browser that is not being displayed.
     this.markTabAsRestoring(aTab);
 
-    if (tabbrowser.updateBrowserRemotenessByURL(browser, uri)) {
+    let isRemotenessUpdate = tabbrowser.updateBrowserRemotenessByURL(browser, uri);
+    if (isRemotenessUpdate) {
       // We updated the remoteness, so we need to send the history down again.
       //
       // Start a new epoch to discard all frame script messages relating to a
       // previous epoch. All async messages that are still on their way to chrome
       // will be ignored and don't override any tab data set when restoring.
       let epoch = this.startNextEpoch(browser);
 
       browser.messageManager.sendAsyncMessage("SessionStore:restoreHistory", {
@@ -3327,17 +3331,17 @@ var SessionStoreInternal = {
 
     // If the restored browser wants to show view source content, start up a
     // view source browser that will load the required frame script.
     if (uri && ViewSourceBrowser.isViewSource(uri)) {
       new ViewSourceBrowser(browser);
     }
 
     browser.messageManager.sendAsyncMessage("SessionStore:restoreTabContent",
-      {loadArguments: aLoadArguments});
+      {loadArguments: aLoadArguments, isRemotenessUpdate});
   },
 
   /**
    * Marks a given pending tab as restoring.
    *
    * @param aTab
    *        the pending tab to mark as restoring
    */
@@ -3964,21 +3968,27 @@ var SessionStoreInternal = {
   _sendWindowStateEvent: function ssi_sendWindowStateEvent(aWindow, aType) {
     let event = aWindow.document.createEvent("Events");
     event.initEvent("SSWindowState" + aType, true, false);
     aWindow.dispatchEvent(event);
   },
 
   /**
    * Dispatch the SSTabRestored event for the given tab.
-   * @param aTab the which has been restored
+   * @param aTab
+   *        The tab which has been restored
+   * @param aIsRemotenessUpdate
+   *        True if this tab was restored due to flip from running from
+   *        out-of-main-process to in-main-process or vice-versa.
    */
-  _sendTabRestoredNotification: function ssi_sendTabRestoredNotification(aTab) {
-    let event = aTab.ownerDocument.createEvent("Events");
-    event.initEvent("SSTabRestored", true, false);
+  _sendTabRestoredNotification(aTab, aIsRemotenessUpdate) {
+    let event = aTab.ownerDocument.createEvent("CustomEvent");
+    event.initCustomEvent("SSTabRestored", true, false, {
+      isRemotenessUpdate: aIsRemotenessUpdate,
+    });
     aTab.dispatchEvent(event);
   },
 
   /**
    * @param aWindow
    *        Window reference
    * @returns whether this window's data is still cached in _statesToRestore
    *          because it's not fully loaded yet
--- a/browser/components/sessionstore/StartupPerformance.jsm
+++ b/browser/components/sessionstore/StartupPerformance.jsm
@@ -194,19 +194,26 @@ this.StartupPerformance = {
           this._totalNumberOfWindows += 1;
 
           // Observe the restoration of all tabs. We assume that all tabs of this
           // window will have been restored before `COLLECT_RESULTS_AFTER_MS`.
           // The last call to `observer` will let us determine how long it took
           // to reach that point.
           let win = subject;
 
-          let observer = () => {
-            this._latestRestoredTimeStamp = Date.now();
-            this._totalNumberOfEagerTabs += 1;
+          let observer = (event) => {
+            // We don't care about tab restorations that are due to
+            // a browser flipping from out-of-main-process to in-main-process
+            // or vice-versa. We only care about restorations that are due
+            // to the user switching to a lazily restored tab, or for tabs
+            // that are restoring eagerly.
+            if (!event.detail.isRemotenessUpdate) {
+              this._latestRestoredTimeStamp = Date.now();
+              this._totalNumberOfEagerTabs += 1;
+            }
           };
           win.gBrowser.tabContainer.addEventListener("SSTabRestored", observer);
           this._totalNumberOfTabs += win.gBrowser.tabContainer.itemCount;
 
           // Once we have finished collecting the results, clean up the observers.
           this._promiseFinished.then(() => {
             if (!win.gBrowser.tabContainer) {
               // May be undefined during shutdown and/or some tests.
--- a/browser/components/sessionstore/content/content-sessionStore.js
+++ b/browser/components/sessionstore/content/content-sessionStore.js
@@ -162,31 +162,31 @@ var MessageListener = {
     // SessionStore.jsm so that it can run SSTabRestoring. Users of
     // SSTabRestoring seem to get confused if chrome and content are out of
     // sync about the state of the restore (particularly regarding
     // docShell.currentURI). Using a synchronous message is the easiest way
     // to temporarily synchronize them.
     sendSyncMessage("SessionStore:restoreHistoryComplete", {epoch});
   },
 
-  restoreTabContent({loadArguments}) {
+  restoreTabContent({loadArguments, isRemotenessUpdate}) {
     let epoch = gCurrentEpoch;
 
     // We need to pass the value of didStartLoad back to SessionStore.jsm.
     let didStartLoad = gContentRestore.restoreTabContent(loadArguments, () => {
       // Tell SessionStore.jsm that it may want to restore some more tabs,
       // since it restores a max of MAX_CONCURRENT_TAB_RESTORES at a time.
-      sendAsyncMessage("SessionStore:restoreTabContentComplete", {epoch});
+      sendAsyncMessage("SessionStore:restoreTabContentComplete", {epoch, isRemotenessUpdate});
     });
 
     sendAsyncMessage("SessionStore:restoreTabContentStarted", {epoch});
 
     if (!didStartLoad) {
       // Pretend that the load succeeded so that event handlers fire correctly.
-      sendAsyncMessage("SessionStore:restoreTabContentComplete", {epoch});
+      sendAsyncMessage("SessionStore:restoreTabContentComplete", {epoch, isRemotenessUpdate});
     }
   },
 
   flush({id}) {
     // Flush the message queue, send the latest updates.
     MessageQueue.send({flushID: id});
   }
 };