From 6409a7f2c3ac7a1d31a22574c7c718e783d05f7d Mon Sep 17 00:00:00 2001 From: Andrew Sutherland Date: Tue, 14 Mar 2023 23:57:56 +0000 Subject: [PATCH] Bug 1775784 - Make PRemoteWorker refcounted instead of ManualDealloc. r=dom-worker-reviewers,smaug Differential Revision: https://phabricator.services.mozilla.com/D164643 --- dom/workers/remoteworkers/PRemoteWorker.ipdl | 1 - dom/workers/remoteworkers/RemoteWorkerChild.h | 6 +++--- .../remoteworkers/RemoteWorkerManager.cpp | 6 +++--- dom/workers/remoteworkers/RemoteWorkerParent.h | 2 +- ipc/glue/BackgroundChildImpl.cpp | 16 +++++----------- ipc/glue/BackgroundChildImpl.h | 5 +---- ipc/glue/BackgroundParentImpl.cpp | 14 -------------- ipc/glue/BackgroundParentImpl.h | 5 ----- 8 files changed, 13 insertions(+), 42 deletions(-) diff --git a/dom/workers/remoteworkers/PRemoteWorker.ipdl b/dom/workers/remoteworkers/PRemoteWorker.ipdl index fcc8b79ff6276..5330ccb7170b5 100644 --- a/dom/workers/remoteworkers/PRemoteWorker.ipdl +++ b/dom/workers/remoteworkers/PRemoteWorker.ipdl @@ -56,7 +56,6 @@ union RemoteWorkerOp { // This protocol is used to make a remote worker controllable from the parent // process. The parent process will receive operations from the // PRemoteWorkerController protocol. -[ManualDealloc] protocol PRemoteWorker { manager PBackground; diff --git a/dom/workers/remoteworkers/RemoteWorkerChild.h b/dom/workers/remoteworkers/RemoteWorkerChild.h index 5d21e23bd5ae8..b863670bb2f87 100644 --- a/dom/workers/remoteworkers/RemoteWorkerChild.h +++ b/dom/workers/remoteworkers/RemoteWorkerChild.h @@ -47,13 +47,13 @@ class RemoteWorkerChild final friend class PRemoteWorkerChild; friend class ServiceWorkerOp; + ~RemoteWorkerChild(); + public: - MOZ_DECLARE_REFCOUNTED_TYPENAME(RemoteWorkerChild) + NS_INLINE_DECL_REFCOUNTING(RemoteWorkerChild, final) explicit RemoteWorkerChild(const RemoteWorkerData& aData); - ~RemoteWorkerChild(); - nsISerialEventTarget* GetOwningEventTarget() const; void ExecWorker(const RemoteWorkerData& aData); diff --git a/dom/workers/remoteworkers/RemoteWorkerManager.cpp b/dom/workers/remoteworkers/RemoteWorkerManager.cpp index 0d525afd3780a..bcc8c7ba3cffa 100644 --- a/dom/workers/remoteworkers/RemoteWorkerManager.cpp +++ b/dom/workers/remoteworkers/RemoteWorkerManager.cpp @@ -469,9 +469,9 @@ void RemoteWorkerManager::LaunchInternal( SchedulerGroup::Dispatch(TaskCategory::Other, r.forget())); } - RemoteWorkerParent* workerActor = static_cast( - aTargetActor->Manager()->SendPRemoteWorkerConstructor(aData)); - if (NS_WARN_IF(!workerActor)) { + RefPtr workerActor = MakeAndAddRef(); + if (!aTargetActor->Manager()->SendPRemoteWorkerConstructor(workerActor, + aData)) { AsyncCreationFailed(aController); return; } diff --git a/dom/workers/remoteworkers/RemoteWorkerParent.h b/dom/workers/remoteworkers/RemoteWorkerParent.h index 7bb91bad2a257..db79fb9cf4e3c 100644 --- a/dom/workers/remoteworkers/RemoteWorkerParent.h +++ b/dom/workers/remoteworkers/RemoteWorkerParent.h @@ -22,7 +22,7 @@ class RemoteWorkerParent final : public PRemoteWorkerParent { friend class PRemoteWorkerParent; public: - NS_INLINE_DECL_REFCOUNTING(RemoteWorkerParent) + NS_INLINE_DECL_REFCOUNTING(RemoteWorkerParent, override); RemoteWorkerParent(); diff --git a/ipc/glue/BackgroundChildImpl.cpp b/ipc/glue/BackgroundChildImpl.cpp index d436692d0cd98..fe735dc854706 100644 --- a/ipc/glue/BackgroundChildImpl.cpp +++ b/ipc/glue/BackgroundChildImpl.cpp @@ -70,9 +70,11 @@ namespace mozilla::ipc { using mozilla::dom::UDPSocketChild; using mozilla::net::PUDPSocketChild; +using mozilla::dom::PRemoteWorkerChild; using mozilla::dom::PServiceWorkerChild; using mozilla::dom::PServiceWorkerContainerChild; using mozilla::dom::PServiceWorkerRegistrationChild; +using mozilla::dom::RemoteWorkerChild; using mozilla::dom::StorageDBChild; using mozilla::dom::cache::PCacheChild; using mozilla::dom::cache::PCacheStreamControlChild; @@ -280,10 +282,9 @@ bool BackgroundChildImpl::DeallocPBackgroundStorageChild( return true; } -dom::PRemoteWorkerChild* BackgroundChildImpl::AllocPRemoteWorkerChild( - const RemoteWorkerData& aData) { - RefPtr agent = new dom::RemoteWorkerChild(aData); - return agent.forget().take(); +already_AddRefed +BackgroundChildImpl::AllocPRemoteWorkerChild(const RemoteWorkerData& aData) { + return MakeAndAddRef(aData); } IPCResult BackgroundChildImpl::RecvPRemoteWorkerConstructor( @@ -293,13 +294,6 @@ IPCResult BackgroundChildImpl::RecvPRemoteWorkerConstructor( return IPC_OK(); } -bool BackgroundChildImpl::DeallocPRemoteWorkerChild( - dom::PRemoteWorkerChild* aActor) { - RefPtr actor = - dont_AddRef(static_cast(aActor)); - return true; -} - dom::PRemoteWorkerControllerChild* BackgroundChildImpl::AllocPRemoteWorkerControllerChild( const dom::RemoteWorkerData& aRemoteWorkerData) { diff --git a/ipc/glue/BackgroundChildImpl.h b/ipc/glue/BackgroundChildImpl.h index 4da0c6237ac82..b4d13fb74b194 100644 --- a/ipc/glue/BackgroundChildImpl.h +++ b/ipc/glue/BackgroundChildImpl.h @@ -116,15 +116,12 @@ class BackgroundChildImpl : public PBackgroundChild { virtual bool DeallocPFileCreatorChild(PFileCreatorChild* aActor) override; - virtual mozilla::dom::PRemoteWorkerChild* AllocPRemoteWorkerChild( + already_AddRefed AllocPRemoteWorkerChild( const RemoteWorkerData& aData) override; virtual mozilla::ipc::IPCResult RecvPRemoteWorkerConstructor( PRemoteWorkerChild* aActor, const RemoteWorkerData& aData) override; - virtual bool DeallocPRemoteWorkerChild( - mozilla::dom::PRemoteWorkerChild* aActor) override; - virtual mozilla::dom::PRemoteWorkerControllerChild* AllocPRemoteWorkerControllerChild( const mozilla::dom::RemoteWorkerData& aRemoteWorkerData) override; diff --git a/ipc/glue/BackgroundParentImpl.cpp b/ipc/glue/BackgroundParentImpl.cpp index 3ca611ad14412..a2050f660eacf 100644 --- a/ipc/glue/BackgroundParentImpl.cpp +++ b/ipc/glue/BackgroundParentImpl.cpp @@ -34,7 +34,6 @@ #include "mozilla/dom/PGamepadEventChannelParent.h" #include "mozilla/dom/PGamepadTestChannelParent.h" #include "mozilla/dom/RemoteWorkerControllerParent.h" -#include "mozilla/dom/RemoteWorkerParent.h" #include "mozilla/dom/RemoteWorkerServiceParent.h" #include "mozilla/dom/ReportingHeader.h" #include "mozilla/dom/ServiceWorkerActors.h" @@ -514,19 +513,6 @@ BackgroundParentImpl::AllocPIdleSchedulerParent() { return actor.forget(); } -mozilla::dom::PRemoteWorkerParent* -BackgroundParentImpl::AllocPRemoteWorkerParent(const RemoteWorkerData& aData) { - RefPtr agent = new dom::RemoteWorkerParent(); - return agent.forget().take(); -} - -bool BackgroundParentImpl::DeallocPRemoteWorkerParent( - mozilla::dom::PRemoteWorkerParent* aActor) { - RefPtr actor = - dont_AddRef(static_cast(aActor)); - return true; -} - dom::PRemoteWorkerControllerParent* BackgroundParentImpl::AllocPRemoteWorkerControllerParent( const dom::RemoteWorkerData& aRemoteWorkerData) { diff --git a/ipc/glue/BackgroundParentImpl.h b/ipc/glue/BackgroundParentImpl.h index c83c4e20126c7..c35f6e7fa699b 100644 --- a/ipc/glue/BackgroundParentImpl.h +++ b/ipc/glue/BackgroundParentImpl.h @@ -164,11 +164,6 @@ class BackgroundParentImpl : public PBackgroundParent { bool DeallocPFileCreatorParent(PFileCreatorParent* aActor) override; - mozilla::dom::PRemoteWorkerParent* AllocPRemoteWorkerParent( - const RemoteWorkerData& aData) override; - - bool DeallocPRemoteWorkerParent(PRemoteWorkerParent* aActor) override; - mozilla::dom::PRemoteWorkerControllerParent* AllocPRemoteWorkerControllerParent( const mozilla::dom::RemoteWorkerData& aRemoteWorkerData) override;