[WebCore] Remove uses of WTF::bind() in the Media Stream module
authorzandobersek@gmail.com <zandobersek@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Oct 2014 18:46:23 +0000 (18:46 +0000)
committerzandobersek@gmail.com <zandobersek@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Oct 2014 18:46:23 +0000 (18:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=138016

Reviewed by Eric Carlson.

Replace uses of WTF::bind() in the Media Stream module with C++11 lambdas.
Internal helper methods are removed in favor of inlining the code directly
into the lambdas. Range-based for-loops are deployed where appropriate.

* Modules/mediastream/MediaStreamTrack.cpp:
(WebCore::MediaStreamTrack::scheduleEventDispatch):
(WebCore::MediaStreamTrack::dispatchQueuedEvents): Deleted.
* Modules/mediastream/MediaStreamTrack.h:
* Modules/mediastream/MediaStreamTrackSourcesRequest.cpp:
(WebCore::MediaStreamTrackSourcesRequest::didCompleteRequest):
(WebCore::MediaStreamTrackSourcesRequest::callCompletionHandler): Deleted.
* Modules/mediastream/MediaStreamTrackSourcesRequest.h:
* Modules/mediastream/UserMediaRequest.cpp:
(WebCore::UserMediaRequest::constraintsValidated):
(WebCore::UserMediaRequest::userMediaAccessGranted):
(WebCore::UserMediaRequest::didCreateStream):
(WebCore::UserMediaRequest::failedToCreateStreamWithConstraintsError):
(WebCore::UserMediaRequest::failedToCreateStreamWithPermissionError):
(WebCore::UserMediaRequest::requestPermission): Deleted.
(WebCore::UserMediaRequest::createMediaStream): Deleted.
(WebCore::UserMediaRequest::callSuccessHandler): Deleted.
(WebCore::UserMediaRequest::callErrorHandler): Deleted.
* Modules/mediastream/UserMediaRequest.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@175265 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/MediaStreamTrack.cpp
Source/WebCore/Modules/mediastream/MediaStreamTrack.h
Source/WebCore/Modules/mediastream/MediaStreamTrackSourcesRequest.cpp
Source/WebCore/Modules/mediastream/MediaStreamTrackSourcesRequest.h
Source/WebCore/Modules/mediastream/UserMediaRequest.cpp
Source/WebCore/Modules/mediastream/UserMediaRequest.h

index b13c3ed..1000c22 100644 (file)
@@ -1,3 +1,34 @@
+2014-10-28  Zan Dobersek  <zdobersek@igalia.com>
+
+        [WebCore] Remove uses of WTF::bind() in the Media Stream module
+        https://bugs.webkit.org/show_bug.cgi?id=138016
+
+        Reviewed by Eric Carlson.
+
+        Replace uses of WTF::bind() in the Media Stream module with C++11 lambdas.
+        Internal helper methods are removed in favor of inlining the code directly
+        into the lambdas. Range-based for-loops are deployed where appropriate.
+
+        * Modules/mediastream/MediaStreamTrack.cpp:
+        (WebCore::MediaStreamTrack::scheduleEventDispatch):
+        (WebCore::MediaStreamTrack::dispatchQueuedEvents): Deleted.
+        * Modules/mediastream/MediaStreamTrack.h:
+        * Modules/mediastream/MediaStreamTrackSourcesRequest.cpp:
+        (WebCore::MediaStreamTrackSourcesRequest::didCompleteRequest):
+        (WebCore::MediaStreamTrackSourcesRequest::callCompletionHandler): Deleted.
+        * Modules/mediastream/MediaStreamTrackSourcesRequest.h:
+        * Modules/mediastream/UserMediaRequest.cpp:
+        (WebCore::UserMediaRequest::constraintsValidated):
+        (WebCore::UserMediaRequest::userMediaAccessGranted):
+        (WebCore::UserMediaRequest::didCreateStream):
+        (WebCore::UserMediaRequest::failedToCreateStreamWithConstraintsError):
+        (WebCore::UserMediaRequest::failedToCreateStreamWithPermissionError):
+        (WebCore::UserMediaRequest::requestPermission): Deleted.
+        (WebCore::UserMediaRequest::createMediaStream): Deleted.
+        (WebCore::UserMediaRequest::callSuccessHandler): Deleted.
+        (WebCore::UserMediaRequest::callErrorHandler): Deleted.
+        * Modules/mediastream/UserMediaRequest.h:
+
 2014-10-28  Pascal Jacquemart  <p.jacquemart@samsung.com>
 
         Abandoned select option is reselected when shift selecting new options
index 1ba5d11..b9c654c 100644 (file)
@@ -298,24 +298,21 @@ void MediaStreamTrack::scheduleEventDispatch(PassRefPtr<Event> event)
         m_eventDispatchScheduled = true;
     }
 
