Improve use of NeverDestroyed
[WebKit-https.git] / Source / WebCore / Modules / encryptedmedia / legacy / LegacyCDM.cpp
index f09b545..f557fa6 100644 (file)
@@ -60,24 +60,19 @@ public:
 
 static Vector<CDMFactory*>& installedCDMFactories()
 {
-    static NeverDestroyed<Vector<CDMFactory*>> cdms;
-    static bool queriedCDMs = false;
-    if (!queriedCDMs) {
-        queriedCDMs = true;
-
-        cdms.get().append(new CDMFactory([](CDM* cdm) { return std::make_unique<CDMPrivateClearKey>(cdm); },
-            CDMPrivateClearKey::supportsKeySystem, CDMPrivateClearKey::supportsKeySystemAndMimeType));
+    static auto cdms = makeNeverDestroyed(Vector<CDMFactory*> {
+        new CDMFactory([](CDM* cdm) { return std::make_unique<CDMPrivateClearKey>(cdm); },
+            CDMPrivateClearKey::supportsKeySystem, CDMPrivateClearKey::supportsKeySystemAndMimeType),
 
         // FIXME: initialize specific UA CDMs. http://webkit.org/b/109318, http://webkit.org/b/109320
-        cdms.get().append(new CDMFactory([](CDM* cdm) { return std::make_unique<CDMPrivateMediaPlayer>(cdm); },
-            CDMPrivateMediaPlayer::supportsKeySystem, CDMPrivateMediaPlayer::supportsKeySystemAndMimeType));
+        new CDMFactory([](CDM* cdm) { return std::make_unique<CDMPrivateMediaPlayer>(cdm); },
+            CDMPrivateMediaPlayer::supportsKeySystem, CDMPrivateMediaPlayer::supportsKeySystemAndMimeType),
 
 #if PLATFORM(MAC) && ENABLE(MEDIA_SOURCE)
-        cdms.get().append(new CDMFactory([](CDM* cdm) { return std::make_unique<CDMPrivateMediaSourceAVFObjC>(cdm); },
-            CDMPrivateMediaSourceAVFObjC::supportsKeySystem, CDMPrivateMediaSourceAVFObjC::supportsKeySystemAndMimeType));
+        new CDMFactory([](CDM* cdm) { return std::make_unique<CDMPrivateMediaSourceAVFObjC>(cdm); },
+            CDMPrivateMediaSourceAVFObjC::supportsKeySystem, CDMPrivateMediaSourceAVFObjC::supportsKeySystemAndMimeType),
 #endif
-    }
-
+    });
     return cdms;
 }
 
@@ -92,7 +87,7 @@ static CDMFactory* CDMFactoryForKeySystem(const String& keySystem)
         if (factory->supportsKeySystem(keySystem))
             return factory;
     }
-    return 0;
+    return nullptr;
 }
 
 bool CDM::supportsKeySystem(const String& keySystem)