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

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

Issue 2004243002: Migrate websockets from url+lineNumber to SourceLocation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@more-source-location-1
Patch Set: rebased Created 4 years, 7 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 12 matching lines...) Expand all
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
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 "bindings/core/v8/ScriptCallStack.h"
34 #include "core/dom/CrossThreadTask.h" 33 #include "core/dom/CrossThreadTask.h"
35 #include "core/dom/DOMArrayBuffer.h" 34 #include "core/dom/DOMArrayBuffer.h"
36 #include "core/dom/Document.h" 35 #include "core/dom/Document.h"
37 #include "core/dom/ExecutionContext.h" 36 #include "core/dom/ExecutionContext.h"
38 #include "core/dom/ExecutionContextTask.h" 37 #include "core/dom/ExecutionContextTask.h"
39 #include "core/fileapi/Blob.h" 38 #include "core/fileapi/Blob.h"
40 #include "core/workers/WorkerGlobalScope.h" 39 #include "core/workers/WorkerGlobalScope.h"
41 #include "core/workers/WorkerLoaderProxy.h" 40 #include "core/workers/WorkerLoaderProxy.h"
42 #include "core/workers/WorkerThread.h" 41 #include "core/workers/WorkerThread.h"
43 #include "modules/websockets/DocumentWebSocketChannel.h" 42 #include "modules/websockets/DocumentWebSocketChannel.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 explicit WebSocketChannelSyncHelper(PassOwnPtr<WaitableEvent> event) 96 explicit WebSocketChannelSyncHelper(PassOwnPtr<WaitableEvent> event)
98 : m_event(std::move(event)) 97 : m_event(std::move(event))
99 , m_connectRequestResult(false) 98 , m_connectRequestResult(false)
100 { 99 {
101 } 100 }
102 101
103 OwnPtr<WaitableEvent> m_event; 102 OwnPtr<WaitableEvent> m_event;
104 bool m_connectRequestResult; 103 bool m_connectRequestResult;
105 }; 104 };
106 105
107 WorkerWebSocketChannel::WorkerWebSocketChannel(WorkerGlobalScope& workerGlobalSc ope, WebSocketChannelClient* client, const String& sourceURL, unsigned lineNumbe r) 106 WorkerWebSocketChannel::WorkerWebSocketChannel(WorkerGlobalScope& workerGlobalSc ope, WebSocketChannelClient* client, PassOwnPtr<SourceLocation> location)
108 : m_bridge(new Bridge(client, workerGlobalScope)) 107 : m_bridge(new Bridge(client, workerGlobalScope))
109 , m_sourceURLAtConnection(sourceURL) 108 , m_locationAtConnection(std::move(location))
110 , m_lineNumberAtConnection(lineNumber)
111 { 109 {
112 m_bridge->initialize(sourceURL, lineNumber); 110 m_bridge->initialize(m_locationAtConnection->clone());
113 } 111 }
114 112
115 WorkerWebSocketChannel::~WorkerWebSocketChannel() 113 WorkerWebSocketChannel::~WorkerWebSocketChannel()
116 { 114 {
117 ASSERT(!m_bridge); 115 ASSERT(!m_bridge);
118 } 116 }
119 117
120 bool WorkerWebSocketChannel::connect(const KURL& url, const String& protocol) 118 bool WorkerWebSocketChannel::connect(const KURL& url, const String& protocol)
121 { 119 {
122 ASSERT(m_bridge); 120 ASSERT(m_bridge);
(...skipping 17 matching lines...) Expand all
140 ASSERT(m_bridge); 138 ASSERT(m_bridge);
141 m_bridge->send(blobData); 139 m_bridge->send(blobData);
142 } 140 }
143 141
144 void WorkerWebSocketChannel::close(int code, const String& reason) 142 void WorkerWebSocketChannel::close(int code, const String& reason)
145 { 143 {
146 ASSERT(m_bridge); 144 ASSERT(m_bridge);
147 m_bridge->close(code, reason); 145 m_bridge->close(code, reason);
148 } 146 }
149 147
150 void WorkerWebSocketChannel::fail(const String& reason, MessageLevel level, cons t String& sourceURL, unsigned lineNumber) 148 void WorkerWebSocketChannel::fail(const String& reason, MessageLevel level, Pass OwnPtr<SourceLocation> location)
151 { 149 {
152 if (!m_bridge) 150 if (!m_bridge)
153 return; 151 return;
154 152
155 RefPtr<ScriptCallStack> callStack = ScriptCallStack::capture(1); 153 OwnPtr<SourceLocation> capturedLocation = SourceLocation::capture();
156 if (callStack && !callStack->isEmpty()) { 154 if (!capturedLocation->isEmpty()) {
157 // In order to emulate the ConsoleMessage behavior, 155 // If we are in JavaScript context, use the current location instead
158 // we should ignore the specified url and line number if 156 // of passed one - it's more precise.
159 // we can get the JavaScript context. 157 m_bridge->fail(reason, level, std::move(capturedLocation));
160 m_bridge->fail(reason, level, callStack->topSourceURL(), callStack->topL ineNumber()); 158 } else if (!location || location->isEmpty()) {
161 } else if (sourceURL.isEmpty() && !lineNumber) {
162 // No information is specified by the caller - use the url 159 // No information is specified by the caller - use the url
163 // and the line number at the connection. 160 // and the line number at the connection.
164 m_bridge->fail(reason, level, m_sourceURLAtConnection, m_lineNumberAtCon nection); 161 m_bridge->fail(reason, level, m_locationAtConnection->clone());
165 } else { 162 } else {
166 // Use the specified information. 163 // Use the specified information.
167 m_bridge->fail(reason, level, sourceURL, lineNumber); 164 m_bridge->fail(reason, level, std::move(location));
168 } 165 }
169 } 166 }
170 167
171 void WorkerWebSocketChannel::disconnect() 168 void WorkerWebSocketChannel::disconnect()
172 { 169 {
173 m_bridge->disconnect(); 170 m_bridge->disconnect();
174 m_bridge.clear(); 171 m_bridge.clear();
175 } 172 }
176 173
177 DEFINE_TRACE(WorkerWebSocketChannel) 174 DEFINE_TRACE(WorkerWebSocketChannel)
178 { 175 {
179 visitor->trace(m_bridge); 176 visitor->trace(m_bridge);
180 WebSocketChannel::trace(visitor); 177 WebSocketChannel::trace(visitor);
181 } 178 }
182 179
183 Peer::Peer(Bridge* bridge, PassRefPtr<WorkerLoaderProxy> loaderProxy, WebSocketC hannelSyncHelper* syncHelper) 180 Peer::Peer(Bridge* bridge, PassRefPtr<WorkerLoaderProxy> loaderProxy, WebSocketC hannelSyncHelper* syncHelper)
184 : m_bridge(bridge) 181 : m_bridge(bridge)
185 , m_loaderProxy(loaderProxy) 182 , m_loaderProxy(loaderProxy)
186 , m_mainWebSocketChannel(nullptr) 183 , m_mainWebSocketChannel(nullptr)
187 , m_syncHelper(syncHelper) 184 , m_syncHelper(syncHelper)
188 { 185 {
189 ASSERT(!isMainThread()); 186 ASSERT(!isMainThread());
190 } 187 }
191 188
192 Peer::~Peer() 189 Peer::~Peer()
193 { 190 {
194 ASSERT(!isMainThread()); 191 ASSERT(!isMainThread());
195 } 192 }
196 193
197 void Peer::initialize(const String& sourceURL, unsigned lineNumber, ExecutionCon text* context) 194 void Peer::initialize(PassOwnPtr<SourceLocation> location, ExecutionContext* con text)
198 { 195 {
199 ASSERT(isMainThread()); 196 ASSERT(isMainThread());
200 Document* document = toDocument(context); 197 Document* document = toDocument(context);
201 m_mainWebSocketChannel = DocumentWebSocketChannel::create(document, this, so urceURL, lineNumber); 198 m_mainWebSocketChannel = DocumentWebSocketChannel::create(document, this, st d::move(location));
202 m_syncHelper->signalWorkerThread(); 199 m_syncHelper->signalWorkerThread();
203 } 200 }
204 201
205 void Peer::connect(const KURL& url, const String& protocol) 202 void Peer::connect(const KURL& url, const String& protocol)
206 { 203 {
207 ASSERT(isMainThread()); 204 ASSERT(isMainThread());
208 ASSERT(m_syncHelper); 205 ASSERT(m_syncHelper);
209 if (!m_mainWebSocketChannel) { 206 if (!m_mainWebSocketChannel) {
210 m_syncHelper->setConnectRequestResult(false); 207 m_syncHelper->setConnectRequestResult(false);
211 } else { 208 } else {
(...skipping 26 matching lines...) Expand all
238 235
239 void Peer::close(int code, const String& reason) 236 void Peer::close(int code, const String& reason)
240 { 237 {
241 ASSERT(isMainThread()); 238 ASSERT(isMainThread());
242 ASSERT(m_syncHelper); 239 ASSERT(m_syncHelper);
243 if (!m_mainWebSocketChannel) 240 if (!m_mainWebSocketChannel)
244 return; 241 return;
245 m_mainWebSocketChannel->close(code, reason); 242 m_mainWebSocketChannel->close(code, reason);
246 } 243 }
247 244
248 void Peer::fail(const String& reason, MessageLevel level, const String& sourceUR L, unsigned lineNumber) 245 void Peer::fail(const String& reason, MessageLevel level, PassOwnPtr<SourceLocat ion> location)
249 { 246 {
250 ASSERT(isMainThread()); 247 ASSERT(isMainThread());
251 ASSERT(m_syncHelper); 248 ASSERT(m_syncHelper);
252 if (!m_mainWebSocketChannel) 249 if (!m_mainWebSocketChannel)
253 return; 250 return;
254 m_mainWebSocketChannel->fail(reason, level, sourceURL, lineNumber); 251 m_mainWebSocketChannel->fail(reason, level, std::move(location));
255 } 252 }
256 253
257 void Peer::disconnect() 254 void Peer::disconnect()
258 { 255 {
259 ASSERT(isMainThread()); 256 ASSERT(isMainThread());
260 ASSERT(m_syncHelper); 257 ASSERT(m_syncHelper);
261 if (m_mainWebSocketChannel) { 258 if (m_mainWebSocketChannel) {
262 m_mainWebSocketChannel->disconnect(); 259 m_mainWebSocketChannel->disconnect();
263 m_mainWebSocketChannel = nullptr; 260 m_mainWebSocketChannel = nullptr;
264 } 261 }
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 , m_syncHelper(WebSocketChannelSyncHelper::create(adoptPtr(new WaitableEvent ()))) 372 , m_syncHelper(WebSocketChannelSyncHelper::create(adoptPtr(new WaitableEvent ())))
376 , m_peer(new Peer(this, m_loaderProxy, m_syncHelper)) 373 , m_peer(new Peer(this, m_loaderProxy, m_syncHelper))
377 { 374 {
378 } 375 }
379 376
380 Bridge::~Bridge() 377 Bridge::~Bridge()
381 { 378 {
382 ASSERT(!m_peer); 379 ASSERT(!m_peer);
383 } 380 }
384 381
385 void Bridge::initialize(const String& sourceURL, unsigned lineNumber) 382 void Bridge::initialize(PassOwnPtr<SourceLocation> location)
386 { 383 {
387 if (!waitForMethodCompletion(createCrossThreadTask(&Peer::initialize, wrapCr ossThreadPersistent(m_peer.get()), sourceURL, lineNumber))) { 384 if (!waitForMethodCompletion(createCrossThreadTask(&Peer::initialize, wrapCr ossThreadPersistent(m_peer.get()), passed(std::move(location))))) {
388 // The worker thread has been signalled to shutdown before method comple tion. 385 // The worker thread has been signalled to shutdown before method comple tion.
389 disconnect(); 386 disconnect();
390 } 387 }
391 } 388 }
392 389
393 bool Bridge::connect(const KURL& url, const String& protocol) 390 bool Bridge::connect(const KURL& url, const String& protocol)
394 { 391 {
395 if (!m_peer) 392 if (!m_peer)
396 return false; 393 return false;
397 394
(...skipping 29 matching lines...) Expand all
427 ASSERT(m_peer); 424 ASSERT(m_peer);
428 m_loaderProxy->postTaskToLoader(createCrossThreadTask(&Peer::sendBlob, wrapC rossThreadPersistent(m_peer.get()), data)); 425 m_loaderProxy->postTaskToLoader(createCrossThreadTask(&Peer::sendBlob, wrapC rossThreadPersistent(m_peer.get()), data));
429 } 426 }
430 427
431 void Bridge::close(int code, const String& reason) 428 void Bridge::close(int code, const String& reason)
432 { 429 {
433 ASSERT(m_peer); 430 ASSERT(m_peer);
434 m_loaderProxy->postTaskToLoader(createCrossThreadTask(&Peer::close, wrapCros sThreadPersistent(m_peer.get()), code, reason)); 431 m_loaderProxy->postTaskToLoader(createCrossThreadTask(&Peer::close, wrapCros sThreadPersistent(m_peer.get()), code, reason));
435 } 432 }
436 433
437 void Bridge::fail(const String& reason, MessageLevel level, const String& source URL, unsigned lineNumber) 434 void Bridge::fail(const String& reason, MessageLevel level, PassOwnPtr<SourceLoc ation> location)
438 { 435 {
439 ASSERT(m_peer); 436 ASSERT(m_peer);
440 m_loaderProxy->postTaskToLoader(createCrossThreadTask(&Peer::fail, wrapCross ThreadPersistent(m_peer.get()), reason, level, sourceURL, lineNumber)); 437 m_loaderProxy->postTaskToLoader(createCrossThreadTask(&Peer::fail, wrapCross ThreadPersistent(m_peer.get()), reason, level, passed(std::move(location))));
441 } 438 }
442 439
443 void Bridge::disconnect() 440 void Bridge::disconnect()
444 { 441 {
445 if (!m_peer) 442 if (!m_peer)
446 return; 443 return;
447 444
448 waitForMethodCompletion(createCrossThreadTask(&Peer::disconnect, wrapCrossTh readPersistent(m_peer.get()))); 445 waitForMethodCompletion(createCrossThreadTask(&Peer::disconnect, wrapCrossTh readPersistent(m_peer.get())));
449 // Here |m_peer| is detached from the main thread and we can delete it. 446 // Here |m_peer| is detached from the main thread and we can delete it.
450 447
(...skipping 23 matching lines...) Expand all
474 471
475 DEFINE_TRACE(Bridge) 472 DEFINE_TRACE(Bridge)
476 { 473 {
477 visitor->trace(m_client); 474 visitor->trace(m_client);
478 visitor->trace(m_workerGlobalScope); 475 visitor->trace(m_workerGlobalScope);
479 visitor->trace(m_syncHelper); 476 visitor->trace(m_syncHelper);
480 visitor->trace(m_peer); 477 visitor->trace(m_peer);
481 } 478 }
482 479
483 } // namespace blink 480 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698