-    callOnMainThread(bind(&MediaStreamTrack::dispatchQueuedEvents, this));
-}
-
-void MediaStreamTrack::dispatchQueuedEvents()
-{
-    Vector<RefPtr<Event>> events;
-    {
-        MutexLocker locker(m_mutex);
-        m_eventDispatchScheduled = false;
-        events.swap(m_scheduledEvents);
-    }
-    if (!scriptExecutionContext())
-        return;
-
-    for (auto it = events.begin(); it != events.end(); ++it)
-        dispatchEvent((*it).release());
+    RefPtr<MediaStreamTrack> protectedThis(this);
+    callOnMainThread([protectedThis] {
+        Vector<RefPtr<Event>> events;
+        {
+            MutexLocker locker(protectedThis->m_mutex);
+            protectedThis->m_eventDispatchScheduled = false;
+            events = WTF::move(protectedThis->m_scheduledEvents);
+        }
+
+        if (!protectedThis->scriptExecutionContext())
+            return;
 
-    events.clear();
+        for (auto& event : events)
+            protectedThis->dispatchEvent(event.release());
+    });
 }
 
 } // namespace WebCore
index ba6e657..427a998 100644 (file)
@@ -116,7 +116,6 @@ private:
     void configureTrackRendering();
     void trackDidEnd();
     void scheduleEventDispatch(PassRefPtr<Event>);
-    void dispatchQueuedEvents();
 
     // ActiveDOMObject
     virtual void stop() override final;
index 18b929a..22c87c2 100644 (file)
@@ -56,15 +56,14 @@ void MediaStreamTrackSourcesRequest::didCompleteRequest(const Vector<RefPtr<Trac
     for (size_t i = 0; i < requestSourceInfos.size(); ++i)
         m_sourceInfos.append(SourceInfo::create(requestSourceInfos[i]));
 
-    callOnMainThread(bind(&MediaStreamTrackSourcesRequest::callCompletionHandler, this));
-}
-
-void MediaStreamTrackSourcesRequest::callCompletionHandler()
-{
-    ASSERT(m_callback);
+    RefPtr<MediaStreamTrackSourcesRequest> protectedThis(this);
+    callOnMainThread([protectedThis] {
+        RefPtr<MediaStreamTrackSourcesCallback>& callback = protectedThis->m_callback;
+        ASSERT(callback);
 
-    m_callback->handleEvent(m_sourceInfos);
-    m_callback = nullptr;
+        callback->handleEvent(protectedThis->m_sourceInfos);
+        callback = nullptr;
+    });
 }
 
 } // namespace WebCore
index 96599b4..1339b1b 100644 (file)
@@ -51,8 +51,6 @@ private:
     virtual const String& requestOrigin() const override { return m_origin; }
     virtual void didCompleteRequest(const Vector<RefPtr<TrackSourceInfo>>&) override;
 
-    void callCompletionHandler();
-
     String m_origin;
     RefPtr<MediaStreamTrackSourcesCallback> m_callback;
     Vector<RefPtr<SourceInfo>> m_sourceInfos;
index e438d35..3d20618 100644 (file)
@@ -119,26 +119,21 @@ void UserMediaRequest::start()
     
 void UserMediaRequest::constraintsValidated()
 {
-    if (m_controller)
-        callOnMainThread(bind(&UserMediaRequest::requestPermission, this));
-}
-
-void UserMediaRequest::requestPermission()
-{
-    // 2 - The constraints are valid, ask the user for access to media.
-    if (m_controller)
-        m_controller->requestPermission(this);
+    RefPtr<UserMediaRequest> protectedThis(this);
+    callOnMainThread([protectedThis] {
+        // 2 - The constraints are valid, ask the user for access to media.
+        if (UserMediaController* controller = protectedThis->m_controller)
+            controller->requestPermission(protectedThis.get());
+    });
 }
 
 void UserMediaRequest::userMediaAccessGranted()
 {
-    callOnMainThread(bind(&UserMediaRequest::createMediaStream, this));
-}
-
-void UserMediaRequest::createMediaStream()
-{
-    // 3 - the user granted access, ask platform to create the media stream descriptors.
-    MediaStreamCenter::shared().createMediaStream(this, m_audioConstraints, m_videoConstraints);
+    RefPtr<UserMediaRequest> protectedThis(this);
+    callOnMainThread([protectedThis] {
+        // 3 - the user granted access, ask platform to create the media stream descriptors.
+        MediaStreamCenter::shared().createMediaStream(protectedThis.get(), protectedThis->m_audioConstraints, protectedThis->m_videoConstraints);
+    });
 }
 
 void UserMediaRequest::userMediaAccessDenied()
