Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: components/precache/core/precache_fetcher.cc

Issue 2061303003: Precache should cancel when there is user traffic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: restructured Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 UMA_HISTOGRAM_CUSTOM_TIMES("Precache.Fetch.TimeToComplete", time_to_fetch, 289 UMA_HISTOGRAM_CUSTOM_TIMES("Precache.Fetch.TimeToComplete", time_to_fetch,
290 base::TimeDelta::FromSeconds(1), 290 base::TimeDelta::FromSeconds(1),
291 base::TimeDelta::FromHours(4), 50); 291 base::TimeDelta::FromHours(4), 50);
292 292
293 // Number of manifests for which we have downloaded all resources. 293 // Number of manifests for which we have downloaded all resources.
294 int manifests_completed = 294 int manifests_completed =
295 unfinished_work.num_manifest_urls() - remaining_manifest_urls_to_fetch; 295 unfinished_work.num_manifest_urls() - remaining_manifest_urls_to_fetch;
296 296
297 // If there are resource URLs left to fetch, the last manifest is not yet 297 // If there are resource URLs left to fetch, the last manifest is not yet
298 // completed. 298 // completed.
299 if (remaining_resource_urls_to_fetch > 0) 299 if (remaining_resource_urls_to_fetch > 0 && manifests_completed > 0)
300 --manifests_completed; 300 --manifests_completed;
301 301
302 DCHECK_GE(manifests_completed, 0); 302 DCHECK_GE(manifests_completed, 0);
303 int percent_completed = unfinished_work.num_manifest_urls() == 0 303 int percent_completed = unfinished_work.num_manifest_urls() == 0
304 ? 0 304 ? 0
305 : (static_cast<double>(manifests_completed) / 305 : (static_cast<double>(manifests_completed) /
306 unfinished_work.num_manifest_urls() * 100); 306 unfinished_work.num_manifest_urls() * 100);
307 307
308 UMA_HISTOGRAM_PERCENTAGE("Precache.Fetch.PercentCompleted", 308 UMA_HISTOGRAM_PERCENTAGE("Precache.Fetch.PercentCompleted",
309 percent_completed); 309 percent_completed);
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 558
559 void PrecacheFetcher::UpdateStats(int64_t response_bytes, 559 void PrecacheFetcher::UpdateStats(int64_t response_bytes,
560 int64_t network_response_bytes) { 560 int64_t network_response_bytes) {
561 unfinished_work_->set_total_bytes( 561 unfinished_work_->set_total_bytes(
562 unfinished_work_->total_bytes() + response_bytes); 562 unfinished_work_->total_bytes() + response_bytes);
563 unfinished_work_->set_network_bytes( 563 unfinished_work_->set_network_bytes(
564 unfinished_work_->network_bytes() + network_response_bytes); 564 unfinished_work_->network_bytes() + network_response_bytes);
565 } 565 }
566 566
567 } // namespace precache 567 } // namespace precache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698