зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1406475 - Convert engines-related sync modules to using Services.prefs. r=sync-reviewers,skhamis
Depends on D180809 Differential Revision: https://phabricator.services.mozilla.com/D180810
This commit is contained in:
Родитель
d744ff76dd
Коммит
0c52758410
|
@ -17,6 +17,7 @@ import {
|
|||
ENGINE_DOWNLOAD_FAIL,
|
||||
ENGINE_UPLOAD_FAIL,
|
||||
VERSION_OUT_OF_DATE,
|
||||
PREFS_BRANCH,
|
||||
} from "resource://services-sync/constants.sys.mjs";
|
||||
|
||||
import {
|
||||
|
@ -646,7 +647,10 @@ EngineManager.prototype = {
|
|||
},
|
||||
|
||||
persistDeclined() {
|
||||
Svc.Prefs.set("declinedEngines", [...this._declined].join(","));
|
||||
Svc.PrefBranch.setCharPref(
|
||||
"declinedEngines",
|
||||
[...this._declined].join(",")
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -872,7 +876,11 @@ SyncEngine.prototype = {
|
|||
async initialize() {
|
||||
await this._toFetchStorage.load();
|
||||
await this._previousFailedStorage.load();
|
||||
Svc.Prefs.observe(`engine.${this.prefName}`, this.asyncObserver);
|
||||
Services.prefs.addObserver(
|
||||
`${PREFS_BRANCH}engine.${this.prefName}`,
|
||||
this.asyncObserver,
|
||||
true
|
||||
);
|
||||
this._log.debug("SyncEngine initialized", this.name);
|
||||
},
|
||||
|
||||
|
@ -886,7 +894,7 @@ SyncEngine.prototype = {
|
|||
|
||||
set enabled(val) {
|
||||
if (!!val != this._enabled) {
|
||||
Svc.Prefs.set("engine." + this.prefName, !!val);
|
||||
Svc.PrefBranch.setBoolPref("engine." + this.prefName, !!val);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -995,8 +1003,8 @@ SyncEngine.prototype = {
|
|||
return existingSyncID;
|
||||
}
|
||||
this._log.debug("Engine syncIDs: " + [newSyncID, existingSyncID]);
|
||||
Svc.Prefs.set(this.name + ".syncID", newSyncID);
|
||||
Svc.Prefs.set(this.name + ".lastSync", "0");
|
||||
Svc.PrefBranch.setStringPref(this.name + ".syncID", newSyncID);
|
||||
Svc.PrefBranch.setCharPref(this.name + ".lastSync", "0");
|
||||
return newSyncID;
|
||||
},
|
||||
|
||||
|
@ -1041,7 +1049,7 @@ SyncEngine.prototype = {
|
|||
},
|
||||
async setLastSync(lastSync) {
|
||||
// Store the value as a string to keep floating point precision
|
||||
Svc.Prefs.set(this.name + ".lastSync", lastSync.toString());
|
||||
Svc.PrefBranch.setCharPref(this.name + ".lastSync", lastSync.toString());
|
||||
},
|
||||
async resetLastSync() {
|
||||
this._log.debug("Resetting " + this.name + " last sync time");
|
||||
|
@ -2173,7 +2181,10 @@ SyncEngine.prototype = {
|
|||
},
|
||||
|
||||
async finalize() {
|
||||
Svc.Prefs.ignore(`engine.${this.prefName}`, this.asyncObserver);
|
||||
Services.prefs.removeObserver(
|
||||
`${PREFS_BRANCH}engine.${this.prefName}`,
|
||||
this.asyncObserver
|
||||
);
|
||||
await this.asyncObserver.promiseObserversComplete();
|
||||
await this._tracker.finalize();
|
||||
await this._toFetchStorage.finalize();
|
||||
|
|
|
@ -35,8 +35,6 @@
|
|||
* See the documentation in all.js for the behavior of these prefs.
|
||||
*/
|
||||
|
||||
import { Preferences } from "resource://gre/modules/Preferences.sys.mjs";
|
||||
|
||||
import { AddonUtils } from "resource://services-sync/addonutils.sys.mjs";
|
||||
import { AddonsReconciler } from "resource://services-sync/addonsreconciler.sys.mjs";
|
||||
import {
|
||||
|
@ -264,7 +262,7 @@ AddonsStore.prototype = {
|
|||
// Define the add-on types (.type) that we support.
|
||||
_syncableTypes: ["extension", "theme"],
|
||||
|
||||
_extensionsPrefs: new Preferences("extensions."),
|
||||
_extensionsPrefs: Services.prefs.getBranch("extensions."),
|
||||
|
||||
get reconciler() {
|
||||
return this.engine._reconciler;
|
||||
|
@ -333,7 +331,7 @@ AddonsStore.prototype = {
|
|||
id: record.addonID,
|
||||
syncGUID: record.id,
|
||||
enabled: record.enabled,
|
||||
requireSecureURI: this._extensionsPrefs.get(
|
||||
requireSecureURI: this._extensionsPrefs.getBoolPref(
|
||||
"install.requireSecureOrigin",
|
||||
true
|
||||
),
|
||||
|
@ -649,7 +647,7 @@ AddonsStore.prototype = {
|
|||
// For security reasons, we currently limit synced add-ons to those
|
||||
// installed from trusted hostname(s). We additionally require TLS with
|
||||
// the add-ons site to help prevent forgeries.
|
||||
let trustedHostnames = Svc.Prefs.get(
|
||||
let trustedHostnames = Svc.PrefBranch.getStringPref(
|
||||
"addons.trustedSourceHostnames",
|
||||
""
|
||||
).split(",");
|
||||
|
@ -693,7 +691,7 @@ AddonsStore.prototype = {
|
|||
}
|
||||
|
||||
// A pref allows changes to the enabled flag to be ignored.
|
||||
if (Svc.Prefs.get("addons.ignoreUserEnabledChanges", false)) {
|
||||
if (Svc.PrefBranch.getBoolPref("addons.ignoreUserEnabledChanges", false)) {
|
||||
this._log.info(
|
||||
"Ignoring enabled state change due to preference: " + addon.id
|
||||
);
|
||||
|
|
|
@ -148,10 +148,13 @@ ClientEngine.prototype = {
|
|||
},
|
||||
|
||||
get lastRecordUpload() {
|
||||
return Svc.Prefs.get(this.name + ".lastRecordUpload", 0);
|
||||
return Svc.PrefBranch.getIntPref(this.name + ".lastRecordUpload", 0);
|
||||
},
|
||||
set lastRecordUpload(value) {
|
||||
Svc.Prefs.set(this.name + ".lastRecordUpload", Math.floor(value));
|
||||
Svc.PrefBranch.setIntPref(
|
||||
this.name + ".lastRecordUpload",
|
||||
Math.floor(value)
|
||||
);
|
||||
},
|
||||
|
||||
get remoteClients() {
|
||||
|
@ -672,7 +675,7 @@ ClientEngine.prototype = {
|
|||
this._lastDeviceCounts == null ||
|
||||
this._lastDeviceCounts.get(prefName) != count
|
||||
) {
|
||||
Svc.Prefs.set(prefName, count);
|
||||
Svc.PrefBranch.setIntPref(prefName, count);
|
||||
}
|
||||
}
|
||||
this._lastDeviceCounts = deviceTypeCounts;
|
||||
|
|
|
@ -42,11 +42,13 @@ function getEngineEnabled() {
|
|||
// However, we also respect engine.extension-storage.force, which
|
||||
// can be set to true or false, if a power user wants to customize
|
||||
// the behavior despite the lack of UI.
|
||||
const forced = lazy.Svc.Prefs.get(PREF_FORCE_ENABLE, undefined);
|
||||
if (forced !== undefined) {
|
||||
return forced;
|
||||
if (
|
||||
lazy.Svc.PrefBranch.getPrefType(PREF_FORCE_ENABLE) !=
|
||||
Ci.nsIPrefBranch.PREF_INVALID
|
||||
) {
|
||||
return lazy.Svc.PrefBranch.getBoolPref(PREF_FORCE_ENABLE);
|
||||
}
|
||||
return lazy.Svc.Prefs.get("engine.addons", false);
|
||||
return lazy.Svc.PrefBranch.getBoolPref("engine.addons", false);
|
||||
}
|
||||
|
||||
function setEngineEnabled(enabled) {
|
||||
|
@ -57,8 +59,11 @@ function setEngineEnabled(enabled) {
|
|||
// preference. So if that pref exists, we set it to this value. If that pref
|
||||
// doesn't exist, we just ignore it and hope that the 'addons' engine is also
|
||||
// going to be set to the same state.
|
||||
if (lazy.Svc.Prefs.has(PREF_FORCE_ENABLE)) {
|
||||
lazy.Svc.Prefs.set(PREF_FORCE_ENABLE, enabled);
|
||||
if (
|
||||
lazy.Svc.PrefBranch.getPrefType(PREF_FORCE_ENABLE) !=
|
||||
Ci.nsIPrefBranch.PREF_INVALID
|
||||
) {
|
||||
lazy.Svc.PrefBranch.setBoolPref(PREF_FORCE_ENABLE, enabled);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ PasswordEngine.prototype = {
|
|||
let legacyValue = await super.getLastSync();
|
||||
if (legacyValue) {
|
||||
await this.setLastSync(legacyValue);
|
||||
Svc.Prefs.reset(this.name + ".lastSync");
|
||||
Svc.PrefBranch.clearUserPref(this.name + ".lastSync");
|
||||
this._log.debug(
|
||||
`migrated timestamp of ${legacyValue} to the logins store`
|
||||
);
|
||||
|
|
|
@ -26,7 +26,6 @@ const PREF_SYNC_PREFS_PREFIX = "services.sync.prefs.sync.";
|
|||
const PREF_SYNC_SEEN_PREFIX = "services.sync.prefs.sync-seen.";
|
||||
|
||||
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
|
||||
import { Preferences } from "resource://gre/modules/Preferences.sys.mjs";
|
||||
|
||||
import {
|
||||
Store,
|
||||
|
@ -175,7 +174,7 @@ PrefStore.prototype = {
|
|||
__prefs: null,
|
||||
get _prefs() {
|
||||
if (!this.__prefs) {
|
||||
this.__prefs = new Preferences();
|
||||
this.__prefs = Services.prefs.getBranch("");
|
||||
}
|
||||
return this.__prefs;
|
||||
},
|
||||
|
@ -200,7 +199,7 @@ PrefStore.prototype = {
|
|||
|
||||
// This is the pref itself - it must be both allowed, and have a control
|
||||
// pref which is true.
|
||||
if (!this._prefs.get(PREF_SYNC_PREFS_PREFIX + pref, false)) {
|
||||
if (!this._prefs.getBoolPref(PREF_SYNC_PREFS_PREFIX + pref, false)) {
|
||||
return false;
|
||||
}
|
||||
return isAllowedPrefName(pref);
|
||||
|
@ -213,19 +212,39 @@ PrefStore.prototype = {
|
|||
// us not to apply (syncable) changes to preferences that are set locally
|
||||
// which have unsyncable urls.
|
||||
if (this._isSynced(pref) && !isUnsyncableURLPref(pref)) {
|
||||
let isSet = this._prefs.isSet(pref);
|
||||
let isSet = this._prefs.prefHasUserValue(pref);
|
||||
// Missing and default prefs get the null value, unless that `seen`
|
||||
// pref is set, in which case it always gets the value.
|
||||
let forceValue = this._prefs.get(PREF_SYNC_SEEN_PREFIX + pref, false);
|
||||
values[pref] = isSet || forceValue ? this._prefs.get(pref, null) : null;
|
||||
let forceValue = this._prefs.getBoolPref(
|
||||
PREF_SYNC_SEEN_PREFIX + pref,
|
||||
false
|
||||
);
|
||||
if (isSet || forceValue) {
|
||||
switch (this._prefs.getPrefType(pref)) {
|
||||
case Ci.nsIPrefBranch.PREF_STRING:
|
||||
values[pref] = this._prefs.getStringPref(pref);
|
||||
break;
|
||||
case Ci.nsIPrefBranch.PREF_INT:
|
||||
values[pref] = this._prefs.getIntPref(pref);
|
||||
break;
|
||||
case Ci.nsIPrefBranch.PREF_BOOL:
|
||||
values[pref] = this._prefs.getBoolPref(pref);
|
||||
break;
|
||||
case Ci.nsIPrefBranch.PREF_INVALID:
|
||||
values[pref] = null;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
values[pref] = null;
|
||||
}
|
||||
// If this is a special "sync-seen" pref, and it's not the default value,
|
||||
// set the seen pref to true.
|
||||
if (
|
||||
isSet &&
|
||||
this._prefs.get(PREF_SYNC_SEEN_PREFIX + pref, false) === false
|
||||
this._prefs.getBoolPref(PREF_SYNC_SEEN_PREFIX + pref, false) === false
|
||||
) {
|
||||
this._log.trace(`toggling sync-seen pref for '${pref}' to true`);
|
||||
this._prefs.set(PREF_SYNC_SEEN_PREFIX + pref, true);
|
||||
this._prefs.setBoolPref(PREF_SYNC_SEEN_PREFIX + pref, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -234,7 +253,10 @@ PrefStore.prototype = {
|
|||
|
||||
_setAllPrefs(values) {
|
||||
const selectedThemeIDPref = "extensions.activeThemeID";
|
||||
let selectedThemeIDBefore = this._prefs.get(selectedThemeIDPref, null);
|
||||
let selectedThemeIDBefore = this._prefs.getCharPref(
|
||||
selectedThemeIDPref,
|
||||
null
|
||||
);
|
||||
let selectedThemeIDAfter = selectedThemeIDBefore;
|
||||
|
||||
// Update 'services.sync.prefs.sync.foo.pref' before 'foo.pref', otherwise
|
||||
|
@ -260,7 +282,7 @@ PrefStore.prototype = {
|
|||
let controlPref = PREF_SYNC_PREFS_PREFIX + pref;
|
||||
let controlPrefExists;
|
||||
try {
|
||||
Services.prefs.getBoolPref(controlPref);
|
||||
this._prefs.getBoolPref(controlPref);
|
||||
controlPrefExists = true;
|
||||
} catch (ex) {
|
||||
controlPrefExists = false;
|
||||
|
@ -297,10 +319,20 @@ PrefStore.prototype = {
|
|||
default:
|
||||
if (value == null) {
|
||||
// Pref has gone missing. The best we can do is reset it.
|
||||
this._prefs.reset(pref);
|
||||
this._prefs.clearUserPref(pref);
|
||||
} else {
|
||||
try {
|
||||
this._prefs.set(pref, value);
|
||||
switch (typeof value) {
|
||||
case "string":
|
||||
this._prefs.setStringPref(pref, value);
|
||||
break;
|
||||
case "number":
|
||||
this._prefs.setIntPref(pref, value);
|
||||
break;
|
||||
case "boolean":
|
||||
this._prefs.setBoolPref(pref, value);
|
||||
break;
|
||||
}
|
||||
} catch (ex) {
|
||||
this._log.trace(`Failed to set pref: ${pref}`, ex);
|
||||
}
|
||||
|
@ -308,8 +340,10 @@ PrefStore.prototype = {
|
|||
// If there's a "sync-seen" pref for this it gets toggled to true
|
||||
// regardless of the value.
|
||||
let seenPref = PREF_SYNC_SEEN_PREFIX + pref;
|
||||
if (this._prefs.get(seenPref, undefined) === false) {
|
||||
this._prefs.set(PREF_SYNC_SEEN_PREFIX + pref, true);
|
||||
if (
|
||||
this._prefs.getPrefType(seenPref) != Ci.nsIPrefBranch.PREF_INVALID
|
||||
) {
|
||||
this._prefs.setBoolPref(PREF_SYNC_SEEN_PREFIX + pref, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -410,10 +444,10 @@ PrefTracker.prototype = {
|
|||
},
|
||||
|
||||
get modified() {
|
||||
return Svc.Prefs.get("engine.prefs.modified", false);
|
||||
return Svc.PrefBranch.getBoolPref("engine.prefs.modified", false);
|
||||
},
|
||||
set modified(value) {
|
||||
Svc.Prefs.set("engine.prefs.modified", value);
|
||||
Svc.PrefBranch.setBoolPref("engine.prefs.modified", value);
|
||||
},
|
||||
|
||||
clearChangedIDs: function clearChangedIDs() {
|
||||
|
@ -423,7 +457,7 @@ PrefTracker.prototype = {
|
|||
__prefs: null,
|
||||
get _prefs() {
|
||||
if (!this.__prefs) {
|
||||
this.__prefs = new Preferences();
|
||||
this.__prefs = Services.prefs.getBranch("");
|
||||
}
|
||||
return this.__prefs;
|
||||
},
|
||||
|
@ -450,7 +484,7 @@ PrefTracker.prototype = {
|
|||
// which prefs are synced or a regular pref change.
|
||||
if (
|
||||
data.indexOf(PREF_SYNC_PREFS_PREFIX) == 0 ||
|
||||
this._prefs.get(PREF_SYNC_PREFS_PREFIX + data, false)
|
||||
this._prefs.getBoolPref(PREF_SYNC_PREFS_PREFIX + data, false)
|
||||
) {
|
||||
this.score += SCORE_INCREMENT_XLARGE;
|
||||
this.modified = true;
|
||||
|
|
|
@ -73,11 +73,11 @@ EngineSynchronizer.prototype = {
|
|||
// Ping the server with a special info request once a day.
|
||||
let infoURL = this.service.infoURL;
|
||||
let now = Math.floor(Date.now() / 1000);
|
||||
let lastPing = Svc.Prefs.get("lastPing", 0);
|
||||
let lastPing = Svc.PrefBranch.getIntPref("lastPing", 0);
|
||||
if (now - lastPing > 86400) {
|
||||
// 60 * 60 * 24
|
||||
infoURL += "?v=" + WEAVE_VERSION;
|
||||
Svc.Prefs.set("lastPing", now);
|
||||
Svc.PrefBranch.setIntPref("lastPing", now);
|
||||
}
|
||||
|
||||
let engineManager = this.service.engineManager;
|
||||
|
@ -111,7 +111,7 @@ EngineSynchronizer.prototype = {
|
|||
// a first sync.
|
||||
let allowEnginesHint = false;
|
||||
// Wipe data in the desired direction if necessary
|
||||
switch (Svc.Prefs.get("firstSync")) {
|
||||
switch (Svc.PrefBranch.getCharPref("firstSync", null)) {
|
||||
case "resetClient":
|
||||
await this.service.resetClient(engineManager.enabledEngineNames);
|
||||
break;
|
||||
|
@ -227,10 +227,10 @@ EngineSynchronizer.prototype = {
|
|||
this.service.status.service == SYNC_FAILED_PARTIAL ||
|
||||
this.service.status.service == STATUS_OK
|
||||
) {
|
||||
Svc.Prefs.set("lastSync", new Date().toString());
|
||||
Svc.PrefBranch.setCharPref("lastSync", new Date().toString());
|
||||
}
|
||||
} finally {
|
||||
Svc.Prefs.reset("firstSync");
|
||||
Svc.PrefBranch.clearUserPref("firstSync");
|
||||
|
||||
let syncTime = ((Date.now() - startTime) / 1000).toFixed(2);
|
||||
let dateStr = Utils.formatTimestamp(new Date());
|
||||
|
@ -326,7 +326,12 @@ EngineSynchronizer.prototype = {
|
|||
|
||||
let attemptedEnable = false;
|
||||
// If the engine was enabled remotely, enable it locally.
|
||||
if (!Svc.Prefs.get("engineStatusChanged." + engine.prefName, false)) {
|
||||
if (
|
||||
!Svc.PrefBranch.getBoolPref(
|
||||
"engineStatusChanged." + engine.prefName,
|
||||
false
|
||||
)
|
||||
) {
|
||||
this._log.trace(
|
||||
"Engine " + engineName + " was enabled. Marking as non-declined."
|
||||
);
|
||||
|
@ -367,7 +372,12 @@ EngineSynchronizer.prototype = {
|
|||
// Any remaining engines were either enabled locally or disabled remotely.
|
||||
for (let engineName of enabled) {
|
||||
let engine = engineManager.get(engineName);
|
||||
if (Svc.Prefs.get("engineStatusChanged." + engine.prefName, false)) {
|
||||
if (
|
||||
Svc.PrefBranch.getBoolPref(
|
||||
"engineStatusChanged." + engine.prefName,
|
||||
false
|
||||
)
|
||||
) {
|
||||
this._log.trace("The " + engineName + " engine was enabled locally.");
|
||||
toUndecline.add(engineName);
|
||||
} else {
|
||||
|
@ -385,7 +395,9 @@ EngineSynchronizer.prototype = {
|
|||
engineManager.decline(toDecline);
|
||||
engineManager.undecline(toUndecline);
|
||||
|
||||
Svc.Prefs.resetBranch("engineStatusChanged.");
|
||||
for (const pref of Svc.PrefBranch.getChildList("engineStatusChanged.")) {
|
||||
Svc.PrefBranch.clearUserPref(pref);
|
||||
}
|
||||
this.service._ignorePrefObserver = false;
|
||||
},
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче