Bug 1317670 Part 1 - r=jib a=gchang
authorRandell Jesup <rjesup@jesup.org>
Sun, 20 Nov 2016 02:39:08 -0500
changeset 356761 fdb0e5daee384bbe9f39d17f82f8c41da5fe0eb9
parent 356760 85f8305e925eeead7a59583c8047a76ea29c1e75
child 356762 814b871c8a171f396036fca6322f891453b9d4db
push id6622
push usercbook@mozilla.com
push dateMon, 28 Nov 2016 15:55:29 +0000
treeherdermozilla-beta@1b954c82dd04 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjib, gchang
bugs1317670
milestone51.0
Bug 1317670 Part 1 - r=jib a=gchang
dom/media/MediaManager.cpp
dom/media/systemservices/DeviceChangeCallback.h
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -2776,25 +2776,26 @@ MediaManager::OnNavigation(uint64_t aWin
   }
 
   RemoveMediaDevicesCallback(aWindowID);
 }
 
 void
 MediaManager::RemoveMediaDevicesCallback(uint64_t aWindowID)
 {
+  MutexAutoLock lock(mCallbackMutex);
   for (DeviceChangeCallback* observer : mDeviceChangeCallbackList)
   {
     dom::MediaDevices* mediadevices = static_cast<dom::MediaDevices *>(observer);
     MOZ_ASSERT(mediadevices);
     if (mediadevices) {
       nsPIDOMWindowInner* window = mediadevices->GetOwner();
       MOZ_ASSERT(window);
       if (window && window->WindowID() == aWindowID) {
-        DeviceChangeCallback::RemoveDeviceChangeCallback(observer);
+        DeviceChangeCallback::RemoveDeviceChangeCallbackLocked(observer);
         return;
       }
     }
   }
 }
 
 StreamListeners*
 MediaManager::AddWindowID(uint64_t aWindowId)
--- a/dom/media/systemservices/DeviceChangeCallback.h
+++ b/dom/media/systemservices/DeviceChangeCallback.h
@@ -27,29 +27,33 @@ public:
     if (mDeviceChangeCallbackList.IndexOf(aCallback) == mDeviceChangeCallbackList.NoIndex)
       mDeviceChangeCallbackList.AppendElement(aCallback);
     return 0;
   }
 
   virtual int RemoveDeviceChangeCallback(DeviceChangeCallback* aCallback)
   {
     MutexAutoLock lock(mCallbackMutex);
+    return RemoveDeviceChangeCallbackLocked(aCallback);
+  }
+
+  virtual int RemoveDeviceChangeCallbackLocked(DeviceChangeCallback* aCallback)
+  {
+    mCallbackMutex.AssertCurrentThreadOwns();
     if (mDeviceChangeCallbackList.IndexOf(aCallback) != mDeviceChangeCallbackList.NoIndex)
       mDeviceChangeCallbackList.RemoveElement(aCallback);
     return 0;
   }
 
   DeviceChangeCallback() : mCallbackMutex("mozilla::media::DeviceChangeCallback::mCallbackMutex")
   {
-    mDeviceChangeCallbackList.Clear();
   }
 
   virtual ~DeviceChangeCallback()
   {
-    mDeviceChangeCallbackList.Clear();
   }
 
 protected:
   nsTArray<DeviceChangeCallback*> mDeviceChangeCallbackList;
   Mutex mCallbackMutex;
 };
 
 } // namespace mozilla