@@ -156,25 +151,18 @@ void UserMediaRequest::didCreateStream(PassRefPtr<MediaStreamPrivate> privateStr
     if (!m_scriptExecutionContext || !m_successCallback)
         return;
 
-    callOnMainThread(bind(&UserMediaRequest::callSuccessHandler, this, privateStream));
-}
-
-void UserMediaRequest::callSuccessHandler(PassRefPtr<MediaStreamPrivate> privateStream)
-{
-    // 4 - Create the MediaStream and pass it to the success callback.
-    ASSERT(m_successCallback);
+    RefPtr<UserMediaRequest> protectedThis(this);
+    callOnMainThread([protectedThis, privateStream] {
+        // 4 - Create the MediaStream and pass it to the success callback.
+        RefPtr<MediaStream> stream = MediaStream::create(*protectedThis->m_scriptExecutionContext, privateStream);
+        for (auto& track : stream->getAudioTracks())
+            track->applyConstraints(protectedThis->m_audioConstraints);
+        for (auto& track : stream->getVideoTracks())
+            track->applyConstraints(protectedThis->m_videoConstraints);
 
-    RefPtr<MediaStream> stream = MediaStream::create(*m_scriptExecutionContext, privateStream);
-
-    Vector<RefPtr<MediaStreamTrack>> tracks = stream->getAudioTracks();
-    for (auto iter = tracks.begin(); iter != tracks.end(); ++iter)
-        (*iter)->applyConstraints(m_audioConstraints);
-
-    tracks = stream->getVideoTracks();
-    for (auto iter = tracks.begin(); iter != tracks.end(); ++iter)
-        (*iter)->applyConstraints(m_videoConstraints);
-
-    m_successCallback->handleEvent(stream.get());
+        ASSERT(protectedThis->m_successCallback);
+        protectedThis->m_successCallback->handleEvent(stream.get());
+    });
 }
 
 void UserMediaRequest::failedToCreateStreamWithConstraintsError(const String& constraintName)
@@ -186,8 +174,11 @@ void UserMediaRequest::failedToCreateStreamWithConstraintsError(const String& co
     if (!m_errorCallback)
         return;
 
+    RefPtr<UserMediaRequest> protectedThis(this);
     RefPtr<NavigatorUserMediaError> error = NavigatorUserMediaError::create(NavigatorUserMediaError::constraintNotSatisfiedErrorName(), constraintName);
-    callOnMainThread(bind(&UserMediaRequest::callErrorHandler, this, error.release()));
+    callOnMainThread([protectedThis, error] {
+        protectedThis->m_errorCallback->handleEvent(error.get());
+    });
 }
 
 void UserMediaRequest::failedToCreateStreamWithPermissionError()
@@ -198,17 +189,11 @@ void UserMediaRequest::failedToCreateStreamWithPermissionError()
     if (!m_errorCallback)
         return;
 
+    RefPtr<UserMediaRequest> protectedThis(this);
     RefPtr<NavigatorUserMediaError> error = NavigatorUserMediaError::create(NavigatorUserMediaError::permissionDeniedErrorName(), emptyString());
-    callOnMainThread(bind(&UserMediaRequest::callErrorHandler, this, error.release()));
-}
-
-void UserMediaRequest::callErrorHandler(PassRefPtr<NavigatorUserMediaError> prpError)
-{
-    RefPtr<NavigatorUserMediaError> error = prpError;
-
-    ASSERT(error);
-    
-    m_errorCallback->handleEvent(error.get());
+    callOnMainThread([protectedThis, error] {
+        protectedThis->m_errorCallback->handleEvent(error.get());
+    });
 }
 
 void UserMediaRequest::contextDestroyed()
index c80a6ba..a04ef06 100644 (file)
@@ -79,11 +79,6 @@ private:
     // ContextDestructionObserver
     virtual void contextDestroyed() override final;
     
-    void callSuccessHandler(PassRefPtr<MediaStreamPrivate>);
-    void callErrorHandler(PassRefPtr<NavigatorUserMediaError>);
-    void requestPermission();
-    void createMediaStream();
-
     RefPtr<MediaConstraints> m_audioConstraints;
     RefPtr<MediaConstraints> m_videoConstraints;