Skip to content

Commit ac65753

Browse files
committed
Bug 1408333 Get rid of nsIIPCBackgroundChildCreateCallback - part 9 - Gamepad Test, r=asuth
1 parent c9b008f commit ac65753

File tree

2 files changed

+23
-118
lines changed

2 files changed

+23
-118
lines changed

dom/gamepad/GamepadServiceTest.cpp

Lines changed: 22 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ NS_IMPL_CYCLE_COLLECTION_INHERITED(GamepadServiceTest, DOMEventTargetHelper,
3535
mWindow)
3636

3737
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(GamepadServiceTest)
38-
NS_INTERFACE_MAP_ENTRY(nsIIPCBackgroundChildCreateCallback)
3938
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
4039

4140
NS_IMPL_ADDREF_INHERITED(GamepadServiceTest, DOMEventTargetHelper)
@@ -74,31 +73,25 @@ void
7473
GamepadServiceTest::InitPBackgroundActor()
7574
{
7675
MOZ_ASSERT(!mChild);
77-
PBackgroundChild *actor = BackgroundChild::GetForCurrentThread();
78-
//Try to get the PBackground Child actor
79-
if (actor) {
80-
ActorCreated(actor);
81-
} else {
82-
Unused << BackgroundChild::GetOrCreateForCurrentThread(this);
76+
77+
PBackgroundChild* actor = BackgroundChild::GetOrCreateForCurrentThread();
78+
if (NS_WARN_IF(!actor)) {
79+
MOZ_CRASH("Failed to create a PBackgroundChild actor!");
80+
}
81+
82+
mChild = new GamepadTestChannelChild();
83+
PGamepadTestChannelChild* initedChild =
84+
actor->SendPGamepadTestChannelConstructor(mChild);
85+
if (NS_WARN_IF(!initedChild)) {
86+
MOZ_CRASH("Failed to create a PBackgroundChild actor!");
8387
}
8488
}
8589

8690
void
8791
GamepadServiceTest::DestroyPBackgroundActor()
8892
{
89-
if (mChild) {
90-
// If mChild exists, which means that IPDL channel
91-
// has been created, our pending operations should
92-
// be empty.
93-
MOZ_ASSERT(mPendingOperations.IsEmpty());
94-
mChild->SendShutdownChannel();
95-
mChild = nullptr;
96-
} else {
97-
// If the IPDL channel has not been created and we
98-
// want to destroy it now, just cancel all pending
99-
// operations.
100-
mPendingOperations.Clear();
101-
}
93+
mChild->SendShutdownChannel();
94+
mChild = nullptr;
10295
}
10396

10497
already_AddRefed<Promise>
@@ -128,13 +121,10 @@ GamepadServiceTest::AddGamepad(const nsAString& aID,
128121
}
129122

130123
uint32_t id = ++mEventNumber;
131-
if (mChild) {
132-
mChild->AddPromise(id, p);
133-
mChild->SendGamepadTestEvent(id, e);
134-
} else {
135-
PendingOperation op(id, e, p);
136-
mPendingOperations.AppendElement(op);
137-
}
124+
125+
mChild->AddPromise(id, p);
126+
mChild->SendGamepadTestEvent(id, e);
127+
138128
return p.forget();
139129
}
140130

@@ -150,12 +140,7 @@ GamepadServiceTest::RemoveGamepad(uint32_t aIndex)
150140
GamepadChangeEvent e(aIndex, GamepadServiceType::Standard, body);
151141

152142
uint32_t id = ++mEventNumber;
153-
if (mChild) {
154-
mChild->SendGamepadTestEvent(id, e);
155-
} else {
156-
PendingOperation op(id, e);
157-
mPendingOperations.AppendElement(op);
158-
}
143+
mChild->SendGamepadTestEvent(id, e);
159144
}
160145

161146
void
@@ -173,12 +158,7 @@ GamepadServiceTest::NewButtonEvent(uint32_t aIndex,
173158
GamepadChangeEvent e(aIndex, GamepadServiceType::Standard, body);
174159

175160
uint32_t id = ++mEventNumber;
176-
if (mChild) {
177-
mChild->SendGamepadTestEvent(id, e);
178-
} else {
179-
PendingOperation op(id, e);
180-
mPendingOperations.AppendElement(op);
181-
}
161+
mChild->SendGamepadTestEvent(id, e);
182162
}
183163

184164
void
@@ -197,12 +177,7 @@ GamepadServiceTest::NewButtonValueEvent(uint32_t aIndex,
197177
GamepadChangeEvent e(aIndex, GamepadServiceType::Standard, body);
198178

199179
uint32_t id = ++mEventNumber;
200-
if (mChild) {
201-
mChild->SendGamepadTestEvent(id, e);
202-
} else {
203-
PendingOperation op(id, e);
204-
mPendingOperations.AppendElement(op);
205-
}
180+
mChild->SendGamepadTestEvent(id, e);
206181
}
207182

