Bug 1559919 - Finish the WorkerHolder cleanup - part 7 - IPCWorkerRef in ClientManagerChild, r=asuth

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrea Marchesini 2019-07-12 11:17:46 +00:00
Родитель f3428b3c3c
Коммит a9f2438114
4 изменённых файлов: 37 добавлений и 43 удалений

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

@ -9,7 +9,6 @@
#include "mozilla/dom/ClientIPCTypes.h"
#include "mozilla/dom/ClientOpPromise.h"
#include "mozilla/dom/DOMMozPromiseRequestHolder.h"
#include "mozilla/dom/WorkerHolderToken.h"
#include "mozilla/dom/WorkerPrivate.h"
class nsIGlobalObject;

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

@ -11,7 +11,6 @@
#include "ClientManagerOpChild.h"
#include "ClientPrefs.h"
#include "ClientSource.h"
#include "mozilla/dom/WorkerHolderToken.h"
#include "mozilla/dom/WorkerPrivate.h"
#include "mozilla/ipc/BackgroundChild.h"
#include "mozilla/ipc/PBackgroundChild.h"
@ -54,27 +53,12 @@ ClientManager::ClientManager() {
return;
}
RefPtr<WorkerHolderToken> workerHolderToken;
if (!NS_IsMainThread()) {
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
MOZ_DIAGNOSTIC_ASSERT(workerPrivate);
// Note, it would be nice to replace this with a WorkerRef, but
// currently there is no WorkerRef option that matches what we
// need here. We need something like a StrongWorkerRef that will
// let us keep the worker alive until our actor is destroyed, but
// we also need to use AllowIdleShutdownStart like WeakWorkerRef.
// We need AllowIdleShutdownStart since every worker thread will
// have a ClientManager to support creating its ClientSource.
workerHolderToken = WorkerHolderToken::Create(
workerPrivate, Canceling, WorkerHolderToken::AllowIdleShutdownStart);
if (NS_WARN_IF(!workerHolderToken)) {
Shutdown();
return;
}
ClientManagerChild* actor = ClientManagerChild::Create();
if (NS_WARN_IF(!actor)) {
Shutdown();
return;
}
ClientManagerChild* actor = new ClientManagerChild(workerHolderToken);
PClientManagerChild* sentActor =
parentActor->SendPClientManagerConstructor(actor);
if (NS_WARN_IF(!sentActor)) {

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

@ -11,14 +11,13 @@
#include "ClientNavigateOpChild.h"
#include "ClientSourceChild.h"
#include "mozilla/dom/WorkerRef.h"
namespace mozilla {
namespace dom {
void ClientManagerChild::ActorDestroy(ActorDestroyReason aReason) {
if (mWorkerHolderToken) {
mWorkerHolderToken->RemoveListener(this);
mWorkerHolderToken = nullptr;
}
mIPCWorkerRef = nullptr;
if (mManager) {
mManager->RevokeActor(this);
@ -81,19 +80,33 @@ bool ClientManagerChild::DeallocPClientSourceChild(PClientSourceChild* aActor) {
return true;
}
void ClientManagerChild::WorkerShuttingDown() { MaybeStartTeardown(); }
// static
ClientManagerChild* ClientManagerChild::Create() {
ClientManagerChild* actor = new ClientManagerChild();
ClientManagerChild::ClientManagerChild(WorkerHolderToken* aWorkerHolderToken)
: mManager(nullptr),
mWorkerHolderToken(aWorkerHolderToken),
mTeardownStarted(false) {
MOZ_ASSERT_IF(!NS_IsMainThread(), mWorkerHolderToken);
if (!NS_IsMainThread()) {
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
MOZ_DIAGNOSTIC_ASSERT(workerPrivate);
if (mWorkerHolderToken) {
mWorkerHolderToken->AddListener(this);
RefPtr<IPCWorkerRefHelper<ClientManagerChild>> helper =
new IPCWorkerRefHelper<ClientManagerChild>(actor);
actor->mIPCWorkerRef = IPCWorkerRef::Create(
workerPrivate, "ClientManagerChild",
[helper] { helper->Actor()->MaybeStartTeardown(); });
if (NS_WARN_IF(!actor->mIPCWorkerRef)) {
delete actor;
return nullptr;
}
}
return actor;
}
ClientManagerChild::ClientManagerChild()
: mManager(nullptr), mTeardownStarted(false) {}
void ClientManagerChild::SetOwner(ClientThing<ClientManagerChild>* aThing) {
MOZ_DIAGNOSTIC_ASSERT(aThing);
MOZ_DIAGNOSTIC_ASSERT(!mManager);
@ -115,10 +128,10 @@ void ClientManagerChild::MaybeStartTeardown() {
}
WorkerPrivate* ClientManagerChild::GetWorkerPrivate() const {
if (!mWorkerHolderToken) {
if (!mIPCWorkerRef) {
return nullptr;
}
return mWorkerHolderToken->GetWorkerPrivate();
return mIPCWorkerRef->Private();
}
} // namespace dom

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

@ -8,20 +8,21 @@
#include "ClientThing.h"
#include "mozilla/dom/PClientManagerChild.h"
#include "mozilla/dom/WorkerHolderToken.h"
namespace mozilla {
namespace dom {
class IPCWorkerRef;
class WorkerPrivate;
class ClientManagerChild final : public PClientManagerChild,
public WorkerHolderToken::Listener {
class ClientManagerChild final : public PClientManagerChild {
ClientThing<ClientManagerChild>* mManager;
RefPtr<WorkerHolderToken> mWorkerHolderToken;
RefPtr<IPCWorkerRef> mIPCWorkerRef;
bool mTeardownStarted;
ClientManagerChild();
// PClientManagerChild interface
void ActorDestroy(ActorDestroyReason aReason) override;
@ -49,11 +50,8 @@ class ClientManagerChild final : public PClientManagerChild,
bool DeallocPClientSourceChild(PClientSourceChild* aActor) override;
// WorkerHolderToken::Listener interface
void WorkerShuttingDown() override;
public:
explicit ClientManagerChild(WorkerHolderToken* aWorkerHolderToken);
static ClientManagerChild* Create();
void SetOwner(ClientThing<ClientManagerChild>* aThing);