diff --git a/dom/workers/ServiceWorkerManager.cpp b/dom/workers/ServiceWorkerManager.cpp index b9206853df17..ab8d8c7a8be5 100644 --- a/dom/workers/ServiceWorkerManager.cpp +++ b/dom/workers/ServiceWorkerManager.cpp @@ -379,7 +379,6 @@ NS_INTERFACE_MAP_END ServiceWorkerManager::ServiceWorkerManager() : mActor(nullptr) - , mShuttingDown(false) { // Register this component to PBackground. MOZ_ALWAYS_TRUE(BackgroundChild::GetOrCreateForCurrentThread(this)); @@ -389,7 +388,14 @@ ServiceWorkerManager::~ServiceWorkerManager() { // The map will assert if it is not empty when destroyed. mRegistrationInfos.Clear(); - MOZ_ASSERT(!mActor); + + if (mActor) { + mActor->ManagerShuttingDown(); + + nsRefPtr runnable = new TeardownRunnable(mActor); + nsresult rv = NS_DispatchToMainThread(runnable); + unused << NS_WARN_IF(NS_FAILED(rv)); + } } void @@ -1547,11 +1553,9 @@ ServiceWorkerManager::AppendPendingOperation(ServiceWorkerJobQueue* aQueue, MOZ_ASSERT(aQueue); MOZ_ASSERT(aJob); - if (!mShuttingDown) { - PendingOperation* opt = mPendingOperations.AppendElement(); - opt->mQueue = aQueue; - opt->mJob = aJob; - } + PendingOperation* opt = mPendingOperations.AppendElement(); + opt->mQueue = aQueue; + opt->mJob = aJob; } void @@ -1560,10 +1564,8 @@ ServiceWorkerManager::AppendPendingOperation(nsIRunnable* aRunnable) MOZ_ASSERT(!mActor); MOZ_ASSERT(aRunnable); - if (!mShuttingDown) { - PendingOperation* opt = mPendingOperations.AppendElement(); - opt->mRunnable = aRunnable; - } + PendingOperation* opt = mPendingOperations.AppendElement(); + opt->mRunnable = aRunnable; } /* @@ -2381,10 +2383,8 @@ private: nsRefPtr swm = ServiceWorkerManager::GetInstance(); - // We could be shutting down. - if (swm->mActor) { - swm->mActor->SendUnregister(principalInfo, NS_ConvertUTF8toUTF16(mScope)); - } + MOZ_ASSERT(swm->mActor); + swm->mActor->SendUnregister(principalInfo, NS_ConvertUTF8toUTF16(mScope)); nsAutoCString scopeKey; nsresult rv = swm->PrincipalToScopeKey(mPrincipal, scopeKey); @@ -2735,15 +2735,10 @@ ServiceWorkerManager::StoreRegistration( nsIPrincipal* aPrincipal, ServiceWorkerRegistrationInfo* aRegistration) { + MOZ_ASSERT(mActor); MOZ_ASSERT(aPrincipal); MOZ_ASSERT(aRegistration); - if (mShuttingDown) { - return; - } - - MOZ_ASSERT(mActor); - ServiceWorkerRegistrationData data; nsresult rv = PopulateRegistrationData(aPrincipal, aRegistration, data); if (NS_WARN_IF(NS_FAILED(rv))) { @@ -4069,10 +4064,6 @@ ServiceWorkerManager::RemoveRegistrationInternal(ServiceWorkerRegistrationInfo* MOZ_ASSERT(aRegistration); MOZ_ASSERT(!aRegistration->IsControllingDocuments()); - if (mShuttingDown) { - return; - } - // All callers should be either from a job in which case the actor is // available, or from MaybeStopControlling(), in which case, this will only be // called if a valid registration is found. If a valid registration exists, @@ -4551,8 +4542,6 @@ ServiceWorkerManager::Observe(nsISupports* aSubject, RemoveAllRegistrations(principal); } else if (strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0) { - mShuttingDown = true; - nsCOMPtr obs = mozilla::services::GetObserverService(); if (obs) { obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID); @@ -4560,15 +4549,6 @@ ServiceWorkerManager::Observe(nsISupports* aSubject, obs->RemoveObserver(this, PURGE_DOMAIN_DATA); obs->RemoveObserver(this, WEBAPPS_CLEAR_DATA); } - - if (mActor) { - mActor->ManagerShuttingDown(); - - nsRefPtr runnable = new TeardownRunnable(mActor); - nsresult rv = NS_DispatchToMainThread(runnable); - unused << NS_WARN_IF(NS_FAILED(rv)); - mActor = nullptr; - } } else { MOZ_CRASH("Received message we aren't supposed to be registered for!"); } diff --git a/dom/workers/ServiceWorkerManager.h b/dom/workers/ServiceWorkerManager.h index e86733c5cf04..a9b41bdeb289 100644 --- a/dom/workers/ServiceWorkerManager.h +++ b/dom/workers/ServiceWorkerManager.h @@ -552,8 +552,6 @@ private: struct PendingOperation; nsTArray mPendingOperations; - - bool mShuttingDown; }; } // namespace workers