Bug 1317670 Part 1 - r=jib
authorRandell Jesup <rjesup@jesup.org>
Sun, 20 Nov 2016 02:39:08 -0500
changeset 324292 01b543e78ae836f9d11f249d4324f75f15e4b12d
parent 324291 06ed2770b58d3610b8b8fecc50cb9e4087dc595d
child 324293 70f538269f501ef0a6269966376a2c441f7e0c1e
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersjib
bugs1317670
milestone53.0a1
Bug 1317670 Part 1 - r=jib
dom/media/MediaManager.cpp
dom/media/systemservices/DeviceChangeCallback.h
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -2691,25 +2691,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