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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 ThreadHolder* m_holder; | 155 ThreadHolder* m_holder; |
156 }; | 156 }; |
157 | 157 |
158 // The reading/updating threads are alive while ThreadHolder is alive. | 158 // The reading/updating threads are alive while ThreadHolder is alive. |
159 class ThreadHolder { | 159 class ThreadHolder { |
160 DISALLOW_NEW(); | 160 DISALLOW_NEW(); |
161 | 161 |
162 public: | 162 public: |
163 ThreadHolder(ThreadingTestBase* test) | 163 ThreadHolder(ThreadingTestBase* test) |
164 : m_context(test->m_context), | 164 : m_context(test->m_context), |
165 m_readingThread(wrapUnique(new Thread("reading thread"))), | 165 m_readingThread(WTF::wrapUnique(new Thread("reading thread"))), |
166 m_updatingThread(wrapUnique(new Thread("updating thread"))) { | 166 m_updatingThread(WTF::wrapUnique(new Thread("updating thread"))) { |
167 m_context->registerThreadHolder(this); | 167 m_context->registerThreadHolder(this); |
168 } | 168 } |
169 ~ThreadHolder() { m_context->unregisterThreadHolder(); } | 169 ~ThreadHolder() { m_context->unregisterThreadHolder(); } |
170 | 170 |
171 WebThreadSupportingGC* readingThread() { | 171 WebThreadSupportingGC* readingThread() { |
172 return m_readingThread->thread(); | 172 return m_readingThread->thread(); |
173 } | 173 } |
174 WebThreadSupportingGC* updatingThread() { | 174 WebThreadSupportingGC* updatingThread() { |
175 return m_updatingThread->thread(); | 175 return m_updatingThread->thread(); |
176 } | 176 } |
(...skipping 27 matching lines...) Expand all Loading... |
204 const String m_name; | 204 const String m_name; |
205 RefPtr<Context> m_context; | 205 RefPtr<Context> m_context; |
206 }; | 206 }; |
207 class DataConsumerHandle final : public WebDataConsumerHandle { | 207 class DataConsumerHandle final : public WebDataConsumerHandle { |
208 USING_FAST_MALLOC(DataConsumerHandle); | 208 USING_FAST_MALLOC(DataConsumerHandle); |
209 | 209 |
210 public: | 210 public: |
211 static std::unique_ptr<WebDataConsumerHandle> create( | 211 static std::unique_ptr<WebDataConsumerHandle> create( |
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 WTF::wrapUnique( |
| 215 new DataConsumerHandle(name, std::move(context))); |
215 } | 216 } |
216 | 217 |
217 private: | 218 private: |
218 DataConsumerHandle(const String& name, PassRefPtr<Context> context) | 219 DataConsumerHandle(const String& name, PassRefPtr<Context> context) |
219 : m_name(name.isolatedCopy()), m_context(context) {} | 220 : m_name(name.isolatedCopy()), m_context(context) {} |
220 | 221 |
221 std::unique_ptr<Reader> obtainReader(Client*) { | 222 std::unique_ptr<Reader> obtainReader(Client*) { |
222 return makeUnique<ReaderImpl>(m_name, m_context); | 223 return WTF::makeUnique<ReaderImpl>(m_name, m_context); |
223 } | 224 } |
224 const char* debugName() const override { | 225 const char* debugName() const override { |
225 return "ThreadingTestBase::DataConsumerHandle"; | 226 return "ThreadingTestBase::DataConsumerHandle"; |
226 } | 227 } |
227 | 228 |
228 const String m_name; | 229 const String m_name; |
229 RefPtr<Context> m_context; | 230 RefPtr<Context> m_context; |
230 }; | 231 }; |
231 | 232 |
232 void resetReader() { m_reader = nullptr; } | 233 void resetReader() { m_reader = nullptr; } |
(...skipping 30 matching lines...) Expand all Loading... |
263 }; | 264 }; |
264 | 265 |
265 class ThreadingHandleNotificationTest : public ThreadingTestBase, | 266 class ThreadingHandleNotificationTest : public ThreadingTestBase, |
266 public WebDataConsumerHandle::Client { | 267 public WebDataConsumerHandle::Client { |
267 public: | 268 public: |
268 using Self = ThreadingHandleNotificationTest; | 269 using Self = ThreadingHandleNotificationTest; |
269 static PassRefPtr<Self> create() { return adoptRef(new Self); } | 270 static PassRefPtr<Self> create() { return adoptRef(new Self); } |
270 | 271 |
271 void run(std::unique_ptr<WebDataConsumerHandle> handle) { | 272 void run(std::unique_ptr<WebDataConsumerHandle> handle) { |
272 ThreadHolder holder(this); | 273 ThreadHolder holder(this); |
273 m_waitableEvent = makeUnique<WaitableEvent>(); | 274 m_waitableEvent = WTF::makeUnique<WaitableEvent>(); |
274 m_handle = std::move(handle); | 275 m_handle = std::move(handle); |
275 | 276 |
276 postTaskToReadingThreadAndWait( | 277 postTaskToReadingThreadAndWait( |
277 BLINK_FROM_HERE, | 278 BLINK_FROM_HERE, |
278 crossThreadBind(&Self::obtainReader, wrapPassRefPtr(this))); | 279 crossThreadBind(&Self::obtainReader, wrapPassRefPtr(this))); |
279 } | 280 } |
280 | 281 |
281 private: | 282 private: |
282 ThreadingHandleNotificationTest() = default; | 283 ThreadingHandleNotificationTest() = default; |
283 void obtainReader() { m_reader = m_handle->obtainReader(this); } | 284 void obtainReader() { m_reader = m_handle->obtainReader(this); } |
(...skipping 11 matching lines...) Expand all Loading... |
295 | 296 |
296 class ThreadingHandleNoNotificationTest | 297 class ThreadingHandleNoNotificationTest |
297 : public ThreadingTestBase, | 298 : public ThreadingTestBase, |
298 public WebDataConsumerHandle::Client { | 299 public WebDataConsumerHandle::Client { |
299 public: | 300 public: |
300 using Self = ThreadingHandleNoNotificationTest; | 301 using Self = ThreadingHandleNoNotificationTest; |
301 static PassRefPtr<Self> create() { return adoptRef(new Self); } | 302 static PassRefPtr<Self> create() { return adoptRef(new Self); } |
302 | 303 |
303 void run(std::unique_ptr<WebDataConsumerHandle> handle) { | 304 void run(std::unique_ptr<WebDataConsumerHandle> handle) { |
304 ThreadHolder holder(this); | 305 ThreadHolder holder(this); |
305 m_waitableEvent = makeUnique<WaitableEvent>(); | 306 m_waitableEvent = WTF::makeUnique<WaitableEvent>(); |
306 m_handle = std::move(handle); | 307 m_handle = std::move(handle); |
307 | 308 |
308 postTaskToReadingThreadAndWait( | 309 postTaskToReadingThreadAndWait( |
309 BLINK_FROM_HERE, | 310 BLINK_FROM_HERE, |
310 crossThreadBind(&Self::obtainReader, wrapPassRefPtr(this))); | 311 crossThreadBind(&Self::obtainReader, wrapPassRefPtr(this))); |
311 } | 312 } |
312 | 313 |
313 private: | 314 private: |
314 ThreadingHandleNoNotificationTest() = default; | 315 ThreadingHandleNoNotificationTest() = default; |
315 void obtainReader() { | 316 void obtainReader() { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 Vector<char> m_body; | 350 Vector<char> m_body; |
350 }; | 351 }; |
351 | 352 |
352 // ReplayingHandle stores commands via |add| and replays the stored commends | 353 // ReplayingHandle stores commands via |add| and replays the stored commends |
353 // when read. | 354 // when read. |
354 class ReplayingHandle final : public WebDataConsumerHandle { | 355 class ReplayingHandle final : public WebDataConsumerHandle { |
355 USING_FAST_MALLOC(ReplayingHandle); | 356 USING_FAST_MALLOC(ReplayingHandle); |
356 | 357 |
357 public: | 358 public: |
358 static std::unique_ptr<ReplayingHandle> create() { | 359 static std::unique_ptr<ReplayingHandle> create() { |
359 return wrapUnique(new ReplayingHandle()); | 360 return WTF::wrapUnique(new ReplayingHandle()); |
360 } | 361 } |
361 ~ReplayingHandle(); | 362 ~ReplayingHandle(); |
362 | 363 |
363 // Add a command to this handle. This function must be called on the | 364 // Add a command to this handle. This function must be called on the |
364 // creator thread. This function must be called BEFORE any reader is | 365 // creator thread. This function must be called BEFORE any reader is |
365 // obtained. | 366 // obtained. |
366 void add(const Command&); | 367 void add(const Command&); |
367 | 368 |
368 class Context final : public ThreadSafeRefCounted<Context> { | 369 class Context final : public ThreadSafeRefCounted<Context> { |
369 public: | 370 public: |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 }; | 469 }; |
469 | 470 |
470 // HandleReaderRunner<T> creates a dedicated thread and run T on the thread | 471 // HandleReaderRunner<T> creates a dedicated thread and run T on the thread |
471 // where T is one of HandleReader and HandleTwophaseReader. | 472 // where T is one of HandleReader and HandleTwophaseReader. |
472 template <typename T> | 473 template <typename T> |
473 class HandleReaderRunner final { | 474 class HandleReaderRunner final { |
474 STACK_ALLOCATED(); | 475 STACK_ALLOCATED(); |
475 | 476 |
476 public: | 477 public: |
477 explicit HandleReaderRunner(std::unique_ptr<WebDataConsumerHandle> handle) | 478 explicit HandleReaderRunner(std::unique_ptr<WebDataConsumerHandle> handle) |
478 : m_thread(wrapUnique(new Thread("reading thread"))), | 479 : m_thread(WTF::wrapUnique(new Thread("reading thread"))), |
479 m_event(makeUnique<WaitableEvent>()), | 480 m_event(WTF::makeUnique<WaitableEvent>()), |
480 m_isDone(false) { | 481 m_isDone(false) { |
481 m_thread->thread()->postTask(BLINK_FROM_HERE, | 482 m_thread->thread()->postTask( |
482 crossThreadBind(&HandleReaderRunner::start, | 483 BLINK_FROM_HERE, crossThreadBind(&HandleReaderRunner::start, |
483 crossThreadUnretained(this), | 484 crossThreadUnretained(this), |
484 passed(std::move(handle)))); | 485 WTF::passed(std::move(handle)))); |
485 } | 486 } |
486 ~HandleReaderRunner() { wait(); } | 487 ~HandleReaderRunner() { wait(); } |
487 | 488 |
488 std::unique_ptr<HandleReadResult> wait() { | 489 std::unique_ptr<HandleReadResult> wait() { |
489 if (m_isDone) | 490 if (m_isDone) |
490 return nullptr; | 491 return nullptr; |
491 m_event->wait(); | 492 m_event->wait(); |
492 m_isDone = true; | 493 m_isDone = true; |
493 return std::move(m_result); | 494 return std::move(m_result); |
494 } | 495 } |
495 | 496 |
496 private: | 497 private: |
497 void start(std::unique_ptr<WebDataConsumerHandle> handle) { | 498 void start(std::unique_ptr<WebDataConsumerHandle> handle) { |
498 m_handleReader = wrapUnique(new T( | 499 m_handleReader = WTF::wrapUnique(new T( |
499 std::move(handle), | 500 std::move(handle), |
500 WTF::bind(&HandleReaderRunner::onFinished, WTF::unretained(this)))); | 501 WTF::bind(&HandleReaderRunner::onFinished, WTF::unretained(this)))); |
501 } | 502 } |
502 | 503 |
503 void onFinished(std::unique_ptr<HandleReadResult> result) { | 504 void onFinished(std::unique_ptr<HandleReadResult> result) { |
504 m_handleReader = nullptr; | 505 m_handleReader = nullptr; |
505 m_result = std::move(result); | 506 m_result = std::move(result); |
506 m_event->signal(); | 507 m_event->signal(); |
507 } | 508 } |
508 | 509 |
509 std::unique_ptr<Thread> m_thread; | 510 std::unique_ptr<Thread> m_thread; |
510 std::unique_ptr<WaitableEvent> m_event; | 511 std::unique_ptr<WaitableEvent> m_event; |
511 std::unique_ptr<HandleReadResult> m_result; | 512 std::unique_ptr<HandleReadResult> m_result; |
512 bool m_isDone; | 513 bool m_isDone; |
513 | 514 |
514 std::unique_ptr<T> m_handleReader; | 515 std::unique_ptr<T> m_handleReader; |
515 }; | 516 }; |
516 | 517 |
517 static std::unique_ptr<WebDataConsumerHandle> | 518 static std::unique_ptr<WebDataConsumerHandle> |
518 createWaitingDataConsumerHandle(); | 519 createWaitingDataConsumerHandle(); |
519 }; | 520 }; |
520 | 521 |
521 } // namespace blink | 522 } // namespace blink |
522 | 523 |
523 #endif // DataConsumerHandleTestUtil_h | 524 #endif // DataConsumerHandleTestUtil_h |
OLD | NEW |