Bug 1260461 - Don't flush windows when shutting down due to a Windows log-out. r?jimm draft
authorMike Conley <mconley@mozilla.com>
Fri, 01 Apr 2016 17:15:37 -0400
changeset 349111 167878a8a2168f8f7e6346b9496f5ba35dedbc91
parent 349110 5111e423f37d0c2bbee69380d3006054679eecfb
child 518011 541e2d7d98e20e2116dc6ec206987dcf4e6707d6
push id14991
push usermconley@mozilla.com
push dateFri, 08 Apr 2016 22:06:08 +0000
reviewersjimm
bugs1260461
milestone48.0a1
Bug 1260461 - Don't flush windows when shutting down due to a Windows log-out. r?jimm 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
@@ -4787,17 +4787,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);