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

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

Issue 2645613006: Worker: Stop using ExecutionContextTask on WorkerLoaderProxy::postTaskToWorkerGlobalScope (Closed)
Patch Set: address review comments Created 3 years, 11 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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 void Peer::disconnect() { 229 void Peer::disconnect() {
230 DCHECK(isMainThread()); 230 DCHECK(isMainThread());
231 if (!m_mainWebSocketChannel) 231 if (!m_mainWebSocketChannel)
232 return; 232 return;
233 m_mainWebSocketChannel->disconnect(); 233 m_mainWebSocketChannel->disconnect();
234 m_mainWebSocketChannel = nullptr; 234 m_mainWebSocketChannel = nullptr;
235 } 235 }
236 236
237 static void workerGlobalScopeDidConnect(Bridge* bridge, 237 static void workerGlobalScopeDidConnect(Bridge* bridge,
238 const String& subprotocol, 238 const String& subprotocol,
239 const String& extensions, 239 const String& extensions) {
240 ExecutionContext* context) {
241 DCHECK(context->isWorkerGlobalScope());
242 if (bridge && bridge->client()) 240 if (bridge && bridge->client())
243 bridge->client()->didConnect(subprotocol, extensions); 241 bridge->client()->didConnect(subprotocol, extensions);
244 } 242 }
245 243
246 void Peer::didConnect(const String& subprotocol, const String& extensions) { 244 void Peer::didConnect(const String& subprotocol, const String& extensions) {
247 DCHECK(isMainThread()); 245 DCHECK(isMainThread());
248 m_loaderProxy->postTaskToWorkerGlobalScope( 246 m_loaderProxy->postTaskToWorkerGlobalScope(
249 BLINK_FROM_HERE, 247 BLINK_FROM_HERE, crossThreadBind(&workerGlobalScopeDidConnect, m_bridge,
250 createCrossThreadTask(&workerGlobalScopeDidConnect, m_bridge, subprotocol, 248 subprotocol, extensions));
251 extensions));
252 } 249 }
253 250
254 static void workerGlobalScopeDidReceiveTextMessage(Bridge* bridge, 251 static void workerGlobalScopeDidReceiveTextMessage(Bridge* bridge,
255 const String& payload, 252 const String& payload) {
256 ExecutionContext* context) {
257 DCHECK(context->isWorkerGlobalScope());
258 if (bridge && bridge->client()) 253 if (bridge && bridge->client())
259 bridge->client()->didReceiveTextMessage(payload); 254 bridge->client()->didReceiveTextMessage(payload);
260 } 255 }
261 256
262 void Peer::didReceiveTextMessage(const String& payload) { 257 void Peer::didReceiveTextMessage(const String& payload) {
263 DCHECK(isMainThread()); 258 DCHECK(isMainThread());
264 m_loaderProxy->postTaskToWorkerGlobalScope( 259 m_loaderProxy->postTaskToWorkerGlobalScope(
265 BLINK_FROM_HERE, 260 BLINK_FROM_HERE, crossThreadBind(&workerGlobalScopeDidReceiveTextMessage,
266 createCrossThreadTask(&workerGlobalScopeDidReceiveTextMessage, m_bridge, 261 m_bridge, payload));
267 payload));
268 } 262 }
269 263
270 static void workerGlobalScopeDidReceiveBinaryMessage( 264 static void workerGlobalScopeDidReceiveBinaryMessage(
271 Bridge* bridge, 265 Bridge* bridge,
272 std::unique_ptr<Vector<char>> payload, 266 std::unique_ptr<Vector<char>> payload) {
273 ExecutionContext* context) {
274 DCHECK(context->isWorkerGlobalScope());
275 if (bridge && bridge->client()) 267 if (bridge && bridge->client())
276 bridge->client()->didReceiveBinaryMessage(std::move(payload)); 268 bridge->client()->didReceiveBinaryMessage(std::move(payload));
277 } 269 }
278 270
279 void Peer::didReceiveBinaryMessage(std::unique_ptr<Vector<char>> payload) { 271 void Peer::didReceiveBinaryMessage(std::unique_ptr<Vector<char>> payload) {
280 DCHECK(isMainThread()); 272 DCHECK(isMainThread());
281 m_loaderProxy->postTaskToWorkerGlobalScope( 273 m_loaderProxy->postTaskToWorkerGlobalScope(
282 BLINK_FROM_HERE, 274 BLINK_FROM_HERE,
283 createCrossThreadTask(&workerGlobalScopeDidReceiveBinaryMessage, m_bridge, 275 crossThreadBind(&workerGlobalScopeDidReceiveBinaryMessage, m_bridge,
284 WTF::passed(std::move(payload)))); 276 WTF::passed(std::move(payload))));
285 } 277 }
286 278
287 static void workerGlobalScopeDidConsumeBufferedAmount( 279 static void workerGlobalScopeDidConsumeBufferedAmount(Bridge* bridge,
288 Bridge* bridge, 280 uint64_t consumed) {
289 uint64_t consumed,
290 ExecutionContext* context) {
291 DCHECK(context->isWorkerGlobalScope());
292 if (bridge && bridge->client()) 281 if (bridge && bridge->client())
293 bridge->client()->didConsumeBufferedAmount(consumed); 282 bridge->client()->didConsumeBufferedAmount(consumed);
294 } 283 }
295 284
296 void Peer::didConsumeBufferedAmount(uint64_t consumed) { 285 void Peer::didConsumeBufferedAmount(uint64_t consumed) {
297 DCHECK(isMainThread()); 286 DCHECK(isMainThread());
298 m_loaderProxy->postTaskToWorkerGlobalScope( 287 m_loaderProxy->postTaskToWorkerGlobalScope(
299 BLINK_FROM_HERE, 288 BLINK_FROM_HERE,
300 createCrossThreadTask(&workerGlobalScopeDidConsumeBufferedAmount, 289 crossThreadBind(&workerGlobalScopeDidConsumeBufferedAmount, m_bridge,
301 m_bridge, consumed)); 290 consumed));
302 } 291 }
303 292
304 static void workerGlobalScopeDidStartClosingHandshake( 293 static void workerGlobalScopeDidStartClosingHandshake(Bridge* bridge) {
305 Bridge* bridge,
306 ExecutionContext* context) {
307 DCHECK(context->isWorkerGlobalScope());
308 if (bridge && bridge->client()) 294 if (bridge && bridge->client())
309 bridge->client()->didStartClosingHandshake(); 295 bridge->client()->didStartClosingHandshake();
310 } 296 }
311 297
312 void Peer::didStartClosingHandshake() { 298 void Peer::didStartClosingHandshake() {
313 DCHECK(isMainThread()); 299 DCHECK(isMainThread());
314 m_loaderProxy->postTaskToWorkerGlobalScope( 300 m_loaderProxy->postTaskToWorkerGlobalScope(
315 BLINK_FROM_HERE, 301 BLINK_FROM_HERE,
316 createCrossThreadTask(&workerGlobalScopeDidStartClosingHandshake, 302 crossThreadBind(&workerGlobalScopeDidStartClosingHandshake, m_bridge));
317 m_bridge));
318 } 303 }
319 304
320 static void workerGlobalScopeDidClose( 305 static void workerGlobalScopeDidClose(
321 Bridge* bridge, 306 Bridge* bridge,
322 WebSocketChannelClient::ClosingHandshakeCompletionStatus 307 WebSocketChannelClient::ClosingHandshakeCompletionStatus
323 closingHandshakeCompletion, 308 closingHandshakeCompletion,
324 unsigned short code, 309 unsigned short code,
325 const String& reason, 310 const String& reason) {
326 ExecutionContext* context) {
327 DCHECK(context->isWorkerGlobalScope());
328 if (bridge && bridge->client()) 311 if (bridge && bridge->client())
329 bridge->client()->didClose(closingHandshakeCompletion, code, reason); 312 bridge->client()->didClose(closingHandshakeCompletion, code, reason);
330 } 313 }
331 314
332 void Peer::didClose(ClosingHandshakeCompletionStatus closingHandshakeCompletion, 315 void Peer::didClose(ClosingHandshakeCompletionStatus closingHandshakeCompletion,
333 unsigned short code, 316 unsigned short code,
334 const String& reason) { 317 const String& reason) {
335 DCHECK(isMainThread()); 318 DCHECK(isMainThread());
336 if (m_mainWebSocketChannel) { 319 if (m_mainWebSocketChannel) {
337 m_mainWebSocketChannel->disconnect(); 320 m_mainWebSocketChannel->disconnect();
338 m_mainWebSocketChannel = nullptr; 321 m_mainWebSocketChannel = nullptr;
339 } 322 }
340 m_loaderProxy->postTaskToWorkerGlobalScope( 323 m_loaderProxy->postTaskToWorkerGlobalScope(
341 BLINK_FROM_HERE, 324 BLINK_FROM_HERE,
342 createCrossThreadTask(&workerGlobalScopeDidClose, m_bridge, 325 crossThreadBind(&workerGlobalScopeDidClose, m_bridge,
343 closingHandshakeCompletion, code, reason)); 326 closingHandshakeCompletion, code, reason));
344 } 327 }
345 328
346 static void workerGlobalScopeDidError(Bridge* bridge, 329 static void workerGlobalScopeDidError(Bridge* bridge) {
347 ExecutionContext* context) {
348 DCHECK(context->isWorkerGlobalScope());
349 if (bridge && bridge->client()) 330 if (bridge && bridge->client())
350 bridge->client()->didError(); 331 bridge->client()->didError();
351 } 332 }
352 333
353 void Peer::didError() { 334 void Peer::didError() {
354 DCHECK(isMainThread()); 335 DCHECK(isMainThread());
355 m_loaderProxy->postTaskToWorkerGlobalScope( 336 m_loaderProxy->postTaskToWorkerGlobalScope(
356 BLINK_FROM_HERE, 337 BLINK_FROM_HERE, crossThreadBind(&workerGlobalScopeDidError, m_bridge));
357 createCrossThreadTask(&workerGlobalScopeDidError, m_bridge));
358 } 338 }
359 339
360 void Peer::contextDestroyed(WorkerThreadLifecycleContext*) { 340 void Peer::contextDestroyed(WorkerThreadLifecycleContext*) {
361 DCHECK(isMainThread()); 341 DCHECK(isMainThread());
362 if (m_mainWebSocketChannel) { 342 if (m_mainWebSocketChannel) {
363 m_mainWebSocketChannel->disconnect(); 343 m_mainWebSocketChannel->disconnect();
364 m_mainWebSocketChannel = nullptr; 344 m_mainWebSocketChannel = nullptr;
365 } 345 }
366 m_bridge = nullptr; 346 m_bridge = nullptr;
367 } 347 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 m_peer = nullptr; 464 m_peer = nullptr;
485 m_workerGlobalScope.clear(); 465 m_workerGlobalScope.clear();
486 } 466 }
487 467
488 DEFINE_TRACE(Bridge) { 468 DEFINE_TRACE(Bridge) {
489 visitor->trace(m_client); 469 visitor->trace(m_client);
490 visitor->trace(m_workerGlobalScope); 470 visitor->trace(m_workerGlobalScope);
491 } 471 }
492 472
493 } // namespace blink 473 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/workers/WorkerThreadTestHelper.h ('k') | third_party/WebKit/Source/web/WebEmbeddedWorkerImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698