Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/precache/core/precache_fetcher.h" | 5 #include "components/precache/core/precache_fetcher.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 } | 228 } |
| 229 network_url_fetcher_->Start(); | 229 network_url_fetcher_->Start(); |
| 230 } | 230 } |
| 231 | 231 |
| 232 void PrecacheFetcher::Fetcher::OnURLFetchDownloadProgress( | 232 void PrecacheFetcher::Fetcher::OnURLFetchDownloadProgress( |
| 233 const net::URLFetcher* source, | 233 const net::URLFetcher* source, |
| 234 int64_t current, | 234 int64_t current, |
| 235 int64_t total) { | 235 int64_t total) { |
| 236 // If going over the per-resource download cap. | 236 // If going over the per-resource download cap. |
| 237 if (fetch_stage_ == FetchStage::NETWORK && | 237 if (fetch_stage_ == FetchStage::NETWORK && |
| 238 // |current| is guaranteed to be non-negative, so this cast is safe. | 238 source->GetTotalReceivedBytes() > max_bytes_) { |
|
twifkak
2016/07/01 23:59:25
Also, the proto says "This max applies only to new
twifkak
2016/07/01 23:59:25
AFAICT this is only available after the request is
Raj
2016/07/14 18:41:30
Yes. You are right. This is updated only after req
Raj
2016/07/14 18:41:30
The proto is correct. Only new downloads have Fetc
| |
| 239 static_cast<size_t>(std::max(current, total)) > max_bytes_) { | |
| 240 VLOG(1) << "Cancelling " << url_ << ": (" << current << "/" << total | 239 VLOG(1) << "Cancelling " << url_ << ": (" << current << "/" << total |
| 241 << ") is over " << max_bytes_; | 240 << ") is over " << max_bytes_; |
| 242 | 241 |
| 243 // Cancel the download. | 242 // Cancel the download. |
| 244 network_url_fetcher_.reset(); | 243 network_url_fetcher_.reset(); |
| 245 | 244 |
| 246 // Call the completion callback, to attempt the next download, or to trigger | 245 // Call the completion callback, to attempt the next download, or to trigger |
| 247 // cleanup in precache_delegate_->OnDone(). | 246 // cleanup in precache_delegate_->OnDone(). |
| 248 response_bytes_ = network_response_bytes_ = current; | 247 response_bytes_ = network_response_bytes_ = current; |
| 249 | 248 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 267 // refresh the cache with minimal network load. | 266 // refresh the cache with minimal network load. |
| 268 LoadFromNetwork(); | 267 LoadFromNetwork(); |
| 269 return; | 268 return; |
| 270 } | 269 } |
| 271 | 270 |
| 272 // If any of: | 271 // If any of: |
| 273 // - The request was for a config or manifest. | 272 // - The request was for a config or manifest. |
| 274 // - The resource was a cache hit without validators. | 273 // - The resource was a cache hit without validators. |
| 275 // - The response came from the network. | 274 // - The response came from the network. |
| 276 // Then Fetcher is done with this URL and can return control to the caller. | 275 // Then Fetcher is done with this URL and can return control to the caller. |
| 277 response_bytes_ = source->GetReceivedResponseContentLength(); | 276 response_bytes_ = source->GetReceivedResponseContentLength(); |
|
Raj
2016/07/14 18:41:30
I checked that response_bytes_ here includes bytes
| |
| 278 network_response_bytes_ = source->GetTotalReceivedBytes(); | 277 network_response_bytes_ = source->GetTotalReceivedBytes(); |
| 279 callback_.Run(*this); | 278 callback_.Run(*this); |
| 280 } | 279 } |
| 281 | 280 |
| 282 // static | 281 // static |
| 283 void PrecacheFetcher::RecordCompletionStatistics( | 282 void PrecacheFetcher::RecordCompletionStatistics( |
| 284 const PrecacheUnfinishedWork& unfinished_work, | 283 const PrecacheUnfinishedWork& unfinished_work, |
| 285 size_t remaining_manifest_urls_to_fetch, | 284 size_t remaining_manifest_urls_to_fetch, |
| 286 size_t remaining_resource_urls_to_fetch) { | 285 size_t remaining_resource_urls_to_fetch) { |
| 287 // These may be unset in tests. | 286 // These may be unset in tests. |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 400 base::Unretained(this)), | 399 base::Unretained(this)), |
| 401 false /* is_resource_request */, std::numeric_limits<int32_t>::max()))); | 400 false /* is_resource_request */, std::numeric_limits<int32_t>::max()))); |
| 402 } | 401 } |
| 403 | 402 |
| 404 void PrecacheFetcher::StartNextResourceFetch() { | 403 void PrecacheFetcher::StartNextResourceFetch() { |
| 405 DCHECK(unfinished_work_->has_config_settings()); | 404 DCHECK(unfinished_work_->has_config_settings()); |
| 406 while (!resource_urls_to_fetch_.empty() && pool_.IsAvailable()) { | 405 while (!resource_urls_to_fetch_.empty() && pool_.IsAvailable()) { |
| 407 const size_t max_bytes = | 406 const size_t max_bytes = |
| 408 std::min(unfinished_work_->config_settings().max_bytes_per_resource(), | 407 std::min(unfinished_work_->config_settings().max_bytes_per_resource(), |
| 409 unfinished_work_->config_settings().max_bytes_total() - | 408 unfinished_work_->config_settings().max_bytes_total() - |
| 410 unfinished_work_->total_bytes()); | 409 unfinished_work_->network_bytes()); |
| 411 VLOG(3) << "Fetching " << resource_urls_to_fetch_.front(); | 410 VLOG(3) << "Fetching " << resource_urls_to_fetch_.front(); |
| 412 pool_.Add(base::WrapUnique( | 411 pool_.Add(base::WrapUnique( |
| 413 new Fetcher(request_context_.get(), resource_urls_to_fetch_.front(), | 412 new Fetcher(request_context_.get(), resource_urls_to_fetch_.front(), |
| 414 base::Bind(&PrecacheFetcher::OnResourceFetchComplete, | 413 base::Bind(&PrecacheFetcher::OnResourceFetchComplete, |
| 415 base::Unretained(this)), | 414 base::Unretained(this)), |
| 416 true /* is_resource_request */, max_bytes))); | 415 true /* is_resource_request */, max_bytes))); |
| 417 | 416 |
| 418 resource_urls_to_fetch_.pop_front(); | 417 resource_urls_to_fetch_.pop_front(); |
| 419 } | 418 } |
| 420 } | 419 } |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 440 size_t remaining_resource_urls_to_fetch) { | 439 size_t remaining_resource_urls_to_fetch) { |
| 441 RecordCompletionStatistics(*unfinished_work_, | 440 RecordCompletionStatistics(*unfinished_work_, |
| 442 remaining_manifest_urls_to_fetch, | 441 remaining_manifest_urls_to_fetch, |
| 443 remaining_resource_urls_to_fetch); | 442 remaining_resource_urls_to_fetch); |
| 444 precache_delegate_->OnDone(); | 443 precache_delegate_->OnDone(); |
| 445 } | 444 } |
| 446 | 445 |
| 447 void PrecacheFetcher::StartNextFetch() { | 446 void PrecacheFetcher::StartNextFetch() { |
| 448 DCHECK(unfinished_work_->has_config_settings()); | 447 DCHECK(unfinished_work_->has_config_settings()); |
| 449 // If over the precache total size cap, then stop prefetching. | 448 // If over the precache total size cap, then stop prefetching. |
| 450 if (unfinished_work_->total_bytes() > | 449 if (unfinished_work_->network_bytes() > |
|
twifkak
2016/07/01 23:59:25
Does this include the size of cache resources, too
Raj
2016/07/14 18:41:30
My code is wrong. It should not be changed. total_
| |
| 451 unfinished_work_->config_settings().max_bytes_total()) { | 450 unfinished_work_->config_settings().max_bytes_total()) { |
| 452 size_t pending_manifests_in_pool = 0; | 451 size_t pending_manifests_in_pool = 0; |
| 453 size_t pending_resources_in_pool = 0; | 452 size_t pending_resources_in_pool = 0; |
| 454 for (const auto& element_pair : pool_.elements()) { | 453 for (const auto& element_pair : pool_.elements()) { |
| 455 const Fetcher* fetcher = element_pair.first; | 454 const Fetcher* fetcher = element_pair.first; |
| 456 if (fetcher->is_resource_request()) | 455 if (fetcher->is_resource_request()) |
| 457 pending_resources_in_pool++; | 456 pending_resources_in_pool++; |
| 458 else if (fetcher->url() != config_url_) | 457 else if (fetcher->url() != config_url_) |
| 459 pending_manifests_in_pool++; | 458 pending_manifests_in_pool++; |
| 460 } | 459 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 567 | 566 |
| 568 void PrecacheFetcher::UpdateStats(int64_t response_bytes, | 567 void PrecacheFetcher::UpdateStats(int64_t response_bytes, |
| 569 int64_t network_response_bytes) { | 568 int64_t network_response_bytes) { |
| 570 unfinished_work_->set_total_bytes( | 569 unfinished_work_->set_total_bytes( |
| 571 unfinished_work_->total_bytes() + response_bytes); | 570 unfinished_work_->total_bytes() + response_bytes); |
| 572 unfinished_work_->set_network_bytes( | 571 unfinished_work_->set_network_bytes( |
| 573 unfinished_work_->network_bytes() + network_response_bytes); | 572 unfinished_work_->network_bytes() + network_response_bytes); |
| 574 } | 573 } |
| 575 | 574 |
| 576 } // namespace precache | 575 } // namespace precache |
| OLD | NEW |