mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1174381 - ServiceWorkerManager::TeardownRunnable should be called when xpcom-shutdown notification is received, r=nsm
This commit is contained in:
parent
8145fcb415
commit
4df32734b9
@ -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,19 +389,19 @@ 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
|
||||
ServiceWorkerManager::Init()
|
||||
{
|
||||
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
||||
if (obs) {
|
||||
DebugOnly<nsresult> rv;
|
||||
rv = obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false /* ownsWeak */);
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||
}
|
||||
|
||||
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
||||
nsRefPtr<ServiceWorkerRegistrar> swr = ServiceWorkerRegistrar::Get();
|
||||
MOZ_ASSERT(swr);
|
||||
@ -409,11 +410,8 @@ ServiceWorkerManager::Init()
|
||||
swr->GetRegistrations(data);
|
||||
LoadRegistrations(data);
|
||||
|
||||
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
||||
if (obs) {
|
||||
DebugOnly<nsresult> rv;
|
||||
rv = obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false /* ownsWeak */);
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||
rv = obs->AddObserver(this, PURGE_SESSION_HISTORY, false /* ownsWeak */);
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||
rv = obs->AddObserver(this, PURGE_DOMAIN_DATA, false /* ownsWeak */);
|
||||
@ -1553,9 +1551,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
|
||||
@ -1564,8 +1564,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;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -2383,8 +2385,10 @@ private:
|
||||
|
||||
nsRefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
|
||||
|
||||
MOZ_ASSERT(swm->mActor);
|
||||
swm->mActor->SendUnregister(principalInfo, NS_ConvertUTF8toUTF16(mScope));
|
||||
// Could it be that we are shutting down.
|
||||
if (swm->mActor) {
|
||||
swm->mActor->SendUnregister(principalInfo, NS_ConvertUTF8toUTF16(mScope));
|
||||
}
|
||||
|
||||
nsAutoCString scopeKey;
|
||||
nsresult rv = swm->PrincipalToScopeKey(mPrincipal, scopeKey);
|
||||
@ -2735,10 +2739,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))) {
|
||||
@ -4064,6 +4073,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,
|
||||
@ -4497,21 +4510,22 @@ ServiceWorkerManager::Observe(nsISupports* aSubject,
|
||||
const char* aTopic,
|
||||
const char16_t* aData)
|
||||
{
|
||||
MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
|
||||
|
||||
if (strcmp(aTopic, PURGE_SESSION_HISTORY) == 0) {
|
||||
MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
|
||||
RemoveAll();
|
||||
PropagateRemoveAll();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (strcmp(aTopic, PURGE_DOMAIN_DATA) == 0) {
|
||||
MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
|
||||
nsAutoString domain(aData);
|
||||
RemoveAndPropagate(NS_ConvertUTF16toUTF8(domain));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (strcmp(aTopic, WEBAPPS_CLEAR_DATA) == 0) {
|
||||
MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
|
||||
nsCOMPtr<mozIApplicationClearPrivateDataParams> params =
|
||||
do_QueryInterface(aSubject);
|
||||
if (NS_WARN_IF(!params)) {
|
||||
@ -4541,18 +4555,35 @@ ServiceWorkerManager::Observe(nsISupports* aSubject,
|
||||
}
|
||||
|
||||
RemoveAllRegistrations(principal);
|
||||
} else if (strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
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);
|
||||
obs->RemoveObserver(this, PURGE_SESSION_HISTORY);
|
||||
obs->RemoveObserver(this, PURGE_DOMAIN_DATA);
|
||||
obs->RemoveObserver(this, WEBAPPS_CLEAR_DATA);
|
||||
|
||||
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
||||
obs->RemoveObserver(this, PURGE_SESSION_HISTORY);
|
||||
obs->RemoveObserver(this, PURGE_DOMAIN_DATA);
|
||||
obs->RemoveObserver(this, WEBAPPS_CLEAR_DATA);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
MOZ_CRASH("Received message we aren't supposed to be registered for!");
|
||||
|
||||
if (mActor) {
|
||||
mActor->ManagerShuttingDown();
|
||||
|
||||
nsRefPtr<TeardownRunnable> runnable = new TeardownRunnable(mActor);
|
||||
nsresult rv = NS_DispatchToMainThread(runnable);
|
||||
unused << NS_WARN_IF(NS_FAILED(rv));
|
||||
mActor = nullptr;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
MOZ_CRASH("Received message we aren't supposed to be registered for!");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -552,6 +552,8 @@ private:
|
||||
|
||||
struct PendingOperation;
|
||||
nsTArray<PendingOperation> mPendingOperations;
|
||||
|
||||
bool mShuttingDown;
|
||||
};
|
||||
|
||||
} // namespace workers
|
||||
|
Loading…
Reference in New Issue
Block a user