зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1772097 - Part 6: Use plain object for lazy getter in services/sync/. r=markh
Differential Revision: https://phabricator.services.mozilla.com/D147921
This commit is contained in:
Родитель
4f3eafb63e
Коммит
adfef21e07
|
@ -6,14 +6,15 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
"resource://gre/modules/XPCOMUtils.jsm"
|
||||
);
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const lazy = {};
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"FileUtils",
|
||||
"resource://gre/modules/FileUtils.jsm"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"syncUsername",
|
||||
"services.sync.username"
|
||||
);
|
||||
|
@ -140,7 +141,7 @@ WeaveService.prototype = {
|
|||
*/
|
||||
get enabled() {
|
||||
return (
|
||||
!!syncUsername &&
|
||||
!!lazy.syncUsername &&
|
||||
Services.prefs.getBoolPref("identity.fxaccounts.enabled")
|
||||
);
|
||||
},
|
||||
|
@ -160,7 +161,7 @@ AboutWeaveLog.prototype = {
|
|||
},
|
||||
|
||||
newChannel(aURI, aLoadInfo) {
|
||||
let dir = FileUtils.getDir("ProfD", ["weave", "logs"], true);
|
||||
let dir = lazy.FileUtils.getDir("ProfD", ["weave", "logs"], true);
|
||||
let uri = Services.io.newFileURI(dir);
|
||||
let channel = Services.io.newChannelFromURIWithLoadInfo(uri, aLoadInfo);
|
||||
|
||||
|
|
|
@ -9,7 +9,9 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
"resource://gre/modules/XPCOMUtils.jsm"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
Services: "resource://gre/modules/Services.jsm",
|
||||
Log: "resource://gre/modules/Log.jsm",
|
||||
Sanitizer: "resource:///modules/Sanitizer.jsm",
|
||||
|
@ -18,13 +20,13 @@ XPCOMUtils.defineLazyModuleGetters(this, {
|
|||
Utils: "resource://services-sync/util.js",
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "fxAccounts", () => {
|
||||
XPCOMUtils.defineLazyGetter(lazy, "fxAccounts", () => {
|
||||
return ChromeUtils.import(
|
||||
"resource://gre/modules/FxAccounts.jsm"
|
||||
).getFxAccountsSingleton();
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "FxAccountsCommon", function() {
|
||||
XPCOMUtils.defineLazyGetter(lazy, "FxAccountsCommon", function() {
|
||||
return ChromeUtils.import("resource://gre/modules/FxAccountsCommon.js");
|
||||
});
|
||||
|
||||
|
@ -48,7 +50,7 @@ const SyncDisconnectInternal = {
|
|||
// but note that Sync probably remains locked in this case regardless.)
|
||||
async promiseNotSyncing(abortController) {
|
||||
let weave = this.getWeave();
|
||||
let log = Log.repository.getLogger("Sync.Service");
|
||||
let log = lazy.Log.repository.getLogger("Sync.Service");
|
||||
// We might be syncing - poll for up to 2 minutes waiting for the lock.
|
||||
// (2 minutes seems extreme, but should be very rare.)
|
||||
return new Promise(resolve => {
|
||||
|
@ -75,7 +77,7 @@ const SyncDisconnectInternal = {
|
|||
return;
|
||||
}
|
||||
log.debug("Waiting a couple of seconds to get the sync lock");
|
||||
setTimeout(checkLock, this.lockRetryInterval);
|
||||
lazy.setTimeout(checkLock, this.lockRetryInterval);
|
||||
};
|
||||
checkLock();
|
||||
});
|
||||
|
@ -86,7 +88,7 @@ const SyncDisconnectInternal = {
|
|||
let weave = this.getWeave();
|
||||
// Get the sync logger - if stuff goes wrong it can be useful to have that
|
||||
// recorded in the sync logs.
|
||||
let log = Log.repository.getLogger("Sync.Service");
|
||||
let log = lazy.Log.repository.getLogger("Sync.Service");
|
||||
log.info("Starting santitize of Sync data");
|
||||
try {
|
||||
// We clobber data for all Sync engines that are enabled.
|
||||
|
@ -107,7 +109,9 @@ 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.
|
||||
Services.prefs.clearUserPref(FxAccountsCommon.PREF_LAST_FXA_USER);
|
||||
lazy.Services.prefs.clearUserPref(
|
||||
lazy.FxAccountsCommon.PREF_LAST_FXA_USER
|
||||
);
|
||||
|
||||
log.info("Finished wiping sync data");
|
||||
} catch (ex) {
|
||||
|
@ -128,10 +132,10 @@ const SyncDisconnectInternal = {
|
|||
// sanitize everything other than "open windows" (and we don't do that
|
||||
// because it may confuse the user - they probably want to see
|
||||
// about:prefs with the disconnection reflected.
|
||||
let itemsToClear = Object.keys(Sanitizer.items).filter(
|
||||
let itemsToClear = Object.keys(lazy.Sanitizer.items).filter(
|
||||
k => k != "openWindows"
|
||||
);
|
||||
await Sanitizer.sanitize(itemsToClear);
|
||||
await lazy.Sanitizer.sanitize(itemsToClear);
|
||||
} catch (ex) {
|
||||
console.error("Failed to sanitize other data", ex);
|
||||
}
|
||||
|
@ -144,7 +148,7 @@ const SyncDisconnectInternal = {
|
|||
let Weave = this.getWeave();
|
||||
await Weave.Service.promiseInitialized;
|
||||
await Weave.Service.startOver();
|
||||
await fxAccounts.signOut();
|
||||
await lazy.fxAccounts.signOut();
|
||||
// Sync may have been disabled if we santized, so re-enable it now or
|
||||
// else the user will be unable to resync should they sign in before a
|
||||
// restart.
|
||||
|
@ -167,12 +171,12 @@ const SyncDisconnectInternal = {
|
|||
// So we do this by using an AbortController and passing that to the
|
||||
// function that waits for the sync lock - it will immediately resolve
|
||||
// if the abort controller is aborted.
|
||||
let log = Log.repository.getLogger("Sync.Service");
|
||||
let log = lazy.Log.repository.getLogger("Sync.Service");
|
||||
|
||||
// If the master-password is locked then we will fail to fully sanitize,
|
||||
// so prompt for that now. If canceled, we just abort now.
|
||||
log.info("checking master-password state");
|
||||
if (!Utils.ensureMPUnlocked()) {
|
||||
if (!lazy.Utils.ensureMPUnlocked()) {
|
||||
log.warn(
|
||||
"The master-password needs to be unlocked to fully disconnect from sync"
|
||||
);
|
||||
|
@ -216,7 +220,7 @@ const SyncDisconnectInternal = {
|
|||
abortController.abort();
|
||||
return promiseDisconnectFinished;
|
||||
};
|
||||
AsyncShutdown.quitApplicationGranted.addBlocker(
|
||||
lazy.AsyncShutdown.quitApplicationGranted.addBlocker(
|
||||
"SyncDisconnect: removing requested data",
|
||||
shutdownBlocker
|
||||
);
|
||||
|
@ -227,7 +231,7 @@ const SyncDisconnectInternal = {
|
|||
|
||||
// sanitize worked so remove our blocker - it's a noop if the blocker
|
||||
// did call us.
|
||||
AsyncShutdown.quitApplicationGranted.removeBlocker(shutdownBlocker);
|
||||
lazy.AsyncShutdown.quitApplicationGranted.removeBlocker(shutdownBlocker);
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -16,8 +16,10 @@ const { Preferences } = ChromeUtils.import(
|
|||
"resource://gre/modules/Preferences.jsm"
|
||||
);
|
||||
|
||||
const lazy = {};
|
||||
|
||||
// The Sync XPCOM service
|
||||
XPCOMUtils.defineLazyGetter(this, "weaveXPCService", function() {
|
||||
XPCOMUtils.defineLazyGetter(lazy, "weaveXPCService", function() {
|
||||
return Cc["@mozilla.org/weave/service;1"].getService(
|
||||
Ci.nsISupports
|
||||
).wrappedJSObject;
|
||||
|
@ -38,7 +40,7 @@ const TOPIC_TABS_CHANGED = "services.sync.tabs.changed";
|
|||
// of tabs "fresh enough" and don't force a new sync.
|
||||
const TABS_FRESH_ENOUGH_INTERVAL = 30;
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "log", function() {
|
||||
XPCOMUtils.defineLazyGetter(lazy, "log", function() {
|
||||
let log = Log.repository.getLogger("Sync.RemoteTabs");
|
||||
log.manageLevelFromPref("services.sync.log.logger.tabs");
|
||||
return log;
|
||||
|
@ -86,12 +88,12 @@ let SyncedTabsInternal = {
|
|||
},
|
||||
|
||||
async getTabClients(filter) {
|
||||
log.info("Generating tab list with filter", filter);
|
||||
lazy.log.info("Generating tab list with filter", filter);
|
||||
let result = [];
|
||||
|
||||
// If Sync isn't ready, don't try and get anything.
|
||||
if (!weaveXPCService.ready) {
|
||||
log.debug("Sync isn't yet ready, so returning an empty tab list");
|
||||
if (!lazy.weaveXPCService.ready) {
|
||||
lazy.log.debug("Sync isn't yet ready, so returning an empty tab list");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -110,11 +112,11 @@ let SyncedTabsInternal = {
|
|||
continue;
|
||||
}
|
||||
let clientRepr = await this._makeClient(client);
|
||||
log.debug("Processing client", clientRepr);
|
||||
lazy.log.debug("Processing client", clientRepr);
|
||||
|
||||
for (let tab of client.tabs) {
|
||||
let url = tab.urlHistory[0];
|
||||
log.trace("remote tab", url);
|
||||
lazy.log.trace("remote tab", url);
|
||||
|
||||
if (!url) {
|
||||
continue;
|
||||
|
@ -130,7 +132,9 @@ let SyncedTabsInternal = {
|
|||
ntabs += clientRepr.tabs.length;
|
||||
result.push(clientRepr);
|
||||
}
|
||||
log.info(`Final tab list has ${result.length} clients with ${ntabs} tabs.`);
|
||||
lazy.log.info(
|
||||
`Final tab list has ${result.length} clients with ${ntabs} tabs.`
|
||||
);
|
||||
return result;
|
||||
},
|
||||
|
||||
|
@ -140,7 +144,7 @@ let SyncedTabsInternal = {
|
|||
let lastFetch = Preferences.get("services.sync.lastTabFetch", 0);
|
||||
let now = Math.floor(Date.now() / 1000);
|
||||
if (now - lastFetch < TABS_FRESH_ENOUGH_INTERVAL) {
|
||||
log.info("_refetchTabs was done recently, do not doing it again");
|
||||
lazy.log.info("_refetchTabs was done recently, do not doing it again");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -148,22 +152,24 @@ let SyncedTabsInternal = {
|
|||
// If Sync isn't configured don't try and sync, else we will get reports
|
||||
// of a login failure.
|
||||
if (Weave.Status.checkSetup() == Weave.CLIENT_NOT_CONFIGURED) {
|
||||
log.info("Sync client is not configured, so not attempting a tab sync");
|
||||
lazy.log.info(
|
||||
"Sync client is not configured, so not attempting a tab sync"
|
||||
);
|
||||
return false;
|
||||
}
|
||||
// Ask Sync to just do the tabs engine if it can.
|
||||
try {
|
||||
log.info("Doing a tab sync.");
|
||||
lazy.log.info("Doing a tab sync.");
|
||||
await Weave.Service.sync({ why: "tabs", engines: ["tabs"] });
|
||||
return true;
|
||||
} catch (ex) {
|
||||
log.error("Sync failed", ex);
|
||||
lazy.log.error("Sync failed", ex);
|
||||
throw ex;
|
||||
}
|
||||
},
|
||||
|
||||
observe(subject, topic, data) {
|
||||
log.trace(`observed topic=${topic}, data=${data}, subject=${subject}`);
|
||||
lazy.log.trace(`observed topic=${topic}, data=${data}, subject=${subject}`);
|
||||
switch (topic) {
|
||||
case "weave:engine:sync:finish":
|
||||
if (data != "tabs") {
|
||||
|
@ -193,8 +199,8 @@ let SyncedTabsInternal = {
|
|||
|
||||
// Returns true if Sync is configured to Sync tabs, false otherwise
|
||||
get isConfiguredToSyncTabs() {
|
||||
if (!weaveXPCService.ready) {
|
||||
log.debug("Sync isn't yet ready; assuming tab engine is enabled");
|
||||
if (!lazy.weaveXPCService.ready) {
|
||||
lazy.log.debug("Sync isn't yet ready; assuming tab engine is enabled");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,8 +17,9 @@
|
|||
var EXPORTED_SYMBOLS = ["UIState"];
|
||||
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const lazy = {};
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"Weave",
|
||||
"resource://services-sync/main.js"
|
||||
);
|
||||
|
@ -225,7 +226,7 @@ const UIStateInternal = {
|
|||
// LOGIN_FAILED_LOGIN_REJECTED explicitly means "you must log back in".
|
||||
// All other login failures are assumed to be transient and should go
|
||||
// away by themselves, so aren't reflected here.
|
||||
return Weave.Status.login == Weave.LOGIN_FAILED_LOGIN_REJECTED;
|
||||
return lazy.Weave.Status.login == lazy.Weave.LOGIN_FAILED_LOGIN_REJECTED;
|
||||
},
|
||||
|
||||
set fxAccounts(mockFxAccounts) {
|
||||
|
|
|
@ -13,13 +13,15 @@ const { Log } = ChromeUtils.import("resource://gre/modules/Log.jsm");
|
|||
const { Svc } = ChromeUtils.import("resource://services-sync/util.js");
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const lazy = {};
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"AddonManager",
|
||||
"resource://gre/modules/AddonManager.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"AddonRepository",
|
||||
"resource://gre/modules/addons/AddonRepository.jsm"
|
||||
);
|
||||
|
@ -46,7 +48,7 @@ AddonUtilsInternal.prototype = {
|
|||
// reflected in the AddonInstall, so we can't use it. If we ever get rid
|
||||
// of sourceURI rewriting, we can avoid having to reconstruct the
|
||||
// AddonInstall.
|
||||
return AddonManager.getInstallForURL(addon.sourceURI.spec, {
|
||||
return lazy.AddonManager.getInstallForURL(addon.sourceURI.spec, {
|
||||
name: addon.name,
|
||||
icons: addon.iconURL,
|
||||
version: addon.version,
|
||||
|
@ -157,7 +159,7 @@ AddonUtilsInternal.prototype = {
|
|||
|
||||
// For non-restartless add-ons, we issue the callback on uninstalling
|
||||
// because we will likely never see the uninstalled event.
|
||||
AddonManager.removeAddonListener(listener);
|
||||
lazy.AddonManager.removeAddonListener(listener);
|
||||
res(addon);
|
||||
},
|
||||
onUninstalled(uninstalled) {
|
||||
|
@ -165,11 +167,11 @@ AddonUtilsInternal.prototype = {
|
|||
return;
|
||||
}
|
||||
|
||||
AddonManager.removeAddonListener(listener);
|
||||
lazy.AddonManager.removeAddonListener(listener);
|
||||
res(addon);
|
||||
},
|
||||
};
|
||||
AddonManager.addAddonListener(listener);
|
||||
lazy.AddonManager.addAddonListener(listener);
|
||||
addon.uninstall();
|
||||
});
|
||||
},
|
||||
|
@ -210,7 +212,7 @@ AddonUtilsInternal.prototype = {
|
|||
ids.push(addon.id);
|
||||
}
|
||||
|
||||
let addons = await AddonRepository.getAddonsByIDs(ids);
|
||||
let addons = await lazy.AddonRepository.getAddonsByIDs(ids);
|
||||
this._log.info(
|
||||
`Found ${addons.length} / ${ids.length}` +
|
||||
" add-ons during repository search."
|
||||
|
|
|
@ -12,25 +12,27 @@ const { CommonUtils } = ChromeUtils.import(
|
|||
);
|
||||
const { Utils } = ChromeUtils.import("resource://services-sync/util.js");
|
||||
|
||||
const lazy = {};
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"Async",
|
||||
"resource://services-common/async.js"
|
||||
);
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"PlacesUtils",
|
||||
"resource://gre/modules/PlacesUtils.jsm"
|
||||
);
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"PlacesSyncUtils",
|
||||
"resource://gre/modules/PlacesSyncUtils.jsm"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyGlobalGetters(this, ["URLSearchParams"]);
|
||||
XPCOMUtils.defineLazyGlobalGetters(lazy, ["URLSearchParams"]);
|
||||
|
||||
var EXPORTED_SYMBOLS = ["BookmarkValidator", "BookmarkProblemData"];
|
||||
|
||||
|
@ -46,12 +48,12 @@ function areURLsEqual(a, b) {
|
|||
// Tag queries are special because we rewrite them to point to the
|
||||
// local tag folder ID. It's expected that the folders won't match,
|
||||
// but all other params should.
|
||||
let aParams = new URLSearchParams(a.slice(QUERY_PROTOCOL.length));
|
||||
let aParams = new lazy.URLSearchParams(a.slice(QUERY_PROTOCOL.length));
|
||||
let aType = +aParams.get("type");
|
||||
if (aType != Ci.nsINavHistoryQueryOptions.RESULTS_AS_TAG_CONTENTS) {
|
||||
return false;
|
||||
}
|
||||
let bParams = new URLSearchParams(b.slice(QUERY_PROTOCOL.length));
|
||||
let bParams = new lazy.URLSearchParams(b.slice(QUERY_PROTOCOL.length));
|
||||
let bType = +bParams.get("type");
|
||||
if (bType != Ci.nsINavHistoryQueryOptions.RESULTS_AS_TAG_CONTENTS) {
|
||||
return false;
|
||||
|
@ -234,28 +236,28 @@ class BookmarkProblemData {
|
|||
}
|
||||
|
||||
// Defined lazily to avoid initializing PlacesUtils.bookmarks too soon.
|
||||
XPCOMUtils.defineLazyGetter(this, "SYNCED_ROOTS", () => [
|
||||
PlacesUtils.bookmarks.menuGuid,
|
||||
PlacesUtils.bookmarks.toolbarGuid,
|
||||
PlacesUtils.bookmarks.unfiledGuid,
|
||||
PlacesUtils.bookmarks.mobileGuid,
|
||||
XPCOMUtils.defineLazyGetter(lazy, "SYNCED_ROOTS", () => [
|
||||
lazy.PlacesUtils.bookmarks.menuGuid,
|
||||
lazy.PlacesUtils.bookmarks.toolbarGuid,
|
||||
lazy.PlacesUtils.bookmarks.unfiledGuid,
|
||||
lazy.PlacesUtils.bookmarks.mobileGuid,
|
||||
]);
|
||||
|
||||
// Maps root GUIDs to their query folder names from
|
||||
// toolkit/components/places/nsNavHistoryQuery.cpp. We follow queries that
|
||||
// reference existing folders in the client tree, and detect cycles where a
|
||||
// query references its containing folder.
|
||||
XPCOMUtils.defineLazyGetter(this, "ROOT_GUID_TO_QUERY_FOLDER_NAME", () => ({
|
||||
[PlacesUtils.bookmarks.rootGuid]: "PLACES_ROOT",
|
||||
[PlacesUtils.bookmarks.menuGuid]: "BOOKMARKS_MENU",
|
||||
XPCOMUtils.defineLazyGetter(lazy, "ROOT_GUID_TO_QUERY_FOLDER_NAME", () => ({
|
||||
[lazy.PlacesUtils.bookmarks.rootGuid]: "PLACES_ROOT",
|
||||
[lazy.PlacesUtils.bookmarks.menuGuid]: "BOOKMARKS_MENU",
|
||||
|
||||
// Tags should never show up in our client tree, and never form cycles, but we
|
||||
// report them just in case.
|
||||
[PlacesUtils.bookmarks.tagsGuid]: "TAGS",
|
||||
[lazy.PlacesUtils.bookmarks.tagsGuid]: "TAGS",
|
||||
|
||||
[PlacesUtils.bookmarks.unfiledGuid]: "UNFILED_BOOKMARKS",
|
||||
[PlacesUtils.bookmarks.toolbarGuid]: "TOOLBAR",
|
||||
[PlacesUtils.bookmarks.mobileGuid]: "MOBILE_BOOKMARKS",
|
||||
[lazy.PlacesUtils.bookmarks.unfiledGuid]: "UNFILED_BOOKMARKS",
|
||||
[lazy.PlacesUtils.bookmarks.toolbarGuid]: "TOOLBAR",
|
||||
[lazy.PlacesUtils.bookmarks.mobileGuid]: "MOBILE_BOOKMARKS",
|
||||
}));
|
||||
|
||||
async function detectCycles(records) {
|
||||
|
@ -266,7 +268,7 @@ async function detectCycles(records) {
|
|||
let currentPath = [];
|
||||
let cycles = [];
|
||||
let seenEver = new Set();
|
||||
const yieldState = Async.yieldState();
|
||||
const yieldState = lazy.Async.yieldState();
|
||||
|
||||
const traverse = async node => {
|
||||
if (pathLookup.has(node)) {
|
||||
|
@ -287,13 +289,13 @@ async function detectCycles(records) {
|
|||
if (children.length) {
|
||||
pathLookup.add(node);
|
||||
currentPath.push(node);
|
||||
await Async.yieldingForEach(children, traverse, yieldState);
|
||||
await lazy.Async.yieldingForEach(children, traverse, yieldState);
|
||||
currentPath.pop();
|
||||
pathLookup.delete(node);
|
||||
}
|
||||
};
|
||||
|
||||
await Async.yieldingForEach(
|
||||
await lazy.Async.yieldingForEach(
|
||||
records,
|
||||
async record => {
|
||||
if (!seenEver.has(record)) {
|
||||
|
@ -326,7 +328,7 @@ class ServerRecordInspection {
|
|||
this._orphans = new Map();
|
||||
this._multipleParents = new Map();
|
||||
|
||||
this.yieldState = Async.yieldState();
|
||||
this.yieldState = lazy.Async.yieldState();
|
||||
}
|
||||
|
||||
static async create(records) {
|
||||
|
@ -381,7 +383,7 @@ class ServerRecordInspection {
|
|||
this.serverRecords = records;
|
||||
let rootChildren = [];
|
||||
|
||||
await Async.yieldingForEach(
|
||||
await lazy.Async.yieldingForEach(
|
||||
this.serverRecords,
|
||||
async record => {
|
||||
if (!record.id) {
|
||||
|
@ -445,7 +447,7 @@ class ServerRecordInspection {
|
|||
// The last two are left alone until later `this._linkChildren`, however.
|
||||
record.childGUIDs = record.children;
|
||||
|
||||
await Async.yieldingForEach(
|
||||
await lazy.Async.yieldingForEach(
|
||||
record.childGUIDs,
|
||||
id => {
|
||||
this.noteParent(id, record.id);
|
||||
|
@ -494,7 +496,7 @@ class ServerRecordInspection {
|
|||
|
||||
// Adds `parent` to all records it can that have `parentid`
|
||||
async _linkParentIDs() {
|
||||
await Async.yieldingForEach(
|
||||
await lazy.Async.yieldingForEach(
|
||||
this.idToRecord,
|
||||
([id, record]) => {
|
||||
if (record == this.root || record.deleted) {
|
||||
|
@ -543,7 +545,7 @@ class ServerRecordInspection {
|
|||
// objects, not ids)
|
||||
async _linkChildren() {
|
||||
// Check that we aren't missing any children.
|
||||
await Async.yieldingForEach(
|
||||
await lazy.Async.yieldingForEach(
|
||||
this.folders,
|
||||
async folder => {
|
||||
folder.children = [];
|
||||
|
@ -551,7 +553,7 @@ class ServerRecordInspection {
|
|||
|
||||
let idsThisFolder = new Set();
|
||||
|
||||
await Async.yieldingForEach(
|
||||
await lazy.Async.yieldingForEach(
|
||||
folder.childGUIDs,
|
||||
childID => {
|
||||
let child = this.idToRecord.get(childID);
|
||||
|
@ -597,7 +599,7 @@ class ServerRecordInspection {
|
|||
async _findOrphans() {
|
||||
let seen = new Set([this.root.id]);
|
||||
|
||||
const inCycle = await Async.yieldingForEach(
|
||||
const inCycle = await lazy.Async.yieldingForEach(
|
||||
Utils.walkTree(this.root),
|
||||
([node]) => {
|
||||
if (seen.has(node.id)) {
|
||||
|
@ -616,7 +618,7 @@ class ServerRecordInspection {
|
|||
return;
|
||||
}
|
||||
|
||||
await Async.yieldingForEach(
|
||||
await lazy.Async.yieldingForEach(
|
||||
this.liveRecords,
|
||||
(record, i) => {
|
||||
if (!seen.has(record.id)) {
|
||||
|
@ -629,7 +631,7 @@ class ServerRecordInspection {
|
|||
this.yieldState
|
||||
);
|
||||
|
||||
await Async.yieldingForEach(
|
||||
await lazy.Async.yieldingForEach(
|
||||
this._orphans,
|
||||
([id, parent]) => {
|
||||
this.problemData.orphans.push({ id, parent });
|
||||
|
@ -664,15 +666,15 @@ class ServerRecordInspection {
|
|||
|
||||
class BookmarkValidator {
|
||||
constructor() {
|
||||
this.yieldState = Async.yieldState();
|
||||
this.yieldState = lazy.Async.yieldState();
|
||||
}
|
||||
|
||||
async canValidate() {
|
||||
return !(await PlacesSyncUtils.bookmarks.havePendingChanges());
|
||||
return !(await lazy.PlacesSyncUtils.bookmarks.havePendingChanges());
|
||||
}
|
||||
|
||||
async _followQueries(recordsByQueryId) {
|
||||
await Async.yieldingForEach(
|
||||
await lazy.Async.yieldingForEach(
|
||||
recordsByQueryId.values(),
|
||||
entry => {
|
||||
if (
|
||||
|
@ -681,7 +683,7 @@ class BookmarkValidator {
|
|||
) {
|
||||
return;
|
||||
}
|
||||
let params = new URLSearchParams(
|
||||
let params = new lazy.URLSearchParams(
|
||||
entry.bmkUri.slice(QUERY_PROTOCOL.length)
|
||||
);
|
||||
// Queries with `excludeQueries` won't form cycles because they'll
|
||||
|
@ -714,33 +716,33 @@ class BookmarkValidator {
|
|||
// still use local IDs. We use this mapping to parse `place:` queries that
|
||||
// refer to folders via their local IDs.
|
||||
let recordsByQueryId = new Map();
|
||||
let syncedRoots = SYNCED_ROOTS;
|
||||
let syncedRoots = lazy.SYNCED_ROOTS;
|
||||
|
||||
const traverse = async (treeNode, synced) => {
|
||||
if (!synced) {
|
||||
synced = syncedRoots.includes(treeNode.guid);
|
||||
}
|
||||
let localId = treeNode.id;
|
||||
let guid = PlacesSyncUtils.bookmarks.guidToRecordId(treeNode.guid);
|
||||
let guid = lazy.PlacesSyncUtils.bookmarks.guidToRecordId(treeNode.guid);
|
||||
let itemType = "item";
|
||||
treeNode.ignored = !synced;
|
||||
treeNode.id = guid;
|
||||
switch (treeNode.type) {
|
||||
case PlacesUtils.TYPE_X_MOZ_PLACE:
|
||||
case lazy.PlacesUtils.TYPE_X_MOZ_PLACE:
|
||||
if (treeNode.uri.startsWith(QUERY_PROTOCOL)) {
|
||||
itemType = "query";
|
||||
} else {
|
||||
itemType = "bookmark";
|
||||
}
|
||||
break;
|
||||
case PlacesUtils.TYPE_X_MOZ_PLACE_CONTAINER:
|
||||
case lazy.PlacesUtils.TYPE_X_MOZ_PLACE_CONTAINER:
|
||||
let isLivemark = false;
|
||||
if (treeNode.annos) {
|
||||
for (let anno of treeNode.annos) {
|
||||
if (anno.name === PlacesUtils.LMANNO_FEEDURI) {
|
||||
if (anno.name === lazy.PlacesUtils.LMANNO_FEEDURI) {
|
||||
isLivemark = true;
|
||||
treeNode.feedUri = anno.value;
|
||||
} else if (anno.name === PlacesUtils.LMANNO_SITEURI) {
|
||||
} else if (anno.name === lazy.PlacesUtils.LMANNO_SITEURI) {
|
||||
isLivemark = true;
|
||||
treeNode.siteUri = anno.value;
|
||||
}
|
||||
|
@ -748,7 +750,7 @@ class BookmarkValidator {
|
|||
}
|
||||
itemType = isLivemark ? "livemark" : "folder";
|
||||
break;
|
||||
case PlacesUtils.TYPE_X_MOZ_PLACE_SEPARATOR:
|
||||
case lazy.PlacesUtils.TYPE_X_MOZ_PLACE_SEPARATOR:
|
||||
itemType = "separator";
|
||||
break;
|
||||
}
|
||||
|
@ -762,8 +764,8 @@ class BookmarkValidator {
|
|||
treeNode.pos = treeNode.index;
|
||||
treeNode.bmkUri = treeNode.uri;
|
||||
records.push(treeNode);
|
||||
if (treeNode.guid in ROOT_GUID_TO_QUERY_FOLDER_NAME) {
|
||||
let queryId = ROOT_GUID_TO_QUERY_FOLDER_NAME[treeNode.guid];
|
||||
if (treeNode.guid in lazy.ROOT_GUID_TO_QUERY_FOLDER_NAME) {
|
||||
let queryId = lazy.ROOT_GUID_TO_QUERY_FOLDER_NAME[treeNode.guid];
|
||||
recordsByQueryId.set(queryId, treeNode);
|
||||
}
|
||||
if (localId) {
|
||||
|
@ -779,7 +781,7 @@ class BookmarkValidator {
|
|||
treeNode.children = [];
|
||||
}
|
||||
|
||||
await Async.yieldingForEach(
|
||||
await lazy.Async.yieldingForEach(
|
||||
treeNode.children,
|
||||
async child => {
|
||||
await traverse(child, synced);
|
||||
|
@ -837,7 +839,7 @@ class BookmarkValidator {
|
|||
// Perform client-side sanity checking that doesn't involve server data
|
||||
async _validateClient(problemData, clientRecords) {
|
||||
problemData.clientCycles = await detectCycles(clientRecords);
|
||||
for (let rootGUID of SYNCED_ROOTS) {
|
||||
for (let rootGUID of lazy.SYNCED_ROOTS) {
|
||||
let record = clientRecords.find(record => record.guid === rootGUID);
|
||||
if (!record || record.parentid !== "places") {
|
||||
problemData.badClientRoots.push(rootGUID);
|
||||
|
@ -847,7 +849,7 @@ class BookmarkValidator {
|
|||
|
||||
async _computeUnifiedRecordMap(serverRecords, clientRecords) {
|
||||
let allRecords = new Map();
|
||||
await Async.yieldingForEach(
|
||||
await lazy.Async.yieldingForEach(
|
||||
serverRecords,
|
||||
sr => {
|
||||
if (sr.fake) {
|
||||
|
@ -858,7 +860,7 @@ class BookmarkValidator {
|
|||
this.yieldState
|
||||
);
|
||||
|
||||
await Async.yieldingForEach(
|
||||
await lazy.Async.yieldingForEach(
|
||||
clientRecords,
|
||||
cr => {
|
||||
let unified = allRecords.get(cr.id);
|
||||
|
@ -895,7 +897,7 @@ class BookmarkValidator {
|
|||
// "Mobile Bookmarks", but the server thinks it's "mobile".
|
||||
// TODO: We probably should be handing other localized bookmarks (e.g.
|
||||
// default bookmarks) here as well, see bug 1316041.
|
||||
if (!SYNCED_ROOTS.includes(client.guid)) {
|
||||
if (!lazy.SYNCED_ROOTS.includes(client.guid)) {
|
||||
// We want to treat undefined, null and an empty string as identical
|
||||
if ((client.title || "") !== (server.title || "")) {
|
||||
differences.push("title");
|
||||
|
@ -997,7 +999,7 @@ class BookmarkValidator {
|
|||
|
||||
let serverDeleted = new Set(inspectionInfo.deletedRecords.map(r => r.id));
|
||||
|
||||
await Async.yieldingForEach(
|
||||
await lazy.Async.yieldingForEach(
|
||||
allRecords,
|
||||
([id, { client, server }]) => {
|
||||
if (!client || !server) {
|
||||
|
@ -1039,7 +1041,7 @@ class BookmarkValidator {
|
|||
throw result.response;
|
||||
}
|
||||
let cleartexts = [];
|
||||
await Async.yieldingForEach(
|
||||
await lazy.Async.yieldingForEach(
|
||||
result.records,
|
||||
async record => {
|
||||
await record.decrypt(collectionKey);
|
||||
|
@ -1052,7 +1054,7 @@ class BookmarkValidator {
|
|||
|
||||
async validate(engine) {
|
||||
let start = Date.now();
|
||||
let clientTree = await PlacesUtils.promiseBookmarksTree("", {
|
||||
let clientTree = await lazy.PlacesUtils.promiseBookmarksTree("", {
|
||||
includeItemIds: true,
|
||||
});
|
||||
let serverState = await this._getServerState(engine);
|
||||
|
|
|
@ -24,7 +24,9 @@ const { RawCryptoWrapper } = ChromeUtils.import(
|
|||
"resource://services-sync/record.js"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
Async: "resource://services-common/async.js",
|
||||
Log: "resource://gre/modules/Log.jsm",
|
||||
PlacesUtils: "resource://gre/modules/PlacesUtils.jsm",
|
||||
|
@ -47,12 +49,15 @@ class BridgedStore {
|
|||
throw new Error("Store must be associated with an Engine instance.");
|
||||
}
|
||||
this.engine = engine;
|
||||
this._log = Log.repository.getLogger(`Sync.Engine.${name}.Store`);
|
||||
this._log = lazy.Log.repository.getLogger(`Sync.Engine.${name}.Store`);
|
||||
this._batchChunkSize = 500;
|
||||
}
|
||||
|
||||
async applyIncomingBatch(records) {
|
||||
for (let chunk of PlacesUtils.chunkArray(records, this._batchChunkSize)) {
|
||||
for (let chunk of lazy.PlacesUtils.chunkArray(
|
||||
records,
|
||||
this._batchChunkSize
|
||||
)) {
|
||||
let incomingEnvelopesAsJSON = chunk.map(record =>
|
||||
JSON.stringify(record.toIncomingEnvelope())
|
||||
);
|
||||
|
@ -161,16 +166,16 @@ class LogAdapter {
|
|||
|
||||
get maxLevel() {
|
||||
let level = this.log.level;
|
||||
if (level <= Log.Level.All) {
|
||||
if (level <= lazy.Log.Level.All) {
|
||||
return Ci.mozIServicesLogSink.LEVEL_TRACE;
|
||||
}
|
||||
if (level <= Log.Level.Info) {
|
||||
if (level <= lazy.Log.Level.Info) {
|
||||
return Ci.mozIServicesLogSink.LEVEL_DEBUG;
|
||||
}
|
||||
if (level <= Log.Level.Warn) {
|
||||
if (level <= lazy.Log.Level.Warn) {
|
||||
return Ci.mozIServicesLogSink.LEVEL_WARN;
|
||||
}
|
||||
if (level <= Log.Level.Error) {
|
||||
if (level <= lazy.Log.Level.Error) {
|
||||
return Ci.mozIServicesLogSink.LEVEL_ERROR;
|
||||
}
|
||||
return Ci.mozIServicesLogSink.LEVEL_OFF;
|
||||
|
|
|
@ -4,8 +4,10 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const lazy = {};
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"Async",
|
||||
"resource://services-common/async.js"
|
||||
);
|
||||
|
@ -82,7 +84,7 @@ class CollectionValidator {
|
|||
}
|
||||
let cleartexts = [];
|
||||
|
||||
await Async.yieldingForEach(result.records, async record => {
|
||||
await lazy.Async.yieldingForEach(result.records, async record => {
|
||||
await record.decrypt(collectionKey);
|
||||
cleartexts.push(record.cleartext);
|
||||
});
|
||||
|
@ -148,11 +150,11 @@ class CollectionValidator {
|
|||
// records: Normalized server records,
|
||||
// deletedRecords: Array of ids that were marked as deleted by the server.
|
||||
async compareClientWithServer(clientItems, serverItems) {
|
||||
const yieldState = Async.yieldState();
|
||||
const yieldState = lazy.Async.yieldState();
|
||||
|
||||
const clientRecords = [];
|
||||
|
||||
await Async.yieldingForEach(
|
||||
await lazy.Async.yieldingForEach(
|
||||
clientItems,
|
||||
item => {
|
||||
clientRecords.push(this.normalizeClientItem(item));
|
||||
|
@ -161,7 +163,7 @@ class CollectionValidator {
|
|||
);
|
||||
|
||||
const serverRecords = [];
|
||||
await Async.yieldingForEach(
|
||||
await lazy.Async.yieldingForEach(
|
||||
serverItems,
|
||||
async item => {
|
||||
serverRecords.push(await this.normalizeServerItem(item));
|
||||
|
|
|
@ -36,20 +36,24 @@ const { SerializableSet, Svc, Utils } = ChromeUtils.import(
|
|||
"resource://services-sync/util.js"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
OS: "resource://gre/modules/osfile.jsm",
|
||||
PlacesUtils: "resource://gre/modules/PlacesUtils.jsm",
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "fxAccounts", () => {
|
||||
XPCOMUtils.defineLazyGetter(lazy, "fxAccounts", () => {
|
||||
return ChromeUtils.import(
|
||||
"resource://gre/modules/FxAccounts.jsm"
|
||||
).getFxAccountsSingleton();
|
||||
});
|
||||
|
||||
function ensureDirectory(path) {
|
||||
let basename = OS.Path.dirname(path);
|
||||
return OS.File.makeDir(basename, { from: OS.Constants.Path.profileDir });
|
||||
let basename = lazy.OS.Path.dirname(path);
|
||||
return lazy.OS.File.makeDir(basename, {
|
||||
from: lazy.OS.Constants.Path.profileDir,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1346,7 +1350,7 @@ SyncEngine.prototype = {
|
|||
// `getBatched` includes the list of IDs as a query parameter, so we need to fetch
|
||||
// records in chunks to avoid exceeding URI length limits.
|
||||
if (this.guidFetchBatchSize) {
|
||||
for (let ids of PlacesUtils.chunkArray(
|
||||
for (let ids of lazy.PlacesUtils.chunkArray(
|
||||
idsToBackfill,
|
||||
this.guidFetchBatchSize
|
||||
)) {
|
||||
|
|
|
@ -60,13 +60,15 @@ const { CollectionValidator } = ChromeUtils.import(
|
|||
"resource://services-sync/collection_validator.js"
|
||||
);
|
||||
|
||||
const lazy = {};
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"AddonManager",
|
||||
"resource://gre/modules/AddonManager.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"AddonRepository",
|
||||
"resource://gre/modules/addons/AddonRepository.jsm"
|
||||
);
|
||||
|
@ -419,7 +421,7 @@ AddonsStore.prototype = {
|
|||
//
|
||||
// We wouldn't get here if the incoming record was for a deletion. So,
|
||||
// check for pending uninstall and cancel if necessary.
|
||||
if (addon.pendingOperations & AddonManager.PENDING_UNINSTALL) {
|
||||
if (addon.pendingOperations & lazy.AddonManager.PENDING_UNINSTALL) {
|
||||
addon.cancelUninstall();
|
||||
|
||||
// We continue with processing because there could be state or ID change.
|
||||
|
@ -559,7 +561,7 @@ AddonsStore.prototype = {
|
|||
* @return Addon or undefined if not found
|
||||
*/
|
||||
async getAddonByID(id) {
|
||||
return AddonManager.getAddonByID(id);
|
||||
return lazy.AddonManager.getAddonByID(id);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -570,7 +572,7 @@ AddonsStore.prototype = {
|
|||
* @return DBAddonInternal or null
|
||||
*/
|
||||
async getAddonByGUID(guid) {
|
||||
return AddonManager.getAddonBySyncGUID(guid);
|
||||
return lazy.AddonManager.getAddonBySyncGUID(guid);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -609,7 +611,7 @@ AddonsStore.prototype = {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!(addon.scope & AddonManager.SCOPE_PROFILE)) {
|
||||
if (!(addon.scope & lazy.AddonManager.SCOPE_PROFILE)) {
|
||||
this._log.debug(addon.id + " not syncable: not installed in profile.");
|
||||
return false;
|
||||
}
|
||||
|
@ -633,12 +635,12 @@ AddonsStore.prototype = {
|
|||
// in tests), getCachedAddonByID always returns null - so skip the check
|
||||
// in that case. We also provide a way to specifically opt-out of the check
|
||||
// even if the cache is enabled, which is used by the validators.
|
||||
if (ignoreRepoCheck || !AddonRepository.cacheEnabled) {
|
||||
if (ignoreRepoCheck || !lazy.AddonRepository.cacheEnabled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
let result = await new Promise(res => {
|
||||
AddonRepository.getCachedAddonByID(addon.id, res);
|
||||
lazy.AddonRepository.getCachedAddonByID(addon.id, res);
|
||||
});
|
||||
|
||||
if (!result) {
|
||||
|
@ -788,14 +790,14 @@ class AddonValidator extends CollectionValidator {
|
|||
}
|
||||
|
||||
async getClientItems() {
|
||||
return AddonManager.getAllAddons();
|
||||
return lazy.AddonManager.getAllAddons();
|
||||
}
|
||||
|
||||
normalizeClientItem(item) {
|
||||
let enabled = !item.userDisabled;
|
||||
if (item.pendingOperations & AddonManager.PENDING_ENABLE) {
|
||||
if (item.pendingOperations & lazy.AddonManager.PENDING_ENABLE) {
|
||||
enabled = true;
|
||||
} else if (item.pendingOperations & AddonManager.PENDING_DISABLE) {
|
||||
} else if (item.pendingOperations & lazy.AddonManager.PENDING_DISABLE) {
|
||||
enabled = false;
|
||||
}
|
||||
return {
|
||||
|
@ -824,7 +826,9 @@ class AddonValidator extends CollectionValidator {
|
|||
return (
|
||||
!item.original.hidden &&
|
||||
!item.original.isSystem &&
|
||||
!(item.original.pendingOperations & AddonManager.PENDING_UNINSTALL) &&
|
||||
!(
|
||||
item.original.pendingOperations & lazy.AddonManager.PENDING_UNINSTALL
|
||||
) &&
|
||||
// No need to await the returned promise explicitely:
|
||||
// |expr1 && expr2| evaluates to expr2 if expr1 is true.
|
||||
this.engine.isAddonSyncable(item.original, true)
|
||||
|
|
|
@ -28,7 +28,9 @@ const { CryptoWrapper } = ChromeUtils.import(
|
|||
);
|
||||
const { Svc, Utils } = ChromeUtils.import("resource://services-sync/util.js");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
BookmarkValidator: "resource://services-sync/bookmark_validator.js",
|
||||
Observers: "resource://services-common/observers.js",
|
||||
OS: "resource://gre/modules/osfile.jsm",
|
||||
|
@ -40,15 +42,15 @@ XPCOMUtils.defineLazyModuleGetters(this, {
|
|||
SyncedBookmarksMirror: "resource://gre/modules/SyncedBookmarksMirror.jsm",
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "PlacesBundle", () => {
|
||||
XPCOMUtils.defineLazyGetter(lazy, "PlacesBundle", () => {
|
||||
return Services.strings.createBundle(
|
||||
"chrome://places/locale/places.properties"
|
||||
);
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "ANNOS_TO_TRACK", () => [
|
||||
PlacesUtils.LMANNO_FEEDURI,
|
||||
PlacesUtils.LMANNO_SITEURI,
|
||||
XPCOMUtils.defineLazyGetter(lazy, "ANNOS_TO_TRACK", () => [
|
||||
lazy.PlacesUtils.LMANNO_FEEDURI,
|
||||
lazy.PlacesUtils.LMANNO_SITEURI,
|
||||
]);
|
||||
|
||||
const PLACES_MAINTENANCE_INTERVAL_SECONDS = 4 * 60 * 60; // 4 hours.
|
||||
|
@ -69,12 +71,12 @@ const FORBIDDEN_INCOMING_PARENT_IDS = ["pinned", "readinglist"];
|
|||
// The tracker ignores changes made by import and restore, to avoid bumping the
|
||||
// score and triggering syncs during the process, as well as changes made by
|
||||
// Sync.
|
||||
XPCOMUtils.defineLazyGetter(this, "IGNORED_SOURCES", () => [
|
||||
PlacesUtils.bookmarks.SOURCES.SYNC,
|
||||
PlacesUtils.bookmarks.SOURCES.IMPORT,
|
||||
PlacesUtils.bookmarks.SOURCES.RESTORE,
|
||||
PlacesUtils.bookmarks.SOURCES.RESTORE_ON_STARTUP,
|
||||
PlacesUtils.bookmarks.SOURCES.SYNC_REPARENT_REMOVED_FOLDER_CHILDREN,
|
||||
XPCOMUtils.defineLazyGetter(lazy, "IGNORED_SOURCES", () => [
|
||||
lazy.PlacesUtils.bookmarks.SOURCES.SYNC,
|
||||
lazy.PlacesUtils.bookmarks.SOURCES.IMPORT,
|
||||
lazy.PlacesUtils.bookmarks.SOURCES.RESTORE,
|
||||
lazy.PlacesUtils.bookmarks.SOURCES.RESTORE_ON_STARTUP,
|
||||
lazy.PlacesUtils.bookmarks.SOURCES.SYNC_REPARENT_REMOVED_FOLDER_CHILDREN,
|
||||
]);
|
||||
|
||||
// The validation telemetry version for the engine. Version 1 is collected
|
||||
|
@ -145,7 +147,7 @@ PlacesItem.prototype = {
|
|||
recordId: this.id,
|
||||
parentRecordId: this.parentid,
|
||||
};
|
||||
let dateAdded = PlacesSyncUtils.bookmarks.ratchetTimestampBackwards(
|
||||
let dateAdded = lazy.PlacesSyncUtils.bookmarks.ratchetTimestampBackwards(
|
||||
this.dateAdded,
|
||||
+this.modified * 1000
|
||||
);
|
||||
|
@ -327,13 +329,13 @@ BookmarksEngine.prototype = {
|
|||
allowSkippedRecord: false,
|
||||
|
||||
async _ensureCurrentSyncID(newSyncID) {
|
||||
await PlacesSyncUtils.bookmarks.ensureCurrentSyncId(newSyncID);
|
||||
await lazy.PlacesSyncUtils.bookmarks.ensureCurrentSyncId(newSyncID);
|
||||
let buf = await this._store.ensureOpenMirror();
|
||||
await buf.ensureCurrentSyncId(newSyncID);
|
||||
},
|
||||
|
||||
async ensureCurrentSyncID(newSyncID) {
|
||||
let shouldWipeRemote = await PlacesSyncUtils.bookmarks.shouldWipeRemote();
|
||||
let shouldWipeRemote = await lazy.PlacesSyncUtils.bookmarks.shouldWipeRemote();
|
||||
if (!shouldWipeRemote) {
|
||||
this._log.debug(
|
||||
"Checking if server sync ID ${newSyncID} matches existing",
|
||||
|
@ -361,7 +363,7 @@ BookmarksEngine.prototype = {
|
|||
},
|
||||
|
||||
async getSyncID() {
|
||||
return PlacesSyncUtils.bookmarks.getSyncId();
|
||||
return lazy.PlacesSyncUtils.bookmarks.getSyncId();
|
||||
},
|
||||
|
||||
async resetSyncID() {
|
||||
|
@ -370,7 +372,7 @@ BookmarksEngine.prototype = {
|
|||
},
|
||||
|
||||
async resetLocalSyncID() {
|
||||
let newSyncID = await PlacesSyncUtils.bookmarks.resetSyncId();
|
||||
let newSyncID = await lazy.PlacesSyncUtils.bookmarks.resetSyncId();
|
||||
this._log.debug("Assigned new sync ID ${newSyncID}", { newSyncID });
|
||||
let buf = await this._store.ensureOpenMirror();
|
||||
await buf.ensureCurrentSyncId(newSyncID);
|
||||
|
@ -387,7 +389,7 @@ BookmarksEngine.prototype = {
|
|||
await mirror.setCollectionLastModified(lastSync);
|
||||
// Update the last sync time in Places so that reverting to the original
|
||||
// bookmarks engine doesn't download records we've already applied.
|
||||
await PlacesSyncUtils.bookmarks.setLastSync(lastSync);
|
||||
await lazy.PlacesSyncUtils.bookmarks.setLastSync(lastSync);
|
||||
},
|
||||
|
||||
async _syncStartup() {
|
||||
|
@ -398,7 +400,7 @@ BookmarksEngine.prototype = {
|
|||
let lastSync = await this.getLastSync();
|
||||
if (!lastSync) {
|
||||
this._log.debug("Bookmarks backup starting");
|
||||
await PlacesBackups.create(null, true);
|
||||
await lazy.PlacesBackups.create(null, true);
|
||||
this._log.debug("Bookmarks backup done");
|
||||
}
|
||||
} catch (ex) {
|
||||
|
@ -450,7 +452,7 @@ BookmarksEngine.prototype = {
|
|||
"elapsed since last run; running Places maintenance",
|
||||
{ elapsedSinceMaintenance }
|
||||
);
|
||||
await PlacesDBUtils.maintenanceOnIdle();
|
||||
await lazy.PlacesDBUtils.maintenanceOnIdle();
|
||||
this._ranMaintenanceOnLastSync = true;
|
||||
this.service.recordTelemetryEvent("maintenance", "run", "bookmarks");
|
||||
} else {
|
||||
|
@ -462,7 +464,7 @@ BookmarksEngine.prototype = {
|
|||
|
||||
async _syncFinish() {
|
||||
await SyncEngine.prototype._syncFinish.call(this);
|
||||
await PlacesSyncUtils.bookmarks.ensureMobileQuery();
|
||||
await lazy.PlacesSyncUtils.bookmarks.ensureMobileQuery();
|
||||
},
|
||||
|
||||
async pullAllChanges() {
|
||||
|
@ -471,7 +473,7 @@ BookmarksEngine.prototype = {
|
|||
|
||||
async trackRemainingChanges() {
|
||||
let changes = this._modified.changes;
|
||||
await PlacesSyncUtils.bookmarks.pushChanges(changes);
|
||||
await lazy.PlacesSyncUtils.bookmarks.pushChanges(changes);
|
||||
},
|
||||
|
||||
_deleteId(id) {
|
||||
|
@ -484,7 +486,7 @@ BookmarksEngine.prototype = {
|
|||
// override with logic that lives in Places and the mirror.
|
||||
async _resetClient() {
|
||||
await super._resetClient();
|
||||
await PlacesSyncUtils.bookmarks.reset();
|
||||
await lazy.PlacesSyncUtils.bookmarks.reset();
|
||||
let buf = await this._store.ensureOpenMirror();
|
||||
await buf.reset();
|
||||
},
|
||||
|
@ -509,7 +511,7 @@ BookmarksEngine.prototype = {
|
|||
|
||||
try {
|
||||
let recordsToUpload = await buf.apply({
|
||||
remoteTimeSeconds: Resource.serverTime,
|
||||
remoteTimeSeconds: lazy.Resource.serverTime,
|
||||
signal: watchdog.signal,
|
||||
});
|
||||
this._modified.replace(recordsToUpload);
|
||||
|
@ -652,7 +654,7 @@ BookmarksStore.prototype = {
|
|||
|
||||
// Create a record starting from the weave id (places guid)
|
||||
async createRecord(id, collection) {
|
||||
let item = await PlacesSyncUtils.bookmarks.fetch(id);
|
||||
let item = await lazy.PlacesSyncUtils.bookmarks.fetch(id);
|
||||
if (!item) {
|
||||
// deleted item
|
||||
let record = new PlacesItem(collection, id);
|
||||
|
@ -690,7 +692,7 @@ BookmarksStore.prototype = {
|
|||
if (record.bmkUri != null) {
|
||||
let frecency = FRECENCY_UNKNOWN;
|
||||
try {
|
||||
frecency = await PlacesSyncUtils.history.fetchURLFrecency(
|
||||
frecency = await lazy.PlacesSyncUtils.history.fetchURLFrecency(
|
||||
record.bmkUri
|
||||
);
|
||||
} catch (ex) {
|
||||
|
@ -710,8 +712,8 @@ BookmarksStore.prototype = {
|
|||
|
||||
async wipe() {
|
||||
// Save a backup before clearing out all bookmarks.
|
||||
await PlacesBackups.create(null, true);
|
||||
await PlacesSyncUtils.bookmarks.wipe();
|
||||
await lazy.PlacesBackups.create(null, true);
|
||||
await lazy.PlacesSyncUtils.bookmarks.wipe();
|
||||
},
|
||||
|
||||
ensureOpenMirror() {
|
||||
|
@ -728,19 +730,19 @@ BookmarksStore.prototype = {
|
|||
},
|
||||
|
||||
async _openMirror() {
|
||||
let mirrorPath = OS.Path.join(
|
||||
OS.Constants.Path.profileDir,
|
||||
let mirrorPath = lazy.OS.Path.join(
|
||||
lazy.OS.Constants.Path.profileDir,
|
||||
"weave",
|
||||
"bookmarks.sqlite"
|
||||
);
|
||||
await OS.File.makeDir(OS.Path.dirname(mirrorPath), {
|
||||
from: OS.Constants.Path.profileDir,
|
||||
await lazy.OS.File.makeDir(lazy.OS.Path.dirname(mirrorPath), {
|
||||
from: lazy.OS.Constants.Path.profileDir,
|
||||
});
|
||||
|
||||
return SyncedBookmarksMirror.open({
|
||||
return lazy.SyncedBookmarksMirror.open({
|
||||
path: mirrorPath,
|
||||
recordStepTelemetry: (name, took, counts) => {
|
||||
Observers.notify(
|
||||
lazy.Observers.notify(
|
||||
"weave:engine:sync:step",
|
||||
{
|
||||
name,
|
||||
|
@ -751,7 +753,7 @@ BookmarksStore.prototype = {
|
|||
);
|
||||
},
|
||||
recordValidationTelemetry: (took, checked, problems) => {
|
||||
Observers.notify(
|
||||
lazy.Observers.notify(
|
||||
"weave:engine:validate:finish",
|
||||
{
|
||||
version: BOOKMARK_VALIDATOR_VERSION,
|
||||
|
@ -767,7 +769,10 @@ BookmarksStore.prototype = {
|
|||
|
||||
async applyIncomingBatch(records) {
|
||||
let buf = await this.ensureOpenMirror();
|
||||
for (let chunk of PlacesUtils.chunkArray(records, this._batchChunkSize)) {
|
||||
for (let chunk of lazy.PlacesUtils.chunkArray(
|
||||
records,
|
||||
this._batchChunkSize
|
||||
)) {
|
||||
await buf.store(chunk);
|
||||
}
|
||||
// Array of failed records.
|
||||
|
@ -800,11 +805,11 @@ BookmarksTracker.prototype = {
|
|||
__proto__: Tracker.prototype,
|
||||
|
||||
onStart() {
|
||||
PlacesUtils.bookmarks.addObserver(this, true);
|
||||
lazy.PlacesUtils.bookmarks.addObserver(this, true);
|
||||
this._placesListener = new PlacesWeakCallbackWrapper(
|
||||
this.handlePlacesEvents.bind(this)
|
||||
);
|
||||
PlacesUtils.observers.addListener(
|
||||
lazy.PlacesUtils.observers.addListener(
|
||||
[
|
||||
"bookmark-added",
|
||||
"bookmark-removed",
|
||||
|
@ -822,8 +827,8 @@ BookmarksTracker.prototype = {
|
|||
},
|
||||
|
||||
onStop() {
|
||||
PlacesUtils.bookmarks.removeObserver(this);
|
||||
PlacesUtils.observers.removeListener(
|
||||
lazy.PlacesUtils.bookmarks.removeObserver(this);
|
||||
lazy.PlacesUtils.observers.removeListener(
|
||||
[
|
||||
"bookmark-added",
|
||||
"bookmark-removed",
|
||||
|
@ -841,7 +846,7 @@ BookmarksTracker.prototype = {
|
|||
},
|
||||
|
||||
async getChangedIDs() {
|
||||
return PlacesSyncUtils.bookmarks.pullChanges();
|
||||
return lazy.PlacesSyncUtils.bookmarks.pullChanges();
|
||||
},
|
||||
|
||||
observe(subject, topic, data) {
|
||||
|
@ -892,7 +897,7 @@ BookmarksTracker.prototype = {
|
|||
case "bookmark-time-changed":
|
||||
case "bookmark-title-changed":
|
||||
case "bookmark-url-changed":
|
||||
if (IGNORED_SOURCES.includes(event.source)) {
|
||||
if (lazy.IGNORED_SOURCES.includes(event.source)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -923,11 +928,11 @@ BookmarksTracker.prototype = {
|
|||
oldValue,
|
||||
source
|
||||
) {
|
||||
if (IGNORED_SOURCES.includes(source)) {
|
||||
if (lazy.IGNORED_SOURCES.includes(source)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isAnno && !ANNOS_TO_TRACK.includes(property)) {
|
||||
if (isAnno && !lazy.ANNOS_TO_TRACK.includes(property)) {
|
||||
// Ignore annotations except for the ones that we sync.
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -43,7 +43,10 @@ const { Svc, Utils } = ChromeUtils.import("resource://services-sync/util.js");
|
|||
const { XPCOMUtils } = ChromeUtils.import(
|
||||
"resource://gre/modules/XPCOMUtils.jsm"
|
||||
);
|
||||
XPCOMUtils.defineLazyGetter(this, "fxAccounts", () => {
|
||||
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyGetter(lazy, "fxAccounts", () => {
|
||||
return ChromeUtils.import(
|
||||
"resource://gre/modules/FxAccounts.jsm"
|
||||
).getFxAccountsSingleton();
|
||||
|
@ -108,7 +111,7 @@ Utils.deferGetSet(ClientsRec, "cleartext", [
|
|||
function ClientEngine(service) {
|
||||
SyncEngine.call(this, "Clients", service);
|
||||
|
||||
this.fxAccounts = fxAccounts;
|
||||
this.fxAccounts = lazy.fxAccounts;
|
||||
this.addClientCommandQueue = Async.asyncQueueCaller(this._log);
|
||||
Utils.defineLazyIDProperty(this, "localID", "services.sync.client.GUID");
|
||||
}
|
||||
|
@ -377,7 +380,7 @@ ClientEngine.prototype = {
|
|||
this._log.debug("Updating the known stale clients");
|
||||
// _fetchFxADevices side effect updates this._knownStaleFxADeviceIds.
|
||||
await this._fetchFxADevices();
|
||||
let localFxADeviceId = await fxAccounts.device.getLocalId();
|
||||
let localFxADeviceId = await lazy.fxAccounts.device.getLocalId();
|
||||
// Process newer records first, so that if we hit a record with a device ID
|
||||
// we've seen before, we can mark it stale immediately.
|
||||
let clientList = Object.values(this._store._remoteClients).sort(
|
||||
|
@ -462,7 +465,7 @@ ClientEngine.prototype = {
|
|||
await this._removeRemoteClient(id);
|
||||
}
|
||||
}
|
||||
let localFxADeviceId = await fxAccounts.device.getLocalId();
|
||||
let localFxADeviceId = await lazy.fxAccounts.device.getLocalId();
|
||||
// Bug 1264498: Mobile clients don't remove themselves from the clients
|
||||
// collection when the user disconnects Sync, so we mark as stale clients
|
||||
// with the same name that haven't synced in over a week.
|
||||
|
@ -632,7 +635,7 @@ ClientEngine.prototype = {
|
|||
};
|
||||
let excludedIds = null;
|
||||
if (!ids) {
|
||||
const localFxADeviceId = await fxAccounts.device.getLocalId();
|
||||
const localFxADeviceId = await lazy.fxAccounts.device.getLocalId();
|
||||
excludedIds = [localFxADeviceId];
|
||||
}
|
||||
try {
|
||||
|
|
|
@ -13,7 +13,9 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
"resource://gre/modules/XPCOMUtils.jsm"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
BridgedEngine: "resource://services-sync/bridged_engine.js",
|
||||
LogAdapter: "resource://services-sync/bridged_engine.js",
|
||||
extensionStorageSync: "resource://gre/modules/ExtensionStorageSync.jsm",
|
||||
|
@ -26,14 +28,14 @@ XPCOMUtils.defineLazyModuleGetters(this, {
|
|||
});
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"extensionStorageSyncKinto",
|
||||
"resource://gre/modules/ExtensionStorageSyncKinto.jsm",
|
||||
"extensionStorageSync"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"StorageSyncService",
|
||||
"@mozilla.org/extensions/storage/sync;1",
|
||||
"nsIInterfaceRequestor"
|
||||
|
@ -50,11 +52,11 @@ 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 = Svc.Prefs.get(PREF_FORCE_ENABLE, undefined);
|
||||
const forced = lazy.Svc.Prefs.get(PREF_FORCE_ENABLE, undefined);
|
||||
if (forced !== undefined) {
|
||||
return forced;
|
||||
}
|
||||
return Svc.Prefs.get("engine.addons", false);
|
||||
return lazy.Svc.Prefs.get("engine.addons", false);
|
||||
}
|
||||
|
||||
function setEngineEnabled(enabled) {
|
||||
|
@ -65,25 +67,25 @@ 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 (Svc.Prefs.has(PREF_FORCE_ENABLE)) {
|
||||
Svc.Prefs.set(PREF_FORCE_ENABLE, enabled);
|
||||
if (lazy.Svc.Prefs.has(PREF_FORCE_ENABLE)) {
|
||||
lazy.Svc.Prefs.set(PREF_FORCE_ENABLE, enabled);
|
||||
}
|
||||
}
|
||||
|
||||
// A "bridged engine" to our webext-storage component.
|
||||
function ExtensionStorageEngineBridge(service) {
|
||||
let bridge = StorageSyncService.getInterface(Ci.mozIBridgedSyncEngine);
|
||||
BridgedEngine.call(this, bridge, "Extension-Storage", service);
|
||||
let bridge = lazy.StorageSyncService.getInterface(Ci.mozIBridgedSyncEngine);
|
||||
lazy.BridgedEngine.call(this, bridge, "Extension-Storage", service);
|
||||
|
||||
let app_services_logger = Cc["@mozilla.org/appservices/logger;1"].getService(
|
||||
Ci.mozIAppServicesLogger
|
||||
);
|
||||
let logger_target = "app-services:webext_storage:sync";
|
||||
app_services_logger.register(logger_target, new LogAdapter(this._log));
|
||||
app_services_logger.register(logger_target, new lazy.LogAdapter(this._log));
|
||||
}
|
||||
|
||||
ExtensionStorageEngineBridge.prototype = {
|
||||
__proto__: BridgedEngine.prototype,
|
||||
__proto__: lazy.BridgedEngine.prototype,
|
||||
syncPriority: 10,
|
||||
|
||||
// Used to override the engine name in telemetry, so that we can distinguish .
|
||||
|
@ -100,7 +102,10 @@ ExtensionStorageEngineBridge.prototype = {
|
|||
]),
|
||||
onChanged: (extId, json) => {
|
||||
try {
|
||||
extensionStorageSync.notifyListeners(extId, JSON.parse(json));
|
||||
lazy.extensionStorageSync.notifyListeners(
|
||||
extId,
|
||||
JSON.parse(json)
|
||||
);
|
||||
} catch (ex) {
|
||||
this._log.warn(
|
||||
`Error notifying change listeners for ${extId}`,
|
||||
|
@ -151,7 +156,11 @@ ExtensionStorageEngineBridge.prototype = {
|
|||
let result = await super._syncStartup();
|
||||
let info = await this._takeMigrationInfo();
|
||||
if (info) {
|
||||
Observers.notify("weave:telemetry:migration", info, "webext-storage");
|
||||
lazy.Observers.notify(
|
||||
"weave:telemetry:migration",
|
||||
info,
|
||||
"webext-storage"
|
||||
);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
@ -192,7 +201,7 @@ ExtensionStorageEngineBridge.prototype = {
|
|||
* framework, so this is something of a stub.
|
||||
*/
|
||||
function ExtensionStorageEngineKinto(service) {
|
||||
SyncEngine.call(this, "Extension-Storage", service);
|
||||
lazy.SyncEngine.call(this, "Extension-Storage", service);
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
this,
|
||||
"_skipPercentageChance",
|
||||
|
@ -201,7 +210,7 @@ function ExtensionStorageEngineKinto(service) {
|
|||
);
|
||||
}
|
||||
ExtensionStorageEngineKinto.prototype = {
|
||||
__proto__: SyncEngine.prototype,
|
||||
__proto__: lazy.SyncEngine.prototype,
|
||||
_trackerObj: ExtensionStorageTracker,
|
||||
// we don't need these since we implement our own sync logic
|
||||
_storeObj: undefined,
|
||||
|
@ -211,7 +220,7 @@ ExtensionStorageEngineKinto.prototype = {
|
|||
allowSkippedRecord: false,
|
||||
|
||||
async _sync() {
|
||||
return extensionStorageSyncKinto.syncAll();
|
||||
return lazy.extensionStorageSyncKinto.syncAll();
|
||||
},
|
||||
|
||||
get enabled() {
|
||||
|
@ -225,7 +234,7 @@ ExtensionStorageEngineKinto.prototype = {
|
|||
},
|
||||
|
||||
_wipeClient() {
|
||||
return extensionStorageSyncKinto.clearAll();
|
||||
return lazy.extensionStorageSyncKinto.clearAll();
|
||||
},
|
||||
|
||||
shouldSkipSync(syncReason) {
|
||||
|
@ -237,7 +246,7 @@ ExtensionStorageEngineKinto.prototype = {
|
|||
return false;
|
||||
}
|
||||
// Ensure this wouldn't cause a resync...
|
||||
if (this._tracker.score >= MULTI_DEVICE_THRESHOLD) {
|
||||
if (this._tracker.score >= lazy.MULTI_DEVICE_THRESHOLD) {
|
||||
this._log.info(
|
||||
"Not skipping extension storage sync: Would trigger resync anyway"
|
||||
);
|
||||
|
@ -257,11 +266,11 @@ ExtensionStorageEngineKinto.prototype = {
|
|||
};
|
||||
|
||||
function ExtensionStorageTracker(name, engine) {
|
||||
Tracker.call(this, name, engine);
|
||||
lazy.Tracker.call(this, name, engine);
|
||||
this._ignoreAll = false;
|
||||
}
|
||||
ExtensionStorageTracker.prototype = {
|
||||
__proto__: Tracker.prototype,
|
||||
__proto__: lazy.Tracker.prototype,
|
||||
|
||||
get ignoreAll() {
|
||||
return this._ignoreAll;
|
||||
|
@ -272,11 +281,11 @@ ExtensionStorageTracker.prototype = {
|
|||
},
|
||||
|
||||
onStart() {
|
||||
Svc.Obs.add("ext.storage.sync-changed", this.asyncObserver);
|
||||
lazy.Svc.Obs.add("ext.storage.sync-changed", this.asyncObserver);
|
||||
},
|
||||
|
||||
onStop() {
|
||||
Svc.Obs.remove("ext.storage.sync-changed", this.asyncObserver);
|
||||
lazy.Svc.Obs.remove("ext.storage.sync-changed", this.asyncObserver);
|
||||
},
|
||||
|
||||
async observe(subject, topic, data) {
|
||||
|
@ -290,6 +299,6 @@ ExtensionStorageTracker.prototype = {
|
|||
|
||||
// Single adds, removes and changes are not so important on their
|
||||
// own, so let's just increment score a bit.
|
||||
this.score += SCORE_INCREMENT_MEDIUM;
|
||||
this.score += lazy.SCORE_INCREMENT_MEDIUM;
|
||||
},
|
||||
};
|
||||
|
|
|
@ -19,8 +19,9 @@ const { CollectionProblemData, CollectionValidator } = ChromeUtils.import(
|
|||
);
|
||||
const { Async } = ChromeUtils.import("resource://services-common/async.js");
|
||||
const { Log } = ChromeUtils.import("resource://gre/modules/Log.jsm");
|
||||
const lazy = {};
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"FormHistory",
|
||||
"resource://gre/modules/FormHistory.jsm"
|
||||
);
|
||||
|
@ -55,12 +56,12 @@ var FormWrapper = {
|
|||
resolve(results);
|
||||
},
|
||||
};
|
||||
FormHistory.search(terms, searchData, callbacks);
|
||||
lazy.FormHistory.search(terms, searchData, callbacks);
|
||||
});
|
||||
},
|
||||
|
||||
async _update(changes) {
|
||||
if (!FormHistory.enabled) {
|
||||
if (!lazy.FormHistory.enabled) {
|
||||
return; // update isn't going to do anything.
|
||||
}
|
||||
await new Promise(resolve => {
|
||||
|
@ -69,7 +70,7 @@ var FormWrapper = {
|
|||
resolve();
|
||||
},
|
||||
};
|
||||
FormHistory.update(changes, callbacks);
|
||||
lazy.FormHistory.update(changes, callbacks);
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -25,14 +25,16 @@ const { CryptoWrapper } = ChromeUtils.import(
|
|||
);
|
||||
const { Utils } = ChromeUtils.import("resource://services-sync/util.js");
|
||||
|
||||
const lazy = {};
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"PlacesUtils",
|
||||
"resource://gre/modules/PlacesUtils.jsm"
|
||||
);
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"PlacesSyncUtils",
|
||||
"resource://gre/modules/PlacesSyncUtils.jsm"
|
||||
);
|
||||
|
@ -61,7 +63,7 @@ HistoryEngine.prototype = {
|
|||
syncPriority: 7,
|
||||
|
||||
async getSyncID() {
|
||||
return PlacesSyncUtils.history.getSyncId();
|
||||
return lazy.PlacesSyncUtils.history.getSyncId();
|
||||
},
|
||||
|
||||
async ensureCurrentSyncID(newSyncID) {
|
||||
|
@ -69,7 +71,7 @@ HistoryEngine.prototype = {
|
|||
"Checking if server sync ID ${newSyncID} matches existing",
|
||||
{ newSyncID }
|
||||
);
|
||||
await PlacesSyncUtils.history.ensureCurrentSyncId(newSyncID);
|
||||
await lazy.PlacesSyncUtils.history.ensureCurrentSyncId(newSyncID);
|
||||
return newSyncID;
|
||||
},
|
||||
|
||||
|
@ -83,18 +85,18 @@ HistoryEngine.prototype = {
|
|||
},
|
||||
|
||||
async resetLocalSyncID() {
|
||||
let newSyncID = await PlacesSyncUtils.history.resetSyncId();
|
||||
let newSyncID = await lazy.PlacesSyncUtils.history.resetSyncId();
|
||||
this._log.debug("Assigned new sync ID ${newSyncID}", { newSyncID });
|
||||
return newSyncID;
|
||||
},
|
||||
|
||||
async getLastSync() {
|
||||
let lastSync = await PlacesSyncUtils.history.getLastSync();
|
||||
let lastSync = await lazy.PlacesSyncUtils.history.getLastSync();
|
||||
return lastSync;
|
||||
},
|
||||
|
||||
async setLastSync(lastSync) {
|
||||
await PlacesSyncUtils.history.setLastSync(lastSync);
|
||||
await lazy.PlacesSyncUtils.history.setLastSync(lastSync);
|
||||
},
|
||||
|
||||
shouldSyncURL(url) {
|
||||
|
@ -108,7 +110,7 @@ HistoryEngine.prototype = {
|
|||
return {};
|
||||
}
|
||||
|
||||
let guidsToRemove = await PlacesSyncUtils.history.determineNonSyncableGuids(
|
||||
let guidsToRemove = await lazy.PlacesSyncUtils.history.determineNonSyncableGuids(
|
||||
modifiedGUIDs
|
||||
);
|
||||
await this._tracker.removeChangedID(...guidsToRemove);
|
||||
|
@ -117,7 +119,7 @@ HistoryEngine.prototype = {
|
|||
|
||||
async _resetClient() {
|
||||
await super._resetClient();
|
||||
await PlacesSyncUtils.history.reset();
|
||||
await lazy.PlacesSyncUtils.history.reset();
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -138,7 +140,7 @@ HistoryStore.prototype = {
|
|||
}
|
||||
|
||||
try {
|
||||
await PlacesSyncUtils.history.changeGuid(uri, guid);
|
||||
await lazy.PlacesSyncUtils.history.changeGuid(uri, guid);
|
||||
} catch (e) {
|
||||
this._log.error("Error setting GUID ${guid} for URI ${uri}", guid, uri);
|
||||
}
|
||||
|
@ -150,7 +152,7 @@ HistoryStore.prototype = {
|
|||
// Use the existing GUID if it exists
|
||||
let guid;
|
||||
try {
|
||||
guid = await PlacesSyncUtils.history.fetchGuidForURL(uri);
|
||||
guid = await lazy.PlacesSyncUtils.history.fetchGuidForURL(uri);
|
||||
} catch (e) {
|
||||
this._log.error("Error fetching GUID for URL ${uri}", uri);
|
||||
}
|
||||
|
@ -170,7 +172,7 @@ HistoryStore.prototype = {
|
|||
},
|
||||
|
||||
async changeItemID(oldID, newID) {
|
||||
let info = await PlacesSyncUtils.history.fetchURLInfoForGuid(oldID);
|
||||
let info = await lazy.PlacesSyncUtils.history.fetchURLInfoForGuid(oldID);
|
||||
if (!info) {
|
||||
throw new Error(`Can't change ID for nonexistent history entry ${oldID}`);
|
||||
}
|
||||
|
@ -178,7 +180,7 @@ HistoryStore.prototype = {
|
|||
},
|
||||
|
||||
async getAllIDs() {
|
||||
let urls = await PlacesSyncUtils.history.getAllURLs({
|
||||
let urls = await lazy.PlacesSyncUtils.history.getAllURLs({
|
||||
since: new Date(Date.now() - THIRTY_DAYS_IN_MS),
|
||||
limit: MAX_HISTORY_UPLOAD,
|
||||
});
|
||||
|
@ -244,14 +246,18 @@ HistoryStore.prototype = {
|
|||
// and log the exceptions seen there as they are likely to be
|
||||
// informative, but we still never abort the sync based on them.
|
||||
try {
|
||||
await PlacesUtils.history.insertMany(chunk, null, failedVisit => {
|
||||
this._log.info(
|
||||
"Failed to insert a history record",
|
||||
failedVisit.guid
|
||||
);
|
||||
this._log.trace("The record that failed", failedVisit);
|
||||
failed.push(failedVisit.guid);
|
||||
});
|
||||
await lazy.PlacesUtils.history.insertMany(
|
||||
chunk,
|
||||
null,
|
||||
failedVisit => {
|
||||
this._log.info(
|
||||
"Failed to insert a history record",
|
||||
failedVisit.guid
|
||||
);
|
||||
this._log.trace("The record that failed", failedVisit);
|
||||
failed.push(failedVisit.guid);
|
||||
}
|
||||
);
|
||||
} catch (ex) {
|
||||
this._log.info("Failed to insert history records", ex);
|
||||
}
|
||||
|
@ -300,7 +306,7 @@ HistoryStore.prototype = {
|
|||
Exists primarily so tests can override it.
|
||||
*/
|
||||
_canAddURI(uri) {
|
||||
return PlacesUtils.history.canAddURI(uri);
|
||||
return lazy.PlacesUtils.history.canAddURI(uri);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -312,7 +318,7 @@ HistoryStore.prototype = {
|
|||
*/
|
||||
async _recordToPlaceInfo(record) {
|
||||
// Sort out invalid URIs and ones Places just simply doesn't want.
|
||||
record.url = PlacesUtils.normalizeToURLOrGUID(record.histUri);
|
||||
record.url = lazy.PlacesUtils.normalizeToURLOrGUID(record.histUri);
|
||||
record.uri = CommonUtils.makeURI(record.histUri);
|
||||
|
||||
if (!Utils.checkGUID(record.id)) {
|
||||
|
@ -342,7 +348,7 @@ HistoryStore.prototype = {
|
|||
let curVisitsAsArray = [];
|
||||
let curVisits = new Set();
|
||||
try {
|
||||
curVisitsAsArray = await PlacesSyncUtils.history.fetchVisitsForURL(
|
||||
curVisitsAsArray = await lazy.PlacesSyncUtils.history.fetchVisitsForURL(
|
||||
record.histUri
|
||||
);
|
||||
} catch (e) {
|
||||
|
@ -351,11 +357,12 @@ HistoryStore.prototype = {
|
|||
record.histUri
|
||||
);
|
||||
}
|
||||
let oldestAllowed = PlacesSyncUtils.bookmarks.EARLIEST_BOOKMARK_TIMESTAMP;
|
||||
let oldestAllowed =
|
||||
lazy.PlacesSyncUtils.bookmarks.EARLIEST_BOOKMARK_TIMESTAMP;
|
||||
if (curVisitsAsArray.length == 20) {
|
||||
let oldestVisit = curVisitsAsArray[curVisitsAsArray.length - 1];
|
||||
oldestAllowed = PlacesSyncUtils.history.clampVisitDate(
|
||||
PlacesUtils.toDate(oldestVisit.date).getTime()
|
||||
oldestAllowed = lazy.PlacesSyncUtils.history.clampVisitDate(
|
||||
lazy.PlacesUtils.toDate(oldestVisit.date).getTime()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -363,8 +370,10 @@ HistoryStore.prototype = {
|
|||
for (i = 0; i < curVisitsAsArray.length; i++) {
|
||||
// Same logic as used in the loop below to generate visitKey.
|
||||
let { date, type } = curVisitsAsArray[i];
|
||||
let dateObj = PlacesUtils.toDate(date);
|
||||
let millis = PlacesSyncUtils.history.clampVisitDate(dateObj).getTime();
|
||||
let dateObj = lazy.PlacesUtils.toDate(date);
|
||||
let millis = lazy.PlacesSyncUtils.history
|
||||
.clampVisitDate(dateObj)
|
||||
.getTime();
|
||||
curVisits.add(`${millis},${type}`);
|
||||
}
|
||||
|
||||
|
@ -386,7 +395,9 @@ HistoryStore.prototype = {
|
|||
|
||||
if (
|
||||
!visit.type ||
|
||||
!Object.values(PlacesUtils.history.TRANSITIONS).includes(visit.type)
|
||||
!Object.values(lazy.PlacesUtils.history.TRANSITIONS).includes(
|
||||
visit.type
|
||||
)
|
||||
) {
|
||||
this._log.warn(
|
||||
"Encountered record with invalid visit type: " +
|
||||
|
@ -398,8 +409,10 @@ HistoryStore.prototype = {
|
|||
|
||||
// Dates need to be integers. Future and far past dates are clamped to the
|
||||
// current date and earliest sensible date, respectively.
|
||||
let originalVisitDate = PlacesUtils.toDate(Math.round(visit.date));
|
||||
visit.date = PlacesSyncUtils.history.clampVisitDate(originalVisitDate);
|
||||
let originalVisitDate = lazy.PlacesUtils.toDate(Math.round(visit.date));
|
||||
visit.date = lazy.PlacesSyncUtils.history.clampVisitDate(
|
||||
originalVisitDate
|
||||
);
|
||||
|
||||
if (visit.date.getTime() < oldestAllowed) {
|
||||
// Visit is older than the oldest visit we have, and we have so many
|
||||
|
@ -452,7 +465,7 @@ HistoryStore.prototype = {
|
|||
|
||||
async remove(record) {
|
||||
this._log.trace("Removing page: " + record.id);
|
||||
let removed = await PlacesUtils.history.remove(record.id);
|
||||
let removed = await lazy.PlacesUtils.history.remove(record.id);
|
||||
if (removed) {
|
||||
this._log.trace("Removed page: " + record.id);
|
||||
} else {
|
||||
|
@ -461,18 +474,18 @@ HistoryStore.prototype = {
|
|||
},
|
||||
|
||||
async itemExists(id) {
|
||||
return !!(await PlacesSyncUtils.history.fetchURLInfoForGuid(id));
|
||||
return !!(await lazy.PlacesSyncUtils.history.fetchURLInfoForGuid(id));
|
||||
},
|
||||
|
||||
async createRecord(id, collection) {
|
||||
let foo = await PlacesSyncUtils.history.fetchURLInfoForGuid(id);
|
||||
let foo = await lazy.PlacesSyncUtils.history.fetchURLInfoForGuid(id);
|
||||
let record = new HistoryRec(collection, id);
|
||||
if (foo) {
|
||||
record.histUri = foo.url;
|
||||
record.title = foo.title;
|
||||
record.sortindex = foo.frecency;
|
||||
try {
|
||||
record.visits = await PlacesSyncUtils.history.fetchVisitsForURL(
|
||||
record.visits = await lazy.PlacesSyncUtils.history.fetchVisitsForURL(
|
||||
record.histUri
|
||||
);
|
||||
} catch (e) {
|
||||
|
@ -490,7 +503,7 @@ HistoryStore.prototype = {
|
|||
},
|
||||
|
||||
async wipe() {
|
||||
return PlacesSyncUtils.history.wipe();
|
||||
return lazy.PlacesSyncUtils.history.wipe();
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -27,12 +27,14 @@ const { CommonUtils } = ChromeUtils.import(
|
|||
"resource://services-common/utils.js"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "PREFS_GUID", () =>
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyGetter(lazy, "PREFS_GUID", () =>
|
||||
CommonUtils.encodeBase64URL(Services.appinfo.ID)
|
||||
);
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"AddonManager",
|
||||
"resource://gre/modules/AddonManager.jsm"
|
||||
);
|
||||
|
@ -48,7 +50,7 @@ const PREF_SYNC_PREFS_ARBITRARY =
|
|||
"services.sync.prefs.dangerously_allow_arbitrary";
|
||||
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"ALLOW_ARBITRARY",
|
||||
PREF_SYNC_PREFS_ARBITRARY
|
||||
);
|
||||
|
@ -57,7 +59,7 @@ XPCOMUtils.defineLazyPreferenceGetter(
|
|||
// continue to be synced. SUMO have told us that this URL will remain "stable".
|
||||
const PREFS_DOC_URL_TEMPLATE =
|
||||
"https://support.mozilla.org/1/firefox/%VERSION%/%OS%/%LOCALE%/sync-custom-preferences";
|
||||
XPCOMUtils.defineLazyGetter(this, "PREFS_DOC_URL", () =>
|
||||
XPCOMUtils.defineLazyGetter(lazy, "PREFS_DOC_URL", () =>
|
||||
Services.urlFormatter.formatURL(PREFS_DOC_URL_TEMPLATE)
|
||||
);
|
||||
|
||||
|
@ -66,7 +68,7 @@ function isAllowedPrefName(prefName) {
|
|||
if (prefName == PREF_SYNC_PREFS_ARBITRARY) {
|
||||
return false; // never allow this.
|
||||
}
|
||||
if (ALLOW_ARBITRARY) {
|
||||
if (lazy.ALLOW_ARBITRARY) {
|
||||
// user has set the "dangerous" pref, so everything is allowed.
|
||||
return true;
|
||||
}
|
||||
|
@ -109,7 +111,7 @@ PrefsEngine.prototype = {
|
|||
// No need for a proper timestamp (no conflict resolution needed).
|
||||
let changedIDs = {};
|
||||
if (this._tracker.modified) {
|
||||
changedIDs[PREFS_GUID] = 0;
|
||||
changedIDs[lazy.PREFS_GUID] = 0;
|
||||
}
|
||||
return changedIDs;
|
||||
},
|
||||
|
@ -252,7 +254,7 @@ PrefStore.prototype = {
|
|||
`Not syncing the preference '${pref}' because it has no local ` +
|
||||
`control preference (${PREF_SYNC_PREFS_PREFIX}${pref}) and ` +
|
||||
`the preference ${PREF_SYNC_PREFS_ARBITRARY} isn't true. ` +
|
||||
`See ${PREFS_DOC_URL} for more information`;
|
||||
`See ${lazy.PREFS_DOC_URL} for more information`;
|
||||
console.warn(msg);
|
||||
this._log.warn(msg);
|
||||
}
|
||||
|
@ -300,7 +302,7 @@ PrefStore.prototype = {
|
|||
async _maybeEnableBuiltinTheme(themeId) {
|
||||
let addon = null;
|
||||
try {
|
||||
addon = await AddonManager.getAddonByID(themeId);
|
||||
addon = await lazy.AddonManager.getAddonByID(themeId);
|
||||
} catch (ex) {
|
||||
this._log.trace(
|
||||
`There's no addon with ID '${themeId} - it can't be a builtin theme`
|
||||
|
@ -320,7 +322,7 @@ PrefStore.prototype = {
|
|||
async getAllIDs() {
|
||||
/* We store all prefs in just one WBO, with just one GUID */
|
||||
let allprefs = {};
|
||||
allprefs[PREFS_GUID] = true;
|
||||
allprefs[lazy.PREFS_GUID] = true;
|
||||
return allprefs;
|
||||
},
|
||||
|
||||
|
@ -329,13 +331,13 @@ PrefStore.prototype = {
|
|||
},
|
||||
|
||||
async itemExists(id) {
|
||||
return id === PREFS_GUID;
|
||||
return id === lazy.PREFS_GUID;
|
||||
},
|
||||
|
||||
async createRecord(id, collection) {
|
||||
let record = new PrefRec(collection, id);
|
||||
|
||||
if (id == PREFS_GUID) {
|
||||
if (id == lazy.PREFS_GUID) {
|
||||
record.value = this._getAllPrefs();
|
||||
} else {
|
||||
record.deleted = true;
|
||||
|
@ -354,7 +356,7 @@ PrefStore.prototype = {
|
|||
|
||||
async update(record) {
|
||||
// Silently ignore pref updates that are for other apps.
|
||||
if (record.id != PREFS_GUID) {
|
||||
if (record.id != lazy.PREFS_GUID) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -436,5 +438,5 @@ PrefTracker.prototype = {
|
|||
};
|
||||
|
||||
function getPrefsGUIDForTest() {
|
||||
return PREFS_GUID;
|
||||
return lazy.PREFS_GUID;
|
||||
}
|
||||
|
|
|
@ -26,33 +26,35 @@ const { SCORE_INCREMENT_SMALL, URI_LENGTH_MAX } = ChromeUtils.import(
|
|||
"resource://services-sync/constants.js"
|
||||
);
|
||||
|
||||
const lazy = {};
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"PrivateBrowsingUtils",
|
||||
"resource://gre/modules/PrivateBrowsingUtils.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"SessionStore",
|
||||
"resource:///modules/sessionstore/SessionStore.jsm"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
PlacesUtils: "resource://gre/modules/PlacesUtils.jsm",
|
||||
});
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"ExperimentAPI",
|
||||
"resource://nimbus/ExperimentAPI.jsm"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
NimbusFeatures: "resource://nimbus/ExperimentAPI.jsm",
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"TABS_FILTERED_SCHEMES",
|
||||
"services.sync.engine.tabs.filteredSchemes",
|
||||
"",
|
||||
|
@ -155,11 +157,11 @@ TabStore.prototype = {
|
|||
},
|
||||
|
||||
shouldSkipWindow(win) {
|
||||
return win.closed || PrivateBrowsingUtils.isWindowPrivate(win);
|
||||
return win.closed || lazy.PrivateBrowsingUtils.isWindowPrivate(win);
|
||||
},
|
||||
|
||||
getTabState(tab) {
|
||||
return JSON.parse(SessionStore.getTabState(tab));
|
||||
return JSON.parse(lazy.SessionStore.getTabState(tab));
|
||||
},
|
||||
|
||||
async getAllTabs(filter) {
|
||||
|
@ -190,7 +192,8 @@ TabStore.prototype = {
|
|||
let acceptable = !filter
|
||||
? url => url
|
||||
: url =>
|
||||
url && !TABS_FILTERED_SCHEMES.has(Services.io.extractScheme(url));
|
||||
url &&
|
||||
!lazy.TABS_FILTERED_SCHEMES.has(Services.io.extractScheme(url));
|
||||
|
||||
let entries = tabState.entries;
|
||||
let index = tabState.index;
|
||||
|
@ -226,7 +229,7 @@ TabStore.prototype = {
|
|||
// tabState has .image, but it's a large data: url. So we ask the favicon service for the url.
|
||||
let icon = "";
|
||||
try {
|
||||
let iconData = await PlacesUtils.promiseFaviconData(urls[0]);
|
||||
let iconData = await lazy.PlacesUtils.promiseFaviconData(urls[0]);
|
||||
icon = iconData.uri.spec;
|
||||
} catch (ex) {
|
||||
this._log.trace(`Failed to fetch favicon for ${urls[0]}`, ex);
|
||||
|
@ -276,7 +279,7 @@ TabStore.prototype = {
|
|||
let ids = {};
|
||||
let allWindowsArePrivate = false;
|
||||
for (let win of Services.wm.getEnumerator("navigator:browser")) {
|
||||
if (PrivateBrowsingUtils.isWindowPrivate(win)) {
|
||||
if (lazy.PrivateBrowsingUtils.isWindowPrivate(win)) {
|
||||
// Ensure that at least there is a private window.
|
||||
allWindowsArePrivate = true;
|
||||
} else {
|
||||
|
@ -288,7 +291,7 @@ TabStore.prototype = {
|
|||
|
||||
if (
|
||||
allWindowsArePrivate &&
|
||||
!PrivateBrowsingUtils.permanentPrivateBrowsing
|
||||
!lazy.PrivateBrowsingUtils.permanentPrivateBrowsing
|
||||
) {
|
||||
return ids;
|
||||
}
|
||||
|
@ -391,8 +394,8 @@ TabTracker.prototype = {
|
|||
if (event.originalTarget.linkedBrowser) {
|
||||
let browser = event.originalTarget.linkedBrowser;
|
||||
if (
|
||||
PrivateBrowsingUtils.isBrowserPrivate(browser) &&
|
||||
!PrivateBrowsingUtils.permanentPrivateBrowsing
|
||||
lazy.PrivateBrowsingUtils.isBrowserPrivate(browser) &&
|
||||
!lazy.PrivateBrowsingUtils.permanentPrivateBrowsing
|
||||
) {
|
||||
this._log.trace("Ignoring tab event from private browsing.");
|
||||
return;
|
||||
|
@ -417,7 +420,7 @@ TabTracker.prototype = {
|
|||
|
||||
// Synced tabs do not sync certain urls, we should ignore scheduling a sync
|
||||
// if we have navigate to one of those urls
|
||||
if (TABS_FILTERED_SCHEMES.has(locationURI.scheme)) {
|
||||
if (lazy.TABS_FILTERED_SCHEMES.has(locationURI.scheme)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -427,7 +430,7 @@ TabTracker.prototype = {
|
|||
callScheduleSync(scoreIncrement) {
|
||||
this.modified = true;
|
||||
|
||||
const delayInMs = NimbusFeatures.syncAfterTabChange.getVariable(
|
||||
const delayInMs = lazy.NimbusFeatures.syncAfterTabChange.getVariable(
|
||||
"syncDelayAfterTabChange"
|
||||
);
|
||||
|
||||
|
|
|
@ -46,29 +46,31 @@ const { CommonUtils } = ChromeUtils.import(
|
|||
"resource://services-common/utils.js"
|
||||
);
|
||||
|
||||
const lazy = {};
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"Status",
|
||||
"resource://services-sync/status.js"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"AddonManager",
|
||||
"resource://gre/modules/AddonManager.jsm"
|
||||
);
|
||||
XPCOMUtils.defineLazyGetter(this, "fxAccounts", () => {
|
||||
XPCOMUtils.defineLazyGetter(lazy, "fxAccounts", () => {
|
||||
return ChromeUtils.import(
|
||||
"resource://gre/modules/FxAccounts.jsm"
|
||||
).getFxAccountsSingleton();
|
||||
});
|
||||
XPCOMUtils.defineLazyServiceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"IdleService",
|
||||
"@mozilla.org/widget/useridleservice;1",
|
||||
"nsIUserIdleService"
|
||||
);
|
||||
XPCOMUtils.defineLazyServiceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"CaptivePortalService",
|
||||
"@mozilla.org/network/captive-portal-service;1",
|
||||
"nsICaptivePortalService"
|
||||
|
@ -206,7 +208,8 @@ SyncScheduler.prototype = {
|
|||
try {
|
||||
if (
|
||||
Services.io.offline ||
|
||||
CaptivePortalService.state == CaptivePortalService.LOCKED_PORTAL
|
||||
lazy.CaptivePortalService.state ==
|
||||
lazy.CaptivePortalService.LOCKED_PORTAL
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
@ -287,11 +290,11 @@ SyncScheduler.prototype = {
|
|||
Svc.Obs.add("weave:service:start-over", this);
|
||||
Svc.Obs.add("FxA:hawk:backoff:interval", this);
|
||||
|
||||
if (Status.checkSetup() == STATUS_OK) {
|
||||
if (lazy.Status.checkSetup() == STATUS_OK) {
|
||||
Svc.Obs.add("wake_notification", this);
|
||||
Svc.Obs.add("captive-portal-login-success", this);
|
||||
Svc.Obs.add("sleep_notification", this);
|
||||
IdleService.addIdleObserver(this, this.idleTime);
|
||||
lazy.IdleService.addIdleObserver(this, this.idleTime);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -300,7 +303,7 @@ SyncScheduler.prototype = {
|
|||
this._log.trace("Handling " + topic);
|
||||
switch (topic) {
|
||||
case "weave:engine:score:updated":
|
||||
if (Status.login == LOGIN_SUCCEEDED) {
|
||||
if (lazy.Status.login == LOGIN_SUCCEEDED) {
|
||||
CommonUtils.namedTimer(
|
||||
this.calculateScore,
|
||||
SCORE_UPDATE_DELAY,
|
||||
|
@ -345,7 +348,7 @@ SyncScheduler.prototype = {
|
|||
|
||||
// reset backoff info, if the server tells us to continue backing off,
|
||||
// we'll handle that later
|
||||
Status.resetBackoff();
|
||||
lazy.Status.resetBackoff();
|
||||
|
||||
this.globalScore = 0;
|
||||
break;
|
||||
|
@ -353,7 +356,10 @@ SyncScheduler.prototype = {
|
|||
this.nextSync = 0;
|
||||
this.adjustSyncInterval();
|
||||
|
||||
if (Status.service == SYNC_FAILED_PARTIAL && this.requiresBackoff) {
|
||||
if (
|
||||
lazy.Status.service == SYNC_FAILED_PARTIAL &&
|
||||
this.requiresBackoff
|
||||
) {
|
||||
this.requiresBackoff = false;
|
||||
this.handleSyncError();
|
||||
return;
|
||||
|
@ -364,7 +370,7 @@ SyncScheduler.prototype = {
|
|||
this.updateGlobalScore();
|
||||
if (
|
||||
this.globalScore > this.syncThreshold &&
|
||||
Status.service == STATUS_OK
|
||||
lazy.Status.service == STATUS_OK
|
||||
) {
|
||||
// The global score should be 0 after a sync. If it's not, either
|
||||
// items were changed during the last sync (and we should schedule an
|
||||
|
@ -386,7 +392,7 @@ SyncScheduler.prototype = {
|
|||
}
|
||||
|
||||
this._syncErrors = 0;
|
||||
if (Status.sync == NO_SYNC_NODE_FOUND) {
|
||||
if (lazy.Status.sync == NO_SYNC_NODE_FOUND) {
|
||||
// If we don't have a Sync node, override the interval, even if we've
|
||||
// scheduled a follow-up sync.
|
||||
this._log.trace("Scheduling a sync at interval NO_SYNC_NODE_FOUND.");
|
||||
|
@ -410,7 +416,7 @@ SyncScheduler.prototype = {
|
|||
case "weave:service:login:error":
|
||||
this.clearSyncTriggers();
|
||||
|
||||
if (Status.login == MASTER_PASSWORD_LOCKED) {
|
||||
if (lazy.Status.login == MASTER_PASSWORD_LOCKED) {
|
||||
// Try again later, just as if we threw an error... only without the
|
||||
// error count.
|
||||
this._log.debug("Couldn't log in: master password is locked.");
|
||||
|
@ -418,7 +424,7 @@ SyncScheduler.prototype = {
|
|||
"Scheduling a sync at MASTER_PASSWORD_LOCKED_RETRY_INTERVAL"
|
||||
);
|
||||
this.scheduleAtInterval(MASTER_PASSWORD_LOCKED_RETRY_INTERVAL);
|
||||
} else if (!this._fatalLoginStatus.includes(Status.login)) {
|
||||
} else if (!this._fatalLoginStatus.includes(lazy.Status.login)) {
|
||||
// Not a fatal login error, just an intermittent network or server
|
||||
// issue. Keep on syncin'.
|
||||
this.checkSyncStatus();
|
||||
|
@ -445,9 +451,11 @@ SyncScheduler.prototype = {
|
|||
);
|
||||
// Leave up to 25% more time for the back off.
|
||||
let interval = requested_interval * (1 + Math.random() * 0.25);
|
||||
Status.backoffInterval = interval;
|
||||
Status.minimumNextSync = Date.now() + requested_interval;
|
||||
this._log.debug("Fuzzed minimum next sync: " + Status.minimumNextSync);
|
||||
lazy.Status.backoffInterval = interval;
|
||||
lazy.Status.minimumNextSync = Date.now() + requested_interval;
|
||||
this._log.debug(
|
||||
"Fuzzed minimum next sync: " + lazy.Status.minimumNextSync
|
||||
);
|
||||
break;
|
||||
case "weave:engine:sync:applied":
|
||||
let numItems = subject.succeeded;
|
||||
|
@ -465,7 +473,7 @@ SyncScheduler.prototype = {
|
|||
break;
|
||||
case "weave:service:setup-complete":
|
||||
Services.prefs.savePrefFile(null);
|
||||
IdleService.addIdleObserver(this, this.idleTime);
|
||||
lazy.IdleService.addIdleObserver(this, this.idleTime);
|
||||
Svc.Obs.add("wake_notification", this);
|
||||
Svc.Obs.add("captive-portal-login-success", this);
|
||||
Svc.Obs.add("sleep_notification", this);
|
||||
|
@ -473,7 +481,7 @@ SyncScheduler.prototype = {
|
|||
case "weave:service:start-over":
|
||||
this.setDefaults();
|
||||
try {
|
||||
IdleService.removeIdleObserver(this, this.idleTime);
|
||||
lazy.IdleService.removeIdleObserver(this, this.idleTime);
|
||||
} catch (ex) {
|
||||
if (ex.result != Cr.NS_ERROR_FAILURE) {
|
||||
throw ex;
|
||||
|
@ -644,8 +652,10 @@ SyncScheduler.prototype = {
|
|||
*/
|
||||
syncIfMPUnlocked(engines, why) {
|
||||
// No point if we got kicked out by the master password dialog.
|
||||
if (Status.login == MASTER_PASSWORD_LOCKED && Utils.mpLocked()) {
|
||||
this._log.debug("Not initiating sync: Login status is " + Status.login);
|
||||
if (lazy.Status.login == MASTER_PASSWORD_LOCKED && Utils.mpLocked()) {
|
||||
this._log.debug(
|
||||
"Not initiating sync: Login status is " + lazy.Status.login
|
||||
);
|
||||
|
||||
// If we're not syncing now, we need to schedule the next one.
|
||||
this._log.trace(
|
||||
|
@ -669,7 +679,7 @@ SyncScheduler.prototype = {
|
|||
now >=
|
||||
this.missedFxACommandsLastFetch + this.missedFxACommandsFetchInterval
|
||||
) {
|
||||
fxAccounts.commands
|
||||
lazy.fxAccounts.commands
|
||||
.pollDeviceCommands()
|
||||
.then(() => {
|
||||
this.missedFxACommandsLastFetch = now;
|
||||
|
@ -691,16 +701,16 @@ SyncScheduler.prototype = {
|
|||
}
|
||||
|
||||
// Ensure the interval is set to no less than the backoff.
|
||||
if (Status.backoffInterval && interval < Status.backoffInterval) {
|
||||
if (lazy.Status.backoffInterval && interval < lazy.Status.backoffInterval) {
|
||||
this._log.trace(
|
||||
"Requested interval " +
|
||||
interval +
|
||||
" ms is smaller than the backoff interval. " +
|
||||
"Using backoff interval " +
|
||||
Status.backoffInterval +
|
||||
lazy.Status.backoffInterval +
|
||||
" ms instead."
|
||||
);
|
||||
interval = Status.backoffInterval;
|
||||
interval = lazy.Status.backoffInterval;
|
||||
}
|
||||
let nextSync = this.nextSync;
|
||||
if (nextSync != 0) {
|
||||
|
@ -747,7 +757,7 @@ SyncScheduler.prototype = {
|
|||
let interval = Utils.calculateBackoff(
|
||||
this._syncErrors,
|
||||
MINIMUM_BACKOFF_INTERVAL,
|
||||
Status.backoffInterval
|
||||
lazy.Status.backoffInterval
|
||||
);
|
||||
if (minimumInterval) {
|
||||
interval = Math.max(minimumInterval, interval);
|
||||
|
@ -778,7 +788,7 @@ SyncScheduler.prototype = {
|
|||
|
||||
// Do nothing on the first couple of failures, if we're not in
|
||||
// backoff due to 5xx errors.
|
||||
if (!Status.enforceBackoff) {
|
||||
if (!lazy.Status.enforceBackoff) {
|
||||
if (this._syncErrors < MAX_ERROR_COUNT_BEFORE_BACKOFF) {
|
||||
this.scheduleNextSync(null, { why: "reschedule" });
|
||||
return;
|
||||
|
@ -788,7 +798,7 @@ SyncScheduler.prototype = {
|
|||
MAX_ERROR_COUNT_BEFORE_BACKOFF +
|
||||
"; enforcing backoff."
|
||||
);
|
||||
Status.enforceBackoff = true;
|
||||
lazy.Status.enforceBackoff = true;
|
||||
}
|
||||
|
||||
this.scheduleAtInterval();
|
||||
|
@ -843,7 +853,7 @@ ErrorHandler.prototype = {
|
|||
// An engine isn't able to apply one or more incoming records.
|
||||
// We don't fail hard on this, but it usually indicates a bug,
|
||||
// so for now treat it as sync error (c.f. Service._syncEngine())
|
||||
Status.engines = [data, ENGINE_APPLY_FAIL];
|
||||
lazy.Status.engines = [data, ENGINE_APPLY_FAIL];
|
||||
this._log.debug(data + " failed to apply some records.");
|
||||
}
|
||||
break;
|
||||
|
@ -853,7 +863,7 @@ ErrorHandler.prototype = {
|
|||
|
||||
this.checkServerError(exception);
|
||||
|
||||
Status.engines = [
|
||||
lazy.Status.engines = [
|
||||
engine_name,
|
||||
exception.failureCode || ENGINE_UNKNOWN_FAIL,
|
||||
];
|
||||
|
@ -872,7 +882,7 @@ ErrorHandler.prototype = {
|
|||
this.resetFileLog();
|
||||
break;
|
||||
case "weave:service:sync:error": {
|
||||
if (Status.sync == CREDENTIALS_CHANGED) {
|
||||
if (lazy.Status.sync == CREDENTIALS_CHANGED) {
|
||||
this.service.logout();
|
||||
}
|
||||
|
||||
|
@ -893,19 +903,22 @@ ErrorHandler.prototype = {
|
|||
break;
|
||||
}
|
||||
case "weave:service:sync:finish":
|
||||
this._log.trace("Status.service is " + Status.service);
|
||||
this._log.trace("Status.service is " + lazy.Status.service);
|
||||
|
||||
// Check both of these status codes: in the event of a failure in one
|
||||
// engine, Status.service will be SYNC_FAILED_PARTIAL despite
|
||||
// Status.sync being SYNC_SUCCEEDED.
|
||||
// *facepalm*
|
||||
if (Status.sync == SYNC_SUCCEEDED && Status.service == STATUS_OK) {
|
||||
if (
|
||||
lazy.Status.sync == SYNC_SUCCEEDED &&
|
||||
lazy.Status.service == STATUS_OK
|
||||
) {
|
||||
// Great. Let's clear our mid-sync 401 note.
|
||||
this._log.trace("Clearing lastSyncReassigned.");
|
||||
Svc.Prefs.reset("lastSyncReassigned");
|
||||
}
|
||||
|
||||
if (Status.service == SYNC_FAILED_PARTIAL) {
|
||||
if (lazy.Status.service == SYNC_FAILED_PARTIAL) {
|
||||
this._log.error("Some engines did not sync correctly.");
|
||||
}
|
||||
this.resetFileLog();
|
||||
|
@ -937,7 +950,7 @@ ErrorHandler.prototype = {
|
|||
// active extensions that are not hidden.
|
||||
let addons = [];
|
||||
try {
|
||||
addons = await AddonManager.getAddonsByTypes(["extension"]);
|
||||
addons = await lazy.AddonManager.getAddonsByTypes(["extension"]);
|
||||
} catch (e) {
|
||||
this._log.warn("Failed to dump addons", e);
|
||||
}
|
||||
|
@ -978,7 +991,7 @@ ErrorHandler.prototype = {
|
|||
switch (resp.status) {
|
||||
case 400:
|
||||
if (resp == RESPONSE_OVER_QUOTA) {
|
||||
Status.sync = OVER_QUOTA;
|
||||
lazy.Status.sync = OVER_QUOTA;
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -1008,14 +1021,14 @@ ErrorHandler.prototype = {
|
|||
case 502:
|
||||
case 503:
|
||||
case 504:
|
||||
Status.enforceBackoff = true;
|
||||
lazy.Status.enforceBackoff = true;
|
||||
if (resp.status == 503 && resp.headers["retry-after"]) {
|
||||
let retryAfter = resp.headers["retry-after"];
|
||||
this._log.debug("Got Retry-After: " + retryAfter);
|
||||
if (this.service.isLoggedIn) {
|
||||
Status.sync = SERVER_MAINTENANCE;
|
||||
lazy.Status.sync = SERVER_MAINTENANCE;
|
||||
} else {
|
||||
Status.login = SERVER_MAINTENANCE;
|
||||
lazy.Status.login = SERVER_MAINTENANCE;
|
||||
}
|
||||
Svc.Obs.notify(
|
||||
"weave:service:backoff:interval",
|
||||
|
@ -1036,9 +1049,9 @@ ErrorHandler.prototype = {
|
|||
// The constant says it's about login, but in fact it just
|
||||
// indicates general network error.
|
||||
if (this.service.isLoggedIn) {
|
||||
Status.sync = LOGIN_FAILED_NETWORK_ERROR;
|
||||
lazy.Status.sync = LOGIN_FAILED_NETWORK_ERROR;
|
||||
} else {
|
||||
Status.login = LOGIN_FAILED_NETWORK_ERROR;
|
||||
lazy.Status.login = LOGIN_FAILED_NETWORK_ERROR;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,8 @@ const { Utils } = ChromeUtils.import("resource://services-sync/util.js");
|
|||
const { setTimeout, clearTimeout } = ChromeUtils.import(
|
||||
"resource://gre/modules/Timer.jsm"
|
||||
);
|
||||
XPCOMUtils.defineLazyGlobalGetters(this, ["fetch", "Headers", "Request"]);
|
||||
const lazy = {};
|
||||
XPCOMUtils.defineLazyGlobalGetters(lazy, ["fetch", "Headers", "Request"]);
|
||||
/* global AbortController */
|
||||
|
||||
/*
|
||||
|
@ -103,7 +104,7 @@ Resource.prototype = {
|
|||
* @returns {Headers}
|
||||
*/
|
||||
async _buildHeaders(method) {
|
||||
const headers = new Headers(this._headers);
|
||||
const headers = new lazy.Headers(this._headers);
|
||||
|
||||
if (Resource.SEND_VERSION_INFO) {
|
||||
headers.append("user-agent", Utils.userAgent);
|
||||
|
@ -167,7 +168,7 @@ Resource.prototype = {
|
|||
this._log.trace(`${method} Body: ${data}`);
|
||||
init.body = data;
|
||||
}
|
||||
return new Request(this.uri.spec, init);
|
||||
return new lazy.Request(this.uri.spec, init);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -178,7 +179,7 @@ Resource.prototype = {
|
|||
async _doRequest(method, data = null) {
|
||||
const controller = new AbortController();
|
||||
const request = await this._createRequest(method, data, controller.signal);
|
||||
const responsePromise = fetch(request); // Rejects on network failure.
|
||||
const responsePromise = lazy.fetch(request); // Rejects on network failure.
|
||||
let didTimeout = false;
|
||||
const timeoutId = setTimeout(() => {
|
||||
didTimeout = true;
|
||||
|
|
|
@ -112,10 +112,12 @@ function getEngineModules() {
|
|||
return result;
|
||||
}
|
||||
|
||||
const lazy = {};
|
||||
|
||||
// A unique identifier for this browser session. Used for logging so
|
||||
// we can easily see whether 2 logs are in the same browser session or
|
||||
// after the browser restarted.
|
||||
XPCOMUtils.defineLazyGetter(this, "browserSessionID", Utils.makeGUID);
|
||||
XPCOMUtils.defineLazyGetter(lazy, "browserSessionID", Utils.makeGUID);
|
||||
|
||||
function Sync11Service() {
|
||||
this._notify = Utils.notify("weave:service:");
|
||||
|
@ -1318,7 +1320,7 @@ Sync11Service.prototype = {
|
|||
this._log.debug("User-Agent: " + Utils.userAgent);
|
||||
await this.promiseInitialized;
|
||||
this._log.info(
|
||||
`Starting sync at ${dateStr} in browser session ${browserSessionID}`
|
||||
`Starting sync at ${dateStr} in browser session ${lazy.browserSessionID}`
|
||||
);
|
||||
return this._catch(async function() {
|
||||
// Make sure we're logged in.
|
||||
|
|
|
@ -21,8 +21,9 @@ const {
|
|||
} = ChromeUtils.import("resource://services-sync/constants.js");
|
||||
const { Svc, Utils } = ChromeUtils.import("resource://services-sync/util.js");
|
||||
const { Async } = ChromeUtils.import("resource://services-common/async.js");
|
||||
const lazy = {};
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"Doctor",
|
||||
"resource://services-sync/doctor.js"
|
||||
);
|
||||
|
@ -212,7 +213,7 @@ EngineSynchronizer.prototype = {
|
|||
}
|
||||
|
||||
if (!fastSync) {
|
||||
await Doctor.consult(enginesToValidate);
|
||||
await lazy.Doctor.consult(enginesToValidate);
|
||||
}
|
||||
|
||||
// If there were no sync engine failures
|
||||
|
|
|
@ -28,39 +28,41 @@ const {
|
|||
STATUS_OK,
|
||||
} = ChromeUtils.import("resource://services-sync/constants.js");
|
||||
|
||||
const lazy = {};
|
||||
|
||||
// Lazy imports to prevent unnecessary load on startup.
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"Weave",
|
||||
"resource://services-sync/main.js"
|
||||
);
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"BulkKeyBundle",
|
||||
"resource://services-sync/keys.js"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "fxAccounts", () => {
|
||||
XPCOMUtils.defineLazyGetter(lazy, "fxAccounts", () => {
|
||||
return ChromeUtils.import(
|
||||
"resource://gre/modules/FxAccounts.jsm"
|
||||
).getFxAccountsSingleton();
|
||||
});
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"CommonUtils",
|
||||
"resource://services-common/utils.js"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "log", function() {
|
||||
XPCOMUtils.defineLazyGetter(lazy, "log", function() {
|
||||
let log = Log.repository.getLogger("Sync.SyncAuthManager");
|
||||
log.manageLevelFromPref("services.sync.log.logger.identity");
|
||||
return log;
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"IGNORE_CACHED_AUTH_CREDENTIALS",
|
||||
"services.sync.debug.ignoreCachedAuthCredentials"
|
||||
);
|
||||
|
@ -107,17 +109,17 @@ AuthenticationError.prototype = {
|
|||
function SyncAuthManager() {
|
||||
// NOTE: _fxaService and _tokenServerClient are replaced with mocks by
|
||||
// the test suite.
|
||||
this._fxaService = fxAccounts;
|
||||
this._fxaService = lazy.fxAccounts;
|
||||
this._tokenServerClient = new TokenServerClient();
|
||||
this._tokenServerClient.observerPrefix = "weave:service";
|
||||
this._log = log;
|
||||
this._log = lazy.log;
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
this,
|
||||
"_username",
|
||||
"services.sync.username"
|
||||
);
|
||||
|
||||
this.asyncObserver = Async.asyncObserver(this, log);
|
||||
this.asyncObserver = Async.asyncObserver(this, lazy.log);
|
||||
for (let topic of OBSERVER_TOPICS) {
|
||||
Services.obs.addObserver(this.asyncObserver, topic);
|
||||
}
|
||||
|
@ -209,14 +211,14 @@ SyncAuthManager.prototype = {
|
|||
// intentional fall-through - the user is verified.
|
||||
case fxAccountsCommon.ONVERIFIED_NOTIFICATION: {
|
||||
this._log.info("The user became verified");
|
||||
Weave.Status.login = LOGIN_SUCCEEDED;
|
||||
lazy.Weave.Status.login = LOGIN_SUCCEEDED;
|
||||
|
||||
// And actually sync. If we've never synced before, we force a full sync.
|
||||
// If we have, then we are probably just reauthenticating so it's a normal sync.
|
||||
// We can use any pref that must be set if we've synced before, and check
|
||||
// the sync lock state because we might already be doing that first sync.
|
||||
let isFirstSync =
|
||||
!Weave.Service.locked && !Svc.Prefs.get("client.syncID", null);
|
||||
!lazy.Weave.Service.locked && !Svc.Prefs.get("client.syncID", null);
|
||||
if (isFirstSync) {
|
||||
this._log.info("Doing initial sync actions");
|
||||
Svc.Prefs.set("firstSync", "resetClient");
|
||||
|
@ -225,13 +227,13 @@ SyncAuthManager.prototype = {
|
|||
// There's no need to wait for sync to complete and it would deadlock
|
||||
// our AsyncObserver.
|
||||
if (!Svc.Prefs.get("testing.tps", false)) {
|
||||
Weave.Service.sync({ why: "login" });
|
||||
lazy.Weave.Service.sync({ why: "login" });
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case fxAccountsCommon.ONLOGOUT_NOTIFICATION:
|
||||
Weave.Service.startOver()
|
||||
lazy.Weave.Service.startOver()
|
||||
.then(() => {
|
||||
this._log.trace("startOver completed");
|
||||
})
|
||||
|
@ -288,7 +290,7 @@ SyncAuthManager.prototype = {
|
|||
this._token = null;
|
||||
// The cluster URL comes from the token, so resetting it to empty will
|
||||
// force Sync to not accidentally use a value from an earlier token.
|
||||
Weave.Service.clusterURL = null;
|
||||
lazy.Weave.Service.clusterURL = null;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -311,21 +313,23 @@ SyncAuthManager.prototype = {
|
|||
let data = await this.getSignedInUser();
|
||||
const fxa = this._fxaService;
|
||||
if (!data) {
|
||||
log.debug("unlockAndVerifyAuthState has no FxA user");
|
||||
lazy.log.debug("unlockAndVerifyAuthState has no FxA user");
|
||||
return LOGIN_FAILED_NO_USERNAME;
|
||||
}
|
||||
if (!this.username) {
|
||||
log.debug("unlockAndVerifyAuthState finds that sync isn't configured");
|
||||
lazy.log.debug(
|
||||
"unlockAndVerifyAuthState finds that sync isn't configured"
|
||||
);
|
||||
return LOGIN_FAILED_NO_USERNAME;
|
||||
}
|
||||
if (!data.verified) {
|
||||
// Treat not verified as if the user needs to re-auth, so the browser
|
||||
// UI reflects the state.
|
||||
log.debug("unlockAndVerifyAuthState has an unverified user");
|
||||
lazy.log.debug("unlockAndVerifyAuthState has an unverified user");
|
||||
return LOGIN_FAILED_LOGIN_REJECTED;
|
||||
}
|
||||
if (await fxa.keys.canGetKeyForScope(SCOPE_OLD_SYNC)) {
|
||||
log.debug(
|
||||
lazy.log.debug(
|
||||
"unlockAndVerifyAuthState already has (or can fetch) sync keys"
|
||||
);
|
||||
return STATUS_OK;
|
||||
|
@ -333,7 +337,7 @@ SyncAuthManager.prototype = {
|
|||
// so no keys - ensure MP unlocked.
|
||||
if (!Utils.ensureMPUnlocked()) {
|
||||
// user declined to unlock, so we don't know if they are stored there.
|
||||
log.debug(
|
||||
lazy.log.debug(
|
||||
"unlockAndVerifyAuthState: user declined to unlock master-password"
|
||||
);
|
||||
return MASTER_PASSWORD_LOCKED;
|
||||
|
@ -347,7 +351,7 @@ SyncAuthManager.prototype = {
|
|||
} else {
|
||||
result = LOGIN_FAILED_LOGIN_REJECTED;
|
||||
}
|
||||
log.debug(
|
||||
lazy.log.debug(
|
||||
"unlockAndVerifyAuthState re-fetched credentials and is returning",
|
||||
result
|
||||
);
|
||||
|
@ -361,7 +365,7 @@ SyncAuthManager.prototype = {
|
|||
_hasValidToken() {
|
||||
// If pref is set to ignore cached authentication credentials for debugging,
|
||||
// then return false to force the fetching of a new token.
|
||||
if (IGNORE_CACHED_AUTH_CREDENTIALS) {
|
||||
if (lazy.IGNORE_CACHED_AUTH_CREDENTIALS) {
|
||||
return false;
|
||||
}
|
||||
if (!this._token) {
|
||||
|
@ -440,9 +444,9 @@ SyncAuthManager.prototype = {
|
|||
// (XXX - the above may no longer be true - someone should check ;)
|
||||
token.expiration = this._now() + token.duration * 1000 * 0.8;
|
||||
if (!this._syncKeyBundle) {
|
||||
this._syncKeyBundle = BulkKeyBundle.fromJWK(key);
|
||||
this._syncKeyBundle = lazy.BulkKeyBundle.fromJWK(key);
|
||||
}
|
||||
Weave.Status.login = LOGIN_SUCCEEDED;
|
||||
lazy.Weave.Status.login = LOGIN_SUCCEEDED;
|
||||
this._token = token;
|
||||
return token;
|
||||
} catch (caughtErr) {
|
||||
|
@ -467,12 +471,12 @@ SyncAuthManager.prototype = {
|
|||
if (err instanceof AuthenticationError) {
|
||||
this._log.error("Authentication error in _fetchTokenForUser", err);
|
||||
// set it to the "fatal" LOGIN_FAILED_LOGIN_REJECTED reason.
|
||||
Weave.Status.login = LOGIN_FAILED_LOGIN_REJECTED;
|
||||
lazy.Weave.Status.login = LOGIN_FAILED_LOGIN_REJECTED;
|
||||
} else {
|
||||
this._log.error("Non-authentication error in _fetchTokenForUser", err);
|
||||
// for now assume it is just a transient network related problem
|
||||
// (although sadly, it might also be a regular unhandled exception)
|
||||
Weave.Status.login = LOGIN_FAILED_NETWORK_ERROR;
|
||||
lazy.Weave.Status.login = LOGIN_FAILED_NETWORK_ERROR;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
@ -617,12 +621,12 @@ SyncAuthManager.prototype = {
|
|||
// resource.js returns to a plain-old string.
|
||||
cluster = cluster.toString();
|
||||
// Don't update stuff if we already have the right cluster
|
||||
if (cluster == Weave.Service.clusterURL) {
|
||||
if (cluster == lazy.Weave.Service.clusterURL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this._log.debug("Setting cluster to " + cluster);
|
||||
Weave.Service.clusterURL = cluster;
|
||||
lazy.Weave.Service.clusterURL = cluster;
|
||||
|
||||
return true;
|
||||
},
|
||||
|
@ -635,7 +639,7 @@ SyncAuthManager.prototype = {
|
|||
// it's likely a 401 was received using the existing token - in which
|
||||
// case we just discard the existing token and fetch a new one.
|
||||
let forceNewToken = false;
|
||||
if (Weave.Service.clusterURL) {
|
||||
if (lazy.Weave.Service.clusterURL) {
|
||||
this._log.debug(
|
||||
"_findCluster has a pre-existing clusterURL, so fetching a new token token"
|
||||
);
|
||||
|
|
|
@ -23,7 +23,9 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
"resource://gre/modules/XPCOMUtils.jsm"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
Async: "resource://services-common/async.js",
|
||||
AuthenticationError: "resource://services-sync/sync_auth.js",
|
||||
FxAccounts: "resource://gre/modules/FxAccounts.jsm",
|
||||
|
@ -41,7 +43,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
|
|||
Weave: "resource://services-sync/main.js",
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "fxAccounts", () => {
|
||||
XPCOMUtils.defineLazyGetter(lazy, "fxAccounts", () => {
|
||||
return ChromeUtils.import(
|
||||
"resource://gre/modules/FxAccounts.jsm"
|
||||
).getFxAccountsSingleton();
|
||||
|
@ -50,11 +52,11 @@ XPCOMUtils.defineLazyGetter(this, "fxAccounts", () => {
|
|||
let constants = ChromeUtils.import("resource://services-sync/constants.js");
|
||||
|
||||
XPCOMUtils.defineLazyGetter(
|
||||
this,
|
||||
lazy,
|
||||
"WeaveService",
|
||||
() => Cc["@mozilla.org/weave/service;1"].getService().wrappedJSObject
|
||||
);
|
||||
const log = Log.repository.getLogger("Sync.Telemetry");
|
||||
const log = lazy.Log.repository.getLogger("Sync.Telemetry");
|
||||
|
||||
const TOPICS = [
|
||||
// For tracking change to account/device identifiers.
|
||||
|
@ -107,7 +109,7 @@ const ENGINES = new Set([
|
|||
|
||||
function tryGetMonotonicTimestamp() {
|
||||
try {
|
||||
return Services.telemetry.msSinceProcessStart();
|
||||
return lazy.Services.telemetry.msSinceProcessStart();
|
||||
} catch (e) {
|
||||
log.warn("Unable to get a monotonic timestamp!");
|
||||
return -1;
|
||||
|
@ -152,7 +154,7 @@ function normalizeExtraTelemetryFields(extra) {
|
|||
);
|
||||
}
|
||||
}
|
||||
return ObjectUtils.isEmpty(result) ? undefined : result;
|
||||
return lazy.ObjectUtils.isEmpty(result) ? undefined : result;
|
||||
}
|
||||
|
||||
// The `ErrorSanitizer` has 2 main jobs:
|
||||
|
@ -220,7 +222,7 @@ class ErrorSanitizer {
|
|||
// This escaping function is from:
|
||||
// https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions
|
||||
static reProfileDir = new RegExp(
|
||||
OS.Constants.Path.profileDir.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"),
|
||||
lazy.OS.Constants.Path.profileDir.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"),
|
||||
"gi"
|
||||
);
|
||||
|
||||
|
@ -303,7 +305,7 @@ class EngineRecord {
|
|||
|
||||
// This allows cases like bookmarks-buffered to have a separate name from
|
||||
// the bookmarks engine.
|
||||
let engineImpl = Weave.Service.engineManager.get(name);
|
||||
let engineImpl = lazy.Weave.Service.engineManager.get(name);
|
||||
if (engineImpl && engineImpl.overrideTelemetryName) {
|
||||
this.overrideTelemetryName = engineImpl.overrideTelemetryName;
|
||||
}
|
||||
|
@ -480,12 +482,12 @@ class SyncRecord {
|
|||
this.failureReason = SyncTelemetry.transformError(error);
|
||||
}
|
||||
|
||||
this.syncNodeType = Weave.Service.identity.telemetryNodeType;
|
||||
this.syncNodeType = lazy.Weave.Service.identity.telemetryNodeType;
|
||||
|
||||
// Check for engine statuses. -- We do this now, and not in engine.finished
|
||||
// to make sure any statuses that get set "late" are recorded
|
||||
for (let engine of this.engines) {
|
||||
let status = Status.engines[engine.name];
|
||||
let status = lazy.Status.engines[engine.name];
|
||||
if (status && status !== constants.ENGINE_SUCCEEDED) {
|
||||
engine.status = status;
|
||||
}
|
||||
|
@ -493,12 +495,12 @@ class SyncRecord {
|
|||
|
||||
let statusObject = {};
|
||||
|
||||
let serviceStatus = Status.service;
|
||||
let serviceStatus = lazy.Status.service;
|
||||
if (serviceStatus && serviceStatus !== constants.STATUS_OK) {
|
||||
statusObject.service = serviceStatus;
|
||||
this.status = statusObject;
|
||||
}
|
||||
let syncStatus = Status.sync;
|
||||
let syncStatus = lazy.Status.sync;
|
||||
if (syncStatus && syncStatus !== constants.SYNC_SUCCEEDED) {
|
||||
statusObject.sync = syncStatus;
|
||||
this.status = statusObject;
|
||||
|
@ -635,11 +637,11 @@ class SyncTelemetryImpl {
|
|||
this.events = [];
|
||||
this.histograms = {};
|
||||
this.migrations = [];
|
||||
this.maxEventsCount = Svc.Prefs.get("telemetry.maxEventsCount", 1000);
|
||||
this.maxPayloadCount = Svc.Prefs.get("telemetry.maxPayloadCount");
|
||||
this.maxEventsCount = lazy.Svc.Prefs.get("telemetry.maxEventsCount", 1000);
|
||||
this.maxPayloadCount = lazy.Svc.Prefs.get("telemetry.maxPayloadCount");
|
||||
this.submissionInterval =
|
||||
Svc.Prefs.get("telemetry.submissionInterval") * 1000;
|
||||
this.lastSubmissionTime = Services.telemetry.msSinceProcessStart();
|
||||
lazy.Svc.Prefs.get("telemetry.submissionInterval") * 1000;
|
||||
this.lastSubmissionTime = lazy.Services.telemetry.msSinceProcessStart();
|
||||
this.lastUID = EMPTY_UID;
|
||||
this.lastSyncNodeType = null;
|
||||
this.currentSyncNodeType = null;
|
||||
|
@ -649,14 +651,14 @@ class SyncTelemetryImpl {
|
|||
// but that's OK for now - if it's a problem we'd need to change the
|
||||
// telemetry modules to expose what it thinks the sessionStartDate is.
|
||||
let sessionStartDate = new Date();
|
||||
this.sessionStartDate = TelemetryUtils.toLocalTimeISOString(
|
||||
TelemetryUtils.truncateToHours(sessionStartDate)
|
||||
this.sessionStartDate = lazy.TelemetryUtils.toLocalTimeISOString(
|
||||
lazy.TelemetryUtils.truncateToHours(sessionStartDate)
|
||||
);
|
||||
TelemetryController.registerSyncPingShutdown(() => this.shutdown());
|
||||
lazy.TelemetryController.registerSyncPingShutdown(() => this.shutdown());
|
||||
}
|
||||
|
||||
sanitizeFxaDeviceId(deviceId) {
|
||||
return fxAccounts.telemetry.sanitizeDeviceId(deviceId);
|
||||
return lazy.fxAccounts.telemetry.sanitizeDeviceId(deviceId);
|
||||
}
|
||||
|
||||
prepareFxaDevices(devices) {
|
||||
|
@ -694,7 +696,7 @@ class SyncTelemetryImpl {
|
|||
}
|
||||
|
||||
syncIsEnabled() {
|
||||
return WeaveService.enabled && WeaveService.ready;
|
||||
return lazy.WeaveService.enabled && lazy.WeaveService.ready;
|
||||
}
|
||||
|
||||
// Separate for testing.
|
||||
|
@ -702,7 +704,7 @@ class SyncTelemetryImpl {
|
|||
if (!this.syncIsEnabled()) {
|
||||
throw new Error("Bug: syncIsEnabled() must be true, check it first");
|
||||
}
|
||||
return Weave.Service.clientsEngine.remoteClients;
|
||||
return lazy.Weave.Service.clientsEngine.remoteClients;
|
||||
}
|
||||
|
||||
updateFxaDevices(devices) {
|
||||
|
@ -716,13 +718,13 @@ class SyncTelemetryImpl {
|
|||
}
|
||||
|
||||
getFxaDevices() {
|
||||
return fxAccounts.device.recentDeviceList;
|
||||
return lazy.fxAccounts.device.recentDeviceList;
|
||||
}
|
||||
|
||||
getPingJSON(reason) {
|
||||
let { devices, deviceID } = this.updateFxaDevices(this.getFxaDevices());
|
||||
return {
|
||||
os: TelemetryEnvironment.currentEnvironment.system.os,
|
||||
os: lazy.TelemetryEnvironment.currentEnvironment.system.os,
|
||||
why: reason,
|
||||
devices,
|
||||
discarded: this.discarded || undefined,
|
||||
|
@ -772,14 +774,14 @@ class SyncTelemetryImpl {
|
|||
|
||||
setupObservers() {
|
||||
for (let topic of TOPICS) {
|
||||
Observers.add(topic, this, this);
|
||||
lazy.Observers.add(topic, this, this);
|
||||
}
|
||||
}
|
||||
|
||||
shutdown() {
|
||||
this.finish("shutdown");
|
||||
for (let topic of TOPICS) {
|
||||
Observers.remove(topic, this, this);
|
||||
lazy.Observers.remove(topic, this, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -796,7 +798,7 @@ class SyncTelemetryImpl {
|
|||
`submitting ${record.syncs.length} sync record(s) and ` +
|
||||
`${numEvents} event(s) to telemetry`
|
||||
);
|
||||
TelemetryController.submitExternalPing("sync", record, {
|
||||
lazy.TelemetryController.submitExternalPing("sync", record, {
|
||||
usePingSender: true,
|
||||
}).catch(err => {
|
||||
log.error("failed to submit ping", err);
|
||||
|
@ -812,8 +814,8 @@ class SyncTelemetryImpl {
|
|||
// need to consider - fxa doesn't consider that as if that's the only
|
||||
// pref set, they *are* running a production fxa, just not production sync.
|
||||
if (
|
||||
!FxAccounts.config.isProductionConfig() ||
|
||||
Services.prefs.prefHasUserValue("services.sync.tokenServerURI")
|
||||
!lazy.FxAccounts.config.isProductionConfig() ||
|
||||
lazy.Services.prefs.prefHasUserValue("services.sync.tokenServerURI")
|
||||
) {
|
||||
log.trace(`Not sending telemetry ping for self-hosted Sync user`);
|
||||
return false;
|
||||
|
@ -845,10 +847,12 @@ class SyncTelemetryImpl {
|
|||
// Awkwardly async, but no need to await. If the user's account state changes while
|
||||
// this promise is in flight, it will reject and we won't record any data in the ping.
|
||||
// (And a new notification will trigger us to try again with the new state).
|
||||
fxAccounts.device
|
||||
lazy.fxAccounts.device
|
||||
.getLocalId()
|
||||
.then(deviceId => {
|
||||
let sanitizedDeviceId = fxAccounts.telemetry.sanitizeDeviceId(deviceId);
|
||||
let sanitizedDeviceId = lazy.fxAccounts.telemetry.sanitizeDeviceId(
|
||||
deviceId
|
||||
);
|
||||
// In the past we did not persist the FxA metrics identifiers to disk,
|
||||
// so this might be missing until we can fetch it from the server for the
|
||||
// first time. There will be a fresh notification tirggered when it's available.
|
||||
|
@ -857,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);
|
||||
Services.telemetry.scalarSet(
|
||||
lazy.Services.telemetry.scalarSet(
|
||||
"deletion.request.sync_device_id",
|
||||
sanitizedDeviceId
|
||||
);
|
||||
|
@ -873,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() {
|
||||
Services.telemetry.scalarSet("deletion.request.sync_device_id", "");
|
||||
lazy.Services.telemetry.scalarSet("deletion.request.sync_device_id", "");
|
||||
}
|
||||
|
||||
_checkCurrent(topic) {
|
||||
|
@ -887,7 +891,7 @@ class SyncTelemetryImpl {
|
|||
}
|
||||
|
||||
_shouldSubmitForDataChange() {
|
||||
let newID = fxAccounts.telemetry.getSanitizedUID() || EMPTY_UID;
|
||||
let newID = lazy.fxAccounts.telemetry.getSanitizedUID() || EMPTY_UID;
|
||||
let oldID = this.lastUID;
|
||||
if (
|
||||
newID != EMPTY_UID &&
|
||||
|
@ -923,11 +927,11 @@ class SyncTelemetryImpl {
|
|||
"Early submission of sync telemetry due to changed IDs/NodeType"
|
||||
);
|
||||
this.finish("idchange"); // this actually submits.
|
||||
this.lastSubmissionTime = Services.telemetry.msSinceProcessStart();
|
||||
this.lastSubmissionTime = lazy.Services.telemetry.msSinceProcessStart();
|
||||
}
|
||||
|
||||
// Only update the last UIDs if we actually know them.
|
||||
let current_uid = fxAccounts.telemetry.getSanitizedUID();
|
||||
let current_uid = lazy.fxAccounts.telemetry.getSanitizedUID();
|
||||
if (current_uid) {
|
||||
this.lastUID = current_uid;
|
||||
}
|
||||
|
@ -942,11 +946,11 @@ class SyncTelemetryImpl {
|
|||
// the sync and the events caused by it in different pings.
|
||||
if (
|
||||
this.current == null &&
|
||||
Services.telemetry.msSinceProcessStart() - this.lastSubmissionTime >
|
||||
lazy.Services.telemetry.msSinceProcessStart() - this.lastSubmissionTime >
|
||||
this.submissionInterval
|
||||
) {
|
||||
this.finish("schedule");
|
||||
this.lastSubmissionTime = Services.telemetry.msSinceProcessStart();
|
||||
this.lastSubmissionTime = lazy.Services.telemetry.msSinceProcessStart();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -973,7 +977,7 @@ class SyncTelemetryImpl {
|
|||
}
|
||||
|
||||
_addHistogram(hist) {
|
||||
let histogram = Services.telemetry.getHistogramById(hist);
|
||||
let histogram = lazy.Services.telemetry.getHistogramById(hist);
|
||||
let s = histogram.snapshot();
|
||||
this.histograms[hist] = s;
|
||||
}
|
||||
|
@ -998,8 +1002,8 @@ class SyncTelemetryImpl {
|
|||
}
|
||||
log.debug("recording event", eventDetails);
|
||||
|
||||
if (extra && Resource.serverTime && !extra.serverTime) {
|
||||
extra.serverTime = String(Resource.serverTime);
|
||||
if (extra && lazy.Resource.serverTime && !extra.serverTime) {
|
||||
extra.serverTime = String(lazy.Resource.serverTime);
|
||||
}
|
||||
let category = "sync";
|
||||
let ts = Math.floor(tryGetMonotonicTimestamp());
|
||||
|
@ -1130,7 +1134,7 @@ class SyncTelemetryImpl {
|
|||
if (typeof error == "object" && error.code && error.cause) {
|
||||
error = error.cause;
|
||||
}
|
||||
if (Async.isShutdownException(error)) {
|
||||
if (lazy.Async.isShutdownException(error)) {
|
||||
return { name: "shutdownerror" };
|
||||
}
|
||||
|
||||
|
@ -1143,7 +1147,7 @@ class SyncTelemetryImpl {
|
|||
return { name: "unexpectederror", error };
|
||||
}
|
||||
|
||||
if (error instanceof AuthenticationError) {
|
||||
if (error instanceof lazy.AuthenticationError) {
|
||||
return { name: "autherror", from: error.source };
|
||||
}
|
||||
|
||||
|
|
|
@ -28,20 +28,21 @@ const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|||
const { XPCOMUtils } = ChromeUtils.import(
|
||||
"resource://gre/modules/XPCOMUtils.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(this, "OS", "resource://gre/modules/osfile.jsm");
|
||||
const lazy = {};
|
||||
ChromeUtils.defineModuleGetter(lazy, "OS", "resource://gre/modules/osfile.jsm");
|
||||
const FxAccountsCommon = ChromeUtils.import(
|
||||
"resource://gre/modules/FxAccountsCommon.js"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"cryptoSDR",
|
||||
"@mozilla.org/login-manager/crypto/SDR;1",
|
||||
"nsILoginManagerCrypto"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"localDeviceType",
|
||||
"services.sync.client.type",
|
||||
DEVICE_TYPE_DESKTOP
|
||||
|
@ -105,7 +106,7 @@ var Utils = {
|
|||
"."; // Build.
|
||||
/* eslint-enable no-multi-spaces */
|
||||
}
|
||||
return this._userAgent + localDeviceType;
|
||||
return this._userAgent + lazy.localDeviceType;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -377,7 +378,7 @@ var Utils = {
|
|||
try {
|
||||
return await CommonUtils.readJSON(path);
|
||||
} catch (e) {
|
||||
if (!(e instanceof OS.File.Error && e.becauseNoSuchFile)) {
|
||||
if (!(e instanceof lazy.OS.File.Error && e.becauseNoSuchFile)) {
|
||||
if (that._log) {
|
||||
that._log.debug("Failed to load json", e);
|
||||
}
|
||||
|
@ -402,14 +403,16 @@ var Utils = {
|
|||
* Promise resolved when the write has been performed.
|
||||
*/
|
||||
async jsonSave(filePath, that, obj) {
|
||||
let path = OS.Path.join(
|
||||
OS.Constants.Path.profileDir,
|
||||
let path = lazy.OS.Path.join(
|
||||
lazy.OS.Constants.Path.profileDir,
|
||||
"weave",
|
||||
...(filePath + ".json").split("/")
|
||||
);
|
||||
let dir = OS.Path.dirname(path);
|
||||
let dir = lazy.OS.Path.dirname(path);
|
||||
|
||||
await OS.File.makeDir(dir, { from: OS.Constants.Path.profileDir });
|
||||
await lazy.OS.File.makeDir(dir, {
|
||||
from: lazy.OS.Constants.Path.profileDir,
|
||||
});
|
||||
|
||||
if (that._log) {
|
||||
that._log.trace("Saving json to disk: " + path);
|
||||
|
@ -472,20 +475,20 @@ var Utils = {
|
|||
* Object to use for logging
|
||||
*/
|
||||
jsonMove(aFrom, aTo, that) {
|
||||
let pathFrom = OS.Path.join(
|
||||
OS.Constants.Path.profileDir,
|
||||
let pathFrom = lazy.OS.Path.join(
|
||||
lazy.OS.Constants.Path.profileDir,
|
||||
"weave",
|
||||
...(aFrom + ".json").split("/")
|
||||
);
|
||||
let pathTo = OS.Path.join(
|
||||
OS.Constants.Path.profileDir,
|
||||
let pathTo = lazy.OS.Path.join(
|
||||
lazy.OS.Constants.Path.profileDir,
|
||||
"weave",
|
||||
...(aTo + ".json").split("/")
|
||||
);
|
||||
if (that._log) {
|
||||
that._log.trace("Moving " + pathFrom + " to " + pathTo);
|
||||
}
|
||||
return OS.File.move(pathFrom, pathTo, { noOverwrite: true });
|
||||
return lazy.OS.File.move(pathFrom, pathTo, { noOverwrite: true });
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -500,15 +503,15 @@ var Utils = {
|
|||
* Object to use for logging
|
||||
*/
|
||||
jsonRemove(filePath, that) {
|
||||
let path = OS.Path.join(
|
||||
OS.Constants.Path.profileDir,
|
||||
let path = lazy.OS.Path.join(
|
||||
lazy.OS.Constants.Path.profileDir,
|
||||
"weave",
|
||||
...(filePath + ".json").split("/")
|
||||
);
|
||||
if (that._log) {
|
||||
that._log.trace("Deleting " + path);
|
||||
}
|
||||
return OS.File.remove(path, { ignoreAbsent: true });
|
||||
return lazy.OS.File.remove(path, { ignoreAbsent: true });
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -636,17 +639,17 @@ var Utils = {
|
|||
* Is there a master password configured and currently locked?
|
||||
*/
|
||||
mpLocked() {
|
||||
return !cryptoSDR.isLoggedIn;
|
||||
return !lazy.cryptoSDR.isLoggedIn;
|
||||
},
|
||||
|
||||
// If Master Password is enabled and locked, present a dialog to unlock it.
|
||||
// Return whether the system is unlocked.
|
||||
ensureMPUnlocked() {
|
||||
if (cryptoSDR.uiBusy) {
|
||||
if (lazy.cryptoSDR.uiBusy) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
cryptoSDR.encrypt("bacon");
|
||||
lazy.cryptoSDR.encrypt("bacon");
|
||||
return true;
|
||||
} catch (e) {}
|
||||
return false;
|
||||
|
@ -729,7 +732,7 @@ var Utils = {
|
|||
},
|
||||
|
||||
getDeviceType() {
|
||||
return localDeviceType;
|
||||
return lazy.localDeviceType;
|
||||
},
|
||||
|
||||
formatTimestamp(date) {
|
||||
|
|
|
@ -24,13 +24,14 @@ const { Logger } = ChromeUtils.import("resource://tps/logger.jsm");
|
|||
const { XPCOMUtils } = ChromeUtils.import(
|
||||
"resource://gre/modules/XPCOMUtils.jsm"
|
||||
);
|
||||
const lazy = {};
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"Services",
|
||||
"resource://gre/modules/Services.jsm"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyGlobalGetters(this, ["fetch"]);
|
||||
XPCOMUtils.defineLazyGlobalGetters(lazy, ["fetch"]);
|
||||
|
||||
/**
|
||||
* Helper object for Firefox Accounts authentication
|
||||
|
@ -74,7 +75,7 @@ var Authentication = {
|
|||
},
|
||||
|
||||
async _openVerificationPage(uri) {
|
||||
let mainWindow = Services.wm.getMostRecentWindow("navigator:browser");
|
||||
let mainWindow = lazy.Services.wm.getMostRecentWindow("navigator:browser");
|
||||
let newtab = mainWindow.gBrowser.addWebTab(uri);
|
||||
let win = mainWindow.gBrowser.getBrowserForTab(newtab);
|
||||
await new Promise(resolve => {
|
||||
|
@ -101,7 +102,7 @@ var Authentication = {
|
|||
const tries = 10;
|
||||
const normalWait = 2000;
|
||||
for (let i = 0; i < tries; ++i) {
|
||||
let resp = await fetch(restmailURI);
|
||||
let resp = await lazy.fetch(restmailURI);
|
||||
let messages = await resp.json();
|
||||
// Sort so that the most recent emails are first.
|
||||
messages.sort((a, b) => new Date(b.receivedAt) - new Date(a.receivedAt));
|
||||
|
@ -148,7 +149,7 @@ var Authentication = {
|
|||
)}`;
|
||||
try {
|
||||
// Clean up after ourselves.
|
||||
let deleteResult = await fetch(restmailURI, { method: "DELETE" });
|
||||
let deleteResult = await lazy.fetch(restmailURI, { method: "DELETE" });
|
||||
if (!deleteResult.ok) {
|
||||
Logger.logInfo(
|
||||
`Warning: Got non-success status ${deleteResult.status} when deleting emails`
|
||||
|
|
|
@ -13,7 +13,9 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
"resource://gre/modules/XPCOMUtils.jsm"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
ObjectUtils: "resource://gre/modules/ObjectUtils.jsm",
|
||||
Services: "resource://gre/modules/Services.jsm",
|
||||
});
|
||||
|
@ -30,9 +32,9 @@ var Logger = {
|
|||
}
|
||||
|
||||
if (path) {
|
||||
Services.prefs.setCharPref("tps.logfile", path);
|
||||
lazy.Services.prefs.setCharPref("tps.logfile", path);
|
||||
} else {
|
||||
path = Services.prefs.getCharPref("tps.logfile");
|
||||
path = lazy.Services.prefs.getCharPref("tps.logfile");
|
||||
}
|
||||
|
||||
this._file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
|
||||
|
@ -86,7 +88,7 @@ var Logger = {
|
|||
},
|
||||
|
||||
AssertEqual(got, expected, msg) {
|
||||
if (!ObjectUtils.deepEqual(got, expected)) {
|
||||
if (!lazy.ObjectUtils.deepEqual(got, expected)) {
|
||||
throw new Error(
|
||||
"ASSERTION FAILED! " +
|
||||
msg +
|
||||
|
|
|
@ -16,14 +16,16 @@ var EXPORTED_SYMBOLS = [
|
|||
|
||||
const { Logger } = ChromeUtils.import("resource://tps/logger.jsm");
|
||||
|
||||
const lazy = {};
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"formAutofillStorage",
|
||||
"resource://autofill/FormAutofillStorage.jsm"
|
||||
);
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
lazy,
|
||||
"OSKeyStore",
|
||||
"resource://gre/modules/OSKeyStore.jsm"
|
||||
);
|
||||
|
@ -44,8 +46,8 @@ class FormAutofillBase {
|
|||
}
|
||||
|
||||
async getStorage() {
|
||||
await formAutofillStorage.initialize();
|
||||
return formAutofillStorage[this._subStorageName];
|
||||
await lazy.formAutofillStorage.initialize();
|
||||
return lazy.formAutofillStorage[this._subStorageName];
|
||||
}
|
||||
|
||||
async Create() {
|
||||
|
@ -74,9 +76,9 @@ class FormAutofillBase {
|
|||
}
|
||||
|
||||
async function DumpStorage(subStorageName) {
|
||||
await formAutofillStorage.initialize();
|
||||
await lazy.formAutofillStorage.initialize();
|
||||
Logger.logInfo(`\ndumping ${subStorageName} list\n`, true);
|
||||
const entries = formAutofillStorage[subStorageName]._data;
|
||||
const entries = lazy.formAutofillStorage[subStorageName]._data;
|
||||
for (const entry of entries) {
|
||||
Logger.logInfo(JSON.stringify(entry), true);
|
||||
}
|
||||
|
@ -124,7 +126,7 @@ class CreditCard extends FormAutofillBase {
|
|||
await Promise.all(
|
||||
storage._data.map(
|
||||
async entry =>
|
||||
(entry["cc-number"] = await OSKeyStore.decrypt(
|
||||
(entry["cc-number"] = await lazy.OSKeyStore.decrypt(
|
||||
entry["cc-number-encrypted"]
|
||||
))
|
||||
)
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Загрузка…
Ссылка в новой задаче