Replace uses of CrossThreadTask in DefaultSharedWorkerRepository, WorkerMessagingProx...
authorzandobersek@gmail.com <zandobersek@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Jun 2014 13:06:47 +0000 (13:06 +0000)
committerzandobersek@gmail.com <zandobersek@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Jun 2014 13:06:47 +0000 (13:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=133375

Reviewed by Darin Adler.

Uses of CrossThreadTask in the two classes are replaced with C++11 lambdas.
The necessary cross-thread copies are created manually and passed into the
lambdas by value, removing the need for CrossThreadTask and its use of CrossThreadCopier.

Remove the explicit use of this pointer in some lambdas -- it is captured automatically when
capturing by value, so enforcing its capturing through explicit use is not necessary.

* workers/DefaultSharedWorkerRepository.cpp:
(WebCore::SharedWorkerProxy::postExceptionToWorkerObject):
(WebCore::SharedWorkerProxy::postConsoleMessageToWorkerObject):
(WebCore::postExceptionTask): Deleted.
(WebCore::postConsoleMessageTask): Deleted.
* workers/WorkerMessagingProxy.cpp:
(WebCore::WorkerMessagingProxy::postMessageToWorkerObject):
(WebCore::WorkerMessagingProxy::postConsoleMessageToWorkerObject):
(WebCore::WorkerMessagingProxy::workerObjectDestroyed):
(WebCore::WorkerMessagingProxy::notifyNetworkStateChange):
(WebCore::WorkerMessagingProxy::connectToInspector):
(WebCore::WorkerMessagingProxy::disconnectFromInspector):
(WebCore::WorkerMessagingProxy::sendMessageToInspector):
(WebCore::WorkerMessagingProxy::postMessageToPageInspector):
(WebCore::WorkerMessagingProxy::confirmMessageFromWorkerObject):
(WebCore::WorkerMessagingProxy::reportPendingActivity):
(WebCore::postConsoleMessageTask): Deleted.
(WebCore::WorkerMessagingProxy::workerObjectDestroyedInternal): Deleted.
(WebCore::connectToWorkerGlobalScopeInspectorTask): Deleted.
(WebCore::disconnectFromWorkerGlobalScopeInspectorTask): Deleted.
(WebCore::dispatchOnInspectorBackendTask): Deleted.
* workers/WorkerMessagingProxy.h:

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

Source/WebCore/ChangeLog
Source/WebCore/workers/DefaultSharedWorkerRepository.cpp
Source/WebCore/workers/WorkerMessagingProxy.cpp
Source/WebCore/workers/WorkerMessagingProxy.h

index a5c3878..c42319f 100644 (file)
@@ -1,3 +1,40 @@
+2014-06-07  Zan Dobersek  <zdobersek@igalia.com>
+
+        Replace uses of CrossThreadTask in DefaultSharedWorkerRepository, WorkerMessagingProxy with C++11 lambdas
+        https://bugs.webkit.org/show_bug.cgi?id=133375
+
+        Reviewed by Darin Adler.
+
+        Uses of CrossThreadTask in the two classes are replaced with C++11 lambdas.
+        The necessary cross-thread copies are created manually and passed into the
+        lambdas by value, removing the need for CrossThreadTask and its use of CrossThreadCopier.
+
+        Remove the explicit use of this pointer in some lambdas -- it is captured automatically when
+        capturing by value, so enforcing its capturing through explicit use is not necessary.
+
+        * workers/DefaultSharedWorkerRepository.cpp:
+        (WebCore::SharedWorkerProxy::postExceptionToWorkerObject):
+        (WebCore::SharedWorkerProxy::postConsoleMessageToWorkerObject):
+        (WebCore::postExceptionTask): Deleted.
+        (WebCore::postConsoleMessageTask): Deleted.
+        * workers/WorkerMessagingProxy.cpp:
+        (WebCore::WorkerMessagingProxy::postMessageToWorkerObject):
+        (WebCore::WorkerMessagingProxy::postConsoleMessageToWorkerObject):
+        (WebCore::WorkerMessagingProxy::workerObjectDestroyed):
+        (WebCore::WorkerMessagingProxy::notifyNetworkStateChange):
+        (WebCore::WorkerMessagingProxy::connectToInspector):
+        (WebCore::WorkerMessagingProxy::disconnectFromInspector):
+        (WebCore::WorkerMessagingProxy::sendMessageToInspector):
+        (WebCore::WorkerMessagingProxy::postMessageToPageInspector):
+        (WebCore::WorkerMessagingProxy::confirmMessageFromWorkerObject):
+        (WebCore::WorkerMessagingProxy::reportPendingActivity):
+        (WebCore::postConsoleMessageTask): Deleted.
+        (WebCore::WorkerMessagingProxy::workerObjectDestroyedInternal): Deleted.
+        (WebCore::connectToWorkerGlobalScopeInspectorTask): Deleted.
+        (WebCore::disconnectFromWorkerGlobalScopeInspectorTask): Deleted.
+        (WebCore::dispatchOnInspectorBackendTask): Deleted.
+        * workers/WorkerMessagingProxy.h:
+
 2014-06-06  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
 
         Scheme of content utils should be compared in an ASCII case-insensitive manner
index 4bd8c57..2151c70 100644 (file)
@@ -35,7 +35,6 @@
 #include "DefaultSharedWorkerRepository.h"
 
 #include "ActiveDOMObject.h"
-#include "CrossThreadTask.h"
 #include "Document.h"
 #include "ExceptionCode.h"
 #include "InspectorInstrumentation.h"
@@ -179,28 +178,28 @@ GroupSettings* SharedWorkerProxy::groupSettings() const
     return 0;
 }
 
