Bug 1559919 - Finish the WorkerHolder cleanup - part 4 - IPCWorkerRef in ServiceWorkerContainerChild, r=asuth

Differential Revision: https://phabricator.services.mozilla.com/D35223

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrea Marchesini 2019-07-12 11:16:15 +00:00
Родитель 6e86832cf2
Коммит dfb7f820f8
3 изменённых файлов: 36 добавлений и 34 удалений

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

@ -199,22 +199,12 @@ RemoteServiceWorkerContainerImpl::RemoteServiceWorkerContainerImpl()
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;
}
ServiceWorkerContainerChild* actor = ServiceWorkerContainerChild::Create();
if (NS_WARN_IF(!actor)) {
Shutdown();
return;
}
ServiceWorkerContainerChild* actor =
new ServiceWorkerContainerChild(workerHolderToken);
PServiceWorkerContainerChild* sentActor =
parentActor->SendPServiceWorkerContainerConstructor(actor);
if (NS_WARN_IF(!sentActor)) {

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

@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/dom/PServiceWorkerContainerChild.h"
#include "mozilla/dom/WorkerRef.h"
#include "RemoteServiceWorkerContainerImpl.h"
@ -12,10 +13,7 @@ namespace mozilla {
namespace dom {
void ServiceWorkerContainerChild::ActorDestroy(ActorDestroyReason aReason) {
if (mWorkerHolderToken) {
mWorkerHolderToken->RemoveListener(this);
mWorkerHolderToken = nullptr;
}
mIPCWorkerRef = nullptr;
if (mOwner) {
mOwner->RevokeActor(this);
@ -23,18 +21,32 @@ void ServiceWorkerContainerChild::ActorDestroy(ActorDestroyReason aReason) {
}
}
void ServiceWorkerContainerChild::WorkerShuttingDown() { MaybeStartTeardown(); }
// static
ServiceWorkerContainerChild* ServiceWorkerContainerChild::Create() {
ServiceWorkerContainerChild* actor = new ServiceWorkerContainerChild();
ServiceWorkerContainerChild::ServiceWorkerContainerChild(
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<ServiceWorkerContainerChild>> helper =
new IPCWorkerRefHelper<ServiceWorkerContainerChild>(actor);
actor->mIPCWorkerRef = IPCWorkerRef::Create(
workerPrivate, "ServiceWorkerContainerChild",
[helper] { helper->Actor()->MaybeStartTeardown(); });
if (NS_WARN_IF(!actor->mIPCWorkerRef)) {
delete actor;
return nullptr;
}
}
return actor;
}
ServiceWorkerContainerChild::ServiceWorkerContainerChild()
: mOwner(nullptr), mTeardownStarted(false) {}
void ServiceWorkerContainerChild::SetOwner(
RemoteServiceWorkerContainerImpl* aOwner) {
MOZ_DIAGNOSTIC_ASSERT(!mOwner);

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

@ -8,25 +8,25 @@
#define mozilla_dom_serviceworkercontainerchild_h__
#include "mozilla/dom/PServiceWorkerContainerChild.h"
#include "mozilla/dom/WorkerHolderToken.h"
namespace mozilla {
namespace dom {
class ServiceWorkerContainerChild final : public PServiceWorkerContainerChild,
public WorkerHolderToken::Listener {
RefPtr<WorkerHolderToken> mWorkerHolderToken;
class IPCWorkerRef;
class ServiceWorkerContainerChild final : public PServiceWorkerContainerChild {
RefPtr<IPCWorkerRef> mIPCWorkerRef;
RemoteServiceWorkerContainerImpl* mOwner;
bool mTeardownStarted;
ServiceWorkerContainerChild();
// PServiceWorkerContainerChild
void ActorDestroy(ActorDestroyReason aReason) override;
// WorkerHolderToken::Listener
void WorkerShuttingDown() override;
public:
explicit ServiceWorkerContainerChild(WorkerHolderToken* aWorkerHolderToken);
static ServiceWorkerContainerChild* Create();
~ServiceWorkerContainerChild() = default;
void SetOwner(RemoteServiceWorkerContainerImpl* aOwner);