mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 15:23:51 +00:00
Bug 1357517 - Remove Preferences.jsm usage from LaterRun.jsm. r=jaws
--HG-- extra : rebase_source : bd04a0e601fad4625be36fd4769d90e1214cf29c
This commit is contained in:
parent
215e8013ba
commit
18ff02cf4e
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user