Bug 1260461 - Don't flush windows when shutting down due to a Windows log-out. r?jimm
MozReview-Commit-ID: 3WWgPTxzdcz
--- 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);