Skip to content

Commit c1246c7

Browse files
author
Chris Martin
committed
Bug 1657404 - Prepare GamepadTestChannelChild for "refcounted protocol" r=handyman
Depends on D93021 Differential Revision: https://phabricator.services.mozilla.com/D93022
1 parent ce23fd6 commit c1246c7

File tree

5 files changed

+25
-8
lines changed

5 files changed

+25
-8
lines changed

dom/gamepad/GamepadServiceTest.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,10 @@ void GamepadServiceTest::InitPBackgroundActor() {
7171
MOZ_CRASH("Failed to create a PBackgroundChild actor!");
7272
}
7373

74-
mChild = new GamepadTestChannelChild();
74+
mChild = GamepadTestChannelChild::Create();
7575
PGamepadTestChannelChild* initedChild =
76-
actor->SendPGamepadTestChannelConstructor(mChild);
76+
actor->SendPGamepadTestChannelConstructor(
77+
RefPtr<GamepadTestChannelChild>(mChild).forget().take());
7778
if (NS_WARN_IF(!initedChild)) {
7879
MOZ_CRASH("Failed to create a PBackgroundChild actor!");
7980
}

dom/gamepad/GamepadServiceTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class GamepadServiceTest final : public DOMEventTargetHelper {
7070
// IPDL Channel for us to send test events to GamepadPlatformService, it
7171
// will only be used in this singleton class and deleted during the IPDL
7272
// shutdown chain
73-
GamepadTestChannelChild* MOZ_NON_OWNING_REF mChild;
73+
RefPtr<GamepadTestChannelChild> mChild;
7474

7575
explicit GamepadServiceTest(nsPIDOMWindowInner* aWindow);
7676
~GamepadServiceTest();

dom/gamepad/ipc/GamepadTestChannelChild.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
namespace mozilla {
1010
namespace dom {
1111

12+
already_AddRefed<GamepadTestChannelChild> GamepadTestChannelChild::Create() {
13+
return RefPtr<GamepadTestChannelChild>(new GamepadTestChannelChild())
14+
.forget();
15+
}
16+
1217
void GamepadTestChannelChild::AddPromise(const uint32_t& aID,
1318
Promise* aPromise) {
1419
MOZ_ASSERT(!mPromiseList.Get(aID, nullptr));

dom/gamepad/ipc/GamepadTestChannelChild.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,28 @@ namespace mozilla {
1414
namespace dom {
1515

1616
class GamepadTestChannelChild final : public PGamepadTestChannelChild {
17-
friend class PGamepadTestChannelChild;
18-
1917
public:
20-
GamepadTestChannelChild() = default;
21-
~GamepadTestChannelChild() = default;
18+
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GamepadTestChannelChild)
19+
20+
static already_AddRefed<GamepadTestChannelChild> Create();
21+
2222
void AddPromise(const uint32_t& aID, Promise* aPromise);
2323

24+
GamepadTestChannelChild(const GamepadTestChannelChild&) = delete;
25+
GamepadTestChannelChild(GamepadTestChannelChild&&) = delete;
26+
GamepadTestChannelChild& operator=(const GamepadTestChannelChild&) = delete;
27+
GamepadTestChannelChild& operator=(GamepadTestChannelChild&&) = delete;
28+
2429
private:
30+
GamepadTestChannelChild() = default;
31+
~GamepadTestChannelChild() = default;
32+
2533
mozilla::ipc::IPCResult RecvReplyGamepadIndex(const uint32_t& aID,
2634
const uint32_t& aIndex);
2735

2836
nsRefPtrHashtable<nsUint32HashKey, dom::Promise> mPromiseList;
37+
38+
friend class PGamepadTestChannelChild;
2939
};
3040

3141
} // namespace dom

ipc/glue/BackgroundChildImpl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,8 @@ BackgroundChildImpl::AllocPGamepadTestChannelChild() {
628628
bool BackgroundChildImpl::DeallocPGamepadTestChannelChild(
629629
PGamepadTestChannelChild* aActor) {
630630
MOZ_ASSERT(aActor);
631-
delete static_cast<dom::GamepadTestChannelChild*>(aActor);
631+
RefPtr<dom::GamepadTestChannelChild> child(
632+
dont_AddRef(static_cast<dom::GamepadTestChannelChild*>(aActor)));
632633
return true;
633634
}
634635

0 commit comments

Comments
 (0)