Bug 506975 - Add preferences to control sessionstore state while on battery. r=Yoric,ttaubert

This commit is contained in:
Manish Goregaokar 2014-10-17 08:06:00 +02:00
Родитель 884b20762e
Коммит 3d066bc28b
2 изменённых файлов: 15 добавлений и 11 удалений

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

@ -1044,6 +1044,8 @@ pref("browser.sessionstore.resume_session_once", false);
// minimal interval between two save operations in milliseconds
pref("browser.sessionstore.interval", 15000);
// Minimal interval between two save operations when device is unplugged
pref("browser.sessionstore.interval_battery", 60000);
// on which sites to save text data, POSTDATA and cookies
// 0 = everywhere, 1 = unencrypted sites, 2 = nowhere
pref("browser.sessionstore.privacy_level", 0);

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

@ -17,6 +17,8 @@ Cu.import("resource://gre/modules/TelemetryStopwatch.jsm", this);
XPCOMUtils.defineLazyModuleGetter(this, "console",
"resource://gre/modules/devtools/Console.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Battery",
"resource://gre/modules/Battery.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PrivacyFilter",
"resource:///modules/sessionstore/PrivacyFilter.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "SessionStore",
@ -26,22 +28,21 @@ XPCOMUtils.defineLazyModuleGetter(this, "SessionFile",
XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
"resource://gre/modules/PrivateBrowsingUtils.jsm");
// Minimal interval between two save operations (in milliseconds).
XPCOMUtils.defineLazyGetter(this, "gInterval", function () {
const PREF = "browser.sessionstore.interval";
function observeSaveIntervalPref(obj, pref, property) {
// Observer that updates the cached value when the preference changes.
Services.prefs.addObserver(PREF, () => {
this.gInterval = Services.prefs.getIntPref(PREF);
Services.prefs.addObserver(pref, () => {
obj[property] = Services.prefs.getIntPref(pref);
// Cancel any pending runs and call runDelayed() with
// zero to apply the newly configured interval.
// Cancel any pending runs and call runDelayed()
// to apply the newly configured interval.
SessionSaverInternal.cancel();
SessionSaverInternal.runDelayed(0);
}, false);
obj[property] = Services.prefs.getIntPref(pref);
}
return Services.prefs.getIntPref(PREF);
});
observeSaveIntervalPref(this, "browser.sessionstore.interval", "gInterval");
observeSaveIntervalPref(this, "browser.sessionstore.interval_battery", "gIntervalBattery");
// Notify observers about a given topic with a given subject.
function notify(subject, topic) {
@ -145,7 +146,8 @@ let SessionSaverInternal = {
}
// Interval until the next disk operation is allowed.
delay = Math.max(this._lastSaveTime + gInterval - Date.now(), delay, 0);
let interval = Battery.charging ? gInterval : gIntervalBattery;
delay = Math.max(this._lastSaveTime + interval - Date.now(), delay, 0);
// Schedule a state save.
this._timeoutID = setTimeout(() => this._saveStateAsync(), delay);