Bug 1260461 - Don't flush windows when shutting down due to a Windows log-out. r=jimm, a=lizzard
authorMike Conley <mconley@mozilla.com>
Fri, 01 Apr 2016 17:15:37 -0400
changeset 310566 7d39fe1e571c9bd656d66e05732ebd11419c5e77
parent 310565 c9962404eb5dfc4c8fed45a1fc964072c1a783e6
child 310567 527bc99e29e1e05c9c487b61e159bb1cbc2cb28e
push id9404
push usercbook@mozilla.com
push dateThu, 14 Apr 2016 06:39:53 +0000
treeherdermozilla-aurora@7d39fe1e571c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm, lizzard
bugs1260461
milestone47.0a2
Bug 1260461 - Don't flush windows when shutting down due to a Windows log-out. r=jimm, a=lizzard MozReview-Commit-ID: 3WWgPTxzdcz
browser/components/sessionstore/SessionStore.jsm
widget/windows/nsWindow.cpp
--- a/browser/components/sessionstore/SessionStore.jsm
+++ b/browser/components/sessionstore/SessionStore.jsm
@@ -634,17 +634,18 @@ var SessionStoreInternal = {
     switch (aTopic) {
       case "browser-window-before-show": // catch new windows
         this.onBeforeBrowserWindowShown(aSubject);
         break;
       case "domwindowclosed": // catch closed windows
         this.onClose(aSubject);
         break;
       case "quit-application-granted":
-        this.onQuitApplicationGranted();
+        let syncShutdown = aData == "syncShutdown";
+        this.onQuitApplicationGranted(syncShutdown);
         break;
       case "browser-lastwindow-close-granted":
         this.onLastWindowCloseGranted();
         break;
       case "quit-application":
         this.onQuitApplication(aData);
         break;
       case "browser:purge-session-history": // catch sanitization
@@ -1417,17 +1418,17 @@ var SessionStoreInternal = {
         this._closedWindows.splice(winIndex, 1);
       }
     }
   },
 
   /**
    * On quit application granted
    */
-  onQuitApplicationGranted: function ssi_onQuitApplicationGranted() {
+  onQuitApplicationGranted: function ssi_onQuitApplicationGranted(syncShutdown=false) {
     // Collect an initial snapshot of window data before we do the flush
     this._forEachBrowserWindow((win) => {
       this._collectWindowData(win);
     });
 
     // Now add an AsyncShutdown blocker that'll spin the event loop
     // until the windows have all been flushed.
 
@@ -1435,20 +1436,26 @@ var SessionStoreInternal = {
     // and will help us debug things that go wrong with our AsyncShutdown
     // blocker.
     let progress = { total: -1, current: -1 };
 
     // We're going down! Switch state so that we treat closing windows and
     // tabs correctly.
     RunState.setQuitting();
 
-    AsyncShutdown.quitApplicationGranted.addBlocker(
-      "SessionStore: flushing all windows",
-      this.flushAllWindowsAsync(progress),
-      () => progress);
+    if (!syncShutdown) {
+      // We've got some time to shut down, so let's do this properly.
+      AsyncShutdown.quitApplicationGranted.addBlocker(
+        "SessionStore: flushing all windows",
+        this.flushAllWindowsAsync(progress),
+        () => progress);
+    } else {
+      // We have to shut down NOW, which means we only get to save whatever
+      // we already had cached.
+    }
   },
 
   /**
    * An async Task that iterates all open browser windows and flushes
    * any outstanding messages from their tabs. This will also close
    * all of the currently open windows while we wait for the flushes
    * to complete.
    *
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -4785,17 +4785,18 @@ nsWindow::ProcessMessage(UINT msg, WPARA
       {
         // Let's fake a shutdown sequence without actually closing windows etc.
         // to avoid Windows killing us in the middle. A proper shutdown would
         // require having a chance to pump some messages. Unfortunately
         // Windows won't let us do that. Bug 212316.
         nsCOMPtr<nsIObserverService> obsServ =
           mozilla::services::GetObserverService();
         NS_NAMED_LITERAL_STRING(context, "shutdown-persist");
-        obsServ->NotifyObservers(nullptr, "quit-application-granted", nullptr);
+        NS_NAMED_LITERAL_STRING(syncShutdown, "syncShutdown");
+        obsServ->NotifyObservers(nullptr, "quit-application-granted", syncShutdown.get());
         obsServ->NotifyObservers(nullptr, "quit-application-forced", nullptr);
         obsServ->NotifyObservers(nullptr, "quit-application", nullptr);
         obsServ->NotifyObservers(nullptr, "profile-change-net-teardown", context.get());
         obsServ->NotifyObservers(nullptr, "profile-change-teardown", context.get());
         obsServ->NotifyObservers(nullptr, "profile-before-change", context.get());
         obsServ->NotifyObservers(nullptr, "profile-before-change2", context.get());
         // Then a controlled but very quick exit.
         _exit(0);