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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 // Config and manifest requests do not need to be revalidated. It's okay if | 279 // Config and manifest requests do not need to be revalidated. It's okay if |
280 // they expire from the cache minutes after we request them. | 280 // they expire from the cache minutes after we request them. |
281 network_url_fetcher_->SetLoadFlags(kNoTracking); | 281 network_url_fetcher_->SetLoadFlags(kNoTracking); |
282 } | 282 } |
283 network_url_fetcher_->Start(); | 283 network_url_fetcher_->Start(); |
284 } | 284 } |
285 | 285 |
286 void PrecacheFetcher::Fetcher::OnURLFetchDownloadProgress( | 286 void PrecacheFetcher::Fetcher::OnURLFetchDownloadProgress( |
287 const net::URLFetcher* source, | 287 const net::URLFetcher* source, |
288 int64_t current, | 288 int64_t current, |
289 int64_t total) { | 289 int64_t total, |
290 // If going over the per-resource download cap. | 290 int64_t current_network_bytes) { |
| 291 // If network bytes going over the per-resource download cap. |
291 if (fetch_stage_ == FetchStage::NETWORK && | 292 if (fetch_stage_ == FetchStage::NETWORK && |
292 // |current| is guaranteed to be non-negative, so this cast is safe. | 293 // |current_network_bytes| is guaranteed to be non-negative, so this cast |
293 static_cast<size_t>(std::max(current, total)) > max_bytes_) { | 294 // is safe. |
| 295 static_cast<size_t>(current_network_bytes) > max_bytes_) { |
294 VLOG(1) << "Cancelling " << url_ << ": (" << current << "/" << total | 296 VLOG(1) << "Cancelling " << url_ << ": (" << current << "/" << total |
295 << ") is over " << max_bytes_; | 297 << ") is over " << max_bytes_; |
296 | 298 |
297 // Call the completion callback, to attempt the next download, or to trigger | 299 // Call the completion callback, to attempt the next download, or to trigger |
298 // cleanup in precache_delegate_->OnDone(). | 300 // cleanup in precache_delegate_->OnDone(). |
299 response_bytes_ = network_response_bytes_ = current; | 301 response_bytes_ = current; |
| 302 network_response_bytes_ = current_network_bytes; |
300 was_cached_ = source->WasCached(); | 303 was_cached_ = source->WasCached(); |
301 | 304 |
302 UMA_HISTOGRAM_CUSTOM_COUNTS("Precache.Fetch.ResponseBytes.NetworkWasted", | 305 UMA_HISTOGRAM_CUSTOM_COUNTS("Precache.Fetch.ResponseBytes.NetworkWasted", |
303 network_response_bytes_, 1, | 306 network_response_bytes_, 1, |
304 1024 * 1024 /* 1 MB */, 100); | 307 1024 * 1024 /* 1 MB */, 100); |
305 | |
306 // Cancel the download. | 308 // Cancel the download. |
307 network_url_fetcher_.reset(); | 309 network_url_fetcher_.reset(); |
308 callback_.Run(*this); | 310 callback_.Run(*this); |
309 } | 311 } |
310 } | 312 } |
311 | 313 |
312 void PrecacheFetcher::Fetcher::OnURLFetchComplete( | 314 void PrecacheFetcher::Fetcher::OnURLFetchComplete( |
313 const net::URLFetcher* source) { | 315 const net::URLFetcher* source) { |
314 CHECK(source); | 316 CHECK(source); |
315 if (fetch_stage_ == FetchStage::CACHE && | 317 if (fetch_stage_ == FetchStage::CACHE && |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
754 remaining = 0; | 756 remaining = 0; |
755 quota_.set_remaining( | 757 quota_.set_remaining( |
756 used_bytes > quota_.remaining() ? 0U : quota_.remaining() - used_bytes); | 758 used_bytes > quota_.remaining() ? 0U : quota_.remaining() - used_bytes); |
757 db_task_runner_->PostTask( | 759 db_task_runner_->PostTask( |
758 FROM_HERE, | 760 FROM_HERE, |
759 base::Bind(&PrecacheDatabase::SaveQuota, precache_database_, quota_)); | 761 base::Bind(&PrecacheDatabase::SaveQuota, precache_database_, quota_)); |
760 } | 762 } |
761 } | 763 } |
762 | 764 |
763 } // namespace precache | 765 } // namespace precache |
OLD | NEW |