Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1343)

Unified Diff: third_party/WebKit/Source/modules/websockets/WorkerWebSocketChannel.cpp

Issue 2270693002: WebSocket: Consolidate inter-thread synchronous function calls (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address review comment Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/websockets/WorkerWebSocketChannel.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/websockets/WorkerWebSocketChannel.cpp
diff --git a/third_party/WebKit/Source/modules/websockets/WorkerWebSocketChannel.cpp b/third_party/WebKit/Source/modules/websockets/WorkerWebSocketChannel.cpp
index 4bcf08becbb71b9600024e3f42871149fbc8fff9..1ab28da6ed97d80e2a29c7707565620e35904d0e 100644
--- a/third_party/WebKit/Source/modules/websockets/WorkerWebSocketChannel.cpp
+++ b/third_party/WebKit/Source/modules/websockets/WorkerWebSocketChannel.cpp
@@ -109,7 +109,6 @@ WorkerWebSocketChannel::WorkerWebSocketChannel(WorkerGlobalScope& workerGlobalSc
: m_bridge(new Bridge(client, workerGlobalScope))
, m_locationAtConnection(std::move(location))
{
- m_bridge->initialize(m_locationAtConnection->clone());
}
WorkerWebSocketChannel::~WorkerWebSocketChannel()
@@ -120,7 +119,7 @@ WorkerWebSocketChannel::~WorkerWebSocketChannel()
bool WorkerWebSocketChannel::connect(const KURL& url, const String& protocol)
{
ASSERT(m_bridge);
- return m_bridge->connect(url, protocol);
+ return m_bridge->connect(m_locationAtConnection->clone(), url, protocol);
}
void WorkerWebSocketChannel::send(const CString& message)
@@ -204,17 +203,12 @@ bool Peer::initialize(std::unique_ptr<SourceLocation> location, ExecutionContext
return true;
}
-void Peer::connect(const KURL& url, const String& protocol)
+bool Peer::connect(const KURL& url, const String& protocol)
{
ASSERT(isMainThread());
- ASSERT(m_syncHelper);
- if (!m_mainWebSocketChannel) {
- m_syncHelper->setConnectRequestResult(false);
- } else {
- bool connectRequestResult = m_mainWebSocketChannel->connect(url, protocol);
- m_syncHelper->setConnectRequestResult(connectRequestResult);
- }
- m_syncHelper->signalWorkerThread();
+ if (!m_mainWebSocketChannel)
+ return false;
+ return m_mainWebSocketChannel->connect(url, protocol);
}
void Peer::sendTextAsCharVector(std::unique_ptr<Vector<char>> data)
@@ -393,34 +387,24 @@ Bridge::~Bridge()
ASSERT(!m_peer);
}
-void Bridge::createPeerOnMainThread(std::unique_ptr<SourceLocation> location, WorkerThreadLifecycleContext* workerThreadLifecycleContext, ExecutionContext* context)
+void Bridge::connectOnMainThread(std::unique_ptr<SourceLocation> location, WorkerThreadLifecycleContext* workerThreadLifecycleContext, const KURL& url, const String& protocol, ExecutionContext* context)
{
DCHECK(isMainThread());
DCHECK(!m_peer);
Peer* peer = new Peer(this, m_loaderProxy, m_syncHelper, workerThreadLifecycleContext);
- if (peer->initialize(std::move(location), context))
+ if (peer->initialize(std::move(location), context)) {
m_peer = peer;
- m_syncHelper->signalWorkerThread();
-}
-
-void Bridge::initialize(std::unique_ptr<SourceLocation> location)
-{
- // Wait for completion of the task on the main thread because the connection
- // must synchronously be established (see Bridge::connect).
- if (!waitForMethodCompletion(BLINK_FROM_HERE, createCrossThreadTask(&Bridge::createPeerOnMainThread, wrapCrossThreadPersistent(this), passed(location->clone()), wrapCrossThreadPersistent(m_workerGlobalScope->thread()->getWorkerThreadLifecycleContext())))) {
- // The worker thread has been signalled to shutdown before method completion.
- disconnect();
+ bool result = m_peer->connect(url, protocol);
+ m_syncHelper->setConnectRequestResult(result);
}
+ m_syncHelper->signalWorkerThread();
}
-bool Bridge::connect(const KURL& url, const String& protocol)
+bool Bridge::connect(std::unique_ptr<SourceLocation> location, const KURL& url, const String& protocol)
{
- if (!m_peer)
- return false;
-
// Wait for completion of the task on the main thread because the mixed
// content check must synchronously be conducted.
- if (!waitForMethodCompletion(BLINK_FROM_HERE, createCrossThreadTask(&Peer::connect, wrapCrossThreadPersistent(m_peer.get()), url, protocol)))
+ if (!waitForMethodCompletion(BLINK_FROM_HERE, createCrossThreadTask(&Bridge::connectOnMainThread, wrapCrossThreadPersistent(this), passed(location->clone()), wrapCrossThreadPersistent(m_workerGlobalScope->thread()->getWorkerThreadLifecycleContext()), url, protocol)))
return false;
return m_syncHelper->connectRequestResult();
« no previous file with comments | « third_party/WebKit/Source/modules/websockets/WorkerWebSocketChannel.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698