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

Side by Side Diff: third_party/WebKit/Source/modules/websockets/WorkerWebSocketChannel.cpp

Issue 2715803004: Introduce ThreadableLoadingContext: make threaded loading code one step away from Document (Closed)
Patch Set: . Created 3 years, 9 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 14 matching lines...) Expand all
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "modules/websockets/WorkerWebSocketChannel.h" 31 #include "modules/websockets/WorkerWebSocketChannel.h"
32 32
33 #include <memory> 33 #include <memory>
34 #include "core/dom/DOMArrayBuffer.h" 34 #include "core/dom/DOMArrayBuffer.h"
35 #include "core/dom/Document.h"
36 #include "core/dom/ExecutionContext.h" 35 #include "core/dom/ExecutionContext.h"
37 #include "core/fileapi/Blob.h" 36 #include "core/fileapi/Blob.h"
37 #include "core/loader/ThreadableLoadingContext.h"
38 #include "core/workers/WorkerGlobalScope.h" 38 #include "core/workers/WorkerGlobalScope.h"
39 #include "core/workers/WorkerLoaderProxy.h" 39 #include "core/workers/WorkerLoaderProxy.h"
40 #include "core/workers/WorkerThread.h" 40 #include "core/workers/WorkerThread.h"
41 #include "modules/websockets/DocumentWebSocketChannel.h" 41 #include "modules/websockets/DocumentWebSocketChannel.h"
42 #include "platform/CrossThreadFunctional.h" 42 #include "platform/CrossThreadFunctional.h"
43 #include "platform/WaitableEvent.h" 43 #include "platform/WaitableEvent.h"
44 #include "platform/heap/SafePoint.h" 44 #include "platform/heap/SafePoint.h"
45 #include "public/platform/Platform.h" 45 #include "public/platform/Platform.h"
46 #include "wtf/Assertions.h" 46 #include "wtf/Assertions.h"
47 #include "wtf/Functional.h" 47 #include "wtf/Functional.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 m_loaderProxy(loaderProxy), 168 m_loaderProxy(loaderProxy),
169 m_mainWebSocketChannel(nullptr) { 169 m_mainWebSocketChannel(nullptr) {
170 DCHECK(isMainThread()); 170 DCHECK(isMainThread());
171 } 171 }
172 172
173 Peer::~Peer() { 173 Peer::~Peer() {
174 DCHECK(isMainThread()); 174 DCHECK(isMainThread());
175 } 175 }
176 176
177 bool Peer::initialize(std::unique_ptr<SourceLocation> location, 177 bool Peer::initialize(std::unique_ptr<SourceLocation> location,
178 ExecutionContext* context) { 178 ThreadableLoadingContext* loadingContext) {
179 DCHECK(isMainThread()); 179 DCHECK(isMainThread());
180 if (wasContextDestroyedBeforeObserverCreation()) 180 if (wasContextDestroyedBeforeObserverCreation())
181 return false; 181 return false;
182 Document* document = toDocument(context); 182 m_mainWebSocketChannel = DocumentWebSocketChannel::create(
183 m_mainWebSocketChannel = 183 loadingContext, this, std::move(location));
184 DocumentWebSocketChannel::create(document, this, std::move(location));
185 return true; 184 return true;
186 } 185 }
187 186
188 bool Peer::connect(const KURL& url, const String& protocol) { 187 bool Peer::connect(const KURL& url, const String& protocol) {
189 DCHECK(isMainThread()); 188 DCHECK(isMainThread());
190 if (!m_mainWebSocketChannel) 189 if (!m_mainWebSocketChannel)
191 return false; 190 return false;
192 return m_mainWebSocketChannel->connect(url, protocol); 191 return m_mainWebSocketChannel->connect(url, protocol);
193 } 192 }
194 193
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 363
365 void Bridge::connectOnMainThread( 364 void Bridge::connectOnMainThread(
366 std::unique_ptr<SourceLocation> location, 365 std::unique_ptr<SourceLocation> location,
367 RefPtr<WorkerLoaderProxy> loaderProxy, 366 RefPtr<WorkerLoaderProxy> loaderProxy,
368 WorkerThreadLifecycleContext* workerThreadLifecycleContext, 367 WorkerThreadLifecycleContext* workerThreadLifecycleContext,
369 const KURL& url, 368 const KURL& url,
370 const String& protocol, 369 const String& protocol,
371 WebSocketChannelSyncHelper* syncHelper) { 370 WebSocketChannelSyncHelper* syncHelper) {
372 DCHECK(isMainThread()); 371 DCHECK(isMainThread());
373 DCHECK(!m_peer); 372 DCHECK(!m_peer);
374 ExecutionContext* loaderContext = loaderProxy->getLoaderExecutionContext(); 373 ThreadableLoadingContext* loadingContext =
375 if (!loaderContext) 374 loaderProxy->getThreadableLoadingContext();
375 if (!loadingContext)
376 return; 376 return;
377 Peer* peer = new Peer(this, m_loaderProxy, workerThreadLifecycleContext); 377 Peer* peer = new Peer(this, m_loaderProxy, workerThreadLifecycleContext);
378 if (peer->initialize(std::move(location), loaderContext)) { 378 if (peer->initialize(std::move(location), loadingContext)) {
379 m_peer = peer; 379 m_peer = peer;
380 syncHelper->setConnectRequestResult(m_peer->connect(url, protocol)); 380 syncHelper->setConnectRequestResult(m_peer->connect(url, protocol));
381 } 381 }
382 syncHelper->signalWorkerThread(); 382 syncHelper->signalWorkerThread();
383 } 383 }
384 384
385 bool Bridge::connect(std::unique_ptr<SourceLocation> location, 385 bool Bridge::connect(std::unique_ptr<SourceLocation> location,
386 const KURL& url, 386 const KURL& url,
387 const String& protocol) { 387 const String& protocol) {
388 // Wait for completion of the task on the main thread because the mixed 388 // Wait for completion of the task on the main thread because the mixed
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 m_peer = nullptr; 467 m_peer = nullptr;
468 m_workerGlobalScope.clear(); 468 m_workerGlobalScope.clear();
469 } 469 }
470 470
471 DEFINE_TRACE(Bridge) { 471 DEFINE_TRACE(Bridge) {
472 visitor->trace(m_client); 472 visitor->trace(m_client);
473 visitor->trace(m_workerGlobalScope); 473 visitor->trace(m_workerGlobalScope);
474 } 474 }
475 475
476 } // namespace blink 476 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698