| 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 "bindings/core/v8/ScriptState.h" | 8 #include "bindings/core/v8/ScriptState.h" |
| 9 #include "core/testing/NullExecutionContext.h" | 9 #include "core/testing/NullExecutionContext.h" |
| 10 #include "gin/public/isolate_holder.h" | 10 #include "gin/public/isolate_holder.h" |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 const String& name, | 212 const String& name, |
| 213 PassRefPtr<Context> context) { | 213 PassRefPtr<Context> context) { |
| 214 return wrapUnique(new DataConsumerHandle(name, std::move(context))); | 214 return wrapUnique(new DataConsumerHandle(name, std::move(context))); |
| 215 } | 215 } |
| 216 | 216 |
| 217 private: | 217 private: |
| 218 DataConsumerHandle(const String& name, PassRefPtr<Context> context) | 218 DataConsumerHandle(const String& name, PassRefPtr<Context> context) |
| 219 : m_name(name.isolatedCopy()), m_context(context) {} | 219 : m_name(name.isolatedCopy()), m_context(context) {} |
| 220 | 220 |
| 221 std::unique_ptr<Reader> obtainReader(Client*) { | 221 std::unique_ptr<Reader> obtainReader(Client*) { |
| 222 return WTF::wrapUnique(new ReaderImpl(m_name, m_context)); | 222 return makeUnique<ReaderImpl>(m_name, m_context); |
| 223 } | 223 } |
| 224 const char* debugName() const override { | 224 const char* debugName() const override { |
| 225 return "ThreadingTestBase::DataConsumerHandle"; | 225 return "ThreadingTestBase::DataConsumerHandle"; |
| 226 } | 226 } |
| 227 | 227 |
| 228 const String m_name; | 228 const String m_name; |
| 229 RefPtr<Context> m_context; | 229 RefPtr<Context> m_context; |
| 230 }; | 230 }; |
| 231 | 231 |
| 232 void resetReader() { m_reader = nullptr; } | 232 void resetReader() { m_reader = nullptr; } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 263 }; | 263 }; |
| 264 | 264 |
| 265 class ThreadingHandleNotificationTest : public ThreadingTestBase, | 265 class ThreadingHandleNotificationTest : public ThreadingTestBase, |
| 266 public WebDataConsumerHandle::Client { | 266 public WebDataConsumerHandle::Client { |
| 267 public: | 267 public: |
| 268 using Self = ThreadingHandleNotificationTest; | 268 using Self = ThreadingHandleNotificationTest; |
| 269 static PassRefPtr<Self> create() { return adoptRef(new Self); } | 269 static PassRefPtr<Self> create() { return adoptRef(new Self); } |
| 270 | 270 |
| 271 void run(std::unique_ptr<WebDataConsumerHandle> handle) { | 271 void run(std::unique_ptr<WebDataConsumerHandle> handle) { |
| 272 ThreadHolder holder(this); | 272 ThreadHolder holder(this); |
| 273 m_waitableEvent = wrapUnique(new WaitableEvent()); | 273 m_waitableEvent = makeUnique<WaitableEvent>(); |
| 274 m_handle = std::move(handle); | 274 m_handle = std::move(handle); |
| 275 | 275 |
| 276 postTaskToReadingThreadAndWait( | 276 postTaskToReadingThreadAndWait( |
| 277 BLINK_FROM_HERE, | 277 BLINK_FROM_HERE, |
| 278 crossThreadBind(&Self::obtainReader, wrapPassRefPtr(this))); | 278 crossThreadBind(&Self::obtainReader, wrapPassRefPtr(this))); |
| 279 } | 279 } |
| 280 | 280 |
| 281 private: | 281 private: |
| 282 ThreadingHandleNotificationTest() = default; | 282 ThreadingHandleNotificationTest() = default; |
| 283 void obtainReader() { m_reader = m_handle->obtainReader(this); } | 283 void obtainReader() { m_reader = m_handle->obtainReader(this); } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 295 | 295 |
| 296 class ThreadingHandleNoNotificationTest | 296 class ThreadingHandleNoNotificationTest |
| 297 : public ThreadingTestBase, | 297 : public ThreadingTestBase, |
| 298 public WebDataConsumerHandle::Client { | 298 public WebDataConsumerHandle::Client { |
| 299 public: | 299 public: |
| 300 using Self = ThreadingHandleNoNotificationTest; | 300 using Self = ThreadingHandleNoNotificationTest; |
| 301 static PassRefPtr<Self> create() { return adoptRef(new Self); } | 301 static PassRefPtr<Self> create() { return adoptRef(new Self); } |
| 302 | 302 |
| 303 void run(std::unique_ptr<WebDataConsumerHandle> handle) { | 303 void run(std::unique_ptr<WebDataConsumerHandle> handle) { |
| 304 ThreadHolder holder(this); | 304 ThreadHolder holder(this); |
| 305 m_waitableEvent = wrapUnique(new WaitableEvent()); | 305 m_waitableEvent = makeUnique<WaitableEvent>(); |
| 306 m_handle = std::move(handle); | 306 m_handle = std::move(handle); |
| 307 | 307 |
| 308 postTaskToReadingThreadAndWait( | 308 postTaskToReadingThreadAndWait( |
| 309 BLINK_FROM_HERE, | 309 BLINK_FROM_HERE, |
| 310 crossThreadBind(&Self::obtainReader, wrapPassRefPtr(this))); | 310 crossThreadBind(&Self::obtainReader, wrapPassRefPtr(this))); |
| 311 } | 311 } |
| 312 | 312 |
| 313 private: | 313 private: |
| 314 ThreadingHandleNoNotificationTest() = default; | 314 ThreadingHandleNoNotificationTest() = default; |
| 315 void obtainReader() { | 315 void obtainReader() { |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 | 469 |
| 470 // HandleReaderRunner<T> creates a dedicated thread and run T on the thread | 470 // HandleReaderRunner<T> creates a dedicated thread and run T on the thread |
| 471 // where T is one of HandleReader and HandleTwophaseReader. | 471 // where T is one of HandleReader and HandleTwophaseReader. |
| 472 template <typename T> | 472 template <typename T> |
| 473 class HandleReaderRunner final { | 473 class HandleReaderRunner final { |
| 474 STACK_ALLOCATED(); | 474 STACK_ALLOCATED(); |
| 475 | 475 |
| 476 public: | 476 public: |
| 477 explicit HandleReaderRunner(std::unique_ptr<WebDataConsumerHandle> handle) | 477 explicit HandleReaderRunner(std::unique_ptr<WebDataConsumerHandle> handle) |
| 478 : m_thread(wrapUnique(new Thread("reading thread"))), | 478 : m_thread(wrapUnique(new Thread("reading thread"))), |
| 479 m_event(wrapUnique(new WaitableEvent())), | 479 m_event(makeUnique<WaitableEvent>()), |
| 480 m_isDone(false) { | 480 m_isDone(false) { |
| 481 m_thread->thread()->postTask(BLINK_FROM_HERE, | 481 m_thread->thread()->postTask(BLINK_FROM_HERE, |
| 482 crossThreadBind(&HandleReaderRunner::start, | 482 crossThreadBind(&HandleReaderRunner::start, |
| 483 crossThreadUnretained(this), | 483 crossThreadUnretained(this), |
| 484 passed(std::move(handle)))); | 484 passed(std::move(handle)))); |
| 485 } | 485 } |
| 486 ~HandleReaderRunner() { wait(); } | 486 ~HandleReaderRunner() { wait(); } |
| 487 | 487 |
| 488 std::unique_ptr<HandleReadResult> wait() { | 488 std::unique_ptr<HandleReadResult> wait() { |
| 489 if (m_isDone) | 489 if (m_isDone) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 514 std::unique_ptr<T> m_handleReader; | 514 std::unique_ptr<T> m_handleReader; |
| 515 }; | 515 }; |
| 516 | 516 |
| 517 static std::unique_ptr<WebDataConsumerHandle> | 517 static std::unique_ptr<WebDataConsumerHandle> |
| 518 createWaitingDataConsumerHandle(); | 518 createWaitingDataConsumerHandle(); |
| 519 }; | 519 }; |
| 520 | 520 |
| 521 } // namespace blink | 521 } // namespace blink |
| 522 | 522 |
| 523 #endif // DataConsumerHandleTestUtil_h | 523 #endif // DataConsumerHandleTestUtil_h |
| OLD | NEW |