From 18ff02cf4eca23e4e073e38873e8c720366af112 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Fri, 28 Jul 2017 21:20:27 +0200 Subject: [PATCH] Bug 1357517 - Remove Preferences.jsm usage from LaterRun.jsm. r=jaws --HG-- extra : rebase_source : bd04a0e601fad4625be36fd4769d90e1214cf29c --- browser/modules/LaterRun.jsm | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/browser/modules/LaterRun.jsm b/browser/modules/LaterRun.jsm index b31bb8e2ead8..59893ac35218 100644 --- a/browser/modules/LaterRun.jsm +++ b/browser/modules/LaterRun.jsm @@ -8,7 +8,6 @@ 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"; @@ -33,7 +32,7 @@ class Page { } get hasRun() { - return Preferences.get(this.pref + "hasRun", false); + return Services.prefs.getBoolPref(this.pref + "hasRun", false); } applies(sessionInfo) { @@ -55,9 +54,9 @@ let LaterRun = { 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++; @@ -70,19 +69,19 @@ let LaterRun = { // 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); }, @@ -90,19 +89,19 @@ let LaterRun = { 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 @@ -115,13 +114,13 @@ let LaterRun = { 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) {