Bug 1772313 - Part 9: Stop calling XPCOMUtils.defineLazyModuleGetters for Services in services/. r=kmag

Differential Revision: https://phabricator.services.mozilla.com/D148162
This commit is contained in:
Tooru Fujisawa 2022-06-06 02:49:11 +00:00
parent eaf1dda701
commit 0605038c2b
6 changed files with 37 additions and 49 deletions

View File

@ -28,11 +28,11 @@ var EXPORTED_SYMBOLS = ["Sync", "Authentication", "initConfig", "triggerSync"];
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const lazy = {};
XPCOMUtils.defineLazyModuleGetters(lazy, {
Services: "resource://gre/modules/Services.jsm",
Log: "resource://gre/modules/Log.jsm",
Weave: "resource://services-sync/main.js",
Svc: "resource://services-sync/util.js",
@ -146,7 +146,7 @@ var Authentication = {
async _confirmUser(uri) {
LOG("Open new tab and load verification page");
let mainWindow = lazy.Services.wm.getMostRecentWindow("navigator:browser");
let mainWindow = Services.wm.getMostRecentWindow("navigator:browser");
let newtab = mainWindow.gBrowser.addWebTab(uri);
let win = mainWindow.gBrowser.getBrowserForTab(newtab);
win.addEventListener("load", function(e) {
@ -414,7 +414,7 @@ var Sync = {
};
function initConfig(autoconfig) {
lazy.Services.prefs.setCharPref(AUTOCONFIG_PREF, autoconfig);
Services.prefs.setCharPref(AUTOCONFIG_PREF, autoconfig);
}
async function triggerSync(username, password, autoconfig) {

View File

@ -12,6 +12,7 @@
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const lazy = {};
@ -19,7 +20,6 @@ XPCOMUtils.defineLazyModuleGetters(lazy, {
// We use this observers module because we leverage its support for richer
// "subject" data.
Observers: "resource://services-common/observers.js",
Services: "resource://gre/modules/Services.jsm",
CryptoUtils: "resource://services-crypto/utils.js",
});
@ -38,7 +38,7 @@ XPCOMUtils.defineLazyPreferenceGetter(
class FxAccountsTelemetry {
constructor(fxai) {
this._fxai = fxai;
lazy.Services.telemetry.setEventRecordingEnabled("fxa", true);
Services.telemetry.setEventRecordingEnabled("fxa", true);
}
// Records an event *in the Fxa/Sync ping*.
@ -55,7 +55,7 @@ class FxAccountsTelemetry {
}
generateUUID() {
return lazy.Services.uuid
return Services.uuid
.generateUUID()
.toString()
.slice(1, -1);
@ -75,9 +75,9 @@ class FxAccountsTelemetry {
// so there's some light hackery to put it in the right place.
_setHashedUID(hashedUID) {
if (!hashedUID) {
lazy.Services.prefs.clearUserPref(PREF_SANITIZED_UID);
Services.prefs.clearUserPref(PREF_SANITIZED_UID);
} else {
lazy.Services.prefs.setStringPref(PREF_SANITIZED_UID, hashedUID);
Services.prefs.setStringPref(PREF_SANITIZED_UID, hashedUID);
}
}
@ -126,13 +126,7 @@ class FxAccountsTelemetry {
if (services.includes("sync")) {
extra.sync = "true";
}
lazy.Services.telemetry.recordEvent(
"fxa",
"connect",
"account",
how,
extra
);
Services.telemetry.recordEvent("fxa", "connect", "account", how, extra);
} catch (ex) {
log.error("Failed to record connection telemetry", ex);
console.error("Failed to record connection telemetry", ex);
@ -159,7 +153,7 @@ class FxAccountsTelemetry {
extra.fxa = "true";
// We need a way to enumerate all services - but for now we just hard-code
// all possibilities here.
if (lazy.Services.prefs.prefHasUserValue("services.sync.username")) {
if (Services.prefs.prefHasUserValue("services.sync.username")) {
extra.sync = "true";
}
} else if (service == "sync") {
@ -170,7 +164,7 @@ class FxAccountsTelemetry {
`recordDisconnection has invalid value for service: ${service}`
);
}
lazy.Services.telemetry.recordEvent(
Services.telemetry.recordEvent(
"fxa",
"disconnect",
"account",

View File

@ -8,11 +8,11 @@
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const lazy = {};
XPCOMUtils.defineLazyModuleGetters(lazy, {
Services: "resource://gre/modules/Services.jsm",
Log: "resource://gre/modules/Log.jsm",
Sanitizer: "resource:///modules/Sanitizer.jsm",
AsyncShutdown: "resource://gre/modules/AsyncShutdown.jsm",
@ -109,9 +109,7 @@ const SyncDisconnectInternal = {
// Reset the pref which is used to show a warning when a different user
// signs in - this is no longer a concern now that we've removed the
// data from the profile.
lazy.Services.prefs.clearUserPref(
lazy.FxAccountsCommon.PREF_LAST_FXA_USER
);
Services.prefs.clearUserPref(lazy.FxAccountsCommon.PREF_LAST_FXA_USER);
log.info("Finished wiping sync data");
} catch (ex) {

View File

@ -22,6 +22,7 @@ var EXPORTED_SYMBOLS = [
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const lazy = {};
@ -34,7 +35,6 @@ XPCOMUtils.defineLazyModuleGetters(lazy, {
Observers: "resource://services-common/observers.js",
OS: "resource://gre/modules/osfile.jsm",
Resource: "resource://services-sync/resource.js",
Services: "resource://gre/modules/Services.jsm",
Status: "resource://services-sync/status.js",
Svc: "resource://services-sync/util.js",
TelemetryController: "resource://gre/modules/TelemetryController.jsm",
@ -109,7 +109,7 @@ const ENGINES = new Set([
function tryGetMonotonicTimestamp() {
try {
return lazy.Services.telemetry.msSinceProcessStart();
return Services.telemetry.msSinceProcessStart();
} catch (e) {
log.warn("Unable to get a monotonic timestamp!");
return -1;
@ -641,7 +641,7 @@ class SyncTelemetryImpl {
this.maxPayloadCount = lazy.Svc.Prefs.get("telemetry.maxPayloadCount");
this.submissionInterval =
lazy.Svc.Prefs.get("telemetry.submissionInterval") * 1000;
this.lastSubmissionTime = lazy.Services.telemetry.msSinceProcessStart();
this.lastSubmissionTime = Services.telemetry.msSinceProcessStart();
this.lastUID = EMPTY_UID;
this.lastSyncNodeType = null;
this.currentSyncNodeType = null;
@ -815,7 +815,7 @@ class SyncTelemetryImpl {
// pref set, they *are* running a production fxa, just not production sync.
if (
!lazy.FxAccounts.config.isProductionConfig() ||
lazy.Services.prefs.prefHasUserValue("services.sync.tokenServerURI")
Services.prefs.prefHasUserValue("services.sync.tokenServerURI")
) {
log.trace(`Not sending telemetry ping for self-hosted Sync user`);
return false;
@ -861,7 +861,7 @@ class SyncTelemetryImpl {
// The first 32 chars are sufficient to uniquely identify the device, so just send those.
// It's hard to change the sync ping itself to only send 32 chars, to b/w compat reasons.
sanitizedDeviceId = sanitizedDeviceId.substr(0, 32);
lazy.Services.telemetry.scalarSet(
Services.telemetry.scalarSet(
"deletion.request.sync_device_id",
sanitizedDeviceId
);
@ -877,7 +877,7 @@ class SyncTelemetryImpl {
// This keeps the `deletion-request` ping up-to-date when the user signs out,
// clearing the now-nonexistent sync device id.
onAccountLogout() {
lazy.Services.telemetry.scalarSet("deletion.request.sync_device_id", "");
Services.telemetry.scalarSet("deletion.request.sync_device_id", "");
}
_checkCurrent(topic) {
@ -927,7 +927,7 @@ class SyncTelemetryImpl {
"Early submission of sync telemetry due to changed IDs/NodeType"
);
this.finish("idchange"); // this actually submits.
this.lastSubmissionTime = lazy.Services.telemetry.msSinceProcessStart();
this.lastSubmissionTime = Services.telemetry.msSinceProcessStart();
}
// Only update the last UIDs if we actually know them.
@ -946,11 +946,11 @@ class SyncTelemetryImpl {
// the sync and the events caused by it in different pings.
if (
this.current == null &&
lazy.Services.telemetry.msSinceProcessStart() - this.lastSubmissionTime >
Services.telemetry.msSinceProcessStart() - this.lastSubmissionTime >
this.submissionInterval
) {
this.finish("schedule");
this.lastSubmissionTime = lazy.Services.telemetry.msSinceProcessStart();
this.lastSubmissionTime = Services.telemetry.msSinceProcessStart();
}
}
@ -977,7 +977,7 @@ class SyncTelemetryImpl {
}
_addHistogram(hist) {
let histogram = lazy.Services.telemetry.getHistogramById(hist);
let histogram = Services.telemetry.getHistogramById(hist);
let s = histogram.snapshot();
this.histograms[hist] = s;
}

View File

@ -12,12 +12,12 @@ var EXPORTED_SYMBOLS = ["Logger"];
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const lazy = {};
XPCOMUtils.defineLazyModuleGetters(lazy, {
ObjectUtils: "resource://gre/modules/ObjectUtils.jsm",
Services: "resource://gre/modules/Services.jsm",
});
var Logger = {
@ -32,9 +32,9 @@ var Logger = {
}
if (path) {
lazy.Services.prefs.setCharPref("tps.logfile", path);
Services.prefs.setCharPref("tps.logfile", path);
} else {
path = lazy.Services.prefs.getCharPref("tps.logfile");
path = Services.prefs.getCharPref("tps.logfile");
}
this._file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);

View File

@ -26,6 +26,7 @@ var EXPORTED_SYMBOLS = [
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const lazy = {};
@ -44,7 +45,6 @@ XPCOMUtils.defineLazyModuleGetters(lazy, {
OS: "resource://gre/modules/osfile.jsm",
PlacesUtils: "resource://gre/modules/PlacesUtils.jsm",
PromiseUtils: "resource://gre/modules/PromiseUtils.jsm",
Services: "resource://gre/modules/Services.jsm",
SessionStore: "resource:///modules/sessionstore/SessionStore.jsm",
Svc: "resource://services-sync/util.js",
SyncTelemetry: "resource://services-sync/telemetry.js",
@ -80,7 +80,7 @@ XPCOMUtils.defineLazyModuleGetters(lazy, {
});
XPCOMUtils.defineLazyGetter(lazy, "fileProtocolHandler", () => {
let fileHandler = lazy.Services.io.getProtocolHandler("file");
let fileHandler = Services.io.getProtocolHandler("file");
return fileHandler.QueryInterface(Ci.nsIFileProtocolHandler);
});
@ -170,14 +170,14 @@ var TPS = {
this.delayAutoSync();
OBSERVER_TOPICS.forEach(function(aTopic) {
lazy.Services.obs.addObserver(this, aTopic, true);
Services.obs.addObserver(this, aTopic, true);
}, this);
// Some engines bump their score during their sync, which then causes
// another sync immediately (notably, prefs and addons). We don't want
// this to happen, and there's no obvious preference to kill it - so
// we do this nasty hack to ensure the global score is always zero.
lazy.Services.prefs.addObserver("services.sync.globalScore", () => {
Services.prefs.addObserver("services.sync.globalScore", () => {
if (lazy.Weave.Service.scheduler.globalScore != 0) {
lazy.Weave.Service.scheduler.globalScore = 0;
}
@ -209,7 +209,7 @@ var TPS = {
switch (topic) {
case "profile-before-change":
OBSERVER_TOPICS.forEach(function(topic) {
lazy.Services.obs.removeObserver(this, topic);
Services.obs.removeObserver(this, topic);
}, this);
lazy.Logger.close();
@ -964,7 +964,7 @@ var TPS = {
this.quit();
return;
}
this.seconds_since_epoch = lazy.Services.prefs.getIntPref(
this.seconds_since_epoch = Services.prefs.getIntPref(
"tps.seconds_since_epoch"
);
if (this.seconds_since_epoch) {
@ -1028,9 +1028,7 @@ var TPS = {
// based on the source of the tps file. Assumes that it's at "../unit/sync_ping_schema.json"
// relative to the directory the tps test file (testFile) is contained in.
_tryLoadPingSchema(testFile) {
if (
lazy.Services.prefs.getBoolPref("testing.tps.skipPingValidation", false)
) {
if (Services.prefs.getBoolPref("testing.tps.skipPingValidation", false)) {
return;
}
try {
@ -1094,10 +1092,8 @@ var TPS = {
lazy.Logger.init(logpath);
lazy.Logger.logInfo("Sync version: " + lazy.WEAVE_VERSION);
lazy.Logger.logInfo(
"Firefox buildid: " + lazy.Services.appinfo.appBuildID
);
lazy.Logger.logInfo("Firefox version: " + lazy.Services.appinfo.version);
lazy.Logger.logInfo("Firefox buildid: " + Services.appinfo.appBuildID);
lazy.Logger.logInfo("Firefox version: " + Services.appinfo.version);
lazy.Logger.logInfo(
"Firefox source revision: " +
(lazy.AppConstants.SOURCE_REVISION_URL || "unknown")
@ -1137,9 +1133,9 @@ var TPS = {
*/
async _executeTestPhase(file, phase, settings) {
try {
this.config = JSON.parse(lazy.Services.prefs.getCharPref("tps.config"));
this.config = JSON.parse(Services.prefs.getCharPref("tps.config"));
// parse the test file
lazy.Services.scriptloader.loadSubScript(file, this);
Services.scriptloader.loadSubScript(file, this);
this._currentPhase = phase;
// cleanup phases are in the format `cleanup-${profileName}`.
if (this._currentPhase.startsWith("cleanup-")) {