mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 03:45:46 +00:00
Bug 1559919 - Finish the WorkerHolder cleanup - part 6 - IPCWorkerRef in ServiceWorkerChild, r=asuth
Differential Revision: https://phabricator.services.mozilla.com/D35225 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
dda55c2dec
commit
f3428b3c3c
@ -85,21 +85,12 @@ RemoteServiceWorkerImpl::RemoteServiceWorkerImpl(
|
||||
return;
|
||||
}
|
||||
|
||||
RefPtr<WorkerHolderToken> 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;
|
||||
}
|
||||
ServiceWorkerChild* actor = ServiceWorkerChild::Create();
|
||||
if (NS_WARN_IF(!actor)) {
|
||||
Shutdown();
|
||||
return;
|
||||
}
|
||||
|
||||
ServiceWorkerChild* actor = new ServiceWorkerChild(workerHolderToken);
|
||||
PServiceWorkerChild* sentActor =
|
||||
parentActor->SendPServiceWorkerConstructor(actor, aDescriptor.ToIPC());
|
||||
if (NS_WARN_IF(!sentActor)) {
|
||||
|
@ -5,15 +5,13 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "ServiceWorkerChild.h"
|
||||
#include "mozilla/dom/WorkerRef.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
void ServiceWorkerChild::ActorDestroy(ActorDestroyReason aReason) {
|
||||
if (mWorkerHolderToken) {
|
||||
mWorkerHolderToken->RemoveListener(this);
|
||||
mWorkerHolderToken = nullptr;
|
||||
}
|
||||
mIPCWorkerRef = nullptr;
|
||||
|
||||
if (mOwner) {
|
||||
mOwner->RevokeActor(this);
|
||||
@ -21,17 +19,33 @@ void ServiceWorkerChild::ActorDestroy(ActorDestroyReason aReason) {
|
||||
}
|
||||
}
|
||||
|
||||
void ServiceWorkerChild::WorkerShuttingDown() { MaybeStartTeardown(); }
|
||||
// static
|
||||
ServiceWorkerChild* ServiceWorkerChild::Create() {
|
||||
ServiceWorkerChild* actor = new ServiceWorkerChild();
|
||||
|
||||
ServiceWorkerChild::ServiceWorkerChild(WorkerHolderToken* aWorkerHolderToken)
|
||||
: mWorkerHolderToken(aWorkerHolderToken),
|
||||
mOwner(nullptr),
|
||||
mTeardownStarted(false) {
|
||||
if (mWorkerHolderToken) {
|
||||
mWorkerHolderToken->AddListener(this);
|
||||
if (!NS_IsMainThread()) {
|
||||
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
||||
MOZ_DIAGNOSTIC_ASSERT(workerPrivate);
|
||||
|
||||
RefPtr<IPCWorkerRefHelper<ServiceWorkerChild>> helper =
|
||||
new IPCWorkerRefHelper<ServiceWorkerChild>(actor);
|
||||
|
||||
actor->mIPCWorkerRef = IPCWorkerRef::Create(
|
||||
workerPrivate, "ServiceWorkerChild",
|
||||
[helper] { helper->Actor()->MaybeStartTeardown(); });
|
||||
|
||||
if (NS_WARN_IF(!actor->mIPCWorkerRef)) {
|
||||
delete actor;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
return actor;
|
||||
}
|
||||
|
||||
ServiceWorkerChild::ServiceWorkerChild()
|
||||
: mOwner(nullptr), mTeardownStarted(false) {}
|
||||
|
||||
void ServiceWorkerChild::SetOwner(RemoteServiceWorkerImpl* aOwner) {
|
||||
MOZ_DIAGNOSTIC_ASSERT(!mOwner);
|
||||
MOZ_DIAGNOSTIC_ASSERT(aOwner);
|
||||
|
@ -8,27 +8,26 @@
|
||||
#define mozilla_dom_serviceworkerchild_h__
|
||||
|
||||
#include "mozilla/dom/PServiceWorkerChild.h"
|
||||
#include "mozilla/dom/WorkerHolderToken.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class IPCWorkerRef;
|
||||
class RemoteServiceWorkerImpl;
|
||||
|
||||
class ServiceWorkerChild final : public PServiceWorkerChild,
|
||||
public WorkerHolderToken::Listener {
|
||||
RefPtr<WorkerHolderToken> mWorkerHolderToken;
|
||||
class ServiceWorkerChild final : public PServiceWorkerChild {
|
||||
RefPtr<IPCWorkerRef> mIPCWorkerRef;
|
||||
RemoteServiceWorkerImpl* mOwner;
|
||||
bool mTeardownStarted;
|
||||
|
||||
ServiceWorkerChild();
|
||||
|
||||
// PServiceWorkerChild
|
||||
void ActorDestroy(ActorDestroyReason aReason) override;
|
||||
|
||||
// WorkerHolderToken::Listener
|
||||
void WorkerShuttingDown() override;
|
||||
|
||||
public:
|
||||
explicit ServiceWorkerChild(WorkerHolderToken* aWorkerHolderToken);
|
||||
static ServiceWorkerChild* Create();
|
||||
|
||||
~ServiceWorkerChild() = default;
|
||||
|
||||
void SetOwner(RemoteServiceWorkerImpl* aOwner);
|
||||
|
Loading…
Reference in New Issue
Block a user