Bug 1337161 - Fix leak of GamepadPlatformService draft
authorChung-Sheng Fu <cfu@mozilla.com>
Thu, 22 Jun 2017 16:56:18 +0800
changeset 601616 863567c6a69e00f08d53626babf90902bf69ad1d
parent 601615 ca03bce8b0947b4a8dd799444ec98e5331543830
child 635338 ba6c64cda465eaf2a21449657e2559d627f49654
push id66146
push userbmo:cfu@mozilla.com
push dateWed, 28 Jun 2017 23:15:04 +0000
bugs1337161
milestone56.0a1
Bug 1337161 - Fix leak of GamepadPlatformService MozReview-Commit-ID: CPLg8kyL0xH
dom/gamepad/GamepadManager.cpp
--- a/dom/gamepad/GamepadManager.cpp
+++ b/dom/gamepad/GamepadManager.cpp
@@ -134,38 +134,36 @@ GamepadManager::BeginShutdown()
 
 void
 GamepadManager::AddListener(nsGlobalWindow* aWindow)
 {
   MOZ_ASSERT(aWindow);
   MOZ_ASSERT(aWindow->IsInnerWindow());
   MOZ_ASSERT(NS_IsMainThread());
 
+  // IPDL child has not been created
+  if (mChannelChildren.IsEmpty()) {
+    PBackgroundChild *actor = BackgroundChild::GetForCurrentThread();
+    //Try to get the PBackground Child actor
+    if (actor) {
+      ActorCreated(actor);
+    } else {
+      Unused << BackgroundChild::GetOrCreateForCurrentThread(this);
+    }
+  }
+
   if (!mEnabled || mShuttingDown || nsContentUtils::ShouldResistFingerprinting()) {
     return;
   }
 
   if (mListeners.IndexOf(aWindow) != NoIndex) {
     return; // already exists
   }
 
   mListeners.AppendElement(aWindow);
-
-  // IPDL child has been created
-  if (!mChannelChildren.IsEmpty()) {
-    return;
-  }
-
-  PBackgroundChild *actor = BackgroundChild::GetForCurrentThread();
-  //Try to get the PBackground Child actor
-  if (actor) {
-    ActorCreated(actor);
-  } else {
-    Unused << BackgroundChild::GetOrCreateForCurrentThread(this);
-  }
 }
 
 void
 GamepadManager::RemoveListener(nsGlobalWindow* aWindow)
 {
   MOZ_ASSERT(aWindow);
   MOZ_ASSERT(aWindow->IsInnerWindow());
 
@@ -496,17 +494,17 @@ GamepadManager::SetWindowHasSeenGamepad(
   } else {
     aWindow->RemoveGamepad(aIndex);
   }
 }
 
 void
 GamepadManager::Update(const GamepadChangeEvent& aEvent)
 {
-  if (mShuttingDown) {
+  if (!mEnabled || mShuttingDown || nsContentUtils::ShouldResistFingerprinting()) {
     return;
   }
 
   if (aEvent.type() == GamepadChangeEvent::TGamepadAdded) {
     const GamepadAdded& a = aEvent.get_GamepadAdded();
     AddGamepad(a.index(), a.id(),
                static_cast<GamepadMappingType>(a.mapping()),
                static_cast<GamepadHand>(a.hand()),