Bug 1047098 - "Clear Recent History" must clean up all the ServiceWorkers, r=bkelly

This includes minor shutdown fixes by :asuth as discussed on
https://bugzilla.mozilla.org/show_bug.cgi?id=1047098#c56 and c57.

--HG--
extra : rebase_source : d1a230cc005b2a6a71f16ef84a55851ee2f4f66e
extra : source : e89d2565799b4b02d5ee2c56da8d44dc0067f26a
This commit is contained in:
Andrea Marchesini 2017-09-21 21:32:00 +02:00
Родитель e12cd767a3
Коммит b7cd7c515d
3 изменённых файлов: 40 добавлений и 1 удалений

Просмотреть файл

@ -20,6 +20,9 @@ XPCOMUtils.defineLazyModuleGetters(this, {
});
XPCOMUtils.defineLazyServiceGetter(this, "serviceWorkerManager",
"@mozilla.org/serviceworkers/manager;1",
"nsIServiceWorkerManager");
XPCOMUtils.defineLazyServiceGetter(this, "quotaManagerService",
"@mozilla.org/dom/quota-manager-service;1",
"nsIQuotaManagerService");
@ -293,6 +296,14 @@ Sanitizer.prototype = {
// LocalStorage
Services.obs.notifyObservers(null, "extension:purge-localStorage");
// ServiceWorkers
let serviceWorkers = serviceWorkerManager.getAllRegistrations();
for (let i = 0; i < serviceWorkers.length; i++) {
let sw = serviceWorkers.queryElementAt(i, Ci.nsIServiceWorkerRegistrationInfo);
let host = sw.principal.URI.host;
serviceWorkerManager.removeAndPropagate(host);
}
// QuotaManager
let promises = [];
await new Promise(resolve => {

Просмотреть файл

@ -1061,6 +1061,34 @@ ServiceWorkerRegistrar::ProfileStopped()
PBackgroundChild* child = BackgroundChild::GetForCurrentThread();
if (!child) {
// Mutations to the ServiceWorkerRegistrar happen on the PBackground thread,
// issued by the ServiceWorkerManagerService, so the appropriate place to
// trigger shutdown is on that thread.
//
// However, it's quite possible that the PBackground thread was not brought
// into existence for xpcshell tests. We don't cause it to be created
// ourselves for any reason, for example.
//
// In this scenario, we know that:
// - We will receive exactly one call to ourself from BlockShutdown() and
// BlockShutdown() will be called (at most) once.
// - The only way our Shutdown() method gets called is via
// BackgroundParentImpl::RecvShutdownServiceWorkerRegistrar() being
// invoked, which only happens if we get to that send below here that we
// can't get to.
// - All Shutdown() does is set mShuttingDown=true (essential for
// invariants) and invoke MaybeScheduleShutdownCompleted().
// - Since there is no PBackground thread, mRunnableCounter must be 0
// because only ScheduleSaveData() increments it and it only runs on the
// background thread, so it cannot have run. And so we would expect
// MaybeScheduleShutdownCompleted() to schedule an invocation of
// ShutdownCompleted on the main thread.
//
// So it's appropriate for us to set mShuttingDown=true (as Shutdown would
// do) and directly invoke ShutdownCompleted() (as Shutdown would indirectly
// do via MaybeScheduleShutdownCompleted).
mShuttingDown = true;
ShutdownCompleted();
return;
}

Просмотреть файл

@ -75,7 +75,7 @@ XPCOMUtils.defineLazyGetter(this, "SMALLSVG_DATA_URI", function() {
var gTestDir = do_get_cwd();
// Initialize profile.
var gProfD = do_get_profile();
var gProfD = do_get_profile(true);
Services.prefs.setBoolPref("browser.urlbar.usepreloadedtopurls.enabled", false);
do_register_cleanup(() =>