зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1772101 - Part 7: Use plain object for lazy getter in toolkit/components/cleardata/. r=pbz
Differential Revision: https://phabricator.services.mozilla.com/D147947
This commit is contained in:
Родитель
6a09464fac
Коммит
88ed6bc47c
|
@ -15,20 +15,22 @@ const { AppConstants } = ChromeUtils.import(
|
|||
"resource://gre/modules/AppConstants.jsm"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
Downloads: "resource://gre/modules/Downloads.jsm",
|
||||
ServiceWorkerCleanUp: "resource://gre/modules/ServiceWorkerCleanUp.jsm",
|
||||
PlacesUtils: "resource://gre/modules/PlacesUtils.jsm",
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"sas",
|
||||
"@mozilla.org/storage/activity-service;1",
|
||||
"nsIStorageActivityService"
|
||||
);
|
||||
XPCOMUtils.defineLazyServiceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"TrackingDBService",
|
||||
"@mozilla.org/tracking-db-service;1",
|
||||
"nsITrackingDBService"
|
||||
|
@ -332,7 +334,7 @@ const DownloadsCleaner = {
|
|||
async _deleteInternal({ hostOrBaseDomain, principal, originAttributes }) {
|
||||
originAttributes = originAttributes || principal?.originAttributes || {};
|
||||
|
||||
let list = await Downloads.getList(Downloads.ALL);
|
||||
let list = await lazy.Downloads.getList(lazy.Downloads.ALL);
|
||||
list.removeFinished(({ source }) => {
|
||||
if (
|
||||
"userContextId" in originAttributes &&
|
||||
|
@ -380,7 +382,7 @@ const DownloadsCleaner = {
|
|||
let rangeBeginMs = aFrom / 1000;
|
||||
let rangeEndMs = aTo / 1000;
|
||||
|
||||
return Downloads.getList(Downloads.ALL).then(aList => {
|
||||
return lazy.Downloads.getList(lazy.Downloads.ALL).then(aList => {
|
||||
aList.removeFinished(
|
||||
aDownload =>
|
||||
aDownload.startTime >= rangeBeginMs &&
|
||||
|
@ -390,7 +392,7 @@ const DownloadsCleaner = {
|
|||
},
|
||||
|
||||
deleteAll() {
|
||||
return Downloads.getList(Downloads.ALL).then(aList => {
|
||||
return lazy.Downloads.getList(lazy.Downloads.ALL).then(aList => {
|
||||
aList.removeFinished(null);
|
||||
});
|
||||
},
|
||||
|
@ -543,7 +545,7 @@ const QuotaCleaner = {
|
|||
Services.sessionStorage.clearStoragesForOrigin(aPrincipal);
|
||||
|
||||
// ServiceWorkers: they must be removed before cleaning QuotaManager.
|
||||
return ServiceWorkerCleanUp.removeFromPrincipal(aPrincipal)
|
||||
return lazy.ServiceWorkerCleanUp.removeFromPrincipal(aPrincipal)
|
||||
.then(
|
||||
_ => /* exceptionThrown = */ false,
|
||||
_ => /* exceptionThrown = */ true
|
||||
|
@ -598,7 +600,7 @@ const QuotaCleaner = {
|
|||
// completed.
|
||||
let swCleanupError;
|
||||
try {
|
||||
await ServiceWorkerCleanUp.removeFromBaseDomain(aBaseDomain);
|
||||
await lazy.ServiceWorkerCleanUp.removeFromBaseDomain(aBaseDomain);
|
||||
} catch (error) {
|
||||
swCleanupError = error;
|
||||
}
|
||||
|
@ -629,7 +631,7 @@ const QuotaCleaner = {
|
|||
// errors so we can re-throw later once all operations have completed.
|
||||
let swCleanupError;
|
||||
try {
|
||||
await ServiceWorkerCleanUp.removeFromHost(aHost);
|
||||
await lazy.ServiceWorkerCleanUp.removeFromHost(aHost);
|
||||
} catch (error) {
|
||||
swCleanupError = error;
|
||||
}
|
||||
|
@ -652,7 +654,7 @@ const QuotaCleaner = {
|
|||
},
|
||||
|
||||
deleteByRange(aFrom, aTo) {
|
||||
let principals = sas
|
||||
let principals = lazy.sas
|
||||
.getActiveOrigins(aFrom, aTo)
|
||||
.QueryInterface(Ci.nsIArray);
|
||||
|
||||
|
@ -679,7 +681,7 @@ const QuotaCleaner = {
|
|||
// And it should've been cleared while notifying observers with
|
||||
// clear-origin-attributes-data.
|
||||
|
||||
return ServiceWorkerCleanUp.removeFromOriginAttributes(
|
||||
return lazy.ServiceWorkerCleanUp.removeFromOriginAttributes(
|
||||
aOriginAttributesString
|
||||
)
|
||||
.then(
|
||||
|
@ -715,7 +717,7 @@ const QuotaCleaner = {
|
|||
// errors so we can re-throw later once all operations have completed.
|
||||
let swCleanupError;
|
||||
try {
|
||||
await ServiceWorkerCleanUp.removeAll();
|
||||
await lazy.ServiceWorkerCleanUp.removeAll();
|
||||
} catch (error) {
|
||||
swCleanupError = error;
|
||||
}
|
||||
|
@ -895,14 +897,14 @@ const HistoryCleaner = {
|
|||
if (!AppConstants.MOZ_PLACES) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return PlacesUtils.history.removeByFilter({ host: "." + aHost });
|
||||
return lazy.PlacesUtils.history.removeByFilter({ host: "." + aHost });
|
||||
},
|
||||
|
||||
deleteByPrincipal(aPrincipal) {
|
||||
if (!AppConstants.MOZ_PLACES) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return PlacesUtils.history.removeByFilter({ host: aPrincipal.host });
|
||||
return lazy.PlacesUtils.history.removeByFilter({ host: aPrincipal.host });
|
||||
},
|
||||
|
||||
deleteByBaseDomain(aBaseDomain) {
|
||||
|
@ -913,7 +915,7 @@ const HistoryCleaner = {
|
|||
if (!AppConstants.MOZ_PLACES) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return PlacesUtils.history.removeVisitsByFilter({
|
||||
return lazy.PlacesUtils.history.removeVisitsByFilter({
|
||||
beginDate: new Date(aFrom / 1000),
|
||||
endDate: new Date(aTo / 1000),
|
||||
});
|
||||
|
@ -923,7 +925,7 @@ const HistoryCleaner = {
|
|||
if (!AppConstants.MOZ_PLACES) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return PlacesUtils.history.clear();
|
||||
return lazy.PlacesUtils.history.clear();
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -1285,7 +1287,7 @@ const ReportsCleaner = {
|
|||
|
||||
const ContentBlockingCleaner = {
|
||||
deleteAll() {
|
||||
return TrackingDBService.clearAll();
|
||||
return lazy.TrackingDBService.clearAll();
|
||||
},
|
||||
|
||||
async deleteByPrincipal(aPrincipal, aIsUserRequest) {
|
||||
|
@ -1303,7 +1305,7 @@ const ContentBlockingCleaner = {
|
|||
},
|
||||
|
||||
deleteByRange(aFrom, aTo) {
|
||||
return TrackingDBService.clearSince(aFrom);
|
||||
return lazy.TrackingDBService.clearSince(aFrom);
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -10,8 +10,10 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
"resource://gre/modules/XPCOMUtils.jsm"
|
||||
);
|
||||
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"serviceWorkerManager",
|
||||
"@mozilla.org/serviceworkers/manager;1",
|
||||
"nsIServiceWorkerManager"
|
||||
|
@ -109,7 +111,7 @@ class PrincipalsCollector {
|
|||
});
|
||||
|
||||
progress.step = "principals-service-workers";
|
||||
let serviceWorkers = serviceWorkerManager.getAllRegistrations();
|
||||
let serviceWorkers = lazy.serviceWorkerManager.getAllRegistrations();
|
||||
for (let i = 0; i < serviceWorkers.length; i++) {
|
||||
let sw = serviceWorkers.queryElementAt(
|
||||
i,
|
||||
|
|
|
@ -9,8 +9,10 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
);
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"serviceWorkerManager",
|
||||
"@mozilla.org/serviceworkers/manager;1",
|
||||
"nsIServiceWorkerManager"
|
||||
|
@ -33,7 +35,7 @@ function unregisterServiceWorker(aSW) {
|
|||
"nsIServiceWorkerUnregisterCallback",
|
||||
]),
|
||||
};
|
||||
serviceWorkerManager.propagateUnregister(
|
||||
lazy.serviceWorkerManager.propagateUnregister(
|
||||
aSW.principal,
|
||||
unregisterCallback,
|
||||
aSW.scope
|
||||
|
@ -43,7 +45,7 @@ function unregisterServiceWorker(aSW) {
|
|||
|
||||
function unregisterServiceWorkersMatching(filterFn) {
|
||||
let promises = [];
|
||||
let serviceWorkers = serviceWorkerManager.getAllRegistrations();
|
||||
let serviceWorkers = lazy.serviceWorkerManager.getAllRegistrations();
|
||||
for (let i = 0; i < serviceWorkers.length; i++) {
|
||||
let sw = serviceWorkers.queryElementAt(
|
||||
i,
|
||||
|
@ -80,7 +82,7 @@ const ServiceWorkerCleanUp = {
|
|||
},
|
||||
|
||||
removeFromOriginAttributes(aOriginAttributesString) {
|
||||
serviceWorkerManager.removeRegistrationsByOriginAttributes(
|
||||
lazy.serviceWorkerManager.removeRegistrationsByOriginAttributes(
|
||||
aOriginAttributesString
|
||||
);
|
||||
return Promise.resolve();
|
||||
|
|
|
@ -14,14 +14,16 @@ const { BrowserTestUtils } = ChromeUtils.import(
|
|||
"resource://testing-common/BrowserTestUtils.jsm"
|
||||
);
|
||||
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"swm",
|
||||
"@mozilla.org/serviceworkers/manager;1",
|
||||
"nsIServiceWorkerManager"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyGlobalGetters(this, ["indexedDB"]);
|
||||
XPCOMUtils.defineLazyGlobalGetters(lazy, ["indexedDB"]);
|
||||
|
||||
/**
|
||||
* This module assists with tasks around testing functionality that shows
|
||||
|
@ -61,7 +63,11 @@ var SiteDataTestUtils = {
|
|||
let principal = Services.scriptSecurityManager.createContentPrincipalFromOrigin(
|
||||
origin
|
||||
);
|
||||
let request = indexedDB.openForPrincipal(principal, "TestDatabase", 1);
|
||||
let request = lazy.indexedDB.openForPrincipal(
|
||||
principal,
|
||||
"TestDatabase",
|
||||
1
|
||||
);
|
||||
request.onupgradeneeded = function(e) {
|
||||
let db = e.target.result;
|
||||
db.createObjectStore("TestStore");
|
||||
|
@ -250,7 +256,11 @@ var SiteDataTestUtils = {
|
|||
);
|
||||
return new Promise(resolve => {
|
||||
let data = true;
|
||||
let request = indexedDB.openForPrincipal(principal, "TestDatabase", 1);
|
||||
let request = lazy.indexedDB.openForPrincipal(
|
||||
principal,
|
||||
"TestDatabase",
|
||||
1
|
||||
);
|
||||
request.onupgradeneeded = function(e) {
|
||||
data = false;
|
||||
};
|
||||
|
@ -310,7 +320,7 @@ var SiteDataTestUtils = {
|
|||
* @returns {Boolean} whether or not the site has ServiceWorkers.
|
||||
*/
|
||||
hasServiceWorkers(origin) {
|
||||
let serviceWorkers = swm.getAllRegistrations();
|
||||
let serviceWorkers = lazy.swm.getAllRegistrations();
|
||||
for (let i = 0; i < serviceWorkers.length; i++) {
|
||||
let sw = serviceWorkers.queryElementAt(
|
||||
i,
|
||||
|
@ -342,11 +352,11 @@ var SiteDataTestUtils = {
|
|||
if (registration.principal.host != url.host) {
|
||||
return;
|
||||
}
|
||||
swm.removeListener(listener);
|
||||
lazy.swm.removeListener(listener);
|
||||
resolve(registration);
|
||||
},
|
||||
};
|
||||
swm.addListener(listener);
|
||||
lazy.swm.addListener(listener);
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -369,11 +379,11 @@ var SiteDataTestUtils = {
|
|||
if (registration.principal.host != url.host) {
|
||||
return;
|
||||
}
|
||||
swm.removeListener(listener);
|
||||
lazy.swm.removeListener(listener);
|
||||
resolve(registration);
|
||||
},
|
||||
};
|
||||
swm.addListener(listener);
|
||||
lazy.swm.addListener(listener);
|
||||
});
|
||||
},
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче