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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 public: | 252 public: |
253 using Self = ThreadingHandleNotificationTest; | 253 using Self = ThreadingHandleNotificationTest; |
254 static PassRefPtr<Self> create() { return adoptRef(new Self); } | 254 static PassRefPtr<Self> create() { return adoptRef(new Self); } |
255 | 255 |
256 void run(PassOwnPtr<WebDataConsumerHandle> handle) | 256 void run(PassOwnPtr<WebDataConsumerHandle> handle) |
257 { | 257 { |
258 ThreadHolder holder(this); | 258 ThreadHolder holder(this); |
259 m_waitableEvent = adoptPtr(Platform::current()->createWaitableEvent(
)); | 259 m_waitableEvent = adoptPtr(Platform::current()->createWaitableEvent(
)); |
260 m_handle = handle; | 260 m_handle = handle; |
261 | 261 |
262 postTaskToReadingThreadAndWait(FROM_HERE, new Task(threadSafeBind(&S
elf::obtainReader, this))); | 262 postTaskToReadingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeB
ind(&Self::obtainReader, this))); |
263 } | 263 } |
264 | 264 |
265 private: | 265 private: |
266 ThreadingHandleNotificationTest() = default; | 266 ThreadingHandleNotificationTest() = default; |
267 void obtainReader() | 267 void obtainReader() |
268 { | 268 { |
269 m_reader = m_handle->obtainReader(this); | 269 m_reader = m_handle->obtainReader(this); |
270 } | 270 } |
271 void didGetReadable() override | 271 void didGetReadable() override |
272 { | 272 { |
273 postTaskToReadingThread(FROM_HERE, new Task(threadSafeBind(&Self::re
setReader, this))); | 273 postTaskToReadingThread(BLINK_FROM_HERE, new Task(threadSafeBind(&Se
lf::resetReader, this))); |
274 postTaskToReadingThread(FROM_HERE, new Task(threadSafeBind(&Self::si
gnalDone, this))); | 274 postTaskToReadingThread(BLINK_FROM_HERE, new Task(threadSafeBind(&Se
lf::signalDone, this))); |
275 } | 275 } |
276 | 276 |
277 OwnPtr<WebDataConsumerHandle> m_handle; | 277 OwnPtr<WebDataConsumerHandle> m_handle; |
278 }; | 278 }; |
279 | 279 |
280 class ThreadingHandleNoNotificationTest : public ThreadingTestBase, public W
ebDataConsumerHandle::Client { | 280 class ThreadingHandleNoNotificationTest : public ThreadingTestBase, public W
ebDataConsumerHandle::Client { |
281 public: | 281 public: |
282 using Self = ThreadingHandleNoNotificationTest; | 282 using Self = ThreadingHandleNoNotificationTest; |
283 static PassRefPtr<Self> create() { return adoptRef(new Self); } | 283 static PassRefPtr<Self> create() { return adoptRef(new Self); } |
284 | 284 |
285 void run(PassOwnPtr<WebDataConsumerHandle> handle) | 285 void run(PassOwnPtr<WebDataConsumerHandle> handle) |
286 { | 286 { |
287 ThreadHolder holder(this); | 287 ThreadHolder holder(this); |
288 m_waitableEvent = adoptPtr(Platform::current()->createWaitableEvent(
)); | 288 m_waitableEvent = adoptPtr(Platform::current()->createWaitableEvent(
)); |
289 m_handle = handle; | 289 m_handle = handle; |
290 | 290 |
291 postTaskToReadingThreadAndWait(FROM_HERE, new Task(threadSafeBind(&S
elf::obtainReader, this))); | 291 postTaskToReadingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeB
ind(&Self::obtainReader, this))); |
292 } | 292 } |
293 | 293 |
294 private: | 294 private: |
295 ThreadingHandleNoNotificationTest() = default; | 295 ThreadingHandleNoNotificationTest() = default; |
296 void obtainReader() | 296 void obtainReader() |
297 { | 297 { |
298 m_reader = m_handle->obtainReader(this); | 298 m_reader = m_handle->obtainReader(this); |
299 m_reader = nullptr; | 299 m_reader = nullptr; |
300 postTaskToReadingThread(FROM_HERE, new Task(threadSafeBind(&Self::si
gnalDone, this))); | 300 postTaskToReadingThread(BLINK_FROM_HERE, new Task(threadSafeBind(&Se
lf::signalDone, this))); |
301 } | 301 } |
302 void didGetReadable() override | 302 void didGetReadable() override |
303 { | 303 { |
304 ASSERT_NOT_REACHED(); | 304 ASSERT_NOT_REACHED(); |
305 } | 305 } |
306 | 306 |
307 OwnPtr<WebDataConsumerHandle> m_handle; | 307 OwnPtr<WebDataConsumerHandle> m_handle; |
308 }; | 308 }; |
309 | 309 |
310 class MockFetchDataConsumerHandle : public FetchDataConsumerHandle { | 310 class MockFetchDataConsumerHandle : public FetchDataConsumerHandle { |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 // where T is one of HandleReader and HandleTwophaseReader. | 495 // where T is one of HandleReader and HandleTwophaseReader. |
496 template <typename T> | 496 template <typename T> |
497 class HandleReaderRunner final { | 497 class HandleReaderRunner final { |
498 STACK_ALLOCATED(); | 498 STACK_ALLOCATED(); |
499 public: | 499 public: |
500 explicit HandleReaderRunner(PassOwnPtr<WebDataConsumerHandle> handle) | 500 explicit HandleReaderRunner(PassOwnPtr<WebDataConsumerHandle> handle) |
501 : m_thread(adoptPtr(new Thread("reading thread"))) | 501 : m_thread(adoptPtr(new Thread("reading thread"))) |
502 , m_event(adoptPtr(Platform::current()->createWaitableEvent())) | 502 , m_event(adoptPtr(Platform::current()->createWaitableEvent())) |
503 , m_isDone(false) | 503 , m_isDone(false) |
504 { | 504 { |
505 m_thread->thread()->postTask(FROM_HERE, new Task(threadSafeBind(&Han
dleReaderRunner::start, AllowCrossThreadAccess(this), handle))); | 505 m_thread->thread()->postTask(BLINK_FROM_HERE, new Task(threadSafeBin
d(&HandleReaderRunner::start, AllowCrossThreadAccess(this), handle))); |
506 } | 506 } |
507 ~HandleReaderRunner() | 507 ~HandleReaderRunner() |
508 { | 508 { |
509 wait(); | 509 wait(); |
510 } | 510 } |
511 | 511 |
512 PassOwnPtr<HandleReadResult> wait() | 512 PassOwnPtr<HandleReadResult> wait() |
513 { | 513 { |
514 if (m_isDone) | 514 if (m_isDone) |
515 return nullptr; | 515 return nullptr; |
(...skipping 20 matching lines...) Expand all Loading... |
536 OwnPtr<HandleReadResult> m_result; | 536 OwnPtr<HandleReadResult> m_result; |
537 bool m_isDone; | 537 bool m_isDone; |
538 | 538 |
539 OwnPtr<T> m_handleReader; | 539 OwnPtr<T> m_handleReader; |
540 }; | 540 }; |
541 }; | 541 }; |
542 | 542 |
543 } // namespace blink | 543 } // namespace blink |
544 | 544 |
545 #endif // DataConsumerHandleTestUtil_h | 545 #endif // DataConsumerHandleTestUtil_h |
OLD | NEW |