OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/loader/ThreadableLoader.h" | 5 #include "core/loader/ThreadableLoader.h" |
6 | 6 |
7 #include "core/dom/ExecutionContextTask.h" | 7 #include "core/dom/ExecutionContextTask.h" |
8 #include "core/fetch/MemoryCache.h" | 8 #include "core/fetch/MemoryCache.h" |
9 #include "core/fetch/ResourceLoaderOptions.h" | 9 #include "core/fetch/ResourceLoaderOptions.h" |
10 #include "core/loader/DocumentThreadableLoader.h" | 10 #include "core/loader/DocumentThreadableLoader.h" |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 &WorkerThreadableLoaderTestHelper::workerStartLoader, | 188 &WorkerThreadableLoaderTestHelper::workerStartLoader, |
189 crossThreadUnretained(this), | 189 crossThreadUnretained(this), |
190 crossThreadUnretained(completionEvent.get()), | 190 crossThreadUnretained(completionEvent.get()), |
191 request)); | 191 request)); |
192 completionEvent->wait(); | 192 completionEvent->wait(); |
193 } | 193 } |
194 | 194 |
195 // Must be called on the worker thread. | 195 // Must be called on the worker thread. |
196 void cancelLoader() override | 196 void cancelLoader() override |
197 { | 197 { |
198 ASSERT(m_workerThread); | 198 DCHECK(m_workerThread); |
199 ASSERT(m_workerThread->isCurrentThread()); | 199 DCHECK(m_workerThread->isCurrentThread()); |
200 m_loader->cancel(); | 200 m_loader->cancel(); |
201 } | 201 } |
202 | 202 |
203 void cancelAndClearLoader() override | 203 void cancelAndClearLoader() override |
204 { | 204 { |
205 DCHECK(m_workerThread); | 205 DCHECK(m_workerThread); |
206 DCHECK(m_workerThread->isCurrentThread()); | 206 DCHECK(m_workerThread->isCurrentThread()); |
207 m_loader->cancel(); | 207 m_loader->cancel(); |
208 m_loader = nullptr; | 208 m_loader = nullptr; |
209 } | 209 } |
210 | 210 |
211 // Must be called on the worker thread. | 211 // Must be called on the worker thread. |
212 void clearLoader() override | 212 void clearLoader() override |
213 { | 213 { |
214 ASSERT(m_workerThread); | 214 DCHECK(m_workerThread); |
215 ASSERT(m_workerThread->isCurrentThread()); | 215 DCHECK(m_workerThread->isCurrentThread()); |
216 m_loader = nullptr; | 216 m_loader = nullptr; |
217 } | 217 } |
218 | 218 |
219 Checkpoint& checkpoint() override | 219 Checkpoint& checkpoint() override |
220 { | 220 { |
221 return m_checkpoint; | 221 return m_checkpoint; |
222 } | 222 } |
223 | 223 |
224 void callCheckpoint(int n) override | 224 void callCheckpoint(int n) override |
225 { | 225 { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 void expectWorkerLifetimeReportingCalls() | 274 void expectWorkerLifetimeReportingCalls() |
275 { | 275 { |
276 EXPECT_CALL(*m_mockWorkerReportingProxy, workerGlobalScopeStarted(_)).Ti
mes(1); | 276 EXPECT_CALL(*m_mockWorkerReportingProxy, workerGlobalScopeStarted(_)).Ti
mes(1); |
277 EXPECT_CALL(*m_mockWorkerReportingProxy, didEvaluateWorkerScript(true)).
Times(1); | 277 EXPECT_CALL(*m_mockWorkerReportingProxy, didEvaluateWorkerScript(true)).
Times(1); |
278 EXPECT_CALL(*m_mockWorkerReportingProxy, workerThreadTerminated()).Times
(1); | 278 EXPECT_CALL(*m_mockWorkerReportingProxy, workerThreadTerminated()).Times
(1); |
279 EXPECT_CALL(*m_mockWorkerReportingProxy, willDestroyWorkerGlobalScope())
.Times(1); | 279 EXPECT_CALL(*m_mockWorkerReportingProxy, willDestroyWorkerGlobalScope())
.Times(1); |
280 } | 280 } |
281 | 281 |
282 void workerCreateLoader(ThreadableLoaderClient* client, WaitableEvent* event
, CrossOriginRequestPolicy crossOriginRequestPolicy) | 282 void workerCreateLoader(ThreadableLoaderClient* client, WaitableEvent* event
, CrossOriginRequestPolicy crossOriginRequestPolicy) |
283 { | 283 { |
284 ASSERT(m_workerThread); | 284 DCHECK(m_workerThread); |
285 ASSERT(m_workerThread->isCurrentThread()); | 285 DCHECK(m_workerThread->isCurrentThread()); |
286 | 286 |
287 ThreadableLoaderOptions options; | 287 ThreadableLoaderOptions options; |
288 options.crossOriginRequestPolicy = crossOriginRequestPolicy; | 288 options.crossOriginRequestPolicy = crossOriginRequestPolicy; |
289 ResourceLoaderOptions resourceLoaderOptions; | 289 ResourceLoaderOptions resourceLoaderOptions; |
290 | 290 |
291 // Ensure that WorkerThreadableLoader is created. | 291 // Ensure that WorkerThreadableLoader is created. |
292 // ThreadableLoader::create() determines whether it should create | 292 // ThreadableLoader::create() determines whether it should create |
293 // a DocumentThreadableLoader or WorkerThreadableLoader based on | 293 // a DocumentThreadableLoader or WorkerThreadableLoader based on |
294 // isWorkerGlobalScope(). | 294 // isWorkerGlobalScope(). |
295 DCHECK(m_workerThread->globalScope()->isWorkerGlobalScope()); | 295 DCHECK(m_workerThread->globalScope()->isWorkerGlobalScope()); |
296 | 296 |
297 m_loader = ThreadableLoader::create(*m_workerThread->globalScope(), clie
nt, options, resourceLoaderOptions); | 297 m_loader = ThreadableLoader::create(*m_workerThread->globalScope(), clie
nt, options, resourceLoaderOptions); |
298 ASSERT(m_loader); | 298 DCHECK(m_loader); |
299 event->signal(); | 299 event->signal(); |
300 } | 300 } |
301 | 301 |
302 void workerStartLoader(WaitableEvent* event, std::unique_ptr<CrossThreadReso
urceRequestData> requestData) | 302 void workerStartLoader(WaitableEvent* event, std::unique_ptr<CrossThreadReso
urceRequestData> requestData) |
303 { | 303 { |
304 ASSERT(m_workerThread); | 304 DCHECK(m_workerThread); |
305 ASSERT(m_workerThread->isCurrentThread()); | 305 DCHECK(m_workerThread->isCurrentThread()); |
306 | 306 |
307 ResourceRequest request(requestData.get()); | 307 ResourceRequest request(requestData.get()); |
308 m_loader->start(request); | 308 m_loader->start(request); |
309 event->signal(); | 309 event->signal(); |
310 } | 310 } |
311 | 311 |
312 void workerCallCheckpoint(WaitableEvent* event, int n) | 312 void workerCallCheckpoint(WaitableEvent* event, int n) |
313 { | 313 { |
314 ASSERT(m_workerThread); | 314 DCHECK(m_workerThread); |
315 ASSERT(m_workerThread->isCurrentThread()); | 315 DCHECK(m_workerThread->isCurrentThread()); |
316 m_checkpoint.Call(n); | 316 m_checkpoint.Call(n); |
317 event->signal(); | 317 event->signal(); |
318 } | 318 } |
319 | 319 |
320 // WorkerLoaderProxyProvider methods. | 320 // WorkerLoaderProxyProvider methods. |
321 void postTaskToLoader(const WebTraceLocation& location, std::unique_ptr<Exec
utionContextTask> task) override | 321 void postTaskToLoader(const WebTraceLocation& location, std::unique_ptr<Exec
utionContextTask> task) override |
322 { | 322 { |
323 ASSERT(m_workerThread); | 323 DCHECK(m_workerThread); |
324 ASSERT(m_workerThread->isCurrentThread()); | 324 DCHECK(m_workerThread->isCurrentThread()); |
325 document().postTask(location, std::move(task)); | 325 document().postTask(location, std::move(task)); |
326 } | 326 } |
327 | 327 |
328 void postTaskToWorkerGlobalScope(const WebTraceLocation& location, std::uniq
ue_ptr<ExecutionContextTask> task) override | 328 void postTaskToWorkerGlobalScope(const WebTraceLocation& location, std::uniq
ue_ptr<ExecutionContextTask> task) override |
329 { | 329 { |
330 ASSERT(m_workerThread); | 330 DCHECK(m_workerThread); |
331 m_workerThread->postTask(location, std::move(task)); | 331 m_workerThread->postTask(location, std::move(task)); |
332 } | 332 } |
333 | 333 |
334 RefPtr<SecurityOrigin> m_securityOrigin; | 334 RefPtr<SecurityOrigin> m_securityOrigin; |
335 std::unique_ptr<MockWorkerReportingProxy> m_mockWorkerReportingProxy; | 335 std::unique_ptr<MockWorkerReportingProxy> m_mockWorkerReportingProxy; |
336 std::unique_ptr<WorkerThreadForTest> m_workerThread; | 336 std::unique_ptr<WorkerThreadForTest> m_workerThread; |
337 | 337 |
338 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; | 338 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; |
339 Checkpoint m_checkpoint; | 339 Checkpoint m_checkpoint; |
340 // |m_loader| must be touched only from the worker thread only. | 340 // |m_loader| must be touched only from the worker thread only. |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 // test is not saying that didFailAccessControlCheck should be dispatched | 871 // test is not saying that didFailAccessControlCheck should be dispatched |
872 // synchronously, but is saying that even when a response is served | 872 // synchronously, but is saying that even when a response is served |
873 // synchronously it should not lead to a crash. | 873 // synchronously it should not lead to a crash. |
874 startLoader(KURL(KURL(), "about:blank")); | 874 startLoader(KURL(KURL(), "about:blank")); |
875 callCheckpoint(2); | 875 callCheckpoint(2); |
876 } | 876 } |
877 | 877 |
878 } // namespace | 878 } // namespace |
879 | 879 |
880 } // namespace blink | 880 } // namespace blink |
OLD | NEW |