Bug 1357517 - Remove Preferences.jsm usage from LaterRun.jsm. r=jaws
authorMarco Castelluccio <mcastelluccio@mozilla.com>
Fri, 28 Jul 2017 21:20:27 +0200
changeset 420584 302da7be5b9a7aff2e230a131dbe3e519b7859c0
parent 420583 731889ddbd52a3abde5ebcc766e09e9f536434e5
child 420585 19e6fdd4a271662f9fca5a0a6bf8b74dcabc1cd4
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1357517
milestone56.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 1357517 - Remove Preferences.jsm usage from LaterRun.jsm. r=jaws
browser/modules/LaterRun.jsm
--- a/browser/modules/LaterRun.jsm
+++ b/browser/modules/LaterRun.jsm
@@ -3,17 +3,16 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
 
 this.EXPORTED_SYMBOLS = ["LaterRun"];
 
-Cu.import("resource://gre/modules/Preferences.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 
 const kEnabledPref = "browser.laterrun.enabled";
 const kPagePrefRoot = "browser.laterrun.pages.";
 // Number of sessions we've been active in
 const kSessionCountPref = "browser.laterrun.bookkeeping.sessionCount";
 // Time the profile was created at:
 const kProfileCreationTime = "browser.laterrun.bookkeeping.profileCreationTime";
@@ -28,17 +27,17 @@ class Page {
     this.pref = pref;
     this.minimumHoursSinceInstall = minimumHoursSinceInstall || 0;
     this.minimumSessionCount = minimumSessionCount || 1;
     this.requireBoth = requireBoth || false;
     this.url = url;
   }
 
   get hasRun() {
-    return Preferences.get(this.pref + "hasRun", false);
+    return Services.prefs.getBoolPref(this.pref + "hasRun", false);
   }
 
   applies(sessionInfo) {
     if (this.hasRun) {
       return false;
     }
     if (this.requireBoth) {
       return sessionInfo.sessionCount >= this.minimumSessionCount &&
@@ -50,83 +49,83 @@ class Page {
 }
 
 let LaterRun = {
   init() {
     if (!this.enabled) {
       return;
     }
     // If this is the first run, set the time we were installed
-    if (!Preferences.has(kProfileCreationTime)) {
+    if (Services.prefs.getPrefType(kProfileCreationTime) == Ci.nsIPrefBranch.PREF_INVALID) {
       // We need to store seconds in order to fit within int prefs.
-      Preferences.set(kProfileCreationTime, Math.floor(Date.now() / 1000));
+      Services.prefs.setIntPref(kProfileCreationTime, Math.floor(Date.now() / 1000));
     }
     this.sessionCount++;
 
     if (this.hoursSinceInstall > kSelfDestructHoursLimit ||
         this.sessionCount > kSelfDestructSessionLimit) {
       this.selfDestruct();
     }
   },
 
   // The enabled, hoursSinceInstall and sessionCount properties mirror the
   // preferences system, and are here for convenience.
   get enabled() {
-    return Preferences.get(kEnabledPref, false);
+    return Services.prefs.getBoolPref(kEnabledPref, false);
   },
 
   set enabled(val) {
     let wasEnabled = this.enabled;
-    Preferences.set(kEnabledPref, val);
+    Services.prefs.setBoolPref(kEnabledPref, val);
     if (val && !wasEnabled) {
       this.init();
     }
   },
 
   get hoursSinceInstall() {
-    let installStamp = Preferences.get(kProfileCreationTime, Date.now() / 1000);
+    let installStamp = Services.prefs.getIntPref(kProfileCreationTime, Date.now() / 1000);
     return Math.floor((Date.now() / 1000 - installStamp) / 3600);
   },
 
   get sessionCount() {
     if (this._sessionCount) {
       return this._sessionCount;
     }
-    return this._sessionCount = Preferences.get(kSessionCountPref, 0);
+    return this._sessionCount = Services.prefs.getIntPref(kSessionCountPref, 0);
   },
 
   set sessionCount(val) {
     this._sessionCount = val;
-    Preferences.set(kSessionCountPref, val);
+    Services.prefs.setIntPref(kSessionCountPref, val);
   },
 
   // Because we don't want to keep incrementing this indefinitely for no reason,
   // we will turn ourselves off after a set amount of time/sessions (see top of
   // file).
   selfDestruct() {
-    Preferences.set(kEnabledPref, false);
+    Services.prefs.setBoolPref(kEnabledPref, false);
   },
 
   // Create an array of Page objects based on the currently set prefs
   readPages() {
     // Enumerate all the pages.
     let allPrefsForPages = Services.prefs.getChildList(kPagePrefRoot);
     let pageDataStore = new Map();
     for (let pref of allPrefsForPages) {
       let [slug, prop] = pref.substring(kPagePrefRoot.length).split(".");
       if (!pageDataStore.has(slug)) {
         pageDataStore.set(slug, {pref: pref.substring(0, pref.length - prop.length)});
       }
-      let defaultPrefValue = 0;
       if (prop == "requireBoth" || prop == "hasRun") {
-        defaultPrefValue = false;
+        pageDataStore.get(slug)[prop] = Services.prefs.getBoolPref(pref, false);
       } else if (prop == "url") {
-        defaultPrefValue = "";
+        pageDataStore.get(slug)[prop] = Services.prefs.getStringPref(pref, "");
+      } else {
+        pageDataStore.get(slug)[prop] = Services.prefs.getIntPref(pref, 0);
       }
-      pageDataStore.get(slug)[prop] = Preferences.get(pref, defaultPrefValue);
     }
     let rv = [];
     for (let [, pageData] of pageDataStore) {
       if (pageData.url) {
         let uri = null;
         try {
           let urlString = Services.urlFormatter.formatURL(pageData.url.trim());
           uri = Services.io.newURI(urlString);