diff --git a/dom/serviceworkers/RemoteServiceWorkerRegistrationImpl.cpp b/dom/serviceworkers/RemoteServiceWorkerRegistrationImpl.cpp index a4230c9b255c..8ade4cdea561 100644 --- a/dom/serviceworkers/RemoteServiceWorkerRegistrationImpl.cpp +++ b/dom/serviceworkers/RemoteServiceWorkerRegistrationImpl.cpp @@ -114,22 +114,13 @@ RemoteServiceWorkerRegistrationImpl::RemoteServiceWorkerRegistrationImpl( return; } - RefPtr workerHolderToken; - if (!NS_IsMainThread()) { - WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate(); - MOZ_DIAGNOSTIC_ASSERT(workerPrivate); - - workerHolderToken = WorkerHolderToken::Create( - workerPrivate, Canceling, WorkerHolderToken::AllowIdleShutdownStart); - - if (NS_WARN_IF(!workerHolderToken)) { - Shutdown(); - return; - } + ServiceWorkerRegistrationChild* actor = + ServiceWorkerRegistrationChild::Create(); + if (NS_WARN_IF(!actor)) { + Shutdown(); + return; } - ServiceWorkerRegistrationChild* actor = - new ServiceWorkerRegistrationChild(workerHolderToken); PServiceWorkerRegistrationChild* sentActor = parentActor->SendPServiceWorkerRegistrationConstructor( actor, aDescriptor.ToIPC()); diff --git a/dom/serviceworkers/ServiceWorkerRegistrationChild.cpp b/dom/serviceworkers/ServiceWorkerRegistrationChild.cpp index c5eb4f5814c9..0ef4444905cf 100644 --- a/dom/serviceworkers/ServiceWorkerRegistrationChild.cpp +++ b/dom/serviceworkers/ServiceWorkerRegistrationChild.cpp @@ -14,10 +14,7 @@ namespace dom { using mozilla::ipc::IPCResult; void ServiceWorkerRegistrationChild::ActorDestroy(ActorDestroyReason aReason) { - if (mWorkerHolderToken) { - mWorkerHolderToken->RemoveListener(this); - mWorkerHolderToken = nullptr; - } + mIPCWorkerRef = nullptr; if (mOwner) { mOwner->RevokeActor(this); @@ -40,19 +37,32 @@ IPCResult ServiceWorkerRegistrationChild::RecvFireUpdateFound() { return IPC_OK(); } -void ServiceWorkerRegistrationChild::WorkerShuttingDown() { - MaybeStartTeardown(); +// static +ServiceWorkerRegistrationChild* ServiceWorkerRegistrationChild::Create() { + ServiceWorkerRegistrationChild* actor = new ServiceWorkerRegistrationChild(); + + if (!NS_IsMainThread()) { + WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate(); + MOZ_DIAGNOSTIC_ASSERT(workerPrivate); + + RefPtr> helper = + new IPCWorkerRefHelper(actor); + + actor->mIPCWorkerRef = IPCWorkerRef::Create( + workerPrivate, "ServiceWorkerRegistrationChild", + [helper] { helper->Actor()->MaybeStartTeardown(); }); + + if (NS_WARN_IF(!actor->mIPCWorkerRef)) { + delete actor; + return nullptr; + } + } + + return actor; } -ServiceWorkerRegistrationChild::ServiceWorkerRegistrationChild( - WorkerHolderToken* aWorkerHolderToken) - : mWorkerHolderToken(aWorkerHolderToken), - mOwner(nullptr), - mTeardownStarted(false) { - if (mWorkerHolderToken) { - mWorkerHolderToken->AddListener(this); - } -} +ServiceWorkerRegistrationChild::ServiceWorkerRegistrationChild() + : mOwner(nullptr), mTeardownStarted(false) {} void ServiceWorkerRegistrationChild::SetOwner( RemoteServiceWorkerRegistrationImpl* aOwner) { diff --git a/dom/serviceworkers/ServiceWorkerRegistrationChild.h b/dom/serviceworkers/ServiceWorkerRegistrationChild.h index 5060e9b78605..a301287d13d7 100644 --- a/dom/serviceworkers/ServiceWorkerRegistrationChild.h +++ b/dom/serviceworkers/ServiceWorkerRegistrationChild.h @@ -8,20 +8,21 @@ #define mozilla_dom_serviceworkerregistrationchild_h__ #include "mozilla/dom/PServiceWorkerRegistrationChild.h" -#include "mozilla/dom/WorkerHolderToken.h" namespace mozilla { namespace dom { +class IPCWorkerRef; class RemoteServiceWorkerRegistrationImpl; class ServiceWorkerRegistrationChild final - : public PServiceWorkerRegistrationChild, - public WorkerHolderToken::Listener { - RefPtr mWorkerHolderToken; + : public PServiceWorkerRegistrationChild { + RefPtr mIPCWorkerRef; RemoteServiceWorkerRegistrationImpl* mOwner; bool mTeardownStarted; + ServiceWorkerRegistrationChild(); + // PServiceWorkerRegistrationChild void ActorDestroy(ActorDestroyReason aReason) override; @@ -30,12 +31,9 @@ class ServiceWorkerRegistrationChild final mozilla::ipc::IPCResult RecvFireUpdateFound() override; - // WorkerHolderToken::Listener - void WorkerShuttingDown() override; - public: - explicit ServiceWorkerRegistrationChild( - WorkerHolderToken* aWorkerHolderToken); + static ServiceWorkerRegistrationChild* Create(); + ~ServiceWorkerRegistrationChild() = default; void SetOwner(RemoteServiceWorkerRegistrationImpl* aOwner);