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

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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 explicit WebSocketChannelSyncHelper(PassOwnPtr<WaitableEvent> event) 97 explicit WebSocketChannelSyncHelper(PassOwnPtr<WaitableEvent> event)
98 : m_event(std::move(event)) 98 : m_event(std::move(event))
99 , m_connectRequestResult(false) 99 , m_connectRequestResult(false)
100 { 100 {
101 } 101 }
102 102
103 OwnPtr<WaitableEvent> m_event; 103 OwnPtr<WaitableEvent> m_event;
104 bool m_connectRequestResult; 104 bool m_connectRequestResult;
105 }; 105 };
106 106
107 WorkerWebSocketChannel::WorkerWebSocketChannel(WorkerGlobalScope& workerGlobalSc ope, WebSocketChannelClient* client, const String& sourceURL, unsigned lineNumbe r) 107 WorkerWebSocketChannel::WorkerWebSocketChannel(WorkerGlobalScope& workerGlobalSc ope, WebSocketChannelClient* client, PassOwnPtr<SourceLocation> location)
108 : m_bridge(new Bridge(client, workerGlobalScope)) 108 : m_bridge(new Bridge(client, workerGlobalScope))
109 , m_sourceURLAtConnection(sourceURL) 109 , m_locationAtConnection(std::move(location))
110 , m_lineNumberAtConnection(lineNumber)
111 { 110 {
112 m_bridge->initialize(sourceURL, lineNumber); 111 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);
(...skipping 17 matching lines...) Expand all
140 ASSERT(m_bridge); 139 ASSERT(m_bridge);
141 m_bridge->send(blobData); 140 m_bridge->send(blobData);
142 } 141 }
143 142
144 void WorkerWebSocketChannel::close(int code, const String& reason) 143 void WorkerWebSocketChannel::close(int code, const String& reason)
145 { 144 {
146 ASSERT(m_bridge); 145 ASSERT(m_bridge);
147 m_bridge->close(code, reason); 146 m_bridge->close(code, reason);
148 } 147 }
149 148
150 void WorkerWebSocketChannel::fail(const String& reason, MessageLevel level, cons t String& sourceURL, unsigned lineNumber) 149 void WorkerWebSocketChannel::fail(const String& reason, MessageLevel level, Pass OwnPtr<SourceLocation> location)
151 { 150 {
152 if (!m_bridge) 151 if (!m_bridge)
153 return; 152 return;
154 153
155 RefPtr<ScriptCallStack> callStack = ScriptCallStack::capture(1); 154 OwnPtr<SourceLocation> capturedLocation = SourceLocation::capture();
156 if (callStack && !callStack->isEmpty()) { 155 if (!capturedLocation->isEmpty()) {
yhirano 2016/05/24 11:30:18 Can you leave some comments saying we ignore the p
dgozman 2016/05/24 22:12:50 Done.
157 // In order to emulate the ConsoleMessage behavior, 156 m_bridge->fail(reason, level, std::move(capturedLocation));
158 // we should ignore the specified url and line number if 157 } else if (!location || location->isEmpty()) {
159 // we can get the JavaScript context.
160 m_bridge->fail(reason, level, callStack->topSourceURL(), callStack->topL ineNumber());
161 } else if (sourceURL.isEmpty() && !lineNumber) {
162 // No information is specified by the caller - use the url 158 // No information is specified by the caller - use the url
163 // and the line number at the connection. 159 // and the line number at the connection.
164 m_bridge->fail(reason, level, m_sourceURLAtConnection, m_lineNumberAtCon nection); 160 m_bridge->fail(reason, level, m_locationAtConnection->clone());
165 } else { 161 } else {
166 // Use the specified information. 162 // Use the specified information.
167 m_bridge->fail(reason, level, sourceURL, lineNumber); 163 m_bridge->fail(reason, level, std::move(location));
168 } 164 }
169 } 165 }
170 166
171 void WorkerWebSocketChannel::disconnect() 167 void WorkerWebSocketChannel::disconnect()
172 { 168 {
173 m_bridge->disconnect(); 169 m_bridge->disconnect();
174 m_bridge.clear(); 170 m_bridge.clear();
175 } 171 }
176 172
177 DEFINE_TRACE(WorkerWebSocketChannel) 173 DEFINE_TRACE(WorkerWebSocketChannel)
178 { 174 {
179 visitor->trace(m_bridge); 175 visitor->trace(m_bridge);
180 WebSocketChannel::trace(visitor); 176 WebSocketChannel::trace(visitor);
181 } 177 }
182 178
183 Peer::Peer(Bridge* bridge, PassRefPtr<WorkerLoaderProxy> loaderProxy, WebSocketC hannelSyncHelper* syncHelper) 179 Peer::Peer(Bridge* bridge, PassRefPtr<WorkerLoaderProxy> loaderProxy, WebSocketC hannelSyncHelper* syncHelper)
184 : m_bridge(bridge) 180 : m_bridge(bridge)
185 , m_loaderProxy(loaderProxy) 181 , m_loaderProxy(loaderProxy)
186 , m_mainWebSocketChannel(nullptr) 182 , m_mainWebSocketChannel(nullptr)
187 , m_syncHelper(syncHelper) 183 , m_syncHelper(syncHelper)
188 { 184 {
189 ASSERT(!isMainThread()); 185 ASSERT(!isMainThread());
190 } 186 }
191 187
192 Peer::~Peer() 188 Peer::~Peer()
193 { 189 {
194 ASSERT(!isMainThread()); 190 ASSERT(!isMainThread());
195 } 191 }
196 192
197 void Peer::initialize(const String& sourceURL, unsigned lineNumber, ExecutionCon text* context) 193 void Peer::initialize(PassOwnPtr<SourceLocation> location, ExecutionContext* con text)
198 { 194 {
199 ASSERT(isMainThread()); 195 ASSERT(isMainThread());
200 Document* document = toDocument(context); 196 Document* document = toDocument(context);
201 m_mainWebSocketChannel = DocumentWebSocketChannel::create(document, this, so urceURL, lineNumber); 197 m_mainWebSocketChannel = DocumentWebSocketChannel::create(document, this, st d::move(location));
202 m_syncHelper->signalWorkerThread(); 198 m_syncHelper->signalWorkerThread();
203 } 199 }
204 200
205 void Peer::connect(const KURL& url, const String& protocol) 201 void Peer::connect(const KURL& url, const String& protocol)
206 { 202 {
207 ASSERT(isMainThread()); 203 ASSERT(isMainThread());
208 ASSERT(m_syncHelper); 204 ASSERT(m_syncHelper);
209 if (!m_mainWebSocketChannel) { 205 if (!m_mainWebSocketChannel) {
210 m_syncHelper->setConnectRequestResult(false); 206 m_syncHelper->setConnectRequestResult(false);
211 } else { 207 } else {
(...skipping 26 matching lines...) Expand all
238 234
239 void Peer::close(int code, const String& reason) 235 void Peer::close(int code, const String& reason)
240 { 236 {
241 ASSERT(isMainThread()); 237 ASSERT(isMainThread());
242 ASSERT(m_syncHelper); 238 ASSERT(m_syncHelper);
243 if (!m_mainWebSocketChannel) 239 if (!m_mainWebSocketChannel)
244 return; 240 return;
245 m_mainWebSocketChannel->close(code, reason); 241 m_mainWebSocketChannel->close(code, reason);
246 } 242 }
247 243
248 void Peer::fail(const String& reason, MessageLevel level, const String& sourceUR L, unsigned lineNumber) 244 void Peer::fail(const String& reason, MessageLevel level, PassOwnPtr<SourceLocat ion> location)
249 { 245 {
250 ASSERT(isMainThread()); 246 ASSERT(isMainThread());
251 ASSERT(m_syncHelper); 247 ASSERT(m_syncHelper);
252 if (!m_mainWebSocketChannel) 248 if (!m_mainWebSocketChannel)
253 return; 249 return;
254 m_mainWebSocketChannel->fail(reason, level, sourceURL, lineNumber); 250 m_mainWebSocketChannel->fail(reason, level, std::move(location));
255 } 251 }
256 252
257 void Peer::disconnect() 253 void Peer::disconnect()
258 { 254 {
259 ASSERT(isMainThread()); 255 ASSERT(isMainThread());
260 ASSERT(m_syncHelper); 256 ASSERT(m_syncHelper);
261 if (m_mainWebSocketChannel) { 257 if (m_mainWebSocketChannel) {
262 m_mainWebSocketChannel->disconnect(); 258 m_mainWebSocketChannel->disconnect();
263 m_mainWebSocketChannel = nullptr; 259 m_mainWebSocketChannel = nullptr;
264 } 260 }
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 , m_syncHelper(WebSocketChannelSyncHelper::create(adoptPtr(new WaitableEvent ()))) 371 , m_syncHelper(WebSocketChannelSyncHelper::create(adoptPtr(new WaitableEvent ())))
376 , m_peer(new Peer(this, m_loaderProxy, m_syncHelper)) 372 , m_peer(new Peer(this, m_loaderProxy, m_syncHelper))
377 { 373 {
378 } 374 }
379 375
380 Bridge::~Bridge() 376 Bridge::~Bridge()
381 { 377 {
382 ASSERT(!m_peer); 378 ASSERT(!m_peer);
383 } 379 }
384 380
385 void Bridge::initialize(const String& sourceURL, unsigned lineNumber) 381 void Bridge::initialize(PassOwnPtr<SourceLocation> location)
386 { 382 {
387 if (!waitForMethodCompletion(createCrossThreadTask(&Peer::initialize, wrapCr ossThreadPersistent(m_peer.get()), sourceURL, lineNumber))) { 383 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. 384 // The worker thread has been signalled to shutdown before method comple tion.
389 disconnect(); 385 disconnect();
390 } 386 }
391 } 387 }
392 388
393 bool Bridge::connect(const KURL& url, const String& protocol) 389 bool Bridge::connect(const KURL& url, const String& protocol)
394 { 390 {
395 if (!m_peer) 391 if (!m_peer)
396 return false; 392 return false;
397 393
(...skipping 29 matching lines...) Expand all
427 ASSERT(m_peer); 423 ASSERT(m_peer);
428 m_loaderProxy->postTaskToLoader(createCrossThreadTask(&Peer::sendBlob, wrapC rossThreadPersistent(m_peer.get()), data)); 424 m_loaderProxy->postTaskToLoader(createCrossThreadTask(&Peer::sendBlob, wrapC rossThreadPersistent(m_peer.get()), data));
429 } 425 }
430 426
431 void Bridge::close(int code, const String& reason) 427 void Bridge::close(int code, const String& reason)
432 { 428 {
433 ASSERT(m_peer); 429 ASSERT(m_peer);
434 m_loaderProxy->postTaskToLoader(createCrossThreadTask(&Peer::close, wrapCros sThreadPersistent(m_peer.get()), code, reason)); 430 m_loaderProxy->postTaskToLoader(createCrossThreadTask(&Peer::close, wrapCros sThreadPersistent(m_peer.get()), code, reason));
435 } 431 }
436 432
437 void Bridge::fail(const String& reason, MessageLevel level, const String& source URL, unsigned lineNumber) 433 void Bridge::fail(const String& reason, MessageLevel level, PassOwnPtr<SourceLoc ation> location)
438 { 434 {
439 ASSERT(m_peer); 435 ASSERT(m_peer);
440 m_loaderProxy->postTaskToLoader(createCrossThreadTask(&Peer::fail, wrapCross ThreadPersistent(m_peer.get()), reason, level, sourceURL, lineNumber)); 436 m_loaderProxy->postTaskToLoader(createCrossThreadTask(&Peer::fail, wrapCross ThreadPersistent(m_peer.get()), reason, level, passed(std::move(location))));
441 } 437 }
442 438
443 void Bridge::disconnect() 439 void Bridge::disconnect()
444 { 440 {
445 if (!m_peer) 441 if (!m_peer)
446 return; 442 return;
447 443
448 waitForMethodCompletion(createCrossThreadTask(&Peer::disconnect, wrapCrossTh readPersistent(m_peer.get()))); 444 waitForMethodCompletion(createCrossThreadTask(&Peer::disconnect, wrapCrossTh readPersistent(m_peer.get())));
449 // Here |m_peer| is detached from the main thread and we can delete it. 445 // Here |m_peer| is detached from the main thread and we can delete it.
450 446
(...skipping 23 matching lines...) Expand all
474 470
475 DEFINE_TRACE(Bridge) 471 DEFINE_TRACE(Bridge)
476 { 472 {
477 visitor->trace(m_client); 473 visitor->trace(m_client);
478 visitor->trace(m_workerGlobalScope); 474 visitor->trace(m_workerGlobalScope);
479 visitor->trace(m_syncHelper); 475 visitor->trace(m_syncHelper);
480 visitor->trace(m_peer); 476 visitor->trace(m_peer);
481 } 477 }
482 478
483 } // namespace blink 479 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698