Bug 639779 - Port Bug 622379 [Current session data is lost upon browser triggered restart (e.g. upgrade) if the option to clear browsing history upon shutdown is set (again)]. r=Neil
authorMisak Khachatryan <misak.bugzilla@gmail.com>
Tue, 08 Mar 2011 17:56:13 +0400
changeset 7279 6499341dae5e67ecaa141020850bc815ebe8777e
parent 7278 382b3365a2e9c19f9ac3227d04e0f43cc6c96ddd
child 7280 ffc62985589918ffe3396d4d95344a85cf44eb7f
push idunknown
push userunknown
push dateunknown
reviewersNeil
bugs639779, 622379
Bug 639779 - Port Bug 622379 [Current session data is lost upon browser triggered restart (e.g. upgrade) if the option to clear browsing history upon shutdown is set (again)]. r=Neil
suite/common/src/nsSessionStore.js
--- a/suite/common/src/nsSessionStore.js
+++ b/suite/common/src/nsSessionStore.js
@@ -419,22 +419,36 @@ SessionStoreService.prototype = {
     case "browser-lastwindow-close-granted":
       // last browser window is quitting.
       // remember to restore the last window when another browser window is openend
       // do not account for pref(resume_session_once) at this point, as it might be
       // set by another observer getting this notice after us
       this._restoreLastWindow = true;
       break;
     case "quit-application":
-      if (aData == "restart" && !this._isSwitchingProfile())
+      if (aData == "restart" && !this._isSwitchingProfile()) {
         this._prefBranch.setBoolPref("sessionstore.resume_session_once", true);
+        // The browser:purge-session-history notification fires after the
+        // quit-application notification so unregister the
+        // browser:purge-session-history notification to prevent clearing
+        // session data on disk on a restart.  It is also unnecessary to
+        // perform any other sanitization processing on a restart as the
+        // browser is about to exit anyway.
+        Services.obs.removeObserver(this, "browser:purge-session-history");
+      }
       this._loadState = STATE_QUITTING; // just to be sure
       this._uninit();
       break;
     case "browser:purge-session-history": // catch sanitization
+      this._clearDisk();
+      // If the browser is shutting down, simply return after clearing the
+      // session data on disk as this notification fires after the
+      // quit-application notification so the browser is about to exit.
+      if (this._loadState == STATE_QUITTING)
+        return;
       let openWindows = {};
       this._forEachBrowserWindow(function(aWindow) {
         Array.forEach(aWindow.getBrowser().tabs, function(aTab) {
           delete aTab.linkedBrowser.__SS_data;
           if (aTab.linkedBrowser.__SS_restoreState)
             this._resetTabRestoringState(aTab);
         });
         openWindows[aWindow.__SSi] = true;
@@ -443,17 +457,16 @@ SessionStoreService.prototype = {
       for (let ix in this._windows) {
         if (ix in openWindows)
           this._windows[ix]._closedTabs = [];
         else
           delete this._windows[ix];
       }
       // also clear all data about closed windows
       this._closedWindows = [];
-      this._clearDisk();
       // give the tabbrowsers a chance to clear their histories first
       var win = this._getMostRecentBrowserWindow();
       if (win)
         win.setTimeout(function() { _this.saveState(true); }, 0);
       else if (this._loadState == STATE_RUNNING)
         this.saveState(true);
       break;
     case "nsPref:changed": // catch pref changes