Bug 1134518 - Cap shistory entries in the SessionWorker when shutting down r=Yoric

This commit is contained in:
Tim Taubert 2015-04-22 18:41:32 +02:00
Родитель bed2a2af1d
Коммит 864092309d
2 изменённых файлов: 41 добавлений и 8 удалений

Просмотреть файл

@ -55,6 +55,9 @@ XPCOMUtils.defineLazyModuleGetter(this, "SessionWorker",
const PREF_UPGRADE_BACKUP = "browser.sessionstore.upgradeBackup.latestBuildID";
const PREF_MAX_UPGRADE_BACKUPS = "browser.sessionstore.upgradeBackup.maxUpgradeBackups";
const PREF_MAX_SERIALIZE_BACK = "browser.sessionstore.max_serialize_back";
const PREF_MAX_SERIALIZE_FWD = "browser.sessionstore.max_serialize_forward";
this.SessionFile = {
/**
* Read the contents of the session file, asynchronously.
@ -256,11 +259,11 @@ let SessionFileInternal = {
// Initialize the worker to let it handle backups and also
// as a workaround for bug 964531.
SessionWorker.post("init", [
result.origin,
this.Paths,
Preferences.get(PREF_MAX_UPGRADE_BACKUPS, 3)
]);
SessionWorker.post("init", [result.origin, this.Paths, {
maxUpgradeBackups: Preferences.get(PREF_MAX_UPGRADE_BACKUPS, 3),
maxSerializeBack: Preferences.get(PREF_MAX_SERIALIZE_BACK, 10),
maxSerializeForward: Preferences.get(PREF_MAX_SERIALIZE_FWD, -1)
}]);
return result;
}),

Просмотреть файл

@ -88,15 +88,25 @@ let Agent = {
* @param {string} origin Which of sessionstore.js or its backups
* was used. One of the `STATE_*` constants defined above.
* @param {object} paths The paths at which to find the various files.
* @param {number} maxUpgradeBackups The number of old upgrade backups that should be kept.
* @param {object} prefs The preferences the worker needs to known.
*/
init: function (origin, paths, maxUpgradeBackups) {
init(origin, paths, prefs = {}) {
if (!(origin in paths || origin == STATE_EMPTY)) {
throw new TypeError("Invalid origin: " + origin);
}
// Check that all required preference values were passed.
for (let pref of ["maxUpgradeBackups", "maxSerializeBack", "maxSerializeForward"]) {
if (!prefs.hasOwnProperty(pref)) {
throw new TypeError(`Missing preference value for ${pref}`);
}
}
this.state = origin;
this.Paths = paths;
this.maxUpgradeBackups = maxUpgradeBackups || 3;
this.maxUpgradeBackups = prefs.maxUpgradeBackups;
this.maxSerializeBack = prefs.maxSerializeBack;
this.maxSerializeForward = prefs.maxSerializeForward;
this.upgradeBackupNeeded = paths.nextUpgradeBackup != paths.upgradeBackup;
return {result: true};
},
@ -118,6 +128,26 @@ let Agent = {
let exn;
let telemetry = {};
// Cap the number of backward and forward shistory entries on shutdown.
if (options.isFinalWrite) {
for (let window of state.windows) {
for (let tab of window.tabs) {
let lower = 0;
let upper = tab.entries.length;
if (this.maxSerializeBack > -1) {
lower = Math.max(lower, tab.index - this.maxSerializeBack - 1);
}
if (this.maxSerializeForward > -1) {
upper = Math.min(upper, tab.index + this.maxSerializeForward);
}
tab.entries = tab.entries.slice(lower, upper);
tab.index -= lower;
}
}
}
let stateString = JSON.stringify(state);
let data = Encoder.encode(stateString);
let startWriteMs, stopWriteMs;