From e23c08adc6180d3b1c45e572094e51c91b494263 Mon Sep 17 00:00:00 2001 From: Chris Martin Date: Mon, 1 Mar 2021 21:59:48 +0000 Subject: [PATCH] Bug 1658419 - Change PGamepadEventChannelParent to have a constructor r=handyman PGamepadEventChannelParent will need to send an async message back to the child with info about the new shared memory region upon creation. The IPDL channel is not ready during allocation, so we need to defer registering the actor with GamepadPlatformService until the IPDL "RecvConstructor" message so the channel will be available. This is just a straight refactor to prepare for the upcoming change. Differential Revision: https://phabricator.services.mozilla.com/D105127 --- dom/gamepad/ipc/GamepadEventChannelParent.cpp | 14 ++++++++------ dom/gamepad/ipc/GamepadEventChannelParent.h | 3 ++- ipc/glue/BackgroundParentImpl.cpp | 10 ++++++++++ ipc/glue/BackgroundParentImpl.h | 3 +++ 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/dom/gamepad/ipc/GamepadEventChannelParent.cpp b/dom/gamepad/ipc/GamepadEventChannelParent.cpp index 910650529fe1..1f770ad4ac1f 100644 --- a/dom/gamepad/ipc/GamepadEventChannelParent.cpp +++ b/dom/gamepad/ipc/GamepadEventChannelParent.cpp @@ -44,23 +44,25 @@ GamepadEventChannelParent::Create() { .forget(); } -GamepadEventChannelParent::GamepadEventChannelParent() : mIsShutdown{false} { +GamepadEventChannelParent::GamepadEventChannelParent() { MOZ_DIAGNOSTIC_ASSERT(IsOnBackgroundThread()); mBackgroundEventTarget = GetCurrentEventTarget(); +} + +bool GamepadEventChannelParent::ActorInit() { + AssertIsOnBackgroundThread(); RefPtr service = GamepadPlatformService::GetParentService(); MOZ_ASSERT(service); - service->AddChannelParent(this); + + return true; } void GamepadEventChannelParent::ActorDestroy(ActorDestroyReason aWhy) { - MOZ_DIAGNOSTIC_ASSERT(IsOnBackgroundThread()); - MOZ_DIAGNOSTIC_ASSERT(!mIsShutdown); - - mIsShutdown = true; + AssertIsOnBackgroundThread(); RefPtr service = GamepadPlatformService::GetParentService(); diff --git a/dom/gamepad/ipc/GamepadEventChannelParent.h b/dom/gamepad/ipc/GamepadEventChannelParent.h index 748b2431726a..f0c9deb7e34a 100644 --- a/dom/gamepad/ipc/GamepadEventChannelParent.h +++ b/dom/gamepad/ipc/GamepadEventChannelParent.h @@ -16,6 +16,8 @@ class GamepadEventChannelParent final : public PGamepadEventChannelParent { NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GamepadEventChannelParent, override) static already_AddRefed Create(); + + bool ActorInit(); void ActorDestroy(ActorDestroyReason aWhy) override; mozilla::ipc::IPCResult RecvVibrateHaptic( @@ -41,7 +43,6 @@ class GamepadEventChannelParent final : public PGamepadEventChannelParent { GamepadEventChannelParent(); ~GamepadEventChannelParent() = default; - bool mIsShutdown; nsCOMPtr mBackgroundEventTarget; }; diff --git a/ipc/glue/BackgroundParentImpl.cpp b/ipc/glue/BackgroundParentImpl.cpp index ec3b6d4fbebd..3702dd223b35 100644 --- a/ipc/glue/BackgroundParentImpl.cpp +++ b/ipc/glue/BackgroundParentImpl.cpp @@ -1166,6 +1166,16 @@ BackgroundParentImpl::AllocPGamepadEventChannelParent() { return dom::GamepadEventChannelParent::Create(); } +mozilla::ipc::IPCResult +BackgroundParentImpl::RecvPGamepadEventChannelConstructor( + PGamepadEventChannelParent* actor) { + if (!static_cast(actor) + ->ActorInit()) { + return IPC_FAIL(this, "ActorInit failed"); + } + return IPC_OK(); +} + already_AddRefed BackgroundParentImpl::AllocPGamepadTestChannelParent() { return dom::GamepadTestChannelParent::Create(); diff --git a/ipc/glue/BackgroundParentImpl.h b/ipc/glue/BackgroundParentImpl.h index ecd9fb493ec7..90177af18149 100644 --- a/ipc/glue/BackgroundParentImpl.h +++ b/ipc/glue/BackgroundParentImpl.h @@ -328,6 +328,9 @@ class BackgroundParentImpl : public PBackgroundParent, already_AddRefed AllocPGamepadEventChannelParent() override; + mozilla::ipc::IPCResult RecvPGamepadEventChannelConstructor( + PGamepadEventChannelParent* actor) override; + already_AddRefed AllocPGamepadTestChannelParent() override;