Improve use of NeverDestroyed
[WebKit-https.git] / Source / WebCore / platform / mock / mediasource / MockMediaPlayerMediaSource.cpp
index c66178b..a5468b3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2015 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 
 #if ENABLE(MEDIA_SOURCE)
 
-#include "ExceptionCodePlaceholder.h"
 #include "MediaPlayer.h"
 #include "MediaSourcePrivateClient.h"
 #include "MockMediaSourcePrivate.h"
-#include <wtf/Functional.h>
 #include <wtf/MainThread.h>
+#include <wtf/NeverDestroyed.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
@@ -41,28 +40,21 @@ namespace WebCore {
 // MediaPlayer Enigne Support
 void MockMediaPlayerMediaSource::registerMediaEngine(MediaEngineRegistrar registrar)
 {
-    registrar(create, getSupportedTypes, supportsType, 0, 0, 0, 0);
+    registrar([] (MediaPlayer* player) { return std::make_unique<MockMediaPlayerMediaSource>(player); }, getSupportedTypes,
+        supportsType, 0, 0, 0, 0);
 }
 
-PassOwnPtr<MediaPlayerPrivateInterface> MockMediaPlayerMediaSource::create(MediaPlayer* player)
+// FIXME: What does the word "cache" mean here?
+static const HashSet<String, ASCIICaseInsensitiveHash>& mimeTypeCache()
 {
-    return adoptPtr(new MockMediaPlayerMediaSource(player));
-}
-
-static HashSet<String> mimeTypeCache()
-{
-    DEPRECATED_DEFINE_STATIC_LOCAL(HashSet<String>, cache, ());
-    static bool isInitialized = false;
-
-    if (!isInitialized) {
-        isInitialized = true;
-        cache.add(ASCIILiteral("video/mock"));
-    }
-
+    static const auto cache = makeNeverDestroyed(HashSet<String, ASCIICaseInsensitiveHash> {
+        "video/mock",
+        "audio/mock",
+    });
     return cache;
 }
 
-void MockMediaPlayerMediaSource::getSupportedTypes(HashSet<String>& supportedTypes)
+void MockMediaPlayerMediaSource::getSupportedTypes(HashSet<String, ASCIICaseInsensitiveHash>& supportedTypes)
 {
     supportedTypes = mimeTypeCache();
 }
@@ -72,13 +64,15 @@ MediaPlayer::SupportsType MockMediaPlayerMediaSource::supportsType(const MediaEn
     if (!parameters.isMediaSource)
         return MediaPlayer::IsNotSupported;
 
-    if (!mimeTypeCache().contains(parameters.type))
+    auto containerType = parameters.type.containerType();
+    if (containerType.isEmpty() || !mimeTypeCache().contains(containerType))
         return MediaPlayer::IsNotSupported;
 
-    if (parameters.codecs.isEmpty())
+    auto codecs = parameters.type.parameter(ContentType::codecsParameter());
+    if (codecs.isEmpty())
         return MediaPlayer::MayBeSupported;
 
-    return parameters.codecs == "mock" ? MediaPlayer::IsSupported : MediaPlayer::MayBeSupported;
+    return codecs == "mock" ? MediaPlayer::IsSupported : MediaPlayer::MayBeSupported;
 }
 
 MockMediaPlayerMediaSource::MockMediaPlayerMediaSource(MediaPlayer* player)
@@ -112,7 +106,9 @@ void MockMediaPlayerMediaSource::cancelLoad()
 void MockMediaPlayerMediaSource::play()
 {
     m_playing = 1;
-    callOnMainThread(bind(&MockMediaPlayerMediaSource::advanceCurrentTime, this));
+    callOnMainThread([this] {
+        advanceCurrentTime();
+    });
 }
 
 void MockMediaPlayerMediaSource::pause()
@@ -120,9 +116,9 @@ void MockMediaPlayerMediaSource::pause()
     m_playing = 0;
 }
 
-IntSize MockMediaPlayerMediaSource::naturalSize() const
+FloatSize MockMediaPlayerMediaSource::naturalSize() const
 {
-    return IntSize();
+    return FloatSize();
 }
 
 bool MockMediaPlayerMediaSource::hasVideo() const
@@ -169,7 +165,7 @@ std::unique_ptr<PlatformTimeRanges> MockMediaPlayerMediaSource::buffered() const
     if (m_mediaSourcePrivate)
         return m_mediaSourcePrivate->buffered();
 
-    return PlatformTimeRanges::create();
+    return std::make_unique<PlatformTimeRanges>();
 }
 
 bool MockMediaPlayerMediaSource::didLoadingProgress() const
@@ -181,7 +177,7 @@ void MockMediaPlayerMediaSource::setSize(const IntSize&)
 {
 }
 
-void MockMediaPlayerMediaSource::paint(GraphicsContext*, const IntRect&)
+void MockMediaPlayerMediaSource::paint(GraphicsContext&, const FloatRect&)
 {
 }
 
@@ -207,7 +203,9 @@ void MockMediaPlayerMediaSource::seekWithTolerance(const MediaTime& time, const
         m_player->timeChanged();
 
         if (m_playing)
-            callOnMainThread(bind(&MockMediaPlayerMediaSource::advanceCurrentTime, this));
+            callOnMainThread([this] {
+                advanceCurrentTime();
+            });
     }
 }
 
@@ -267,7 +265,9 @@ void MockMediaPlayerMediaSource::seekCompleted()
     m_player->timeChanged();
 
     if (m_playing)
-        callOnMainThread(bind(&MockMediaPlayerMediaSource::advanceCurrentTime, this));
+        callOnMainThread([this] {
+            advanceCurrentTime();
+        });
 }
 
 unsigned long MockMediaPlayerMediaSource::totalVideoFrames()