| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef DataConsumerHandleTestUtil_h | 5 #ifndef DataConsumerHandleTestUtil_h |
| 6 #define DataConsumerHandleTestUtil_h | 6 #define DataConsumerHandleTestUtil_h |
| 7 | 7 |
| 8 #include <gmock/gmock.h> | 8 #include <gmock/gmock.h> |
| 9 #include <gtest/gtest.h> | 9 #include <gtest/gtest.h> |
| 10 #include <v8.h> | 10 #include <v8.h> |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 template <typename T> | 473 template <typename T> |
| 474 class HandleReaderRunner final { | 474 class HandleReaderRunner final { |
| 475 STACK_ALLOCATED(); | 475 STACK_ALLOCATED(); |
| 476 | 476 |
| 477 public: | 477 public: |
| 478 explicit HandleReaderRunner(std::unique_ptr<WebDataConsumerHandle> handle) | 478 explicit HandleReaderRunner(std::unique_ptr<WebDataConsumerHandle> handle) |
| 479 : m_thread(WTF::wrapUnique(new Thread("reading thread"))), | 479 : m_thread(WTF::wrapUnique(new Thread("reading thread"))), |
| 480 m_event(WTF::makeUnique<WaitableEvent>()), | 480 m_event(WTF::makeUnique<WaitableEvent>()), |
| 481 m_isDone(false) { | 481 m_isDone(false) { |
| 482 m_thread->thread()->postTask( | 482 m_thread->thread()->postTask( |
| 483 BLINK_FROM_HERE, crossThreadBind(&HandleReaderRunner::start, | 483 BLINK_FROM_HERE, |
| 484 crossThreadUnretained(this), | 484 crossThreadBind(&HandleReaderRunner::start, |
| 485 WTF::passed(std::move(handle)))); | 485 crossThreadUnretained(this), |
| 486 WTF::passed(std::move(handle)))); |
| 486 } | 487 } |
| 487 ~HandleReaderRunner() { wait(); } | 488 ~HandleReaderRunner() { wait(); } |
| 488 | 489 |
| 489 std::unique_ptr<HandleReadResult> wait() { | 490 std::unique_ptr<HandleReadResult> wait() { |
| 490 if (m_isDone) | 491 if (m_isDone) |
| 491 return nullptr; | 492 return nullptr; |
| 492 m_event->wait(); | 493 m_event->wait(); |
| 493 m_isDone = true; | 494 m_isDone = true; |
| 494 return std::move(m_result); | 495 return std::move(m_result); |
| 495 } | 496 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 515 std::unique_ptr<T> m_handleReader; | 516 std::unique_ptr<T> m_handleReader; |
| 516 }; | 517 }; |
| 517 | 518 |
| 518 static std::unique_ptr<WebDataConsumerHandle> | 519 static std::unique_ptr<WebDataConsumerHandle> |
| 519 createWaitingDataConsumerHandle(); | 520 createWaitingDataConsumerHandle(); |
| 520 }; | 521 }; |
| 521 | 522 |
| 522 } // namespace blink | 523 } // namespace blink |
| 523 | 524 |
| 524 #endif // DataConsumerHandleTestUtil_h | 525 #endif // DataConsumerHandleTestUtil_h |
| OLD | NEW |