Bug 1176019 - Don't let cache interfere with tab warming r?mconley draft
authorDoug Thayer <dothayer@mozilla.com>
Tue, 15 May 2018 09:31:13 -0700
changeset 797880 8a51c1473ef48b2cad410b156e4b8acf80cc6d68
parent 797879 72125d5d399da91ca48d7f02e109d3a28a9161e9
push id110615
push userbmo:dothayer@mozilla.com
push dateMon, 21 May 2018 22:41:06 +0000
reviewersmconley
bugs1176019
milestone62.0a1
Bug 1176019 - Don't let cache interfere with tab warming r?mconley While working to reproduce the stale content bug with tab warming I realized that my work here had inadvertently clobbered tab warming by immediately calling the tab unload code. This wasn't necessary, and I didn't need to put the cached tab deactivation code in the unload method, it just seemed initially convenient. This should make more sense overall. MozReview-Commit-ID: 9v9dYZTa1Dv
browser/modules/AsyncTabSwitcher.jsm
--- a/browser/modules/AsyncTabSwitcher.jsm
+++ b/browser/modules/AsyncTabSwitcher.jsm
@@ -617,20 +617,22 @@ class AsyncTabSwitcher {
     // handlers, which might cause finish() to already have been called.
     // Check for that before calling finish() again.
     if (!this.tabbrowser._switcher) {
       return;
     }
 
     this.maybeFinishTabSwitch();
 
-    if (numWarming > gTabWarmingMax || numBackgroundCached > 0) {
-      if (numWarming > gTabWarmingMax) {
-        this.logState("Hit tabWarmingMax");
-      }
+    if (numBackgroundCached > 0) {
+      this.deactivateCachedBackgroundTabs();
+    }
+
+    if (numWarming > gTabWarmingMax) {
+      this.logState("Hit tabWarmingMax");
       if (this.unloadTimer) {
         this.clearTimer(this.unloadTimer);
       }
       this.unloadNonRequiredTabs();
     }
 
     if (numPending == 0) {
       this.finish();
@@ -645,32 +647,34 @@ class AsyncTabSwitcher {
     this.preActions();
     this.unloadTimer = null;
 
     this.unloadNonRequiredTabs();
 
     this.postActions();
   }
 
+  deactivateCachedBackgroundTabs() {
+    for (let tab of this.tabLayerCache) {
+      if (tab !== this.requestedTab) {
+        let browser = tab.linkedBrowser;
+        browser.preserveLayers(true);
+        browser.docShellIsActive = false;
+      }
+    }
+  }
+
   // If there are any non-visible and non-requested tabs in
   // STATE_LOADED, sets them to STATE_UNLOADING. Also queues
   // up the unloadTimer to run onUnloadTimeout if there are still
   // tabs in the process of unloading.
   unloadNonRequiredTabs() {
     this.warmingTabs = new WeakSet();
     let numPending = 0;
 
-    for (let tab of this.tabLayerCache) {
-      if (tab !== this.requestedTab) {
-        let browser = tab.linkedBrowser;
-        browser.preserveLayers(true);
-        browser.docShellIsActive = false;
-      }
-    }
-
     // Unload any tabs that can be unloaded.
     for (let [tab, state] of this.tabState) {
       if (this.tabbrowser._printPreviewBrowsers.has(tab.linkedBrowser)) {
         continue;
       }
 
       let isInLayerCache = this.tabLayerCache.includes(tab);