Bug 506975 - Add preferences to control sessionstore state while on battery. r=Yoric,ttaubert
☠☠ backed out by ca94702ad5cb ☠ ☠
authorManish Goregaokar <manishearth@gmail.com>
Fri, 17 Oct 2014 08:06:00 +0200
changeset 235591 be4c66d5dc65833bbed0eaf527bdb58da0f9b68a
parent 235554 5aafff0e71c4a80032dd3e8667725384c6685ef3
child 235592 76caa49941209748033572ce07dd34a44df2125d
push id4311
push userraliiev@mozilla.com
push dateMon, 12 Jan 2015 19:37:41 +0000
treeherdermozilla-beta@150c9fed433b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersYoric, ttaubert
bugs506975
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 506975 - Add preferences to control sessionstore state while on battery. r=Yoric,ttaubert
browser/app/profile/firefox.js
browser/components/sessionstore/SessionSaver.jsm
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -1039,16 +1039,18 @@ pref("browser.rights.3.shown", false);
 pref("browser.rights.override", true);
 #endif
 
 pref("browser.sessionstore.resume_from_crash", true);
 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);
 // the same as browser.sessionstore.privacy_level, but for saving deferred session data
 pref("browser.sessionstore.privacy_level_deferred", 1);
 // how many tabs can be reopened (per window)
 pref("browser.sessionstore.max_tabs_undo", 10);
 // how many windows can be reopened (per session) - on non-OS X platforms this
--- a/browser/components/sessionstore/SessionSaver.jsm
+++ b/browser/components/sessionstore/SessionSaver.jsm
@@ -12,41 +12,42 @@ const Ci = Components.interfaces;
 
 Cu.import("resource://gre/modules/Timer.jsm", this);
 Cu.import("resource://gre/modules/Services.jsm", this);
 Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
 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",
   "resource:///modules/sessionstore/SessionStore.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "SessionFile",
   "resource:///modules/sessionstore/SessionFile.jsm");
 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) {
   Services.obs.notifyObservers(subject, topic, "");
 }
 
 // TelemetryStopwatch helper functions.
 function stopWatch(method) {
@@ -140,17 +141,18 @@ let SessionSaverInternal = {
    */
   runDelayed: function (delay = 2000) {
     // Bail out if there's a pending run.
     if (this._timeoutID) {
       return;
     }
 
     // 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);
   },
 
   /**
    * Sets the last save time to the current time. This will cause us to wait for
    * at least the configured interval when runDelayed() is called next.