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 #include "modules/fetch/DataConsumerHandleTestUtil.h" | 5 #include "modules/fetch/DataConsumerHandleTestUtil.h" |
6 | 6 |
7 #include "bindings/core/v8/DOMWrapperWorld.h" | 7 #include "bindings/core/v8/DOMWrapperWorld.h" |
8 | 8 |
9 namespace blink { | 9 namespace blink { |
10 | 10 |
11 DataConsumerHandleTestUtil::Thread::Thread(const char* name, InitializationPolic
y initializationPolicy) | 11 DataConsumerHandleTestUtil::Thread::Thread(const char* name, InitializationPolic
y initializationPolicy) |
12 : m_thread(WebThreadSupportingGC::create(name)) | 12 : m_thread(WebThreadSupportingGC::create(name)) |
13 , m_initializationPolicy(initializationPolicy) | 13 , m_initializationPolicy(initializationPolicy) |
14 , m_waitableEvent(adoptPtr(new WaitableEvent())) | 14 , m_waitableEvent(adoptPtr(new WaitableEvent())) |
15 { | 15 { |
16 m_thread->postTask(BLINK_FROM_HERE, new Task(threadSafeBind(&Thread::initial
ize, AllowCrossThreadAccess(this)))); | 16 m_thread->postTask(BLINK_FROM_HERE, threadSafeBind(&Thread::initialize, Allo
wCrossThreadAccess(this))); |
17 m_waitableEvent->wait(); | 17 m_waitableEvent->wait(); |
18 } | 18 } |
19 | 19 |
20 DataConsumerHandleTestUtil::Thread::~Thread() | 20 DataConsumerHandleTestUtil::Thread::~Thread() |
21 { | 21 { |
22 m_thread->postTask(BLINK_FROM_HERE, new Task(threadSafeBind(&Thread::shutdow
n, AllowCrossThreadAccess(this)))); | 22 m_thread->postTask(BLINK_FROM_HERE, threadSafeBind(&Thread::shutdown, AllowC
rossThreadAccess(this))); |
23 m_waitableEvent->wait(); | 23 m_waitableEvent->wait(); |
24 } | 24 } |
25 | 25 |
26 void DataConsumerHandleTestUtil::Thread::initialize() | 26 void DataConsumerHandleTestUtil::Thread::initialize() |
27 { | 27 { |
28 if (m_initializationPolicy >= ScriptExecution) { | 28 if (m_initializationPolicy >= ScriptExecution) { |
29 m_isolateHolder = adoptPtr(new gin::IsolateHolder()); | 29 m_isolateHolder = adoptPtr(new gin::IsolateHolder()); |
30 isolate()->Enter(); | 30 isolate()->Enter(); |
31 } | 31 } |
32 m_thread->initialize(); | 32 m_thread->initialize(); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 } else { | 186 } else { |
187 m_offset += size; | 187 m_offset += size; |
188 } | 188 } |
189 } | 189 } |
190 | 190 |
191 void DataConsumerHandleTestUtil::ReplayingHandle::Context::notify() | 191 void DataConsumerHandleTestUtil::ReplayingHandle::Context::notify() |
192 { | 192 { |
193 if (!m_client) | 193 if (!m_client) |
194 return; | 194 return; |
195 ASSERT(m_readerThread); | 195 ASSERT(m_readerThread); |
196 m_readerThread->taskRunner()->postTask(BLINK_FROM_HERE, new Task(threadSafeB
ind(&Context::notifyInternal, this))); | 196 m_readerThread->taskRunner()->postTask(BLINK_FROM_HERE, threadSafeBind(&Cont
ext::notifyInternal, this)); |
197 } | 197 } |
198 | 198 |
199 void DataConsumerHandleTestUtil::ReplayingHandle::Context::notifyInternal() | 199 void DataConsumerHandleTestUtil::ReplayingHandle::Context::notifyInternal() |
200 { | 200 { |
201 { | 201 { |
202 MutexLocker locker(m_mutex); | 202 MutexLocker locker(m_mutex); |
203 if (!m_client || !m_readerThread->isCurrentThread()) { | 203 if (!m_client || !m_readerThread->isCurrentThread()) { |
204 // There is no client, or a new reader is attached. | 204 // There is no client, or a new reader is attached. |
205 return; | 205 return; |
206 } | 206 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 size_t size; | 243 size_t size; |
244 r = m_reader->read(buffer, sizeof(buffer), WebDataConsumerHandle::FlagNo
ne, &size); | 244 r = m_reader->read(buffer, sizeof(buffer), WebDataConsumerHandle::FlagNo
ne, &size); |
245 if (r == WebDataConsumerHandle::ShouldWait) | 245 if (r == WebDataConsumerHandle::ShouldWait) |
246 return; | 246 return; |
247 if (r != WebDataConsumerHandle::Ok) | 247 if (r != WebDataConsumerHandle::Ok) |
248 break; | 248 break; |
249 m_data.append(buffer, size); | 249 m_data.append(buffer, size); |
250 } | 250 } |
251 OwnPtr<HandleReadResult> result = adoptPtr(new HandleReadResult(r, m_data)); | 251 OwnPtr<HandleReadResult> result = adoptPtr(new HandleReadResult(r, m_data)); |
252 m_data.clear(); | 252 m_data.clear(); |
253 Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_HERE
, new Task(bind(&HandleReader::runOnFinishedReading, this, result.release()))); | 253 Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_HERE
, bind(&HandleReader::runOnFinishedReading, this, result.release())); |
254 m_reader = nullptr; | 254 m_reader = nullptr; |
255 } | 255 } |
256 | 256 |
257 void DataConsumerHandleTestUtil::HandleReader::runOnFinishedReading(PassOwnPtr<H
andleReadResult> result) | 257 void DataConsumerHandleTestUtil::HandleReader::runOnFinishedReading(PassOwnPtr<H
andleReadResult> result) |
258 { | 258 { |
259 ASSERT(m_onFinishedReading); | 259 ASSERT(m_onFinishedReading); |
260 (*m_onFinishedReading.release())(result); | 260 (*m_onFinishedReading.release())(result); |
261 } | 261 } |
262 | 262 |
263 DataConsumerHandleTestUtil::HandleTwoPhaseReader::HandleTwoPhaseReader(PassOwnPt
r<WebDataConsumerHandle> handle, PassOwnPtr<OnFinishedReading> onFinishedReading
) | 263 DataConsumerHandleTestUtil::HandleTwoPhaseReader::HandleTwoPhaseReader(PassOwnPt
r<WebDataConsumerHandle> handle, PassOwnPtr<OnFinishedReading> onFinishedReading
) |
(...skipping 13 matching lines...) Expand all Loading... |
277 return; | 277 return; |
278 if (r != WebDataConsumerHandle::Ok) | 278 if (r != WebDataConsumerHandle::Ok) |
279 break; | 279 break; |
280 // Read smaller than available in order to test |endRead|. | 280 // Read smaller than available in order to test |endRead|. |
281 size_t readSize = std::min(size, std::max(size * 2 / 3, static_cast<size
_t>(1))); | 281 size_t readSize = std::min(size, std::max(size * 2 / 3, static_cast<size
_t>(1))); |
282 m_data.append(static_cast<const char*>(buffer), readSize); | 282 m_data.append(static_cast<const char*>(buffer), readSize); |
283 m_reader->endRead(readSize); | 283 m_reader->endRead(readSize); |
284 } | 284 } |
285 OwnPtr<HandleReadResult> result = adoptPtr(new HandleReadResult(r, m_data)); | 285 OwnPtr<HandleReadResult> result = adoptPtr(new HandleReadResult(r, m_data)); |
286 m_data.clear(); | 286 m_data.clear(); |
287 Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_HERE
, new Task(bind(&HandleTwoPhaseReader::runOnFinishedReading, this, result.releas
e()))); | 287 Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_HERE
, bind(&HandleTwoPhaseReader::runOnFinishedReading, this, result.release())); |
288 m_reader = nullptr; | 288 m_reader = nullptr; |
289 } | 289 } |
290 | 290 |
291 void DataConsumerHandleTestUtil::HandleTwoPhaseReader::runOnFinishedReading(Pass
OwnPtr<HandleReadResult> result) | 291 void DataConsumerHandleTestUtil::HandleTwoPhaseReader::runOnFinishedReading(Pass
OwnPtr<HandleReadResult> result) |
292 { | 292 { |
293 ASSERT(m_onFinishedReading); | 293 ASSERT(m_onFinishedReading); |
294 (*m_onFinishedReading.release())(result); | 294 (*m_onFinishedReading.release())(result); |
295 } | 295 } |
296 | 296 |
297 } // namespace blink | 297 } // namespace blink |
OLD | NEW |