208183
void
@@ -219,12 +194,7 @@ GamepadServiceTest::NewAxisMoveEvent(uint32_t aIndex,
219194
GamepadChangeEvent e(aIndex, GamepadServiceType::Standard, body);
220195

221196
uint32_t id = ++mEventNumber;
222-
if (mChild) {
223-
mChild->SendGamepadTestEvent(id, e);
224-
} else {
225-
PendingOperation op(id, e);
226-
mPendingOperations.AppendElement(op);
227-
}
197+
mChild->SendGamepadTestEvent(id, e);
228198
}
229199

230200
void
@@ -302,54 +272,7 @@ GamepadServiceTest::NewPoseMove(uint32_t aIndex,
302272
GamepadChangeEvent e(aIndex, GamepadServiceType::Standard, body);
303273

304274
uint32_t id = ++mEventNumber;
305-
if (mChild) {
306-
mChild->SendGamepadTestEvent(id, e);
307-
} else {
308-
PendingOperation op(id, e);
309-
mPendingOperations.AppendElement(op);
310-
}
311-
}
312-
313-
void
314-
GamepadServiceTest::FlushPendingOperations()
315-
{
316-
for (uint32_t i=0; i < mPendingOperations.Length(); ++i) {
317-
PendingOperation op = mPendingOperations[i];
318-
if (op.mPromise) {
319-
mChild->AddPromise(op.mID, op.mPromise);
320-
}
321-
mChild->SendGamepadTestEvent(op.mID, op.mEvent);
322-
}
323-
mPendingOperations.Clear();
324-
}
325-
326-
void
327-
GamepadServiceTest::ActorCreated(PBackgroundChild* aActor)
328-
{
329-
MOZ_ASSERT(aActor);
330-
// If we are shutting down, we don't need to create the
331-
// IPDL child/parent pair anymore.
332-
if (mShuttingDown) {
333-
// mPendingOperations should be cleared in
334-
// DestroyPBackgroundActor()
335-
MOZ_ASSERT(mPendingOperations.IsEmpty());
336-
return;
337-
}
338-
339-
mChild = new GamepadTestChannelChild();
340-
PGamepadTestChannelChild* initedChild =
341-
aActor->SendPGamepadTestChannelConstructor(mChild);
342-
if (NS_WARN_IF(!initedChild)) {
343-
ActorFailed();
344-
return;
345-
}
346-
FlushPendingOperations();
347-
}
348-
349-
void
350-
GamepadServiceTest::ActorFailed()
351-
{
352-
MOZ_CRASH("Failed to create background child actor!");
275+
mChild->SendGamepadTestEvent(id, e);
353276
}
354277

355278
JSObject*

dom/gamepad/GamepadServiceTest.h

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#ifndef mozilla_dom_GamepadServiceTest_h_
88
#define mozilla_dom_GamepadServiceTest_h_
99

10-
#include "nsIIPCBackgroundChildCreateCallback.h"
1110
#include "mozilla/DOMEventTargetHelper.h"
1211
#include "mozilla/dom/GamepadBinding.h"
1312

@@ -20,11 +19,9 @@ class GamepadTestChannelChild;
2019
class Promise;
2120

2221
// Service for testing purposes
23-
class GamepadServiceTest final : public DOMEventTargetHelper,
24-
public nsIIPCBackgroundChildCreateCallback
22+
class GamepadServiceTest final : public DOMEventTargetHelper
2523
{
2624
public:
27-
NS_DECL_NSIIPCBACKGROUNDCHILDCREATECALLBACK
2825
NS_DECL_ISUPPORTS_INHERITED
2926
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(GamepadServiceTest,
3027
DOMEventTargetHelper)
@@ -62,24 +59,10 @@ class GamepadServiceTest final : public DOMEventTargetHelper,
6259

6360
private:
6461

65-
// We need to asynchronously create IPDL channel, it is possible that
66-
// we send commands before the channel is created, so we have to buffer
67-
// them until the channel is created in that case.
68-
struct PendingOperation {
69-
explicit PendingOperation(const uint32_t& aID,
70-
const GamepadChangeEvent& aEvent,
71-
Promise* aPromise = nullptr)
72-
: mID(aID), mEvent(aEvent), mPromise(aPromise) {}
73-
uint32_t mID;
74-
const GamepadChangeEvent& mEvent;
75-
RefPtr<Promise> mPromise;
76-
};
77-
7862
// Hold a reference to the gamepad service so we don't have to worry about
7963
// execution order in tests.
8064
RefPtr<GamepadManager> mService;
8165
nsCOMPtr<nsPIDOMWindowInner> mWindow;
82-
nsTArray<PendingOperation> mPendingOperations;
8366
uint32_t mEventNumber;
8467
bool mShuttingDown;
8568

@@ -92,7 +75,6 @@ class GamepadServiceTest final : public DOMEventTargetHelper,
9275
~GamepadServiceTest();
9376
void InitPBackgroundActor();
9477
void DestroyPBackgroundActor();
95-
void FlushPendingOperations();
9678

9779
};
9880

0 commit comments

Comments
 (0)