Bug 1314858 - Make content process cache of GMP capabilities thread safe. r=gerald
authorChris Pearce <cpearce@mozilla.com>
Wed, 02 Nov 2016 09:47:00 +1300
changeset 347649 86b73731ba98bf9e2cebeca248469f5ecca25790
parent 347648 018ce7c8c41584b01e732574997f14e2bc685bb3
child 347650 a37b70e85582ca5c46d5f9e7874c340472f27af1
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1314858
milestone52.0a1
Bug 1314858 - Make content process cache of GMP capabilities thread safe. r=gerald MozReview-Commit-ID: 5zTFlfReBne
dom/media/gmp/GMPServiceChild.cpp
--- a/dom/media/gmp/GMPServiceChild.cpp
+++ b/dom/media/gmp/GMPServiceChild.cpp
@@ -9,16 +9,17 @@
 #include "mozilla/StaticPtr.h"
 #include "mozIGeckoMediaPluginService.h"
 #include "mozIGeckoMediaPluginChromeService.h"
 #include "nsCOMPtr.h"
 #include "GMPParent.h"
 #include "GMPContentParent.h"
 #include "nsXPCOMPrivate.h"
 #include "mozilla/SyncRunnable.h"
+#include "mozilla/StaticMutex.h"
 #include "runnable_utils.h"
 #include "base/task.h"
 #include "nsIObserverService.h"
 #include "nsComponentManagerUtils.h"
 
 namespace mozilla {
 
 #ifdef LOG
@@ -174,16 +175,17 @@ struct GMPCapabilityAndVersion
     return s;
   }
 
   nsCString mName;
   nsCString mVersion;
   nsTArray<GMPCapability> mCapabilities;
 };
 
+StaticMutex sGMPCapabilitiesMutex;
 StaticAutoPtr<nsTArray<GMPCapabilityAndVersion>> sGMPCapabilities;
 
 static nsCString
 GMPCapabilitiesToString()
 {
   nsCString s;
   for (const GMPCapabilityAndVersion& gmp : *sGMPCapabilities) {
     if (!s.IsEmpty()) {
@@ -193,16 +195,17 @@ GMPCapabilitiesToString()
   }
   return s;
 }
 
 /* static */
 void
 GeckoMediaPluginServiceChild::UpdateGMPCapabilities(nsTArray<GMPCapabilityData>&& aCapabilities)
 {
+  StaticMutexAutoLock lock(sGMPCapabilitiesMutex);
   if (!sGMPCapabilities) {
     sGMPCapabilities = new nsTArray<GMPCapabilityAndVersion>();
     ClearOnShutdown(&sGMPCapabilities);
   }
   sGMPCapabilities->Clear();
   for (const GMPCapabilityData& plugin : aCapabilities) {
     sGMPCapabilities->AppendElement(GMPCapabilityAndVersion(plugin));
   }
@@ -218,17 +221,17 @@ GeckoMediaPluginServiceChild::UpdateGMPC
   }
 }
 
 NS_IMETHODIMP
 GeckoMediaPluginServiceChild::HasPluginForAPI(const nsACString& aAPI,
                                               nsTArray<nsCString>* aTags,
                                               bool* aHasPlugin)
 {
-  MOZ_ASSERT(NS_IsMainThread());
+  StaticMutexAutoLock lock(sGMPCapabilitiesMutex);
   if (!sGMPCapabilities) {
     *aHasPlugin = false;
     return NS_OK;
   }
 
   nsCString api(aAPI);
   for (const GMPCapabilityAndVersion& plugin : *sGMPCapabilities) {
     if (GMPCapability::Supports(plugin.mCapabilities, api, *aTags)) {