Bug 1437388 - Don't set different session store write interval while in background. r?esawin
We had some issues with tabs closed shortly before backgrounding Firefox re-
appearing during session restore, however in hindsight
bug 1282830 (closing a
zombie tab didn't trigger a session store file write) seems a more likely cause
for that than my initial theory from
bug 1256277 comment 6 (tab events
dispatched *just* before backgrounding might be processed only after our
application-background handling), because as far as I can tell the latter theory
actually requires really split-second timing.
With that in mind, the differing, smaller minimum file write interval while in
background can be removed again.
MozReview-Commit-ID: GSQZYKeYME6
--- a/mobile/android/components/SessionStore.js
+++ b/mobile/android/components/SessionStore.js
@@ -44,37 +44,32 @@ const STATE_RUNNING = 1;
const STATE_QUITTING = -1;
const STATE_QUITTING_FLUSHED = -2;
const PREFS_RESTORE_FROM_CRASH = "browser.sessionstore.resume_from_crash";
const PREFS_MAX_CRASH_RESUMES = "browser.sessionstore.max_resumed_crashes";
const PREFS_MAX_TABS_UNDO = "browser.sessionstore.max_tabs_undo";
const MINIMUM_SAVE_DELAY = 2000;
-// We reduce the delay in background because we could be killed at any moment,
-// however we don't set it to 0 in order to allow for multiple events arriving
-// one after the other to be batched together in one write operation.
-const MINIMUM_SAVE_DELAY_BACKGROUND = 200;
function SessionStore() { }
SessionStore.prototype = {
classID: Components.ID("{8c1f07d6-cba3-4226-a315-8bd43d67d032}"),
QueryInterface: XPCOMUtils.generateQI([Ci.nsISessionStore,
Ci.nsIDOMEventListener,
Ci.nsIObserver,
Ci.nsISupportsWeakReference]),
_windows: {},
_lastSaveTime: 0,
_lastBackupTime: 0,
_interval: 10000,
_backupInterval: 120000, // 2 minutes
- _minSaveDelay: MINIMUM_SAVE_DELAY,
_maxTabsUndo: 5,
_pendingWrite: 0,
_scrollSavePending: null,
_writeInProgress: false,
// We only want to start doing backups if we've successfully
// written the session data at least once.
_sessionDataIsGood: false,
@@ -381,30 +376,22 @@ SessionStore.prototype = {
break;
}
case "application-background":
// We receive this notification when Android's onPause callback is
// executed. After onPause, the application may be terminated at any
// point without notice; therefore, we must synchronously write out any
// pending save state to ensure that this data does not get lost.
log("application-background");
- // Tab events dispatched immediately before the application was backgrounded
- // might actually arrive after this point, therefore save them without delay.
if (this._loadState == STATE_RUNNING) {
- this._interval = 0;
- this._minSaveDelay = MINIMUM_SAVE_DELAY_BACKGROUND; // A small delay allows successive tab events to be batched together.
this.flushPendingState();
}
break;
case "application-foreground":
- // Reset minimum interval between session store writes back to default.
log("application-foreground");
- this._interval = Services.prefs.getIntPref("browser.sessionstore.interval");
- this._minSaveDelay = MINIMUM_SAVE_DELAY;
-
// If we skipped restoring a zombified tab before backgrounding,
// we might have to do it now instead.
let window = Services.wm.getMostRecentWindow("navigator:browser");
if (window && window.BrowserApp) { // Might not yet be ready during a cold startup.
let tab = window.BrowserApp.selectedTab;
if (tab) { // Can be null if closing a tab triggered an activity switch.
this.restoreZombieTab(tab);
}
@@ -977,17 +964,17 @@ SessionStore.prototype = {
},
saveStateDelayed: function ss_saveStateDelayed() {
if (!this._saveTimer) {
// Interval until the next disk operation is allowed
let currentDelay = this._lastSaveTime + this._interval - Date.now();
// If we have to wait, set a timer, otherwise saveState directly
- let delay = Math.max(currentDelay, this._minSaveDelay);
+ let delay = Math.max(currentDelay, MINIMUM_SAVE_DELAY);
if (delay > 0) {
this._pendingWrite++;
this._saveTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
this._saveTimer.init(this, delay, Ci.nsITimer.TYPE_ONE_SHOT);
log("saveStateDelayed() timer delay = " + delay +
", incrementing _pendingWrite to " + this._pendingWrite);
} else {
log("saveStateDelayed() no delay");