-static void postExceptionTask(ScriptExecutionContext* context, const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL)
-{
-    context->reportException(errorMessage, lineNumber, columnNumber, sourceURL, 0);
-}
-
 void SharedWorkerProxy::postExceptionToWorkerObject(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL)
 {
     MutexLocker lock(m_workerDocumentsLock);
-    for (auto& document : m_workerDocuments)
-        document->postTask(CrossThreadTask(&postExceptionTask, errorMessage, lineNumber, columnNumber, sourceURL));
-}
+    String errorMessageCopy = errorMessage.isolatedCopy();
+    String sourceURLCopy = sourceURL.isolatedCopy();
 
-static void postConsoleMessageTask(ScriptExecutionContext* document, MessageSource source, MessageLevel level, const String& message, const String& sourceURL, unsigned lineNumber, unsigned columnNumber)
-{
-    document->addConsoleMessage(source, level, message, sourceURL, lineNumber, columnNumber);
+    for (auto& document : m_workerDocuments)
+        document->postTask([=] (ScriptExecutionContext* context) {
+            context->reportException(errorMessageCopy, lineNumber, columnNumber, sourceURLCopy, nullptr);
+        });
 }
 
 void SharedWorkerProxy::postConsoleMessageToWorkerObject(MessageSource source, MessageLevel level, const String& message, int lineNumber, int columnNumber, const String& sourceURL)
 {
     MutexLocker lock(m_workerDocumentsLock);
+    String messageCopy = message.isolatedCopy();
+    String sourceURLCopy = sourceURL.isolatedCopy();
+
     for (auto& document : m_workerDocuments)
-        document->postTask(CrossThreadTask(&postConsoleMessageTask, source, level, message, sourceURL, lineNumber, columnNumber));
+        document->postTask([=] (ScriptExecutionContext* context) {
+            context->addConsoleMessage(source, level, messageCopy, sourceURLCopy, lineNumber, columnNumber);
+        });
 }
 
 #if ENABLE(INSPECTOR)
index 3c30313..074f7c0 100644 (file)
@@ -29,7 +29,6 @@
 #include "WorkerMessagingProxy.h"
 
 #include "ContentSecurityPolicy.h"
-#include "CrossThreadTask.h"
 #include "DOMWindow.h"
 #include "DedicatedWorkerGlobalScope.h"
 #include "DedicatedWorkerThread.h"
