Bug 960740 - skip writing session state data if it fails sanity check. r=msamuel a=metro-only
authorSam Foster <sfoster@mozilla.com>
Thu, 23 Jan 2014 16:58:33 -0800
changeset 176106 fb2b1405f49374cf0651d9a77ba02afb9e33aed3
parent 176105 08ecd63975b7779583b4b9b6291125311a7c4447
child 176107 efa507a8e34e0f4008beaf996a350d35e589fc2b
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmsamuel, metro-only
bugs960740
milestone28.0a2
Bug 960740 - skip writing session state data if it fails sanity check. r=msamuel a=metro-only
browser/metro/components/SessionStore.js
--- a/browser/metro/components/SessionStore.js
+++ b/browser/metro/components/SessionStore.js
@@ -267,17 +267,17 @@ SessionStore.prototype = {
 
         // If a save has been queued, kill the timer and save state now
         if (this._saveTimer) {
           this._saveTimer.cancel();
           this._saveTimer = null;
           this.saveState();
         }
         break;
-      case "browser:purge-session-history": // catch sanitization 
+      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;
 
@@ -509,19 +509,24 @@ SessionStore.prototype = {
       this._saveTimer.cancel();
       this._saveTimer = null;
     }
     this.saveState();
   },
 
   saveState: function ss_saveState() {
     let data = this._getCurrentState();
-    this._writeFile(this._sessionFile, JSON.stringify(data));
+    // sanity check before we overwrite the session file
+    if (data.windows && data.windows.length && data.selectedWindow) {
+      this._writeFile(this._sessionFile, JSON.stringify(data));
 
-    this._lastSaveTime = Date.now();
+      this._lastSaveTime = Date.now();
+    } else {
+      dump("SessionStore: Not saving state with invalid data: " + JSON.stringify(data) + "\n");
+    }
   },
 
   _getCurrentState: function ss_getCurrentState() {
     let self = this;
     this._forEachBrowserWindow(function(aWindow) {
       self._collectWindowData(aWindow);
     });
 
@@ -842,17 +847,17 @@ SessionStore.prototype = {
             tab.browser.__SS_restore = true;
 
             // Restore current title
             tab.chromeTab.updateTitle(tabData.entries[tabData.index - 1].title);
           }
 
           tab.browser.__SS_extdata = tabData.extData;
         }
-    
+
         notifyObservers();
       }.bind(this));
     } catch (ex) {
       Cu.reportError("SessionStore: Could not read from sessionstore.bak file: " + ex);
       notifyObservers("fail");
     }
   }
 };