OLD | NEW |
---|---|
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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
102 } | 102 } |
103 | 103 |
104 std::unique_ptr<WaitableEvent> m_event; | 104 std::unique_ptr<WaitableEvent> m_event; |
105 bool m_connectRequestResult; | 105 bool m_connectRequestResult; |
106 }; | 106 }; |
107 | 107 |
108 WorkerWebSocketChannel::WorkerWebSocketChannel(WorkerGlobalScope& workerGlobalSc ope, WebSocketChannelClient* client, std::unique_ptr<SourceLocation> location) | 108 WorkerWebSocketChannel::WorkerWebSocketChannel(WorkerGlobalScope& workerGlobalSc ope, WebSocketChannelClient* client, std::unique_ptr<SourceLocation> location) |
109 : m_bridge(new Bridge(client, workerGlobalScope)) | 109 : m_bridge(new Bridge(client, workerGlobalScope)) |
110 , m_locationAtConnection(std::move(location)) | 110 , m_locationAtConnection(std::move(location)) |
111 { | 111 { |
112 m_bridge->initialize(m_locationAtConnection->clone()); | |
113 } | 112 } |
114 | 113 |
115 WorkerWebSocketChannel::~WorkerWebSocketChannel() | 114 WorkerWebSocketChannel::~WorkerWebSocketChannel() |
116 { | 115 { |
117 ASSERT(!m_bridge); | 116 ASSERT(!m_bridge); |
118 } | 117 } |
119 | 118 |
120 bool WorkerWebSocketChannel::connect(const KURL& url, const String& protocol) | 119 bool WorkerWebSocketChannel::connect(const KURL& url, const String& protocol) |
121 { | 120 { |
122 ASSERT(m_bridge); | 121 ASSERT(m_bridge); |
123 return m_bridge->connect(url, protocol); | 122 return m_bridge->connect(m_locationAtConnection->clone(), url, protocol); |
124 } | 123 } |
125 | 124 |
126 void WorkerWebSocketChannel::send(const CString& message) | 125 void WorkerWebSocketChannel::send(const CString& message) |
127 { | 126 { |
128 ASSERT(m_bridge); | 127 ASSERT(m_bridge); |
129 m_bridge->send(message); | 128 m_bridge->send(message); |
130 } | 129 } |
131 | 130 |
132 void WorkerWebSocketChannel::send(const DOMArrayBuffer& binaryData, unsigned byt eOffset, unsigned byteLength) | 131 void WorkerWebSocketChannel::send(const DOMArrayBuffer& binaryData, unsigned byt eOffset, unsigned byteLength) |
133 { | 132 { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 bool Peer::initialize(std::unique_ptr<SourceLocation> location, ExecutionContext * context) | 196 bool Peer::initialize(std::unique_ptr<SourceLocation> location, ExecutionContext * context) |
198 { | 197 { |
199 ASSERT(isMainThread()); | 198 ASSERT(isMainThread()); |
200 if (wasContextDestroyedBeforeObserverCreation()) | 199 if (wasContextDestroyedBeforeObserverCreation()) |
201 return false; | 200 return false; |
202 Document* document = toDocument(context); | 201 Document* document = toDocument(context); |
203 m_mainWebSocketChannel = DocumentWebSocketChannel::create(document, this, st d::move(location)); | 202 m_mainWebSocketChannel = DocumentWebSocketChannel::create(document, this, st d::move(location)); |
204 return true; | 203 return true; |
205 } | 204 } |
206 | 205 |
207 void Peer::connect(const KURL& url, const String& protocol) | 206 void Peer::connect(const KURL& url, const String& protocol) |
yhirano
2016/08/24 04:46:32
How about making this function return a boolean in
nhiroki
2016/08/24 04:58:03
Done.
| |
208 { | 207 { |
209 ASSERT(isMainThread()); | 208 ASSERT(isMainThread()); |
210 ASSERT(m_syncHelper); | 209 ASSERT(m_syncHelper); |
211 if (!m_mainWebSocketChannel) { | 210 if (!m_mainWebSocketChannel) { |
212 m_syncHelper->setConnectRequestResult(false); | 211 m_syncHelper->setConnectRequestResult(false); |
213 } else { | 212 } else { |
214 bool connectRequestResult = m_mainWebSocketChannel->connect(url, protoco l); | 213 bool connectRequestResult = m_mainWebSocketChannel->connect(url, protoco l); |
215 m_syncHelper->setConnectRequestResult(connectRequestResult); | 214 m_syncHelper->setConnectRequestResult(connectRequestResult); |
216 } | 215 } |
217 m_syncHelper->signalWorkerThread(); | |
218 } | 216 } |
219 | 217 |
220 void Peer::sendTextAsCharVector(std::unique_ptr<Vector<char>> data) | 218 void Peer::sendTextAsCharVector(std::unique_ptr<Vector<char>> data) |
221 { | 219 { |
222 ASSERT(isMainThread()); | 220 ASSERT(isMainThread()); |
223 if (m_mainWebSocketChannel) | 221 if (m_mainWebSocketChannel) |
224 m_mainWebSocketChannel->sendTextAsCharVector(std::move(data)); | 222 m_mainWebSocketChannel->sendTextAsCharVector(std::move(data)); |
225 } | 223 } |
226 | 224 |
227 void Peer::sendBinaryAsCharVector(std::unique_ptr<Vector<char>> data) | 225 void Peer::sendBinaryAsCharVector(std::unique_ptr<Vector<char>> data) |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
386 , m_loaderProxy(m_workerGlobalScope->thread()->workerLoaderProxy()) | 384 , m_loaderProxy(m_workerGlobalScope->thread()->workerLoaderProxy()) |
387 , m_syncHelper(WebSocketChannelSyncHelper::create(wrapUnique(new WaitableEve nt()))) | 385 , m_syncHelper(WebSocketChannelSyncHelper::create(wrapUnique(new WaitableEve nt()))) |
388 { | 386 { |
389 } | 387 } |
390 | 388 |
391 Bridge::~Bridge() | 389 Bridge::~Bridge() |
392 { | 390 { |
393 ASSERT(!m_peer); | 391 ASSERT(!m_peer); |
394 } | 392 } |
395 | 393 |
396 void Bridge::createPeerOnMainThread(std::unique_ptr<SourceLocation> location, Wo rkerThreadLifecycleContext* workerThreadLifecycleContext, ExecutionContext* cont ext) | 394 void Bridge::connectOnMainThread(std::unique_ptr<SourceLocation> location, Worke rThreadLifecycleContext* workerThreadLifecycleContext, const KURL& url, const St ring& protocol, ExecutionContext* context) |
397 { | 395 { |
398 DCHECK(isMainThread()); | 396 DCHECK(isMainThread()); |
399 DCHECK(!m_peer); | 397 DCHECK(!m_peer); |
400 Peer* peer = new Peer(this, m_loaderProxy, m_syncHelper, workerThreadLifecyc leContext); | 398 Peer* peer = new Peer(this, m_loaderProxy, m_syncHelper, workerThreadLifecyc leContext); |
401 if (peer->initialize(std::move(location), context)) | 399 if (peer->initialize(std::move(location), context)) { |
402 m_peer = peer; | 400 m_peer = peer; |
401 m_peer->connect(url, protocol); | |
402 } | |
403 m_syncHelper->signalWorkerThread(); | 403 m_syncHelper->signalWorkerThread(); |
404 } | 404 } |
405 | 405 |
406 void Bridge::initialize(std::unique_ptr<SourceLocation> location) | 406 bool Bridge::connect(std::unique_ptr<SourceLocation> location, const KURL& url, const String& protocol) |
407 { | 407 { |
408 // Wait for completion of the task on the main thread because the connection | |
409 // must synchronously be established (see Bridge::connect). | |
410 if (!waitForMethodCompletion(BLINK_FROM_HERE, createCrossThreadTask(&Bridge: :createPeerOnMainThread, wrapCrossThreadPersistent(this), passed(location->clone ()), wrapCrossThreadPersistent(m_workerGlobalScope->thread()->getWorkerThreadLif ecycleContext())))) { | |
411 // The worker thread has been signalled to shutdown before method comple tion. | |
412 disconnect(); | |
413 } | |
414 } | |
415 | |
416 bool Bridge::connect(const KURL& url, const String& protocol) | |
417 { | |
418 if (!m_peer) | |
419 return false; | |
420 | |
421 // Wait for completion of the task on the main thread because the mixed | 408 // Wait for completion of the task on the main thread because the mixed |
422 // content check must synchronously be conducted. | 409 // content check must synchronously be conducted. |
423 if (!waitForMethodCompletion(BLINK_FROM_HERE, createCrossThreadTask(&Peer::c onnect, wrapCrossThreadPersistent(m_peer.get()), url, protocol))) | 410 if (!waitForMethodCompletion(BLINK_FROM_HERE, createCrossThreadTask(&Bridge: :connectOnMainThread, wrapCrossThreadPersistent(this), passed(location->clone()) , wrapCrossThreadPersistent(m_workerGlobalScope->thread()->getWorkerThreadLifecy cleContext()), url, protocol))) |
424 return false; | 411 return false; |
425 | 412 |
426 return m_syncHelper->connectRequestResult(); | 413 return m_syncHelper->connectRequestResult(); |
427 } | 414 } |
428 | 415 |
429 void Bridge::send(const CString& message) | 416 void Bridge::send(const CString& message) |
430 { | 417 { |
431 ASSERT(m_peer); | 418 ASSERT(m_peer); |
432 std::unique_ptr<Vector<char>> data = wrapUnique(new Vector<char>(message.len gth())); | 419 std::unique_ptr<Vector<char>> data = wrapUnique(new Vector<char>(message.len gth())); |
433 if (message.length()) | 420 if (message.length()) |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
499 } | 486 } |
500 | 487 |
501 DEFINE_TRACE(Bridge) | 488 DEFINE_TRACE(Bridge) |
502 { | 489 { |
503 visitor->trace(m_client); | 490 visitor->trace(m_client); |
504 visitor->trace(m_workerGlobalScope); | 491 visitor->trace(m_workerGlobalScope); |
505 visitor->trace(m_syncHelper); | 492 visitor->trace(m_syncHelper); |
506 } | 493 } |
507 | 494 |
508 } // namespace blink | 495 } // namespace blink |
OLD | NEW |