Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(745)

Side by Side Diff: third_party/WebKit/Source/modules/fetch/DataConsumerHandleTestUtil.h

Issue 1713143002: Remove most of the blink::Task wrapping of WTF::Function outside WebTaskRunner (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "modules/fetch/DataConsumerHandleUtil.h" 11 #include "modules/fetch/DataConsumerHandleUtil.h"
12 #include "modules/fetch/FetchDataConsumerHandle.h" 12 #include "modules/fetch/FetchDataConsumerHandle.h"
13 #include "modules/fetch/FetchDataLoader.h" 13 #include "modules/fetch/FetchDataLoader.h"
14 #include "platform/Task.h"
15 #include "platform/ThreadSafeFunctional.h" 14 #include "platform/ThreadSafeFunctional.h"
16 #include "platform/WaitableEvent.h" 15 #include "platform/WaitableEvent.h"
17 #include "platform/WebThreadSupportingGC.h" 16 #include "platform/WebThreadSupportingGC.h"
18 #include "platform/heap/Handle.h" 17 #include "platform/heap/Handle.h"
19 #include "public/platform/Platform.h" 18 #include "public/platform/Platform.h"
20 #include "public/platform/WebDataConsumerHandle.h" 19 #include "public/platform/WebDataConsumerHandle.h"
21 #include "public/platform/WebTraceLocation.h" 20 #include "public/platform/WebTraceLocation.h"
22 #include "wtf/Deque.h" 21 #include "wtf/Deque.h"
23 #include "wtf/Locker.h" 22 #include "wtf/Locker.h"
24 #include "wtf/OwnPtr.h" 23 #include "wtf/OwnPtr.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 MutexLocker locker(m_holderMutex); 108 MutexLocker locker(m_holderMutex);
110 ASSERT(!m_holder); 109 ASSERT(!m_holder);
111 m_holder = holder; 110 m_holder = holder;
112 } 111 }
113 void unregisterThreadHolder() 112 void unregisterThreadHolder()
114 { 113 {
115 MutexLocker locker(m_holderMutex); 114 MutexLocker locker(m_holderMutex);
116 ASSERT(m_holder); 115 ASSERT(m_holder);
117 m_holder = nullptr; 116 m_holder = nullptr;
118 } 117 }
119 void postTaskToReadingThread(const WebTraceLocation& location, Task* task) 118 void postTaskToReadingThread(const WebTraceLocation& location, PassO wnPtr<Closure> task)
120 { 119 {
121 MutexLocker locker(m_holderMutex); 120 MutexLocker locker(m_holderMutex);
122 ASSERT(m_holder); 121 ASSERT(m_holder);
123 m_holder->readingThread()->postTask(location, task); 122 m_holder->readingThread()->postTask(location, task);
124 } 123 }
125 void postTaskToUpdatingThread(const WebTraceLocation& location, Task * task) 124 void postTaskToUpdatingThread(const WebTraceLocation& location, Pass OwnPtr<Closure> task)
126 { 125 {
127 MutexLocker locker(m_holderMutex); 126 MutexLocker locker(m_holderMutex);
128 ASSERT(m_holder); 127 ASSERT(m_holder);
129 m_holder->updatingThread()->postTask(location, task); 128 m_holder->updatingThread()->postTask(location, task);
130 } 129 }
131 130
132 private: 131 private:
133 Context() 132 Context()
134 : m_holder(nullptr) { } 133 : m_holder(nullptr) { }
135 String currentThreadName() 134 String currentThreadName()
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 Reader* obtainReaderInternal(Client*) { return new ReaderImpl(m_name , m_context); } 211 Reader* obtainReaderInternal(Client*) { return new ReaderImpl(m_name , m_context); }
213 const char* debugName() const override { return "ThreadingTestBase:: DataConsumerHandle"; } 212 const char* debugName() const override { return "ThreadingTestBase:: DataConsumerHandle"; }
214 213
215 const String m_name; 214 const String m_name;
216 RefPtr<Context> m_context; 215 RefPtr<Context> m_context;
217 }; 216 };
218 217
219 void resetReader() { m_reader = nullptr; } 218 void resetReader() { m_reader = nullptr; }
220 void signalDone() { m_waitableEvent->signal(); } 219 void signalDone() { m_waitableEvent->signal(); }
221 const String& result() { return m_context->result(); } 220 const String& result() { return m_context->result(); }
222 void postTaskToReadingThread(const WebTraceLocation& location, Task* tas k) 221 void postTaskToReadingThread(const WebTraceLocation& location, PassOwnPt r<Closure> task)
223 { 222 {
224 m_context->postTaskToReadingThread(location, task); 223 m_context->postTaskToReadingThread(location, task);
225 } 224 }
226 void postTaskToUpdatingThread(const WebTraceLocation& location, Task* ta sk) 225 void postTaskToUpdatingThread(const WebTraceLocation& location, PassOwnP tr<Closure> task)
227 { 226 {
228 m_context->postTaskToUpdatingThread(location, task); 227 m_context->postTaskToUpdatingThread(location, task);
229 } 228 }
230 void postTaskToReadingThreadAndWait(const WebTraceLocation& location, Ta sk* task) 229 void postTaskToReadingThreadAndWait(const WebTraceLocation& location, Pa ssOwnPtr<Closure> task)
231 { 230 {
232 postTaskToReadingThread(location, task); 231 postTaskToReadingThread(location, task);
233 m_waitableEvent->wait(); 232 m_waitableEvent->wait();
234 } 233 }
235 void postTaskToUpdatingThreadAndWait(const WebTraceLocation& location, T ask* task) 234 void postTaskToUpdatingThreadAndWait(const WebTraceLocation& location, P assOwnPtr<Closure> task)
236 { 235 {
237 postTaskToUpdatingThread(location, task); 236 postTaskToUpdatingThread(location, task);
238 m_waitableEvent->wait(); 237 m_waitableEvent->wait();
239 } 238 }
240 protected: 239 protected:
241 ThreadingTestBase() 240 ThreadingTestBase()
242 : m_context(Context::create()) { } 241 : m_context(Context::create()) { }
243 242
244 RefPtr<Context> m_context; 243 RefPtr<Context> m_context;
245 OwnPtr<WebDataConsumerHandle::Reader> m_reader; 244 OwnPtr<WebDataConsumerHandle::Reader> m_reader;
246 OwnPtr<WaitableEvent> m_waitableEvent; 245 OwnPtr<WaitableEvent> m_waitableEvent;
247 NoopClient m_client; 246 NoopClient m_client;
248 }; 247 };
249 248
250 class ThreadingHandleNotificationTest : public ThreadingTestBase, public Web DataConsumerHandle::Client { 249 class ThreadingHandleNotificationTest : public ThreadingTestBase, public Web DataConsumerHandle::Client {
251 public: 250 public:
252 using Self = ThreadingHandleNotificationTest; 251 using Self = ThreadingHandleNotificationTest;
253 static PassRefPtr<Self> create() { return adoptRef(new Self); } 252 static PassRefPtr<Self> create() { return adoptRef(new Self); }
254 253
255 void run(PassOwnPtr<WebDataConsumerHandle> handle) 254 void run(PassOwnPtr<WebDataConsumerHandle> handle)
256 { 255 {
257 ThreadHolder holder(this); 256 ThreadHolder holder(this);
258 m_waitableEvent = adoptPtr(new WaitableEvent()); 257 m_waitableEvent = adoptPtr(new WaitableEvent());
259 m_handle = handle; 258 m_handle = handle;
260 259
261 postTaskToReadingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeB ind(&Self::obtainReader, this))); 260 postTaskToReadingThreadAndWait(BLINK_FROM_HERE, threadSafeBind(&Self ::obtainReader, this));
262 } 261 }
263 262
264 private: 263 private:
265 ThreadingHandleNotificationTest() = default; 264 ThreadingHandleNotificationTest() = default;
266 void obtainReader() 265 void obtainReader()
267 { 266 {
268 m_reader = m_handle->obtainReader(this); 267 m_reader = m_handle->obtainReader(this);
269 } 268 }
270 void didGetReadable() override 269 void didGetReadable() override
271 { 270 {
272 postTaskToReadingThread(BLINK_FROM_HERE, new Task(threadSafeBind(&Se lf::resetReader, this))); 271 postTaskToReadingThread(BLINK_FROM_HERE, threadSafeBind(&Self::reset Reader, this));
273 postTaskToReadingThread(BLINK_FROM_HERE, new Task(threadSafeBind(&Se lf::signalDone, this))); 272 postTaskToReadingThread(BLINK_FROM_HERE, threadSafeBind(&Self::signa lDone, this));
274 } 273 }
275 274
276 OwnPtr<WebDataConsumerHandle> m_handle; 275 OwnPtr<WebDataConsumerHandle> m_handle;
277 }; 276 };
278 277
279 class ThreadingHandleNoNotificationTest : public ThreadingTestBase, public W ebDataConsumerHandle::Client { 278 class ThreadingHandleNoNotificationTest : public ThreadingTestBase, public W ebDataConsumerHandle::Client {
280 public: 279 public:
281 using Self = ThreadingHandleNoNotificationTest; 280 using Self = ThreadingHandleNoNotificationTest;
282 static PassRefPtr<Self> create() { return adoptRef(new Self); } 281 static PassRefPtr<Self> create() { return adoptRef(new Self); }
283 282
284 void run(PassOwnPtr<WebDataConsumerHandle> handle) 283 void run(PassOwnPtr<WebDataConsumerHandle> handle)
285 { 284 {
286 ThreadHolder holder(this); 285 ThreadHolder holder(this);
287 m_waitableEvent = adoptPtr(new WaitableEvent()); 286 m_waitableEvent = adoptPtr(new WaitableEvent());
288 m_handle = handle; 287 m_handle = handle;
289 288
290 postTaskToReadingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeB ind(&Self::obtainReader, this))); 289 postTaskToReadingThreadAndWait(BLINK_FROM_HERE, threadSafeBind(&Self ::obtainReader, this));
291 } 290 }
292 291
293 private: 292 private:
294 ThreadingHandleNoNotificationTest() = default; 293 ThreadingHandleNoNotificationTest() = default;
295 void obtainReader() 294 void obtainReader()
296 { 295 {
297 m_reader = m_handle->obtainReader(this); 296 m_reader = m_handle->obtainReader(this);
298 m_reader = nullptr; 297 m_reader = nullptr;
299 postTaskToReadingThread(BLINK_FROM_HERE, new Task(threadSafeBind(&Se lf::signalDone, this))); 298 postTaskToReadingThread(BLINK_FROM_HERE, threadSafeBind(&Self::signa lDone, this));
300 } 299 }
301 void didGetReadable() override 300 void didGetReadable() override
302 { 301 {
303 ASSERT_NOT_REACHED(); 302 ASSERT_NOT_REACHED();
304 } 303 }
305 304
306 OwnPtr<WebDataConsumerHandle> m_handle; 305 OwnPtr<WebDataConsumerHandle> m_handle;
307 }; 306 };
308 307
309 class MockFetchDataConsumerHandle : public FetchDataConsumerHandle { 308 class MockFetchDataConsumerHandle : public FetchDataConsumerHandle {
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 // where T is one of HandleReader and HandleTwophaseReader. 493 // where T is one of HandleReader and HandleTwophaseReader.
495 template <typename T> 494 template <typename T>
496 class HandleReaderRunner final { 495 class HandleReaderRunner final {
497 STACK_ALLOCATED(); 496 STACK_ALLOCATED();
498 public: 497 public:
499 explicit HandleReaderRunner(PassOwnPtr<WebDataConsumerHandle> handle) 498 explicit HandleReaderRunner(PassOwnPtr<WebDataConsumerHandle> handle)
500 : m_thread(adoptPtr(new Thread("reading thread"))) 499 : m_thread(adoptPtr(new Thread("reading thread")))
501 , m_event(adoptPtr(new WaitableEvent())) 500 , m_event(adoptPtr(new WaitableEvent()))
502 , m_isDone(false) 501 , m_isDone(false)
503 { 502 {
504 m_thread->thread()->postTask(BLINK_FROM_HERE, new Task(threadSafeBin d(&HandleReaderRunner::start, AllowCrossThreadAccess(this), handle))); 503 m_thread->thread()->postTask(BLINK_FROM_HERE, threadSafeBind(&Handle ReaderRunner::start, AllowCrossThreadAccess(this), handle));
505 } 504 }
506 ~HandleReaderRunner() 505 ~HandleReaderRunner()
507 { 506 {
508 wait(); 507 wait();
509 } 508 }
510 509
511 PassOwnPtr<HandleReadResult> wait() 510 PassOwnPtr<HandleReadResult> wait()
512 { 511 {
513 if (m_isDone) 512 if (m_isDone)
514 return nullptr; 513 return nullptr;
(...skipping 20 matching lines...) Expand all
535 OwnPtr<HandleReadResult> m_result; 534 OwnPtr<HandleReadResult> m_result;
536 bool m_isDone; 535 bool m_isDone;
537 536
538 OwnPtr<T> m_handleReader; 537 OwnPtr<T> m_handleReader;
539 }; 538 };
540 }; 539 };
541 540
542 } // namespace blink 541 } // namespace blink
543 542
544 #endif // DataConsumerHandleTestUtil_h 543 #endif // DataConsumerHandleTestUtil_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698