| 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 <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 // Config and manifest requests do not need to be revalidated. It's okay if | 260 // Config and manifest requests do not need to be revalidated. It's okay if |
| 261 // they expire from the cache minutes after we request them. | 261 // they expire from the cache minutes after we request them. |
| 262 network_url_fetcher_->SetLoadFlags(kNoTracking); | 262 network_url_fetcher_->SetLoadFlags(kNoTracking); |
| 263 } | 263 } |
| 264 network_url_fetcher_->Start(); | 264 network_url_fetcher_->Start(); |
| 265 } | 265 } |
| 266 | 266 |
| 267 void PrecacheFetcher::Fetcher::OnURLFetchDownloadProgress( | 267 void PrecacheFetcher::Fetcher::OnURLFetchDownloadProgress( |
| 268 const net::URLFetcher* source, | 268 const net::URLFetcher* source, |
| 269 int64_t current, | 269 int64_t current, |
| 270 int64_t total) { | 270 int64_t total, |
| 271 // If going over the per-resource download cap. | 271 int64_t current_network_bytes) { |
| 272 // If network bytes going over the per-resource download cap. |
| 272 if (fetch_stage_ == FetchStage::NETWORK && | 273 if (fetch_stage_ == FetchStage::NETWORK && |
| 273 // |current| is guaranteed to be non-negative, so this cast is safe. | 274 // |current_network_bytes| is guaranteed to be non-negative, so this cast |
| 274 static_cast<size_t>(std::max(current, total)) > max_bytes_) { | 275 // is safe. |
| 276 static_cast<size_t>(current_network_bytes) > max_bytes_) { |
| 275 VLOG(1) << "Cancelling " << url_ << ": (" << current << "/" << total | 277 VLOG(1) << "Cancelling " << url_ << ": (" << current << "/" << total |
| 276 << ") is over " << max_bytes_; | 278 << ") is over " << max_bytes_; |
| 277 | 279 |
| 278 // Call the completion callback, to attempt the next download, or to trigger | 280 // Call the completion callback, to attempt the next download, or to trigger |
| 279 // cleanup in precache_delegate_->OnDone(). | 281 // cleanup in precache_delegate_->OnDone(). |
| 280 response_bytes_ = network_response_bytes_ = current; | 282 response_bytes_ = current; |
| 283 network_response_bytes_ = current_network_bytes; |
| 281 was_cached_ = source->WasCached(); | 284 was_cached_ = source->WasCached(); |
| 282 | 285 |
| 283 // Cancel the download. | 286 // Cancel the download. |
| 284 network_url_fetcher_.reset(); | 287 network_url_fetcher_.reset(); |
| 285 callback_.Run(*this); | 288 callback_.Run(*this); |
| 286 } | 289 } |
| 287 } | 290 } |
| 288 | 291 |
| 289 void PrecacheFetcher::Fetcher::OnURLFetchComplete( | 292 void PrecacheFetcher::Fetcher::OnURLFetchComplete( |
| 290 const net::URLFetcher* source) { | 293 const net::URLFetcher* source) { |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 | 695 |
| 693 void PrecacheFetcher::UpdateStats(int64_t response_bytes, | 696 void PrecacheFetcher::UpdateStats(int64_t response_bytes, |
| 694 int64_t network_response_bytes) { | 697 int64_t network_response_bytes) { |
| 695 unfinished_work_->set_total_bytes( | 698 unfinished_work_->set_total_bytes( |
| 696 unfinished_work_->total_bytes() + response_bytes); | 699 unfinished_work_->total_bytes() + response_bytes); |
| 697 unfinished_work_->set_network_bytes( | 700 unfinished_work_->set_network_bytes( |
| 698 unfinished_work_->network_bytes() + network_response_bytes); | 701 unfinished_work_->network_bytes() + network_response_bytes); |
| 699 } | 702 } |
| 700 | 703 |
| 701 } // namespace precache | 704 } // namespace precache |
| OLD | NEW |