OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009, 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2009, 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 DCHECK(client); | 217 DCHECK(client); |
218 } | 218 } |
219 | 219 |
220 void WorkerThreadableLoader::loadResourceSynchronously(WorkerGlobalScope& worker
GlobalScope, const ResourceRequest& request, ThreadableLoaderClient& client, con
st ThreadableLoaderOptions& options, const ResourceLoaderOptions& resourceLoader
Options) | 220 void WorkerThreadableLoader::loadResourceSynchronously(WorkerGlobalScope& worker
GlobalScope, const ResourceRequest& request, ThreadableLoaderClient& client, con
st ThreadableLoaderOptions& options, const ResourceLoaderOptions& resourceLoader
Options) |
221 { | 221 { |
222 (new WorkerThreadableLoader(workerGlobalScope, &client, options, resourceLoa
derOptions, LoadSynchronously))->start(request); | 222 (new WorkerThreadableLoader(workerGlobalScope, &client, options, resourceLoa
derOptions, LoadSynchronously))->start(request); |
223 } | 223 } |
224 | 224 |
225 WorkerThreadableLoader::~WorkerThreadableLoader() | 225 WorkerThreadableLoader::~WorkerThreadableLoader() |
226 { | 226 { |
227 DCHECK(!m_peer); | 227 DCHECK(!m_mainThreadLoaderHolder); |
228 DCHECK(!m_client); | 228 DCHECK(!m_client); |
229 } | 229 } |
230 | 230 |
231 void WorkerThreadableLoader::start(const ResourceRequest& originalRequest) | 231 void WorkerThreadableLoader::start(const ResourceRequest& originalRequest) |
232 { | 232 { |
233 ResourceRequest request(originalRequest); | 233 ResourceRequest request(originalRequest); |
234 if (!request.didSetHTTPReferrer()) | 234 if (!request.didSetHTTPReferrer()) |
235 request.setHTTPReferrer(SecurityPolicy::generateReferrer(m_workerGlobalS
cope->getReferrerPolicy(), request.url(), m_workerGlobalScope->outgoingReferrer(
))); | 235 request.setHTTPReferrer(SecurityPolicy::generateReferrer(m_workerGlobalS
cope->getReferrerPolicy(), request.url(), m_workerGlobalScope->outgoingReferrer(
))); |
236 | 236 |
237 DCHECK(!isMainThread()); | 237 DCHECK(!isMainThread()); |
238 RefPtr<WaitableEventWithTasks> eventWithTasks; | 238 RefPtr<WaitableEventWithTasks> eventWithTasks; |
239 if (m_blockingBehavior == LoadSynchronously) | 239 if (m_blockingBehavior == LoadSynchronously) |
240 eventWithTasks = WaitableEventWithTasks::create(); | 240 eventWithTasks = WaitableEventWithTasks::create(); |
241 | 241 |
242 m_workerLoaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThreadTask
( | 242 m_workerLoaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThreadTask
( |
243 &Peer::createAndStart, | 243 &MainThreadLoaderHolder::createAndStart, |
244 wrapCrossThreadPersistent(this), | 244 wrapCrossThreadPersistent(this), |
245 m_workerLoaderProxy, | 245 m_workerLoaderProxy, |
246 wrapCrossThreadPersistent(m_workerGlobalScope->thread()->getWorkerThread
LifecycleContext()), | 246 wrapCrossThreadPersistent(m_workerGlobalScope->thread()->getWorkerThread
LifecycleContext()), |
247 request, | 247 request, |
248 m_threadableLoaderOptions, | 248 m_threadableLoaderOptions, |
249 m_resourceLoaderOptions, | 249 m_resourceLoaderOptions, |
250 eventWithTasks)); | 250 eventWithTasks)); |
251 | 251 |
252 if (m_blockingBehavior == LoadAsynchronously) | 252 if (m_blockingBehavior == LoadAsynchronously) |
253 return; | 253 return; |
(...skipping 17 matching lines...) Expand all Loading... |
271 | 271 |
272 // m_clientTask contains only CallClosureTasks. So, it's ok to pass | 272 // m_clientTask contains only CallClosureTasks. So, it's ok to pass |
273 // the nullptr. | 273 // the nullptr. |
274 task.m_task->performTask(nullptr); | 274 task.m_task->performTask(nullptr); |
275 } | 275 } |
276 } | 276 } |
277 | 277 |
278 void WorkerThreadableLoader::overrideTimeout(unsigned long timeoutMilliseconds) | 278 void WorkerThreadableLoader::overrideTimeout(unsigned long timeoutMilliseconds) |
279 { | 279 { |
280 DCHECK(!isMainThread()); | 280 DCHECK(!isMainThread()); |
281 if (!m_peer) | 281 if (!m_mainThreadLoaderHolder) |
282 return; | 282 return; |
283 m_workerLoaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThreadTask
(&Peer::overrideTimeout, m_peer, timeoutMilliseconds)); | 283 m_workerLoaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThreadTask
(&MainThreadLoaderHolder::overrideTimeout, m_mainThreadLoaderHolder, timeoutMill
iseconds)); |
284 } | 284 } |
285 | 285 |
286 void WorkerThreadableLoader::cancel() | 286 void WorkerThreadableLoader::cancel() |
287 { | 287 { |
288 DCHECK(!isMainThread()); | 288 DCHECK(!isMainThread()); |
289 if (m_peer) { | 289 if (m_mainThreadLoaderHolder) { |
290 m_workerLoaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThread
Task(&Peer::cancel, m_peer)); | 290 m_workerLoaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThread
Task(&MainThreadLoaderHolder::cancel, m_mainThreadLoaderHolder)); |
291 m_peer = nullptr; | 291 m_mainThreadLoaderHolder = nullptr; |
292 } | 292 } |
293 | 293 |
294 if (!m_client) | 294 if (!m_client) |
295 return; | 295 return; |
296 | 296 |
297 // If the client hasn't reached a termination state, then transition it | 297 // If the client hasn't reached a termination state, then transition it |
298 // by sending a cancellation error. | 298 // by sending a cancellation error. |
299 // Note: no more client callbacks will be done after this method -- the | 299 // Note: no more client callbacks will be done after this method -- the |
300 // clearClient() call ensures that. | 300 // clearClient() call ensures that. |
301 ResourceError error(String(), 0, String(), String()); | 301 ResourceError error(String(), 0, String(), String()); |
302 error.setIsCancellation(true); | 302 error.setIsCancellation(true); |
303 didFail(error); | 303 didFail(error); |
304 DCHECK(!m_client); | 304 DCHECK(!m_client); |
305 } | 305 } |
306 | 306 |
307 void WorkerThreadableLoader::didStart(Peer* peer) | 307 void WorkerThreadableLoader::didStart(MainThreadLoaderHolder* mainThreadLoaderHo
lder) |
308 { | 308 { |
309 DCHECK(!isMainThread()); | 309 DCHECK(!isMainThread()); |
310 DCHECK(!m_peer); | 310 DCHECK(!m_mainThreadLoaderHolder); |
311 DCHECK(peer); | 311 DCHECK(mainThreadLoaderHolder); |
312 if (!m_client) { | 312 if (!m_client) { |
313 // The thread is terminating. | 313 // The thread is terminating. |
314 m_workerLoaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThread
Task(&Peer::cancel, wrapCrossThreadPersistent(peer))); | 314 m_workerLoaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThread
Task(&MainThreadLoaderHolder::cancel, wrapCrossThreadPersistent(mainThreadLoader
Holder))); |
315 return; | 315 return; |
316 } | 316 } |
317 | 317 |
318 m_peer = peer; | 318 m_mainThreadLoaderHolder = mainThreadLoaderHolder; |
319 } | 319 } |
320 | 320 |
321 void WorkerThreadableLoader::didSendData(unsigned long long bytesSent, unsigned
long long totalBytesToBeSent) | 321 void WorkerThreadableLoader::didSendData(unsigned long long bytesSent, unsigned
long long totalBytesToBeSent) |
322 { | 322 { |
323 DCHECK(!isMainThread()); | 323 DCHECK(!isMainThread()); |
324 if (!m_client) | 324 if (!m_client) |
325 return; | 325 return; |
326 m_client->didSendData(bytesSent, totalBytesToBeSent); | 326 m_client->didSendData(bytesSent, totalBytesToBeSent); |
327 } | 327 } |
328 | 328 |
(...skipping 23 matching lines...) Expand all Loading... |
352 m_client->didReceiveCachedMetadata(data->data(), data->size()); | 352 m_client->didReceiveCachedMetadata(data->data(), data->size()); |
353 } | 353 } |
354 | 354 |
355 void WorkerThreadableLoader::didFinishLoading(unsigned long identifier, double f
inishTime) | 355 void WorkerThreadableLoader::didFinishLoading(unsigned long identifier, double f
inishTime) |
356 { | 356 { |
357 DCHECK(!isMainThread()); | 357 DCHECK(!isMainThread()); |
358 if (!m_client) | 358 if (!m_client) |
359 return; | 359 return; |
360 auto* client = m_client; | 360 auto* client = m_client; |
361 m_client = nullptr; | 361 m_client = nullptr; |
362 m_peer = nullptr; | 362 m_mainThreadLoaderHolder = nullptr; |
363 client->didFinishLoading(identifier, finishTime); | 363 client->didFinishLoading(identifier, finishTime); |
364 } | 364 } |
365 | 365 |
366 void WorkerThreadableLoader::didFail(const ResourceError& error) | 366 void WorkerThreadableLoader::didFail(const ResourceError& error) |
367 { | 367 { |
368 DCHECK(!isMainThread()); | 368 DCHECK(!isMainThread()); |
369 if (!m_client) | 369 if (!m_client) |
370 return; | 370 return; |
371 auto* client = m_client; | 371 auto* client = m_client; |
372 m_client = nullptr; | 372 m_client = nullptr; |
373 m_peer = nullptr; | 373 m_mainThreadLoaderHolder = nullptr; |
374 client->didFail(error); | 374 client->didFail(error); |
375 } | 375 } |
376 | 376 |
377 void WorkerThreadableLoader::didFailAccessControlCheck(const ResourceError& erro
r) | 377 void WorkerThreadableLoader::didFailAccessControlCheck(const ResourceError& erro
r) |
378 { | 378 { |
379 DCHECK(!isMainThread()); | 379 DCHECK(!isMainThread()); |
380 if (!m_client) | 380 if (!m_client) |
381 return; | 381 return; |
382 auto* client = m_client; | 382 auto* client = m_client; |
383 m_client = nullptr; | 383 m_client = nullptr; |
384 m_peer = nullptr; | 384 m_mainThreadLoaderHolder = nullptr; |
385 client->didFailAccessControlCheck(error); | 385 client->didFailAccessControlCheck(error); |
386 } | 386 } |
387 | 387 |
388 void WorkerThreadableLoader::didFailRedirectCheck() | 388 void WorkerThreadableLoader::didFailRedirectCheck() |
389 { | 389 { |
390 DCHECK(!isMainThread()); | 390 DCHECK(!isMainThread()); |
391 if (!m_client) | 391 if (!m_client) |
392 return; | 392 return; |
393 auto* client = m_client; | 393 auto* client = m_client; |
394 m_client = nullptr; | 394 m_client = nullptr; |
395 m_peer = nullptr; | 395 m_mainThreadLoaderHolder = nullptr; |
396 client->didFailRedirectCheck(); | 396 client->didFailRedirectCheck(); |
397 } | 397 } |
398 | 398 |
399 void WorkerThreadableLoader::didDownloadData(int dataLength) | 399 void WorkerThreadableLoader::didDownloadData(int dataLength) |
400 { | 400 { |
401 DCHECK(!isMainThread()); | 401 DCHECK(!isMainThread()); |
402 if (!m_client) | 402 if (!m_client) |
403 return; | 403 return; |
404 m_client->didDownloadData(dataLength); | 404 m_client->didDownloadData(dataLength); |
405 } | 405 } |
406 | 406 |
407 void WorkerThreadableLoader::didReceiveResourceTiming(std::unique_ptr<CrossThrea
dResourceTimingInfoData> timingData) | 407 void WorkerThreadableLoader::didReceiveResourceTiming(std::unique_ptr<CrossThrea
dResourceTimingInfoData> timingData) |
408 { | 408 { |
409 DCHECK(!isMainThread()); | 409 DCHECK(!isMainThread()); |
410 if (!m_client) | 410 if (!m_client) |
411 return; | 411 return; |
412 std::unique_ptr<ResourceTimingInfo> info(ResourceTimingInfo::adopt(std::move
(timingData))); | 412 std::unique_ptr<ResourceTimingInfo> info(ResourceTimingInfo::adopt(std::move
(timingData))); |
413 WorkerGlobalScopePerformance::performance(*m_workerGlobalScope)->addResource
Timing(*info); | 413 WorkerGlobalScopePerformance::performance(*m_workerGlobalScope)->addResource
Timing(*info); |
414 m_client->didReceiveResourceTiming(*info); | 414 m_client->didReceiveResourceTiming(*info); |
415 } | 415 } |
416 | 416 |
417 DEFINE_TRACE(WorkerThreadableLoader) | 417 DEFINE_TRACE(WorkerThreadableLoader) |
418 { | 418 { |
419 visitor->trace(m_workerGlobalScope); | 419 visitor->trace(m_workerGlobalScope); |
420 ThreadableLoader::trace(visitor); | 420 ThreadableLoader::trace(visitor); |
421 } | 421 } |
422 | 422 |
423 void WorkerThreadableLoader::Peer::createAndStart( | 423 void WorkerThreadableLoader::MainThreadLoaderHolder::createAndStart( |
424 WorkerThreadableLoader* workerLoader, | 424 WorkerThreadableLoader* workerLoader, |
425 PassRefPtr<WorkerLoaderProxy> passLoaderProxy, | 425 PassRefPtr<WorkerLoaderProxy> passLoaderProxy, |
426 WorkerThreadLifecycleContext* workerThreadLifecycleContext, | 426 WorkerThreadLifecycleContext* workerThreadLifecycleContext, |
427 std::unique_ptr<CrossThreadResourceRequestData> request, | 427 std::unique_ptr<CrossThreadResourceRequestData> request, |
428 const ThreadableLoaderOptions& options, | 428 const ThreadableLoaderOptions& options, |
429 const ResourceLoaderOptions& resourceLoaderOptions, | 429 const ResourceLoaderOptions& resourceLoaderOptions, |
430 PassRefPtr<WaitableEventWithTasks> eventWithTasks, | 430 PassRefPtr<WaitableEventWithTasks> eventWithTasks, |
431 ExecutionContext* executionContext) | 431 ExecutionContext* executionContext) |
432 { | 432 { |
433 DCHECK(isMainThread()); | 433 DCHECK(isMainThread()); |
434 TaskForwarder* forwarder; | 434 TaskForwarder* forwarder; |
435 RefPtr<WorkerLoaderProxy> loaderProxy = passLoaderProxy; | 435 RefPtr<WorkerLoaderProxy> loaderProxy = passLoaderProxy; |
436 if (eventWithTasks) | 436 if (eventWithTasks) |
437 forwarder = new SyncTaskForwarder(eventWithTasks); | 437 forwarder = new SyncTaskForwarder(eventWithTasks); |
438 else | 438 else |
439 forwarder = new AsyncTaskForwarder(loaderProxy); | 439 forwarder = new AsyncTaskForwarder(loaderProxy); |
440 | 440 |
441 Peer* peer = new Peer(forwarder, workerThreadLifecycleContext); | 441 MainThreadLoaderHolder* mainThreadLoaderHolder = new MainThreadLoaderHolder(
forwarder, workerThreadLifecycleContext); |
442 if (peer->wasContextDestroyedBeforeObserverCreation()) { | 442 if (mainThreadLoaderHolder->wasContextDestroyedBeforeObserverCreation()) { |
443 // The thread is already terminating. | 443 // The thread is already terminating. |
444 forwarder->abort(); | 444 forwarder->abort(); |
445 peer->m_forwarder = nullptr; | 445 mainThreadLoaderHolder->m_forwarder = nullptr; |
446 return; | 446 return; |
447 } | 447 } |
448 peer->m_workerLoader = workerLoader; | 448 mainThreadLoaderHolder->m_workerLoader = workerLoader; |
449 peer->start(*toDocument(executionContext), std::move(request), options, reso
urceLoaderOptions); | 449 mainThreadLoaderHolder->start(*toDocument(executionContext), std::move(reque
st), options, resourceLoaderOptions); |
450 forwarder->forwardTask(BLINK_FROM_HERE, createCrossThreadTask(&WorkerThreada
bleLoader::didStart, wrapCrossThreadPersistent(workerLoader), wrapCrossThreadPer
sistent(peer))); | 450 forwarder->forwardTask(BLINK_FROM_HERE, createCrossThreadTask(&WorkerThreada
bleLoader::didStart, wrapCrossThreadPersistent(workerLoader), wrapCrossThreadPer
sistent(mainThreadLoaderHolder))); |
451 } | 451 } |
452 | 452 |
453 WorkerThreadableLoader::Peer::~Peer() | 453 WorkerThreadableLoader::MainThreadLoaderHolder::~MainThreadLoaderHolder() |
454 { | 454 { |
455 DCHECK(isMainThread()); | 455 DCHECK(isMainThread()); |
456 DCHECK(!m_workerLoader); | 456 DCHECK(!m_workerLoader); |
457 } | 457 } |
458 | 458 |
459 void WorkerThreadableLoader::Peer::overrideTimeout(unsigned long timeoutMillisec
onds) | 459 void WorkerThreadableLoader::MainThreadLoaderHolder::overrideTimeout(unsigned lo
ng timeoutMilliseconds) |
460 { | 460 { |
461 DCHECK(isMainThread()); | 461 DCHECK(isMainThread()); |
462 if (!m_mainThreadLoader) | 462 if (!m_mainThreadLoader) |
463 return; | 463 return; |
464 m_mainThreadLoader->overrideTimeout(timeoutMilliseconds); | 464 m_mainThreadLoader->overrideTimeout(timeoutMilliseconds); |
465 } | 465 } |
466 | 466 |
467 void WorkerThreadableLoader::Peer::cancel() | 467 void WorkerThreadableLoader::MainThreadLoaderHolder::cancel() |
468 { | 468 { |
469 DCHECK(isMainThread()); | 469 DCHECK(isMainThread()); |
470 if (!m_mainThreadLoader) | 470 if (!m_mainThreadLoader) |
471 return; | 471 return; |
472 m_mainThreadLoader->cancel(); | 472 m_mainThreadLoader->cancel(); |
473 m_mainThreadLoader = nullptr; | 473 m_mainThreadLoader = nullptr; |
474 } | 474 } |
475 | 475 |
476 void WorkerThreadableLoader::Peer::didSendData(unsigned long long bytesSent, uns
igned long long totalBytesToBeSent) | 476 void WorkerThreadableLoader::MainThreadLoaderHolder::didSendData(unsigned long l
ong bytesSent, unsigned long long totalBytesToBeSent) |
477 { | 477 { |
478 DCHECK(isMainThread()); | 478 DCHECK(isMainThread()); |
479 CrossThreadPersistent<WorkerThreadableLoader> workerLoader = m_workerLoader.
get(); | 479 CrossThreadPersistent<WorkerThreadableLoader> workerLoader = m_workerLoader.
get(); |
480 if (!workerLoader || !m_forwarder) | 480 if (!workerLoader || !m_forwarder) |
481 return; | 481 return; |
482 m_forwarder->forwardTask(BLINK_FROM_HERE, createCrossThreadTask(&WorkerThrea
dableLoader::didSendData, workerLoader, bytesSent, totalBytesToBeSent)); | 482 m_forwarder->forwardTask(BLINK_FROM_HERE, createCrossThreadTask(&WorkerThrea
dableLoader::didSendData, workerLoader, bytesSent, totalBytesToBeSent)); |
483 } | 483 } |
484 | 484 |
485 void WorkerThreadableLoader::Peer::didReceiveResponse(unsigned long identifier,
const ResourceResponse& response, std::unique_ptr<WebDataConsumerHandle> handle) | 485 void WorkerThreadableLoader::MainThreadLoaderHolder::didReceiveResponse(unsigned
long identifier, const ResourceResponse& response, std::unique_ptr<WebDataConsu
merHandle> handle) |
486 { | 486 { |
487 DCHECK(isMainThread()); | 487 DCHECK(isMainThread()); |
488 CrossThreadPersistent<WorkerThreadableLoader> workerLoader = m_workerLoader.
get(); | 488 CrossThreadPersistent<WorkerThreadableLoader> workerLoader = m_workerLoader.
get(); |
489 if (!workerLoader || !m_forwarder) | 489 if (!workerLoader || !m_forwarder) |
490 return; | 490 return; |
491 m_forwarder->forwardTask(BLINK_FROM_HERE, createCrossThreadTask(&WorkerThrea
dableLoader::didReceiveResponse, workerLoader, identifier, response, passed(std:
:move(handle)))); | 491 m_forwarder->forwardTask(BLINK_FROM_HERE, createCrossThreadTask(&WorkerThrea
dableLoader::didReceiveResponse, workerLoader, identifier, response, passed(std:
:move(handle)))); |
492 } | 492 } |
493 | 493 |
494 void WorkerThreadableLoader::Peer::didReceiveData(const char* data, unsigned dat
aLength) | 494 void WorkerThreadableLoader::MainThreadLoaderHolder::didReceiveData(const char*
data, unsigned dataLength) |
495 { | 495 { |
496 DCHECK(isMainThread()); | 496 DCHECK(isMainThread()); |
497 CrossThreadPersistent<WorkerThreadableLoader> workerLoader = m_workerLoader.
get(); | 497 CrossThreadPersistent<WorkerThreadableLoader> workerLoader = m_workerLoader.
get(); |
498 if (!workerLoader || !m_forwarder) | 498 if (!workerLoader || !m_forwarder) |
499 return; | 499 return; |
500 m_forwarder->forwardTask(BLINK_FROM_HERE, createCrossThreadTask(&WorkerThrea
dableLoader::didReceiveData, workerLoader, passed(createVectorFromMemoryRegion(d
ata, dataLength)))); | 500 m_forwarder->forwardTask(BLINK_FROM_HERE, createCrossThreadTask(&WorkerThrea
dableLoader::didReceiveData, workerLoader, passed(createVectorFromMemoryRegion(d
ata, dataLength)))); |
501 } | 501 } |
502 | 502 |
503 void WorkerThreadableLoader::Peer::didDownloadData(int dataLength) | 503 void WorkerThreadableLoader::MainThreadLoaderHolder::didDownloadData(int dataLen
gth) |
504 { | 504 { |
505 DCHECK(isMainThread()); | 505 DCHECK(isMainThread()); |
506 CrossThreadPersistent<WorkerThreadableLoader> workerLoader = m_workerLoader.
get(); | 506 CrossThreadPersistent<WorkerThreadableLoader> workerLoader = m_workerLoader.
get(); |
507 if (!workerLoader || !m_forwarder) | 507 if (!workerLoader || !m_forwarder) |
508 return; | 508 return; |
509 m_forwarder->forwardTask(BLINK_FROM_HERE, createCrossThreadTask(&WorkerThrea
dableLoader::didDownloadData, workerLoader, dataLength)); | 509 m_forwarder->forwardTask(BLINK_FROM_HERE, createCrossThreadTask(&WorkerThrea
dableLoader::didDownloadData, workerLoader, dataLength)); |
510 } | 510 } |
511 | 511 |
512 void WorkerThreadableLoader::Peer::didReceiveCachedMetadata(const char* data, in
t dataLength) | 512 void WorkerThreadableLoader::MainThreadLoaderHolder::didReceiveCachedMetadata(co
nst char* data, int dataLength) |
513 { | 513 { |
514 DCHECK(isMainThread()); | 514 DCHECK(isMainThread()); |
515 CrossThreadPersistent<WorkerThreadableLoader> workerLoader = m_workerLoader.
get(); | 515 CrossThreadPersistent<WorkerThreadableLoader> workerLoader = m_workerLoader.
get(); |
516 if (!workerLoader || !m_forwarder) | 516 if (!workerLoader || !m_forwarder) |
517 return; | 517 return; |
518 m_forwarder->forwardTask(BLINK_FROM_HERE, createCrossThreadTask(&WorkerThrea
dableLoader::didReceiveCachedMetadata, workerLoader, passed(createVectorFromMemo
ryRegion(data, dataLength)))); | 518 m_forwarder->forwardTask(BLINK_FROM_HERE, createCrossThreadTask(&WorkerThrea
dableLoader::didReceiveCachedMetadata, workerLoader, passed(createVectorFromMemo
ryRegion(data, dataLength)))); |
519 } | 519 } |
520 | 520 |
521 void WorkerThreadableLoader::Peer::didFinishLoading(unsigned long identifier, do
uble finishTime) | 521 void WorkerThreadableLoader::MainThreadLoaderHolder::didFinishLoading(unsigned l
ong identifier, double finishTime) |
522 { | 522 { |
523 DCHECK(isMainThread()); | 523 DCHECK(isMainThread()); |
524 CrossThreadPersistent<WorkerThreadableLoader> workerLoader = m_workerLoader.
get(); | 524 CrossThreadPersistent<WorkerThreadableLoader> workerLoader = m_workerLoader.
get(); |
525 if (!workerLoader || !m_forwarder) | 525 if (!workerLoader || !m_forwarder) |
526 return; | 526 return; |
527 m_forwarder->forwardTaskWithDoneSignal(BLINK_FROM_HERE, createCrossThreadTas
k(&WorkerThreadableLoader::didFinishLoading, workerLoader, identifier, finishTim
e)); | 527 m_forwarder->forwardTaskWithDoneSignal(BLINK_FROM_HERE, createCrossThreadTas
k(&WorkerThreadableLoader::didFinishLoading, workerLoader, identifier, finishTim
e)); |
528 m_forwarder = nullptr; | 528 m_forwarder = nullptr; |
529 } | 529 } |
530 | 530 |
531 void WorkerThreadableLoader::Peer::didFail(const ResourceError& error) | 531 void WorkerThreadableLoader::MainThreadLoaderHolder::didFail(const ResourceError
& error) |
532 { | 532 { |
533 DCHECK(isMainThread()); | 533 DCHECK(isMainThread()); |
534 CrossThreadPersistent<WorkerThreadableLoader> workerLoader = m_workerLoader.
get(); | 534 CrossThreadPersistent<WorkerThreadableLoader> workerLoader = m_workerLoader.
get(); |
535 if (!workerLoader || !m_forwarder) | 535 if (!workerLoader || !m_forwarder) |
536 return; | 536 return; |
537 m_forwarder->forwardTaskWithDoneSignal(BLINK_FROM_HERE, createCrossThreadTas
k(&WorkerThreadableLoader::didFail, workerLoader, error)); | 537 m_forwarder->forwardTaskWithDoneSignal(BLINK_FROM_HERE, createCrossThreadTas
k(&WorkerThreadableLoader::didFail, workerLoader, error)); |
538 m_forwarder = nullptr; | 538 m_forwarder = nullptr; |
539 } | 539 } |
540 | 540 |
541 void WorkerThreadableLoader::Peer::didFailAccessControlCheck(const ResourceError
& error) | 541 void WorkerThreadableLoader::MainThreadLoaderHolder::didFailAccessControlCheck(c
onst ResourceError& error) |
542 { | 542 { |
543 DCHECK(isMainThread()); | 543 DCHECK(isMainThread()); |
544 CrossThreadPersistent<WorkerThreadableLoader> workerLoader = m_workerLoader.
get(); | 544 CrossThreadPersistent<WorkerThreadableLoader> workerLoader = m_workerLoader.
get(); |
545 if (!workerLoader || !m_forwarder) | 545 if (!workerLoader || !m_forwarder) |
546 return; | 546 return; |
547 m_forwarder->forwardTaskWithDoneSignal(BLINK_FROM_HERE, createCrossThreadTas
k(&WorkerThreadableLoader::didFailAccessControlCheck, workerLoader, error)); | 547 m_forwarder->forwardTaskWithDoneSignal(BLINK_FROM_HERE, createCrossThreadTas
k(&WorkerThreadableLoader::didFailAccessControlCheck, workerLoader, error)); |
548 m_forwarder = nullptr; | 548 m_forwarder = nullptr; |
549 } | 549 } |
550 | 550 |
551 void WorkerThreadableLoader::Peer::didFailRedirectCheck() | 551 void WorkerThreadableLoader::MainThreadLoaderHolder::didFailRedirectCheck() |
552 { | 552 { |
553 DCHECK(isMainThread()); | 553 DCHECK(isMainThread()); |
554 CrossThreadPersistent<WorkerThreadableLoader> workerLoader = m_workerLoader.
get(); | 554 CrossThreadPersistent<WorkerThreadableLoader> workerLoader = m_workerLoader.
get(); |
555 if (!workerLoader || !m_forwarder) | 555 if (!workerLoader || !m_forwarder) |
556 return; | 556 return; |
557 m_forwarder->forwardTaskWithDoneSignal(BLINK_FROM_HERE, createCrossThreadTas
k(&WorkerThreadableLoader::didFailRedirectCheck, workerLoader)); | 557 m_forwarder->forwardTaskWithDoneSignal(BLINK_FROM_HERE, createCrossThreadTas
k(&WorkerThreadableLoader::didFailRedirectCheck, workerLoader)); |
558 m_forwarder = nullptr; | 558 m_forwarder = nullptr; |
559 } | 559 } |
560 | 560 |
561 void WorkerThreadableLoader::Peer::didReceiveResourceTiming(const ResourceTiming
Info& info) | 561 void WorkerThreadableLoader::MainThreadLoaderHolder::didReceiveResourceTiming(co
nst ResourceTimingInfo& info) |
562 { | 562 { |
563 DCHECK(isMainThread()); | 563 DCHECK(isMainThread()); |
564 CrossThreadPersistent<WorkerThreadableLoader> workerLoader = m_workerLoader.
get(); | 564 CrossThreadPersistent<WorkerThreadableLoader> workerLoader = m_workerLoader.
get(); |
565 if (!workerLoader || !m_forwarder) | 565 if (!workerLoader || !m_forwarder) |
566 return; | 566 return; |
567 m_forwarder->forwardTask(BLINK_FROM_HERE, createCrossThreadTask(&WorkerThrea
dableLoader::didReceiveResourceTiming, workerLoader, info)); | 567 m_forwarder->forwardTask(BLINK_FROM_HERE, createCrossThreadTask(&WorkerThrea
dableLoader::didReceiveResourceTiming, workerLoader, info)); |
568 } | 568 } |
569 | 569 |
570 void WorkerThreadableLoader::Peer::contextDestroyed() | 570 void WorkerThreadableLoader::MainThreadLoaderHolder::contextDestroyed() |
571 { | 571 { |
572 DCHECK(isMainThread()); | 572 DCHECK(isMainThread()); |
573 if (m_forwarder) { | 573 if (m_forwarder) { |
574 m_forwarder->abort(); | 574 m_forwarder->abort(); |
575 m_forwarder = nullptr; | 575 m_forwarder = nullptr; |
576 } | 576 } |
577 m_workerLoader = nullptr; | 577 m_workerLoader = nullptr; |
578 cancel(); | 578 cancel(); |
579 } | 579 } |
580 | 580 |
581 DEFINE_TRACE(WorkerThreadableLoader::Peer) | 581 DEFINE_TRACE(WorkerThreadableLoader::MainThreadLoaderHolder) |
582 { | 582 { |
583 visitor->trace(m_forwarder); | 583 visitor->trace(m_forwarder); |
584 visitor->trace(m_mainThreadLoader); | 584 visitor->trace(m_mainThreadLoader); |
585 WorkerThreadLifecycleObserver::trace(visitor); | 585 WorkerThreadLifecycleObserver::trace(visitor); |
586 } | 586 } |
587 | 587 |
588 WorkerThreadableLoader::Peer::Peer(TaskForwarder* forwarder, WorkerThreadLifecyc
leContext* context) | 588 WorkerThreadableLoader::MainThreadLoaderHolder::MainThreadLoaderHolder(TaskForwa
rder* forwarder, WorkerThreadLifecycleContext* context) |
589 : WorkerThreadLifecycleObserver(context) | 589 : WorkerThreadLifecycleObserver(context) |
590 , m_forwarder(forwarder) | 590 , m_forwarder(forwarder) |
591 { | 591 { |
592 DCHECK(isMainThread()); | 592 DCHECK(isMainThread()); |
593 } | 593 } |
594 | 594 |
595 void WorkerThreadableLoader::Peer::start( | 595 void WorkerThreadableLoader::MainThreadLoaderHolder::start( |
596 Document& document, | 596 Document& document, |
597 std::unique_ptr<CrossThreadResourceRequestData> request, | 597 std::unique_ptr<CrossThreadResourceRequestData> request, |
598 const ThreadableLoaderOptions& options, | 598 const ThreadableLoaderOptions& options, |
599 const ResourceLoaderOptions& originalResourceLoaderOptions) | 599 const ResourceLoaderOptions& originalResourceLoaderOptions) |
600 { | 600 { |
601 DCHECK(isMainThread()); | 601 DCHECK(isMainThread()); |
602 ResourceLoaderOptions resourceLoaderOptions = originalResourceLoaderOptions; | 602 ResourceLoaderOptions resourceLoaderOptions = originalResourceLoaderOptions; |
603 resourceLoaderOptions.requestInitiatorContext = WorkerContext; | 603 resourceLoaderOptions.requestInitiatorContext = WorkerContext; |
604 m_mainThreadLoader = DocumentThreadableLoader::create(document, this, option
s, resourceLoaderOptions); | 604 m_mainThreadLoader = DocumentThreadableLoader::create(document, this, option
s, resourceLoaderOptions); |
605 m_mainThreadLoader->start(ResourceRequest(request.get())); | 605 m_mainThreadLoader->start(ResourceRequest(request.get())); |
606 } | 606 } |
607 | 607 |
608 } // namespace blink | 608 } // namespace blink |
OLD | NEW |