Chromium Code Reviews| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 return new WebSocketChannelSyncHelper(std::move(event)); | 65 return new WebSocketChannelSyncHelper(std::move(event)); |
| 66 } | 66 } |
| 67 | 67 |
| 68 ~WebSocketChannelSyncHelper() | 68 ~WebSocketChannelSyncHelper() |
| 69 { | 69 { |
| 70 } | 70 } |
| 71 | 71 |
| 72 // All setters are called on the main thread. | 72 // All setters are called on the main thread. |
| 73 void setConnectRequestResult(bool connectRequestResult) | 73 void setConnectRequestResult(bool connectRequestResult) |
| 74 { | 74 { |
| 75 DCHECK(isMainThread()); | |
| 75 m_connectRequestResult = connectRequestResult; | 76 m_connectRequestResult = connectRequestResult; |
| 76 } | 77 } |
| 77 | 78 |
| 79 void setWorkerThreadTerminated(bool workerThreadTerminated) | |
| 80 { | |
| 81 DCHECK(isMainThread()); | |
| 82 m_workerThreadTerminated = workerThreadTerminated; | |
| 83 } | |
| 84 | |
| 78 // All getter are called on the worker thread. | 85 // All getter are called on the worker thread. |
| 79 bool connectRequestResult() const | 86 bool connectRequestResult() const |
| 80 { | 87 { |
| 88 DCHECK(!isMainThread()); | |
| 81 return m_connectRequestResult; | 89 return m_connectRequestResult; |
| 82 } | 90 } |
| 83 | 91 |
| 92 bool workerThreadTerminated() const | |
| 93 { | |
| 94 DCHECK(!isMainThread()); | |
| 95 return m_workerThreadTerminated; | |
| 96 } | |
| 97 | |
| 84 // This should be called after all setters are called and before any | 98 // This should be called after all setters are called and before any |
| 85 // getters are called. | 99 // getters are called. |
| 86 void signalWorkerThread() | 100 void signalWorkerThread() |
| 87 { | 101 { |
| 88 m_event->signal(); | 102 m_event->signal(); |
| 89 } | 103 } |
| 90 void wait() | 104 void wait() |
| 91 { | 105 { |
| 92 m_event->wait(); | 106 m_event->wait(); |
| 93 } | 107 } |
| 94 | 108 |
| 95 DEFINE_INLINE_TRACE() { } | 109 DEFINE_INLINE_TRACE() { } |
| 96 | 110 |
| 97 private: | 111 private: |
| 98 explicit WebSocketChannelSyncHelper(std::unique_ptr<WaitableEvent> event) | 112 explicit WebSocketChannelSyncHelper(std::unique_ptr<WaitableEvent> event) |
| 99 : m_event(std::move(event)) | 113 : m_event(std::move(event)) |
| 100 , m_connectRequestResult(false) | |
| 101 { | 114 { |
| 102 } | 115 } |
| 103 | 116 |
| 104 std::unique_ptr<WaitableEvent> m_event; | 117 std::unique_ptr<WaitableEvent> m_event; |
| 105 bool m_connectRequestResult; | 118 bool m_connectRequestResult = false; |
| 119 bool m_workerThreadTerminated = false; | |
| 106 }; | 120 }; |
| 107 | 121 |
| 108 WorkerWebSocketChannel::WorkerWebSocketChannel(WorkerGlobalScope& workerGlobalSc ope, WebSocketChannelClient* client, std::unique_ptr<SourceLocation> location) | 122 WorkerWebSocketChannel::WorkerWebSocketChannel(WorkerGlobalScope& workerGlobalSc ope, WebSocketChannelClient* client, std::unique_ptr<SourceLocation> location) |
| 109 : m_bridge(new Bridge(client, workerGlobalScope)) | 123 : m_bridge(new Bridge(client, workerGlobalScope)) |
| 110 , m_locationAtConnection(std::move(location)) | 124 , m_locationAtConnection(std::move(location)) |
| 111 { | 125 { |
| 112 m_bridge->initialize(m_locationAtConnection->clone()); | 126 m_bridge->initialize(m_locationAtConnection->clone()); |
| 113 } | 127 } |
| 114 | 128 |
| 115 WorkerWebSocketChannel::~WorkerWebSocketChannel() | 129 WorkerWebSocketChannel::~WorkerWebSocketChannel() |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 | 372 |
| 359 void Peer::didError() | 373 void Peer::didError() |
| 360 { | 374 { |
| 361 ASSERT(isMainThread()); | 375 ASSERT(isMainThread()); |
| 362 m_loaderProxy->postTaskToWorkerGlobalScope(BLINK_FROM_HERE, createCrossThrea dTask(&workerGlobalScopeDidError, m_bridge)); | 376 m_loaderProxy->postTaskToWorkerGlobalScope(BLINK_FROM_HERE, createCrossThrea dTask(&workerGlobalScopeDidError, m_bridge)); |
| 363 } | 377 } |
| 364 | 378 |
| 365 void Peer::contextDestroyed() | 379 void Peer::contextDestroyed() |
| 366 { | 380 { |
| 367 DCHECK(isMainThread()); | 381 DCHECK(isMainThread()); |
| 382 m_syncHelper->setWorkerThreadTerminated(true); | |
|
yhirano
2016/08/23 02:27:15
I think this can be called after m_syncHelper->sig
| |
| 368 if (m_mainWebSocketChannel) { | 383 if (m_mainWebSocketChannel) { |
| 369 m_mainWebSocketChannel->disconnect(); | 384 m_mainWebSocketChannel->disconnect(); |
| 370 m_mainWebSocketChannel = nullptr; | 385 m_mainWebSocketChannel = nullptr; |
| 371 } | 386 } |
| 372 m_bridge = nullptr; | 387 m_bridge = nullptr; |
| 373 } | 388 } |
| 374 | 389 |
| 375 DEFINE_TRACE(Peer) | 390 DEFINE_TRACE(Peer) |
| 376 { | 391 { |
| 377 visitor->trace(m_mainWebSocketChannel); | 392 visitor->trace(m_mainWebSocketChannel); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 488 ASSERT(m_workerGlobalScope); | 503 ASSERT(m_workerGlobalScope); |
| 489 ASSERT(m_syncHelper); | 504 ASSERT(m_syncHelper); |
| 490 | 505 |
| 491 m_loaderProxy->postTaskToLoader(location, std::move(task)); | 506 m_loaderProxy->postTaskToLoader(location, std::move(task)); |
| 492 | 507 |
| 493 // We wait for the syncHelper event even if a shutdown event is fired. | 508 // We wait for the syncHelper event even if a shutdown event is fired. |
| 494 // See https://codereview.chromium.org/267323004/#msg43 for why we need to w ait this. | 509 // See https://codereview.chromium.org/267323004/#msg43 for why we need to w ait this. |
| 495 SafePointScope scope(BlinkGC::HeapPointersOnStack); | 510 SafePointScope scope(BlinkGC::HeapPointersOnStack); |
| 496 m_syncHelper->wait(); | 511 m_syncHelper->wait(); |
| 497 // This is checking whether a shutdown event is fired or not. | 512 // This is checking whether a shutdown event is fired or not. |
| 498 return !m_workerGlobalScope->thread()->terminated(); | 513 return !m_syncHelper->workerThreadTerminated(); |
| 499 } | 514 } |
| 500 | 515 |
| 501 DEFINE_TRACE(Bridge) | 516 DEFINE_TRACE(Bridge) |
| 502 { | 517 { |
| 503 visitor->trace(m_client); | 518 visitor->trace(m_client); |
| 504 visitor->trace(m_workerGlobalScope); | 519 visitor->trace(m_workerGlobalScope); |
| 505 visitor->trace(m_syncHelper); | 520 visitor->trace(m_syncHelper); |
| 506 } | 521 } |
| 507 | 522 |
| 508 } // namespace blink | 523 } // namespace blink |
| OLD | NEW |