Bug 1317670 Part 1 - r=jib
authorRandell Jesup <rjesup@jesup.org>
Sun, 20 Nov 2016 02:39:08 -0500
changeset 352677 7fcfc4939f2439d5bc90ed1066082240ef96bba9
parent 352676 be65a95a6b4b0f22d238003e367539a6336e88be
child 352678 2b50647ce630beef1640f11487cedfea3460c1d1
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjib
bugs1317670
milestone52.0a2
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
@@ -2696,25 +2696,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