Skip to content

Commit

Permalink
Bug 1775784 - Make PRemoteWorker refcounted instead of ManualDealloc.…
Browse files Browse the repository at this point in the history
… r=dom-worker-reviewers,smaug

Differential Revision: https://phabricator.services.mozilla.com/D164643
  • Loading branch information
asutherland committed Mar 14, 2023
1 parent 938860f commit 6409a7f
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 42 deletions.
1 change: 0 additions & 1 deletion dom/workers/remoteworkers/PRemoteWorker.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions dom/workers/remoteworkers/RemoteWorkerChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions dom/workers/remoteworkers/RemoteWorkerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,9 @@ void RemoteWorkerManager::LaunchInternal(
SchedulerGroup::Dispatch(TaskCategory::Other, r.forget()));
}

RemoteWorkerParent* workerActor = static_cast<RemoteWorkerParent*>(
aTargetActor->Manager()->SendPRemoteWorkerConstructor(aData));
if (NS_WARN_IF(!workerActor)) {
RefPtr<RemoteWorkerParent> workerActor = MakeAndAddRef<RemoteWorkerParent>();
if (!aTargetActor->Manager()->SendPRemoteWorkerConstructor(workerActor,
aData)) {
AsyncCreationFailed(aController);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion dom/workers/remoteworkers/RemoteWorkerParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
16 changes: 5 additions & 11 deletions ipc/glue/BackgroundChildImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -280,10 +282,9 @@ bool BackgroundChildImpl::DeallocPBackgroundStorageChild(
return true;
}

dom::PRemoteWorkerChild* BackgroundChildImpl::AllocPRemoteWorkerChild(
const RemoteWorkerData& aData) {
RefPtr<dom::RemoteWorkerChild> agent = new dom::RemoteWorkerChild(aData);
return agent.forget().take();
already_AddRefed<PRemoteWorkerChild>
BackgroundChildImpl::AllocPRemoteWorkerChild(const RemoteWorkerData& aData) {
return MakeAndAddRef<RemoteWorkerChild>(aData);
}

IPCResult BackgroundChildImpl::RecvPRemoteWorkerConstructor(
Expand All @@ -293,13 +294,6 @@ IPCResult BackgroundChildImpl::RecvPRemoteWorkerConstructor(
return IPC_OK();
}

bool BackgroundChildImpl::DeallocPRemoteWorkerChild(
dom::PRemoteWorkerChild* aActor) {
RefPtr<dom::RemoteWorkerChild> actor =
dont_AddRef(static_cast<dom::RemoteWorkerChild*>(aActor));
return true;
}

dom::PRemoteWorkerControllerChild*
BackgroundChildImpl::AllocPRemoteWorkerControllerChild(
const dom::RemoteWorkerData& aRemoteWorkerData) {
Expand Down
5 changes: 1 addition & 4 deletions ipc/glue/BackgroundChildImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,12 @@ class BackgroundChildImpl : public PBackgroundChild {

virtual bool DeallocPFileCreatorChild(PFileCreatorChild* aActor) override;

virtual mozilla::dom::PRemoteWorkerChild* AllocPRemoteWorkerChild(
already_AddRefed<mozilla::dom::PRemoteWorkerChild> 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;
Expand Down
14 changes: 0 additions & 14 deletions ipc/glue/BackgroundParentImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -514,19 +513,6 @@ BackgroundParentImpl::AllocPIdleSchedulerParent() {
return actor.forget();
}

mozilla::dom::PRemoteWorkerParent*
BackgroundParentImpl::AllocPRemoteWorkerParent(const RemoteWorkerData& aData) {
RefPtr<dom::RemoteWorkerParent> agent = new dom::RemoteWorkerParent();
return agent.forget().take();
}

bool BackgroundParentImpl::DeallocPRemoteWorkerParent(
mozilla::dom::PRemoteWorkerParent* aActor) {
RefPtr<mozilla::dom::RemoteWorkerParent> actor =
dont_AddRef(static_cast<mozilla::dom::RemoteWorkerParent*>(aActor));
return true;
}

dom::PRemoteWorkerControllerParent*
BackgroundParentImpl::AllocPRemoteWorkerControllerParent(
const dom::RemoteWorkerData& aRemoteWorkerData) {
Expand Down
5 changes: 0 additions & 5 deletions ipc/glue/BackgroundParentImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6409a7f

Please sign in to comment.