OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2010, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2010, 2011 Apple Inc. All rights reserved. |
3 * (C) 2007 Graham Dennis (graham.dennis@gmail.com) | 3 * (C) 2007 Graham Dennis (graham.dennis@gmail.com) |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * | 8 * |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 void ResourceLoader::DidDownloadData(int length, int encoded_data_length) { | 393 void ResourceLoader::DidDownloadData(int length, int encoded_data_length) { |
394 Context().DispatchDidDownloadData(resource_->Identifier(), length, | 394 Context().DispatchDidDownloadData(resource_->Identifier(), length, |
395 encoded_data_length); | 395 encoded_data_length); |
396 resource_->DidDownloadData(length); | 396 resource_->DidDownloadData(length); |
397 } | 397 } |
398 | 398 |
399 void ResourceLoader::DidReceiveData(const char* data, int length) { | 399 void ResourceLoader::DidReceiveData(const char* data, int length) { |
400 CHECK_GE(length, 0); | 400 CHECK_GE(length, 0); |
401 | 401 |
402 Context().DispatchDidReceiveData(resource_->Identifier(), data, length); | 402 Context().DispatchDidReceiveData(resource_->Identifier(), data, length); |
403 resource_->AddToDecodedBodyLength(length); | |
404 resource_->AppendData(data, length); | 403 resource_->AppendData(data, length); |
405 } | 404 } |
406 | 405 |
407 void ResourceLoader::DidReceiveTransferSizeUpdate(int transfer_size_diff) { | 406 void ResourceLoader::DidReceiveTransferSizeUpdate(int transfer_size_diff) { |
408 DCHECK_GT(transfer_size_diff, 0); | 407 DCHECK_GT(transfer_size_diff, 0); |
409 Context().DispatchDidReceiveEncodedData(resource_->Identifier(), | 408 Context().DispatchDidReceiveEncodedData(resource_->Identifier(), |
410 transfer_size_diff); | 409 transfer_size_diff); |
411 } | 410 } |
412 | 411 |
413 void ResourceLoader::DidFinishLoadingFirstPartInMultipart() { | 412 void ResourceLoader::DidFinishLoadingFirstPartInMultipart() { |
414 network_instrumentation::endResourceLoad( | 413 network_instrumentation::endResourceLoad( |
415 resource_->Identifier(), | 414 resource_->Identifier(), |
416 network_instrumentation::RequestOutcome::Success); | 415 network_instrumentation::RequestOutcome::Success); |
417 | 416 |
418 fetcher_->HandleLoaderFinish(resource_.Get(), 0, | 417 fetcher_->HandleLoaderFinish(resource_.Get(), 0, |
419 ResourceFetcher::kDidFinishFirstPartInMultipart); | 418 ResourceFetcher::kDidFinishFirstPartInMultipart); |
420 } | 419 } |
421 | 420 |
422 void ResourceLoader::DidFinishLoading(double finish_time, | 421 void ResourceLoader::DidFinishLoading(double finish_time, |
423 int64_t encoded_data_length, | 422 int64_t encoded_data_length, |
424 int64_t encoded_body_length) { | 423 int64_t encoded_body_length, |
| 424 int64_t decoded_body_length) { |
425 resource_->SetEncodedDataLength(encoded_data_length); | 425 resource_->SetEncodedDataLength(encoded_data_length); |
426 resource_->AddToEncodedBodyLength(encoded_body_length); | 426 resource_->SetEncodedBodyLength(encoded_body_length); |
| 427 resource_->SetDecodedBodyLength(decoded_body_length); |
427 | 428 |
428 loader_.reset(); | 429 loader_.reset(); |
429 | 430 |
430 network_instrumentation::endResourceLoad( | 431 network_instrumentation::endResourceLoad( |
431 resource_->Identifier(), | 432 resource_->Identifier(), |
432 network_instrumentation::RequestOutcome::Success); | 433 network_instrumentation::RequestOutcome::Success); |
433 | 434 |
434 fetcher_->HandleLoaderFinish(resource_.Get(), finish_time, | 435 fetcher_->HandleLoaderFinish(resource_.Get(), finish_time, |
435 ResourceFetcher::kDidFinishLoading); | 436 ResourceFetcher::kDidFinishLoading); |
436 } | 437 } |
437 | 438 |
438 void ResourceLoader::DidFail(const WebURLError& error, | 439 void ResourceLoader::DidFail(const WebURLError& error, |
439 int64_t encoded_data_length, | 440 int64_t encoded_data_length, |
440 int64_t encoded_body_length) { | 441 int64_t encoded_body_length, |
| 442 int64_t decoded_body_length) { |
441 resource_->SetEncodedDataLength(encoded_data_length); | 443 resource_->SetEncodedDataLength(encoded_data_length); |
442 resource_->AddToEncodedBodyLength(encoded_body_length); | 444 resource_->SetEncodedBodyLength(encoded_body_length); |
| 445 resource_->SetDecodedBodyLength(decoded_body_length); |
443 HandleError(error); | 446 HandleError(error); |
444 } | 447 } |
445 | 448 |
446 void ResourceLoader::HandleError(const ResourceError& error) { | 449 void ResourceLoader::HandleError(const ResourceError& error) { |
447 if (is_cache_aware_loading_activated_ && error.IsCacheMiss() && | 450 if (is_cache_aware_loading_activated_ && error.IsCacheMiss() && |
448 Context().ShouldLoadNewResource(resource_->GetType())) { | 451 Context().ShouldLoadNewResource(resource_->GetType())) { |
449 resource_->WillReloadAfterDiskCacheMiss(); | 452 resource_->WillReloadAfterDiskCacheMiss(); |
450 is_cache_aware_loading_activated_ = false; | 453 is_cache_aware_loading_activated_ = false; |
451 Restart(resource_->GetResourceRequest()); | 454 Restart(resource_->GetResourceRequest()); |
452 return; | 455 return; |
(...skipping 19 matching lines...) Expand all Loading... |
472 WebData data_out; | 475 WebData data_out; |
473 int64_t encoded_data_length = WebURLLoaderClient::kUnknownEncodedDataLength; | 476 int64_t encoded_data_length = WebURLLoaderClient::kUnknownEncodedDataLength; |
474 int64_t encoded_body_length = 0; | 477 int64_t encoded_body_length = 0; |
475 loader_->LoadSynchronously(request_in, response_out, error_out, data_out, | 478 loader_->LoadSynchronously(request_in, response_out, error_out, data_out, |
476 encoded_data_length, encoded_body_length); | 479 encoded_data_length, encoded_body_length); |
477 | 480 |
478 // A message dispatched while synchronously fetching the resource | 481 // A message dispatched while synchronously fetching the resource |
479 // can bring about the cancellation of this load. | 482 // can bring about the cancellation of this load. |
480 if (!loader_) | 483 if (!loader_) |
481 return; | 484 return; |
| 485 int64_t decoded_body_length = data_out.size(); |
482 if (error_out.reason) { | 486 if (error_out.reason) { |
483 DidFail(error_out, encoded_data_length, encoded_body_length); | 487 DidFail(error_out, encoded_data_length, encoded_body_length, |
| 488 decoded_body_length); |
484 return; | 489 return; |
485 } | 490 } |
486 DidReceiveResponse(response_out); | 491 DidReceiveResponse(response_out); |
487 if (!loader_) | 492 if (!loader_) |
488 return; | 493 return; |
489 DCHECK_GE(response_out.ToResourceResponse().EncodedBodyLength(), 0); | 494 DCHECK_GE(response_out.ToResourceResponse().EncodedBodyLength(), 0); |
490 | 495 |
491 // Follow the async case convention of not calling didReceiveData or | 496 // Follow the async case convention of not calling didReceiveData or |
492 // appending data to m_resource if the response body is empty. Copying the | 497 // appending data to m_resource if the response body is empty. Copying the |
493 // empty buffer is a noop in most cases, but is destructive in the case of | 498 // empty buffer is a noop in most cases, but is destructive in the case of |
494 // a 304, where it will overwrite the cached data we should be reusing. | 499 // a 304, where it will overwrite the cached data we should be reusing. |
495 if (data_out.size()) { | 500 if (data_out.size()) { |
496 Context().DispatchDidReceiveData(resource_->Identifier(), data_out.Data(), | 501 Context().DispatchDidReceiveData(resource_->Identifier(), data_out.Data(), |
497 data_out.size()); | 502 data_out.size()); |
498 resource_->SetResourceBuffer(data_out); | 503 resource_->SetResourceBuffer(data_out); |
499 } | 504 } |
500 DidFinishLoading(MonotonicallyIncreasingTime(), encoded_data_length, | 505 DidFinishLoading(MonotonicallyIncreasingTime(), encoded_data_length, |
501 encoded_body_length); | 506 encoded_body_length, decoded_body_length); |
502 } | 507 } |
503 | 508 |
504 void ResourceLoader::Dispose() { | 509 void ResourceLoader::Dispose() { |
505 loader_ = nullptr; | 510 loader_ = nullptr; |
506 } | 511 } |
507 | 512 |
508 void ResourceLoader::ActivateCacheAwareLoadingIfNeeded( | 513 void ResourceLoader::ActivateCacheAwareLoadingIfNeeded( |
509 const ResourceRequest& request) { | 514 const ResourceRequest& request) { |
510 DCHECK(!is_cache_aware_loading_activated_); | 515 DCHECK(!is_cache_aware_loading_activated_); |
511 | 516 |
(...skipping 10 matching lines...) Expand all Loading... |
522 return; | 527 return; |
523 | 528 |
524 // Don't activate if cache policy is explicitly set. | 529 // Don't activate if cache policy is explicitly set. |
525 if (request.GetCachePolicy() != WebCachePolicy::kUseProtocolCachePolicy) | 530 if (request.GetCachePolicy() != WebCachePolicy::kUseProtocolCachePolicy) |
526 return; | 531 return; |
527 | 532 |
528 is_cache_aware_loading_activated_ = true; | 533 is_cache_aware_loading_activated_ = true; |
529 } | 534 } |
530 | 535 |
531 } // namespace blink | 536 } // namespace blink |
OLD | NEW |