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
This commit is contained in:
Chris Martin 2021-03-02 23:02:35 +00:00
Родитель fb50e372a9
Коммит 0c5f377529
4 изменённых файлов: 23 добавлений и 7 удалений

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

@ -44,23 +44,25 @@ GamepadEventChannelParent::Create() {
.forget();
}
GamepadEventChannelParent::GamepadEventChannelParent() : mIsShutdown{false} {
GamepadEventChannelParent::GamepadEventChannelParent() {
MOZ_DIAGNOSTIC_ASSERT(IsOnBackgroundThread());
mBackgroundEventTarget = GetCurrentEventTarget();
}
bool GamepadEventChannelParent::ActorInit() {
AssertIsOnBackgroundThread();
RefPtr<GamepadPlatformService> 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<GamepadPlatformService> service =
GamepadPlatformService::GetParentService();

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

@ -16,6 +16,8 @@ class GamepadEventChannelParent final : public PGamepadEventChannelParent {
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GamepadEventChannelParent, override)
static already_AddRefed<GamepadEventChannelParent> 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<nsIEventTarget> mBackgroundEventTarget;
};

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

@ -1166,6 +1166,16 @@ BackgroundParentImpl::AllocPGamepadEventChannelParent() {
return dom::GamepadEventChannelParent::Create();
}
mozilla::ipc::IPCResult
BackgroundParentImpl::RecvPGamepadEventChannelConstructor(
PGamepadEventChannelParent* actor) {
if (!static_cast<mozilla::dom::GamepadEventChannelParent*>(actor)
->ActorInit()) {
return IPC_FAIL(this, "ActorInit failed");
}
return IPC_OK();
}
already_AddRefed<dom::PGamepadTestChannelParent>
BackgroundParentImpl::AllocPGamepadTestChannelParent() {
return dom::GamepadTestChannelParent::Create();

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

@ -328,6 +328,9 @@ class BackgroundParentImpl : public PBackgroundParent,
already_AddRefed<PGamepadEventChannelParent> AllocPGamepadEventChannelParent()
override;
mozilla::ipc::IPCResult RecvPGamepadEventChannelConstructor(
PGamepadEventChannelParent* actor) override;
already_AddRefed<PGamepadTestChannelParent> AllocPGamepadTestChannelParent()
override;