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

Depends on D93021

Differential Revision: https://phabricator.services.mozilla.com/D93022
This commit is contained in:
Chris Martin 2020-10-09 16:42:17 +00:00
Родитель ce23fd6cf4
Коммит c1246c7e52
5 изменённых файлов: 25 добавлений и 8 удалений

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

@ -71,9 +71,10 @@ void GamepadServiceTest::InitPBackgroundActor() {
MOZ_CRASH("Failed to create a PBackgroundChild actor!"); MOZ_CRASH("Failed to create a PBackgroundChild actor!");
} }
mChild = new GamepadTestChannelChild(); mChild = GamepadTestChannelChild::Create();
PGamepadTestChannelChild* initedChild = PGamepadTestChannelChild* initedChild =
actor->SendPGamepadTestChannelConstructor(mChild); actor->SendPGamepadTestChannelConstructor(
RefPtr<GamepadTestChannelChild>(mChild).forget().take());
if (NS_WARN_IF(!initedChild)) { if (NS_WARN_IF(!initedChild)) {
MOZ_CRASH("Failed to create a PBackgroundChild actor!"); MOZ_CRASH("Failed to create a PBackgroundChild actor!");
} }

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

@ -70,7 +70,7 @@ class GamepadServiceTest final : public DOMEventTargetHelper {
// IPDL Channel for us to send test events to GamepadPlatformService, it // IPDL Channel for us to send test events to GamepadPlatformService, it
// will only be used in this singleton class and deleted during the IPDL // will only be used in this singleton class and deleted during the IPDL
// shutdown chain // shutdown chain
GamepadTestChannelChild* MOZ_NON_OWNING_REF mChild; RefPtr<GamepadTestChannelChild> mChild;
explicit GamepadServiceTest(nsPIDOMWindowInner* aWindow); explicit GamepadServiceTest(nsPIDOMWindowInner* aWindow);
~GamepadServiceTest(); ~GamepadServiceTest();

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

@ -9,6 +9,11 @@
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
already_AddRefed<GamepadTestChannelChild> GamepadTestChannelChild::Create() {
return RefPtr<GamepadTestChannelChild>(new GamepadTestChannelChild())
.forget();
}
void GamepadTestChannelChild::AddPromise(const uint32_t& aID, void GamepadTestChannelChild::AddPromise(const uint32_t& aID,
Promise* aPromise) { Promise* aPromise) {
MOZ_ASSERT(!mPromiseList.Get(aID, nullptr)); MOZ_ASSERT(!mPromiseList.Get(aID, nullptr));

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

@ -14,18 +14,28 @@ namespace mozilla {
namespace dom { namespace dom {
class GamepadTestChannelChild final : public PGamepadTestChannelChild { class GamepadTestChannelChild final : public PGamepadTestChannelChild {
friend class PGamepadTestChannelChild;
public: public:
GamepadTestChannelChild() = default; NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GamepadTestChannelChild)
~GamepadTestChannelChild() = default;
static already_AddRefed<GamepadTestChannelChild> Create();
void AddPromise(const uint32_t& aID, Promise* aPromise); void AddPromise(const uint32_t& aID, Promise* aPromise);
GamepadTestChannelChild(const GamepadTestChannelChild&) = delete;
GamepadTestChannelChild(GamepadTestChannelChild&&) = delete;
GamepadTestChannelChild& operator=(const GamepadTestChannelChild&) = delete;
GamepadTestChannelChild& operator=(GamepadTestChannelChild&&) = delete;
private: private:
GamepadTestChannelChild() = default;
~GamepadTestChannelChild() = default;
mozilla::ipc::IPCResult RecvReplyGamepadIndex(const uint32_t& aID, mozilla::ipc::IPCResult RecvReplyGamepadIndex(const uint32_t& aID,
const uint32_t& aIndex); const uint32_t& aIndex);
nsRefPtrHashtable<nsUint32HashKey, dom::Promise> mPromiseList; nsRefPtrHashtable<nsUint32HashKey, dom::Promise> mPromiseList;
friend class PGamepadTestChannelChild;
}; };
} // namespace dom } // namespace dom

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

@ -628,7 +628,8 @@ BackgroundChildImpl::AllocPGamepadTestChannelChild() {
bool BackgroundChildImpl::DeallocPGamepadTestChannelChild( bool BackgroundChildImpl::DeallocPGamepadTestChannelChild(
PGamepadTestChannelChild* aActor) { PGamepadTestChannelChild* aActor) {
MOZ_ASSERT(aActor); MOZ_ASSERT(aActor);
delete static_cast<dom::GamepadTestChannelChild*>(aActor); RefPtr<dom::GamepadTestChannelChild> child(
dont_AddRef(static_cast<dom::GamepadTestChannelChild*>(aActor)));
return true; return true;
} }