Bug 1657404 - Change PGamepadEventChannel to "refcounted protocol" r=handyman

Differential Revision: https://phabricator.services.mozilla.com/D93119
This commit is contained in:
Chris Martin 2020-10-14 15:58:36 +00:00
Родитель 0780d3cbda
Коммит eb0f286337
11 изменённых файлов: 44 добавлений и 72 удалений

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

@ -115,8 +115,9 @@ GamepadManager::Observe(nsISupports* aSubject, const char* aTopic,
}
void GamepadManager::StopMonitoring() {
for (uint32_t i = 0; i < mChannelChildren.Length(); ++i) {
PGamepadEventChannelChild::Send__delete__(mChannelChildren[i]);
for (auto& channelChild : mChannelChildren) {
PGamepadEventChannelChild::Send__delete__(channelChild);
channelChild = nullptr;
}
if (gfx::VRManagerChild::IsCreated()) {
gfx::VRManagerChild* vm = gfx::VRManagerChild::Get();
@ -149,15 +150,12 @@ void GamepadManager::AddListener(nsGlobalWindowInner* aWindow) {
return;
}
GamepadEventChannelChild* child = new GamepadEventChannelChild();
PGamepadEventChannelChild* initedChild =
actor->SendPGamepadEventChannelConstructor(child);
if (NS_WARN_IF(!initedChild)) {
RefPtr<GamepadEventChannelChild> child(GamepadEventChannelChild::Create());
if (!actor->SendPGamepadEventChannelConstructor(child.get())) {
// We are probably shutting down.
return;
}
MOZ_ASSERT(initedChild == child);
mChannelChildren.AppendElement(child);
if (gfx::VRManagerChild::IsCreated()) {

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

@ -119,11 +119,7 @@ class GamepadManager final : public nsIObserver {
// true when shutdown has begun
bool mShuttingDown;
// Gamepad IPDL child
// This pointer is only used by this singleton instance and
// will be destroyed during the IPDL shutdown chain, so we
// don't need to refcount it here.
nsTArray<GamepadEventChannelChild*> mChannelChildren;
nsTArray<RefPtr<GamepadEventChannelChild>> mChannelChildren;
private:
nsresult Init();

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

@ -29,6 +29,11 @@ class GamepadUpdateRunnable final : public Runnable {
} // namespace
already_AddRefed<GamepadEventChannelChild> GamepadEventChannelChild::Create() {
return RefPtr<GamepadEventChannelChild>(new GamepadEventChannelChild())
.forget();
}
mozilla::ipc::IPCResult GamepadEventChannelChild::RecvGamepadUpdate(
const GamepadChangeEvent& aGamepadEvent) {
DebugOnly<nsresult> rv =

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

@ -14,15 +14,24 @@ namespace dom {
class GamepadEventChannelChild final : public PGamepadEventChannelChild {
public:
GamepadEventChannelChild() = default;
~GamepadEventChannelChild() = default;
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GamepadEventChannelChild, override)
static already_AddRefed<GamepadEventChannelChild> Create();
mozilla::ipc::IPCResult RecvGamepadUpdate(
const GamepadChangeEvent& aGamepadEvent);
mozilla::ipc::IPCResult RecvReplyGamepadPromise(const uint32_t& aPromiseID);
void AddPromise(const uint32_t& aID, dom::Promise* aPromise);
GamepadEventChannelChild(const GamepadEventChannelChild&) = delete;
GamepadEventChannelChild(GamepadEventChannelChild&&) = delete;
GamepadEventChannelChild& operator=(const GamepadEventChannelChild&) = delete;
GamepadEventChannelChild& operator=(GamepadEventChannelChild&&) = delete;
private:
GamepadEventChannelChild() = default;
~GamepadEventChannelChild() = default;
nsRefPtrHashtable<nsUint32HashKey, dom::Promise> mPromiseList;
};

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

@ -38,7 +38,13 @@ class SendGamepadUpdateRunnable final : public Runnable {
} // namespace
bool GamepadEventChannelParent::Init() {
already_AddRefed<GamepadEventChannelParent>
GamepadEventChannelParent::Create() {
return RefPtr<GamepadEventChannelParent>(new GamepadEventChannelParent())
.forget();
}
GamepadEventChannelParent::GamepadEventChannelParent() {
AssertIsOnBackgroundThread();
mBackgroundEventTarget = GetCurrentEventTarget();
@ -48,8 +54,6 @@ bool GamepadEventChannelParent::Init() {
MOZ_ASSERT(service);
service->AddChannelParent(this);
return true;
}
void GamepadEventChannelParent::ActorDestroy(ActorDestroyReason aWhy) {

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

@ -13,10 +13,9 @@ namespace dom {
class GamepadEventChannelParent final : public PGamepadEventChannelParent {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GamepadEventChannelParent)
GamepadEventChannelParent() = default;
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GamepadEventChannelParent, override)
bool Init();
static already_AddRefed<GamepadEventChannelParent> Create();
void ActorDestroy(ActorDestroyReason aWhy) override;
mozilla::ipc::IPCResult RecvVibrateHaptic(const uint32_t& aControllerIdx,
@ -31,8 +30,16 @@ class GamepadEventChannelParent final : public PGamepadEventChannelParent {
const uint32_t& aPromiseID);
void DispatchUpdateEvent(const GamepadChangeEvent& aEvent);
GamepadEventChannelParent(const GamepadEventChannelParent&) = delete;
GamepadEventChannelParent(GamepadEventChannelParent&&) = delete;
GamepadEventChannelParent& operator=(const GamepadEventChannelParent&) =
delete;
GamepadEventChannelParent& operator=(GamepadEventChannelParent&&) = delete;
private:
GamepadEventChannelParent();
~GamepadEventChannelParent() = default;
nsCOMPtr<nsIEventTarget> mBackgroundEventTarget;
};

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

@ -7,7 +7,7 @@ include GamepadEventTypes;
namespace mozilla {
namespace dom {
async protocol PGamepadEventChannel {
refcounted protocol PGamepadEventChannel {
manager PBackground;
parent:
async __delete__();

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

@ -605,20 +605,6 @@ bool BackgroundChildImpl::DeallocPMIDIManagerChild(PMIDIManagerChild* aActor) {
return true;
}
// Gamepad API Background IPC
dom::PGamepadEventChannelChild*
BackgroundChildImpl::AllocPGamepadEventChannelChild() {
MOZ_CRASH("PGamepadEventChannelChild actor should be manually constructed!");
return nullptr;
}
bool BackgroundChildImpl::DeallocPGamepadEventChannelChild(
PGamepadEventChannelChild* aActor) {
MOZ_ASSERT(aActor);
delete static_cast<dom::GamepadEventChannelChild*>(aActor);
return true;
}
dom::PGamepadTestChannelChild*
BackgroundChildImpl::AllocPGamepadTestChannelChild() {
MOZ_CRASH("PGamepadTestChannelChild actor should be manually constructed!");

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

@ -223,12 +223,6 @@ class BackgroundChildImpl : public PBackgroundChild,
virtual bool DeallocPQuotaChild(PQuotaChild* aActor) override;
// Gamepad API Background IPC
virtual PGamepadEventChannelChild* AllocPGamepadEventChannelChild() override;
virtual bool DeallocPGamepadEventChannelChild(
PGamepadEventChannelChild* aActor) override;
virtual PGamepadTestChannelChild* AllocPGamepadTestChannelChild() override;
virtual bool DeallocPGamepadTestChannelChild(

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

@ -1135,30 +1135,9 @@ mozilla::ipc::IPCResult BackgroundParentImpl::RecvPFileSystemRequestConstructor(
}
// Gamepad API Background IPC
dom::PGamepadEventChannelParent*
already_AddRefed<dom::PGamepadEventChannelParent>
BackgroundParentImpl::AllocPGamepadEventChannelParent() {
RefPtr<dom::GamepadEventChannelParent> parent =
new dom::GamepadEventChannelParent();
return parent.forget().take();
}
bool BackgroundParentImpl::DeallocPGamepadEventChannelParent(
dom::PGamepadEventChannelParent* aActor) {
MOZ_ASSERT(aActor);
RefPtr<dom::GamepadEventChannelParent> parent =
dont_AddRef(static_cast<dom::GamepadEventChannelParent*>(aActor));
return true;
}
mozilla::ipc::IPCResult
BackgroundParentImpl::RecvPGamepadEventChannelConstructor(
PGamepadEventChannelParent* aActor) {
MOZ_ASSERT(aActor);
if (!static_cast<dom::GamepadEventChannelParent*>(aActor)->Init()) {
return IPC_FAIL_NO_REASON(this);
}
return IPC_OK();
return dom::GamepadEventChannelParent::Create();
}
dom::PGamepadTestChannelParent*

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

@ -333,14 +333,8 @@ class BackgroundParentImpl : public PBackgroundParent,
PFileSystemRequestParent* actor, const FileSystemParams& params) override;
// Gamepad API Background IPC
virtual PGamepadEventChannelParent* AllocPGamepadEventChannelParent()
override;
virtual bool DeallocPGamepadEventChannelParent(
PGamepadEventChannelParent* aActor) override;
virtual mozilla::ipc::IPCResult RecvPGamepadEventChannelConstructor(
PGamepadEventChannelParent* aActor) override;
virtual already_AddRefed<PGamepadEventChannelParent>
AllocPGamepadEventChannelParent() override;
virtual PGamepadTestChannelParent* AllocPGamepadTestChannelParent() override;