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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 MutexLocker locker(m_holderMutex); | 108 MutexLocker locker(m_holderMutex); |
109 ASSERT(!m_holder); | 109 ASSERT(!m_holder); |
110 m_holder = holder; | 110 m_holder = holder; |
111 } | 111 } |
112 void unregisterThreadHolder() | 112 void unregisterThreadHolder() |
113 { | 113 { |
114 MutexLocker locker(m_holderMutex); | 114 MutexLocker locker(m_holderMutex); |
115 ASSERT(m_holder); | 115 ASSERT(m_holder); |
116 m_holder = nullptr; | 116 m_holder = nullptr; |
117 } | 117 } |
118 void postTaskToReadingThread(const WebTraceLocation& location, PassO
wnPtr<Closure> task) | 118 void postTaskToReadingThread(const WebTraceLocation& location, PassO
wnPtr<CrossThreadClosure> task) |
119 { | 119 { |
120 MutexLocker locker(m_holderMutex); | 120 MutexLocker locker(m_holderMutex); |
121 ASSERT(m_holder); | 121 ASSERT(m_holder); |
122 m_holder->readingThread()->postTask(location, task); | 122 m_holder->readingThread()->postTask(location, task); |
123 } | 123 } |
124 void postTaskToUpdatingThread(const WebTraceLocation& location, Pass
OwnPtr<Closure> task) | 124 void postTaskToUpdatingThread(const WebTraceLocation& location, Pass
OwnPtr<CrossThreadClosure> task) |
125 { | 125 { |
126 MutexLocker locker(m_holderMutex); | 126 MutexLocker locker(m_holderMutex); |
127 ASSERT(m_holder); | 127 ASSERT(m_holder); |
128 m_holder->updatingThread()->postTask(location, task); | 128 m_holder->updatingThread()->postTask(location, task); |
129 } | 129 } |
130 | 130 |
131 private: | 131 private: |
132 Context() | 132 Context() |
133 : m_holder(nullptr) { } | 133 : m_holder(nullptr) { } |
134 String currentThreadName() | 134 String currentThreadName() |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 Reader* obtainReaderInternal(Client*) { return new ReaderImpl(m_name
, m_context); } | 211 Reader* obtainReaderInternal(Client*) { return new ReaderImpl(m_name
, m_context); } |
212 const char* debugName() const override { return "ThreadingTestBase::
DataConsumerHandle"; } | 212 const char* debugName() const override { return "ThreadingTestBase::
DataConsumerHandle"; } |
213 | 213 |
214 const String m_name; | 214 const String m_name; |
215 RefPtr<Context> m_context; | 215 RefPtr<Context> m_context; |
216 }; | 216 }; |
217 | 217 |
218 void resetReader() { m_reader = nullptr; } | 218 void resetReader() { m_reader = nullptr; } |
219 void signalDone() { m_waitableEvent->signal(); } | 219 void signalDone() { m_waitableEvent->signal(); } |
220 const String& result() { return m_context->result(); } | 220 const String& result() { return m_context->result(); } |
221 void postTaskToReadingThread(const WebTraceLocation& location, PassOwnPt
r<Closure> task) | 221 void postTaskToReadingThread(const WebTraceLocation& location, PassOwnPt
r<CrossThreadClosure> task) |
222 { | 222 { |
223 m_context->postTaskToReadingThread(location, task); | 223 m_context->postTaskToReadingThread(location, task); |
224 } | 224 } |
225 void postTaskToUpdatingThread(const WebTraceLocation& location, PassOwnP
tr<Closure> task) | 225 void postTaskToUpdatingThread(const WebTraceLocation& location, PassOwnP
tr<CrossThreadClosure> task) |
226 { | 226 { |
227 m_context->postTaskToUpdatingThread(location, task); | 227 m_context->postTaskToUpdatingThread(location, task); |
228 } | 228 } |
229 void postTaskToReadingThreadAndWait(const WebTraceLocation& location, Pa
ssOwnPtr<Closure> task) | 229 void postTaskToReadingThreadAndWait(const WebTraceLocation& location, Pa
ssOwnPtr<CrossThreadClosure> task) |
230 { | 230 { |
231 postTaskToReadingThread(location, task); | 231 postTaskToReadingThread(location, task); |
232 m_waitableEvent->wait(); | 232 m_waitableEvent->wait(); |
233 } | 233 } |
234 void postTaskToUpdatingThreadAndWait(const WebTraceLocation& location, P
assOwnPtr<Closure> task) | 234 void postTaskToUpdatingThreadAndWait(const WebTraceLocation& location, P
assOwnPtr<CrossThreadClosure> task) |
235 { | 235 { |
236 postTaskToUpdatingThread(location, task); | 236 postTaskToUpdatingThread(location, task); |
237 m_waitableEvent->wait(); | 237 m_waitableEvent->wait(); |
238 } | 238 } |
239 protected: | 239 protected: |
240 ThreadingTestBase() | 240 ThreadingTestBase() |
241 : m_context(Context::create()) { } | 241 : m_context(Context::create()) { } |
242 | 242 |
243 RefPtr<Context> m_context; | 243 RefPtr<Context> m_context; |
244 OwnPtr<WebDataConsumerHandle::Reader> m_reader; | 244 OwnPtr<WebDataConsumerHandle::Reader> m_reader; |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 OwnPtr<HandleReadResult> m_result; | 534 OwnPtr<HandleReadResult> m_result; |
535 bool m_isDone; | 535 bool m_isDone; |
536 | 536 |
537 OwnPtr<T> m_handleReader; | 537 OwnPtr<T> m_handleReader; |
538 }; | 538 }; |
539 }; | 539 }; |
540 | 540 |
541 } // namespace blink | 541 } // namespace blink |
542 | 542 |
543 #endif // DataConsumerHandleTestUtil_h | 543 #endif // DataConsumerHandleTestUtil_h |
OLD | NEW |