Bug 1174381 - ServiceWorkerManager::TeardownRunnable should be called when xpcom-shutdown notification is received, r=nsm

This commit is contained in:
Andrea Marchesini 2015-06-21 10:21:28 +01:00
Родитель b4ac1c6491
Коммит c7076248d9
2 изменённых файлов: 38 добавлений и 16 удалений

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

@ -379,6 +379,7 @@ NS_INTERFACE_MAP_END
ServiceWorkerManager::ServiceWorkerManager()
: mActor(nullptr)
, mShuttingDown(false)
{
// Register this component to PBackground.
MOZ_ALWAYS_TRUE(BackgroundChild::GetOrCreateForCurrentThread(this));
@ -388,14 +389,7 @@ ServiceWorkerManager::~ServiceWorkerManager()
{
// The map will assert if it is not empty when destroyed.
mRegistrationInfos.Clear();
if (mActor) {
mActor->ManagerShuttingDown();
nsRefPtr<TeardownRunnable> runnable = new TeardownRunnable(mActor);
nsresult rv = NS_DispatchToMainThread(runnable);
unused << NS_WARN_IF(NS_FAILED(rv));
}
MOZ_ASSERT(!mActor);
}
void
@ -1483,9 +1477,11 @@ ServiceWorkerManager::AppendPendingOperation(ServiceWorkerJobQueue* aQueue,
MOZ_ASSERT(aQueue);
MOZ_ASSERT(aJob);
PendingOperation* opt = mPendingOperations.AppendElement();
opt->mQueue = aQueue;
opt->mJob = aJob;
if (!mShuttingDown) {
PendingOperation* opt = mPendingOperations.AppendElement();
opt->mQueue = aQueue;
opt->mJob = aJob;
}
}
void
@ -1494,8 +1490,10 @@ ServiceWorkerManager::AppendPendingOperation(nsIRunnable* aRunnable)
MOZ_ASSERT(!mActor);
MOZ_ASSERT(aRunnable);
PendingOperation* opt = mPendingOperations.AppendElement();
opt->mRunnable = aRunnable;
if (!mShuttingDown) {
PendingOperation* opt = mPendingOperations.AppendElement();
opt->mRunnable = aRunnable;
}
}
/*
@ -2355,8 +2353,10 @@ private:
swm->RemoveRegistration(registration);
}
MOZ_ASSERT(swm->mActor);
swm->mActor->SendUnregister(principalInfo, NS_ConvertUTF8toUTF16(mScope));
// We could be shutting down.
if (swm->mActor) {
swm->mActor->SendUnregister(principalInfo, NS_ConvertUTF8toUTF16(mScope));
}
return NS_OK;
}
@ -2665,10 +2665,15 @@ 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))) {
@ -3994,6 +3999,10 @@ 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,
@ -4432,6 +4441,8 @@ ServiceWorkerManager::Observe(nsISupports* aSubject,
RemoveAllRegistrations(principal);
} else if (strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0) {
mShuttingDown = true;
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (obs) {
obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
@ -4439,6 +4450,15 @@ ServiceWorkerManager::Observe(nsISupports* aSubject,
obs->RemoveObserver(this, PURGE_DOMAIN_DATA);
obs->RemoveObserver(this, WEBAPPS_CLEAR_DATA);
}
if (mActor) {
mActor->ManagerShuttingDown();
nsRefPtr<TeardownRunnable> 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!");
}

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

@ -540,6 +540,8 @@ private:
struct PendingOperation;
nsTArray<PendingOperation> mPendingOperations;
bool mShuttingDown;
};
} // namespace workers