Bug 1360287 - Factor out history/tabs data purging into separate function to reduce session store observer complexity. r?sebastian draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Wed, 10 May 2017 23:55:26 +0200
changeset 575803 d95fc66b1a62594c302dca10a1c1532e1c2fb1d3
parent 575614 a117fd795f9fd86e0332c37c93000677d8211fcb
child 628026 f5fb1d45a09a3691f03bfdefff7a8ad05918671a
push id58178
push usermozilla@buttercookie.de
push dateWed, 10 May 2017 22:00:57 +0000
reviewerssebastian
bugs1360287
milestone55.0a1
Bug 1360287 - Factor out history/tabs data purging into separate function to reduce session store observer complexity. r?sebastian MozReview-Commit-ID: IhxMfUKEDgh
mobile/android/components/SessionStore.js
--- a/mobile/android/components/SessionStore.js
+++ b/mobile/android/components/SessionStore.js
@@ -133,16 +133,55 @@ SessionStore.prototype = {
 
   _updateMaxTabsUndo: function ss_updateMaxTabsUndo() {
     this._maxTabsUndo = Services.prefs.getIntPref(PREFS_MAX_TABS_UNDO);
     if (this._maxTabsUndo == 0) {
       this._forgetClosedTabs();
     }
   },
 
+  _purgeHistory: function ss_purgeHistory(topic) {
+    log(topic);
+    this._clearDisk();
+
+    // Clear all data about closed tabs
+    this._forgetClosedTabs();
+
+    // Clear all cached session history data.
+    if (topic == "browser:purge-session-history") {
+      this._forEachBrowserWindow((window) => {
+        let tabs = window.BrowserApp.tabs;
+        for (let i = 0; i < tabs.length; i++) {
+          let data = tabs[i].browser.__SS_data;
+          let sHistory = data.entries;
+          // Copy the current history entry to the end...
+          sHistory.push(sHistory[data.index - 1]);
+          // ... and then remove everything else.
+          sHistory.splice(0, sHistory.length - 1);
+          data.index = 1;
+        }
+      });
+    }
+
+    if (this._loadState == STATE_RUNNING) {
+      // Save the purged state immediately
+      this.saveState();
+    } else if (this._loadState <= STATE_QUITTING) {
+      this.saveStateDelayed();
+      if (this._loadState == STATE_QUITTING_FLUSHED) {
+        this.flushPendingState();
+      }
+    }
+
+    Services.obs.notifyObservers(null, "sessionstore-state-purge-complete");
+    if (this._notifyClosedTabs) {
+      this._sendClosedTabsToJava(Services.wm.getMostRecentWindow("navigator:browser"));
+    }
+  },
+
   _clearDisk: function ss_clearDisk() {
     this._sessionDataIsGood = false;
     this._lastBackupTime = 0;
 
     if (this._loadState > STATE_QUITTING) {
       OS.File.remove(this._sessionFile.path);
       OS.File.remove(this._sessionFileBackup.path);
       OS.File.remove(this._sessionFilePrevious.path);
@@ -228,18 +267,16 @@ SessionStore.prototype = {
             type: "Tabs:TabsOpened"
           });
         }
         break;
       }
     }
   },
 
-  // Removal of line below tracked by bug 1360287
-  // eslint-disable-next-line complexity
   observe: function ss_observe(aSubject, aTopic, aData) {
     let observerService = Services.obs;
     switch (aTopic) {
       case "app-startup":
         EventDispatcher.instance.registerListener(this, [
           "ClosedTabs:StartNotifications",
           "ClosedTabs:StopNotifications",
           "Session:Restore",
@@ -299,52 +336,17 @@ SessionStore.prototype = {
 
         // Flush all pending writes to disk now
         this.flushPendingState();
         this._loadState = STATE_QUITTING_FLUSHED;
 
         break;
       case "browser:purge-session-tabs":
       case "browser:purge-session-history": // catch sanitization
-        log(aTopic);
-        this._clearDisk();
-
-        // Clear all data about closed tabs
-        this._forgetClosedTabs();
-
-        // Clear all cached session history data.
-        if (aTopic == "browser:purge-session-history") {
-          this._forEachBrowserWindow((window) => {
-            let tabs = window.BrowserApp.tabs;
-            for (let i = 0; i < tabs.length; i++) {
-              let data = tabs[i].browser.__SS_data;
-              let sHistory = data.entries;
-              // Copy the current history entry to the end...
-              sHistory.push(sHistory[data.index - 1]);
-              // ... and then remove everything else.
-              sHistory.splice(0, sHistory.length - 1);
-              data.index = 1;
-            }
-          });
-        }
-
-        if (this._loadState == STATE_RUNNING) {
-          // Save the purged state immediately
-          this.saveState();
-        } else if (this._loadState <= STATE_QUITTING) {
-          this.saveStateDelayed();
-          if (this._loadState == STATE_QUITTING_FLUSHED) {
-            this.flushPendingState();
-          }
-        }
-
-        Services.obs.notifyObservers(null, "sessionstore-state-purge-complete");
-        if (this._notifyClosedTabs) {
-          this._sendClosedTabsToJava(Services.wm.getMostRecentWindow("navigator:browser"));
-        }
+        this._purgeHistory(aTopic);
         break;
       case "timer-callback":
         if (this._loadState == STATE_RUNNING) {
           // Timer call back for delayed saving
           this._saveTimer = null;
           log("timer-callback, pendingWrite = " + this._pendingWrite);
           if (this._pendingWrite) {
             this.saveState();