@@ -99,7 +98,7 @@ void WorkerMessagingProxy::postMessageToWorkerObject(PassRefPtr<SerializedScript
     MessagePortChannelArray* channelsPtr = channels.release();
     m_scriptExecutionContext->postTask([=] (ScriptExecutionContext* context) {
         Worker* workerObject = this->workerObject();
-        if (!workerObject || this->askedToTerminate())
+        if (!workerObject || askedToTerminate())
             return;
 
         std::unique_ptr<MessagePortArray> ports = MessagePort::entanglePorts(*context, std::unique_ptr<MessagePortChannelArray>(channelsPtr));
@@ -163,16 +162,15 @@ void WorkerMessagingProxy::postExceptionToWorkerObject(const String& errorMessag
     });
 }
 
-static void postConsoleMessageTask(ScriptExecutionContext* context, WorkerMessagingProxy* messagingProxy, MessageSource source, MessageLevel level, const String& message, unsigned lineNumber, unsigned columnNumber, const String& sourceURL)
-{
-    if (messagingProxy->askedToTerminate())
-        return;
-    context->addConsoleMessage(source, level, message, sourceURL, lineNumber, columnNumber);
-}
-
 void WorkerMessagingProxy::postConsoleMessageToWorkerObject(MessageSource source, MessageLevel level, const String& message, int lineNumber, int columnNumber, const String& sourceURL)
 {
-    m_scriptExecutionContext->postTask(CrossThreadTask(&postConsoleMessageTask, AllowCrossThreadAccess(this), source, level, message, lineNumber, columnNumber, sourceURL));
+    String messageCopy = message.isolatedCopy();
+    String sourceURLCopy = sourceURL.isolatedCopy();
+    m_scriptExecutionContext->postTask([=] (ScriptExecutionContext* context) {
+        if (askedToTerminate())
+            return;
+        context->addConsoleMessage(source, level, messageCopy, sourceURLCopy, lineNumber, columnNumber);
+    });
 }
 
 void WorkerMessagingProxy::workerThreadCreated(PassRefPtr<DedicatedWorkerThread> workerThread)
@@ -196,7 +194,13 @@ void WorkerMessagingProxy::workerThreadCreated(PassRefPtr<DedicatedWorkerThread>
 void WorkerMessagingProxy::workerObjectDestroyed()
 {
     m_workerObject = 0;
-    m_scriptExecutionContext->postTask(CrossThreadTask(&workerObjectDestroyedInternal, AllowCrossThreadAccess(this)));
+    m_scriptExecutionContext->postTask([this] (ScriptExecutionContext*) {
+        m_mayBeDestroyed = true;
+        if (m_workerThread)
+            terminateWorkerGlobalScope();
+        else
+            workerGlobalScopeDestroyedInternal();
+    });
 }
 
 void WorkerMessagingProxy::notifyNetworkStateChange(bool isOnline)
@@ -208,38 +212,20 @@ void WorkerMessagingProxy::notifyNetworkStateChange(bool isOnline)
         return;
 
     m_workerThread->runLoop().postTask([=] (ScriptExecutionContext* context) {
-        WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(context);
-        workerGlobalScope->dispatchEvent(Event::create(isOnline ? eventNames().onlineEvent : eventNames().offlineEvent, false, false));
+        toWorkerGlobalScope(context)->dispatchEvent(Event::create(isOnline ? eventNames().onlineEvent : eventNames().offlineEvent, false, false));
     });
 }
 
-void WorkerMessagingProxy::workerObjectDestroyedInternal(ScriptExecutionContext*, WorkerMessagingProxy* proxy)
-{
-    proxy->m_mayBeDestroyed = true;
-    if (proxy->m_workerThread)
-        proxy->terminateWorkerGlobalScope();
-    else
-        proxy->workerGlobalScopeDestroyedInternal();
-}
-
 #if ENABLE(INSPECTOR)
-static void connectToWorkerGlobalScopeInspectorTask(ScriptExecutionContext* context, bool)
-{
-    toWorkerGlobalScope(context)->workerInspectorController().connectFrontend();
-}
-
 void WorkerMessagingProxy::connectToInspector(WorkerGlobalScopeProxy::PageInspector* pageInspector)
 {
     if (m_askedToTerminate)
         return;
     ASSERT(!m_pageInspector);
     m_pageInspector = pageInspector;
-    m_workerThread->runLoop().postTaskForMode(CrossThreadTask(connectToWorkerGlobalScopeInspectorTask, true), WorkerDebuggerAgent::debuggerTaskMode);
-}
-
-static void disconnectFromWorkerGlobalScopeInspectorTask(ScriptExecutionContext* context, bool)
-{
-    toWorkerGlobalScope(context)->workerInspectorController().disconnectFrontend(Inspector::InspectorDisconnectReason::InspectorDestroyed);
+    m_workerThread->runLoop().postTaskForMode([] (ScriptExecutionContext* context) {
+        toWorkerGlobalScope(context)->workerInspectorController().connectFrontend();
+    }, WorkerDebuggerAgent::debuggerTaskMode);
 }
 
 void WorkerMessagingProxy::disconnectFromInspector()
@@ -247,19 +233,19 @@ void WorkerMessagingProxy::disconnectFromInspector()
     m_pageInspector = 0;
     if (m_askedToTerminate)
         return;
-    m_workerThread->runLoop().postTaskForMode(CrossThreadTask(disconnectFromWorkerGlobalScopeInspectorTask, true), WorkerDebuggerAgent::debuggerTaskMode);
-}
-
-static void dispatchOnInspectorBackendTask(ScriptExecutionContext* context, const String& message)
-{
-    toWorkerGlobalScope(context)->workerInspectorController().dispatchMessageFromFrontend(message);
+    m_workerThread->runLoop().postTaskForMode([] (ScriptExecutionContext* context) {
+        toWorkerGlobalScope(context)->workerInspectorController().disconnectFrontend(Inspector::InspectorDisconnectReason::InspectorDestroyed);
+    }, WorkerDebuggerAgent::debuggerTaskMode);
 }
 
 void WorkerMessagingProxy::sendMessageToInspector(const String& message)
 {
     if (m_askedToTerminate)
         return;
-    m_workerThread->runLoop().postTaskForMode(CrossThreadTask(dispatchOnInspectorBackendTask, String(message)), WorkerDebuggerAgent::debuggerTaskMode);
+    String messageCopy = message.isolatedCopy();
+    m_workerThread->runLoop().postTaskForMode([messageCopy] (ScriptExecutionContext* context) {
+        toWorkerGlobalScope(context)->workerInspectorController().dispatchMessageFromFrontend(messageCopy);
+    }, WorkerDebuggerAgent::debuggerTaskMode);
     WorkerDebuggerAgent::interruptAndDispatchInspectorCommands(m_workerThread.get());
 }
 #endif
