@@ -35,7 +35,6 @@ NS_IMPL_CYCLE_COLLECTION_INHERITED(GamepadServiceTest, DOMEventTargetHelper,
35
35
mWindow )
36
36
37
37
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION (GamepadServiceTest)
38
- NS_INTERFACE_MAP_ENTRY (nsIIPCBackgroundChildCreateCallback)
39
38
NS_INTERFACE_MAP_END_INHERITING (DOMEventTargetHelper)
40
39
41
40
NS_IMPL_ADDREF_INHERITED (GamepadServiceTest, DOMEventTargetHelper)
74
73
GamepadServiceTest::InitPBackgroundActor ()
75
74
{
76
75
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!" );
83
87
}
84
88
}
85
89
86
90
void
87
91
GamepadServiceTest::DestroyPBackgroundActor ()
88
92
{
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 ;
102
95
}
103
96
104
97
already_AddRefed<Promise>
@@ -128,13 +121,10 @@ GamepadServiceTest::AddGamepad(const nsAString& aID,
128
121
}
129
122
130
123
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
+
138
128
return p.forget ();
139
129
}
140
130
@@ -150,12 +140,7 @@ GamepadServiceTest::RemoveGamepad(uint32_t aIndex)
150
140
GamepadChangeEvent e (aIndex, GamepadServiceType::Standard, body);
151
141
152
142
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);
159
144
}
160
145
161
146
void
@@ -173,12 +158,7 @@ GamepadServiceTest::NewButtonEvent(uint32_t aIndex,
173
158
GamepadChangeEvent e (aIndex, GamepadServiceType::Standard, body);
174
159
175
160
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);
182
162
}
183
163
184
164
void
@@ -197,12 +177,7 @@ GamepadServiceTest::NewButtonValueEvent(uint32_t aIndex,
197
177
GamepadChangeEvent e (aIndex, GamepadServiceType::Standard, body);
198
178
199
179
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);
206
181
}
207
182
208
183
void
@@ -219,12 +194,7 @@ GamepadServiceTest::NewAxisMoveEvent(uint32_t aIndex,
219
194
GamepadChangeEvent e (aIndex, GamepadServiceType::Standard, body);
220
195
221
196
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);
228
198
}
229
199
230
200
void
@@ -302,54 +272,7 @@ GamepadServiceTest::NewPoseMove(uint32_t aIndex,
302
272
GamepadChangeEvent e (aIndex, GamepadServiceType::Standard, body);
303
273
304
274
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);
353
276
}
354
277
355
278
JSObject*
0 commit comments