Bug 1362774 - return early from willOverrideHomepage if we know we won't override again, r?mikedeboer draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Tue, 24 Jul 2018 12:33:44 +0100
changeset 821974 f9b49f77e60f6f8b3ed97448d4d31a3b13a3a7d3
parent 821973 29bdcc8f7ed3e301094dd0ec51491255fbb17664
push id117240
push userbmo:gijskruitbosch+bugs@gmail.com
push dateTue, 24 Jul 2018 13:13:26 +0000
reviewersmikedeboer
bugs1362774
milestone63.0a1
Bug 1362774 - return early from willOverrideHomepage if we know we won't override again, r?mikedeboer This is a small performance optimization for callers of willOverrideHomepage. They want to know if the URL the window was passed will be overridden. Once we finish restoring windows, that'll never happen again, and we can return without waiting for a promise. MozReview-Commit-ID: NhKDHT6rBX
browser/components/sessionstore/nsSessionStartup.js
--- a/browser/components/sessionstore/nsSessionStartup.js
+++ b/browser/components/sessionstore/nsSessionStartup.js
@@ -261,16 +261,17 @@ SessionStartup.prototype = {
       Services.obs.removeObserver(this, "quit-application");
       if (this._sessionType != Ci.nsISessionStartup.NO_SESSION)
         Services.obs.removeObserver(this, "browser:purge-session-history");
       break;
     case "sessionstore-windows-restored":
       Services.obs.removeObserver(this, "sessionstore-windows-restored");
       // free _initialState after nsSessionStore is done with it
       this._initialState = null;
+      this._didRestore = true;
       break;
     case "browser:purge-session-history":
       Services.obs.removeObserver(this, "browser:purge-session-history");
       // reset all state on sanitization
       this._sessionType = Ci.nsISessionStartup.NO_SESSION;
       break;
     }
   },
@@ -334,16 +335,20 @@ SessionStartup.prototype = {
     // If the session file hasn't been read yet and resuming the session isn't
     // enabled via prefs, go ahead and load the homepage. We may still replace
     // it when recovering from a crash, which we'll only know after reading the
     // session file, but waiting for that would delay loading the homepage in
     // the non-crash case.
     if (!this._initialState && !this._resumeSessionEnabled) {
       return false;
     }
+    // If we've already restored the session, we won't override again.
+    if (this._didRestore) {
+      return false;
+    }
 
     return new Promise(resolve => {
       this.onceInitialized.then(() => {
         // If there are valid windows with not only pinned tabs, signal that we
         // will override the default homepage by restoring a session.
         resolve(this._willRestore() &&
                 this._initialState &&
                 this._initialState.windows &&