Bug 1254741 P2 Don't aggressively terminate service workers when last controlled window is closed. r=baku

This commit is contained in:
Ben Kelly 2016-05-23 02:46:26 -07:00
parent 05c6dff3b5
commit 05565765eb
3 changed files with 4 additions and 29 deletions

View File

@ -1918,13 +1918,10 @@ ServiceWorkerManager::StopControllingADocument(ServiceWorkerRegistrationInfo* aR
if (aRegistration->mPendingUninstall) { if (aRegistration->mPendingUninstall) {
RemoveRegistration(aRegistration); RemoveRegistration(aRegistration);
} else { } else {
// If the registration has an active worker that is running // We use to aggressively terminate the worker at this point, but it
// this might be a good time to stop it. // caused problems. There are more uses for a service worker than actively
if (aRegistration->GetActive()) { // controlled documents. We need to let the worker naturally terminate
ServiceWorkerPrivate* serviceWorkerPrivate = // in case its handling push events, message events, etc.
aRegistration->GetActive()->WorkerPrivate();
serviceWorkerPrivate->NoteStoppedControllingDocuments();
}
aRegistration->TryToActivateAsync(); aRegistration->TryToActivateAsync();
} }
} }

View File

@ -84,7 +84,6 @@ NS_IMPL_ISUPPORTS0(KeepAliveToken)
ServiceWorkerPrivate::ServiceWorkerPrivate(ServiceWorkerInfo* aInfo) ServiceWorkerPrivate::ServiceWorkerPrivate(ServiceWorkerInfo* aInfo)
: mInfo(aInfo) : mInfo(aInfo)
, mIsPushWorker(false)
, mDebuggerCount(0) , mDebuggerCount(0)
, mTokenCount(0) , mTokenCount(0)
{ {
@ -1598,7 +1597,6 @@ ServiceWorkerPrivate::SpawnWorkerIfNeeded(WakeUpReason aWhy,
return error.StealNSResult(); return error.StealNSResult();
} }
mIsPushWorker = false;
RenewKeepAliveToken(aWhy); RenewKeepAliveToken(aWhy);
return NS_OK; return NS_OK;
@ -1659,17 +1657,6 @@ ServiceWorkerPrivate::NoteDeadServiceWorkerInfo()
TerminateWorker(); TerminateWorker();
} }
void
ServiceWorkerPrivate::NoteStoppedControllingDocuments()
{
AssertIsOnMainThread();
if (mIsPushWorker || mDebuggerCount) {
return;
}
TerminateWorker();
}
void void
ServiceWorkerPrivate::Activated() ServiceWorkerPrivate::Activated()
{ {
@ -1801,10 +1788,6 @@ ServiceWorkerPrivate::RenewKeepAliveToken(WakeUpReason aWhy)
// We should have an active worker if we're renewing the keep alive token. // We should have an active worker if we're renewing the keep alive token.
MOZ_ASSERT(mWorkerPrivate); MOZ_ASSERT(mWorkerPrivate);
if (aWhy == PushEvent || aWhy == PushSubscriptionChangeEvent) {
mIsPushWorker = true;
}
// If there is at least one debugger attached to the worker, the idle worker // If there is at least one debugger attached to the worker, the idle worker
// timeout was canceled when the first debugger attached to the worker. It // timeout was canceled when the first debugger attached to the worker. It
// should not be reset until the last debugger detaches from the worker. // should not be reset until the last debugger detaches from the worker.

View File

@ -193,11 +193,6 @@ private:
nsCOMPtr<nsITimer> mIdleWorkerTimer; nsCOMPtr<nsITimer> mIdleWorkerTimer;
// We keep track if this worker received any push events since it was last
// woken up. The flag is reset to false every time a new WorkerPrivate
// is created.
bool mIsPushWorker;
// We keep a token for |dom.serviceWorkers.idle_timeout| seconds to give the // We keep a token for |dom.serviceWorkers.idle_timeout| seconds to give the
// worker a grace period after each event. // worker a grace period after each event.
RefPtr<KeepAliveToken> mKeepAliveToken; RefPtr<KeepAliveToken> mKeepAliveToken;