@@ -310,7 +296,7 @@ void WorkerMessagingProxy::postMessageToPageInspector(const String& message)
 {
     String messageCopy = message.isolatedCopy();
     m_scriptExecutionContext->postTask([=] (ScriptExecutionContext*) {
-        this->m_pageInspector->dispatchMessageFromWorker(messageCopy);
+        m_pageInspector->dispatchMessageFromWorker(messageCopy);
     });
 }
 #endif
@@ -318,7 +304,7 @@ void WorkerMessagingProxy::postMessageToPageInspector(const String& message)
 void WorkerMessagingProxy::confirmMessageFromWorkerObject(bool hasPendingActivity)
 {
     m_scriptExecutionContext->postTask([=] (ScriptExecutionContext*) {
-        this->reportPendingActivityInternal(true, hasPendingActivity);
+        reportPendingActivityInternal(true, hasPendingActivity);
     });
     // Will execute reportPendingActivityInternal() on context's thread.
 }
@@ -326,7 +312,7 @@ void WorkerMessagingProxy::confirmMessageFromWorkerObject(bool hasPendingActivit
 void WorkerMessagingProxy::reportPendingActivity(bool hasPendingActivity)
 {
     m_scriptExecutionContext->postTask([=] (ScriptExecutionContext*) {
-        this->reportPendingActivityInternal(false, hasPendingActivity);
+        reportPendingActivityInternal(false, hasPendingActivity);
     });
     // Will execute reportPendingActivityInternal() on context's thread.
 }
index 564dee9..3120d9b 100644 (file)
@@ -98,7 +98,6 @@ namespace WebCore {
         friend class WorkerThreadActivityReportTask;
 
         void workerGlobalScopeDestroyedInternal();
-        static void workerObjectDestroyedInternal(ScriptExecutionContext*, WorkerMessagingProxy*);
         void reportPendingActivityInternal(bool confirmingMessage, bool hasPendingActivity);
         Worker* workerObject() const { return m_workerObject; }