Bug 1657404 - Prepare GamepadTestChannelParent for "refcounted protocol" r=handyman

Differential Revision: https://phabricator.services.mozilla.com/D93021
This commit is contained in:
Chris Martin 2020-10-14 20:33:13 +00:00
Родитель a09ab4afe6
Коммит 54487648eb
4 изменённых файлов: 19 добавлений и 26 удалений

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

@ -12,18 +12,21 @@
namespace mozilla {
namespace dom {
bool GamepadTestChannelParent::Init() {
already_AddRefed<GamepadTestChannelParent> GamepadTestChannelParent::Create() {
return RefPtr<GamepadTestChannelParent>(new GamepadTestChannelParent())
.forget();
}
GamepadTestChannelParent::GamepadTestChannelParent() {
AssertIsOnBackgroundThread();
RefPtr<GamepadPlatformService> service =
GamepadPlatformService::GetParentService();
MOZ_ASSERT(service);
service->GetMonitoringState().AddObserver(this);
return true;
}
void GamepadTestChannelParent::ActorDestroy(ActorDestroyReason aWhy) {
GamepadTestChannelParent::~GamepadTestChannelParent() {
AssertIsOnBackgroundThread();
RefPtr<GamepadPlatformService> service =
GamepadPlatformService::GetParentService();

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

@ -18,24 +18,30 @@ class GamepadTestChannelParent final : public PGamepadTestChannelParent,
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GamepadTestChannelParent)
GamepadTestChannelParent() = default;
bool Init();
void ActorDestroy(ActorDestroyReason aWhy) override;
static already_AddRefed<GamepadTestChannelParent> Create();
mozilla::ipc::IPCResult RecvGamepadTestEvent(
const uint32_t& aID, const GamepadChangeEvent& aGamepadEvent);
void OnMonitoringStateChanged(bool aNewState);
GamepadTestChannelParent(const GamepadTestChannelParent&) = delete;
GamepadTestChannelParent(GamepadTestChannelParent&&) = delete;
GamepadTestChannelParent& operator=(const GamepadTestChannelParent&) = delete;
GamepadTestChannelParent& operator=(GamepadTestChannelParent&&) = delete;
private:
struct DeferredGamepadAdded {
uint32_t promiseId;
GamepadAdded gamepadAdded;
};
GamepadTestChannelParent();
~GamepadTestChannelParent();
void AddGamepadToPlatformService(uint32_t aPromiseId,
const GamepadAdded& aGamepadAdded);
~GamepadTestChannelParent() = default;
nsTArray<DeferredGamepadAdded> mDeferredGamepadAdded;
};

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

@ -1142,20 +1142,7 @@ BackgroundParentImpl::AllocPGamepadEventChannelParent() {
dom::PGamepadTestChannelParent*
BackgroundParentImpl::AllocPGamepadTestChannelParent() {
RefPtr<dom::GamepadTestChannelParent> parent =
new dom::GamepadTestChannelParent();
return parent.forget().take();
}
mozilla::ipc::IPCResult
BackgroundParentImpl::RecvPGamepadTestChannelConstructor(
PGamepadTestChannelParent* aActor) {
MOZ_ASSERT(aActor);
if (!static_cast<dom::GamepadTestChannelParent*>(aActor)->Init()) {
return IPC_FAIL_NO_REASON(this);
}
return IPC_OK();
return dom::GamepadTestChannelParent::Create().take();
}
bool BackgroundParentImpl::DeallocPGamepadTestChannelParent(

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

@ -338,9 +338,6 @@ class BackgroundParentImpl : public PBackgroundParent,
virtual PGamepadTestChannelParent* AllocPGamepadTestChannelParent() override;
virtual mozilla::ipc::IPCResult RecvPGamepadTestChannelConstructor(
PGamepadTestChannelParent* aActor) override;
virtual bool DeallocPGamepadTestChannelParent(
PGamepadTestChannelParent* aActor) override;