Bug 1299975 - Part 2: Make GamepadManager own multiple GamepadEventChannelChild; r=kip, r=lenzak800
authorDaosheng Mu <daoshengmu@gmail.com>
Wed, 07 Sep 2016 18:31:53 +0800
changeset 313222 9e4c73d21811d7b57ac952ae2891a7d7f412352a
parent 313221 4b9c964265fae1cae81a26ab12a8da3d7a09e532
child 313223 ad2e3708134aa669bf2950671482f482254daf5d
push id30676
push userkwierso@gmail.com
push dateThu, 08 Sep 2016 22:22:24 +0000
treeherdermozilla-central@176aff980979 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskip, lenzak800
bugs1299975
milestone51.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1299975 - Part 2: Make GamepadManager own multiple GamepadEventChannelChild; r=kip, r=lenzak800 MozReview-Commit-ID: ITvS4a9ONh3
dom/gamepad/GamepadManager.cpp
dom/gamepad/GamepadManager.h
--- a/dom/gamepad/GamepadManager.cpp
+++ b/dom/gamepad/GamepadManager.cpp
@@ -53,18 +53,17 @@ StaticRefPtr<GamepadManager> gGamepadMan
 
 } // namespace
 
 NS_IMPL_ISUPPORTS(GamepadManager, nsIObserver)
 
 GamepadManager::GamepadManager()
   : mEnabled(false),
     mNonstandardEventsEnabled(false),
-    mShuttingDown(false),
-    mChild(nullptr)
+    mShuttingDown(false)
 {}
 
 nsresult
 GamepadManager::Init()
 {
   mEnabled = IsAPIEnabled();
   mNonstandardEventsEnabled =
     Preferences::GetBool(kGamepadEventsEnabledPref, false);
@@ -99,20 +98,20 @@ GamepadManager::Observe(nsISupports* aSu
   }
   BeginShutdown();
   return NS_OK;
 }
 
 void
 GamepadManager::StopMonitoring()
 {
-  if(mChild) {
-    mChild->SendGamepadListenerRemoved();
-    mChild = nullptr;
+  for (uint32_t i = 0; i < mChannelChildren.Length(); ++i) {
+    mChannelChildren[i]->SendGamepadListenerRemoved();
   }
+  mChannelChildren.Clear();
   mGamepads.Clear();
 }
 
 void
 GamepadManager::BeginShutdown()
 {
   mShuttingDown = true;
   StopMonitoring();
@@ -137,19 +136,20 @@ GamepadManager::AddListener(nsGlobalWind
 
   if (mListeners.IndexOf(aWindow) != NoIndex) {
     return; // already exists
   }
 
   mListeners.AppendElement(aWindow);
 
   // IPDL child has been created
-  if (mChild) {
+  if (!mChannelChildren.IsEmpty()) {
     return;
   }
+
   PBackgroundChild *actor = BackgroundChild::GetForCurrentThread();
   //Try to get the PBackground Child actor
   if (actor) {
     ActorCreated(actor);
   } else {
     Unused << BackgroundChild::GetOrCreateForCurrentThread(this);
   }
 }
@@ -576,18 +576,21 @@ GamepadManager::ActorCreated(PBackground
   GamepadEventChannelChild *child = new GamepadEventChannelChild();
   PGamepadEventChannelChild *initedChild =
     aActor->SendPGamepadEventChannelConstructor(child);
   if (NS_WARN_IF(!initedChild)) {
     ActorFailed();
     return;
   }
   MOZ_ASSERT(initedChild == child);
-  mChild = child;
-  mChild->SendGamepadListenerAdded();
+  child->SendGamepadListenerAdded();
+  mChannelChildren.AppendElement(child);
+
+  // TODO: Add more event channels to mChannelChildren if you would
+  // like to support more kinds of devices.
 }
 
 //Override nsIIPCBackgroundChildCreateCallback
 void
 GamepadManager::ActorFailed()
 {
   MOZ_CRASH("Gamepad IPC actor create failed!");
 }
--- a/dom/gamepad/GamepadManager.h
+++ b/dom/gamepad/GamepadManager.h
@@ -106,18 +106,18 @@ class GamepadManager final : public nsIO
   // true if non-standard events are enabled in preferences
   bool mNonstandardEventsEnabled;
   // true when shutdown has begun
   bool mShuttingDown;
 
   // Gamepad IPDL child
   // This pointer is only used by this singleton instance and
   // will be destroyed during the IPDL shutdown chain, so we
-  // don't need to refcount it here
-  GamepadEventChannelChild MOZ_NON_OWNING_REF *mChild;
+  // don't need to refcount it here.
+  nsTArray<GamepadEventChannelChild *> mChannelChildren;
 
  private:
 
   nsresult Init();
 
   bool MaybeWindowHasSeenGamepad(nsGlobalWindow* aWindow, uint32_t aIndex);
   // Returns true if we have already sent data from this gamepad
   // to this window. This should only return true if the user