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

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

Issue 2037903002: Precache manifest should not be added to fetcher pool which is full (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments 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 28 matching lines...) Expand all
39 // The following flags are for privacy reasons. For example, if a user clears 39 // The following flags are for privacy reasons. For example, if a user clears
40 // their cookies, but a tracking beacon is prefetched and the beacon specifies 40 // their cookies, but a tracking beacon is prefetched and the beacon specifies
41 // its source URL in a URL param, the beacon site would be able to rebuild a 41 // its source URL in a URL param, the beacon site would be able to rebuild a
42 // profile of the user. All three flags should occur together, or not at all, 42 // profile of the user. All three flags should occur together, or not at all,
43 // per 43 // per
44 // https://groups.google.com/a/chromium.org/d/topic/net-dev/vvcodRV6SdM/discussi on. 44 // https://groups.google.com/a/chromium.org/d/topic/net-dev/vvcodRV6SdM/discussi on.
45 const int kNoTracking = 45 const int kNoTracking =
46 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_COOKIES | 46 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_COOKIES |
47 net::LOAD_DO_NOT_SEND_AUTH_DATA; 47 net::LOAD_DO_NOT_SEND_AUTH_DATA;
48 48
49 namespace {
50
51 // The maximum number of URLFetcher requests that can be on flight in parallel. 49 // The maximum number of URLFetcher requests that can be on flight in parallel.
52 const int kMaxParallelFetches = 10; 50 const int kMaxParallelFetches = 10;
53 51
52 int GetDefaultMaxParallelFetches() {
53 return kMaxParallelFetches;
54 }
55
56 namespace {
57
54 // The maximum for the Precache.Fetch.ResponseBytes.* histograms. We set this to 58 // The maximum for the Precache.Fetch.ResponseBytes.* histograms. We set this to
55 // a number we expect to be in the 99th percentile for the histogram, give or 59 // a number we expect to be in the 99th percentile for the histogram, give or
56 // take. 60 // take.
57 const int kMaxResponseBytes = 500 * 1024 * 1024; 61 const int kMaxResponseBytes = 500 * 1024 * 1024;
58 62
59 GURL GetDefaultConfigURL() { 63 GURL GetDefaultConfigURL() {
60 const base::CommandLine& command_line = 64 const base::CommandLine& command_line =
61 *base::CommandLine::ForCurrentProcess(); 65 *base::CommandLine::ForCurrentProcess();
62 if (command_line.HasSwitch(switches::kPrecacheConfigSettingsURL)) { 66 if (command_line.HasSwitch(switches::kPrecacheConfigSettingsURL)) {
63 return GURL( 67 return GURL(
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 net::URLRequestContextGetter* request_context, 324 net::URLRequestContextGetter* request_context,
321 const GURL& config_url, 325 const GURL& config_url,
322 const std::string& manifest_url_prefix, 326 const std::string& manifest_url_prefix,
323 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work, 327 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work,
324 uint32_t experiment_id, 328 uint32_t experiment_id,
325 PrecacheFetcher::PrecacheDelegate* precache_delegate) 329 PrecacheFetcher::PrecacheDelegate* precache_delegate)
326 : request_context_(request_context), 330 : request_context_(request_context),
327 config_url_(config_url), 331 config_url_(config_url),
328 manifest_url_prefix_(manifest_url_prefix), 332 manifest_url_prefix_(manifest_url_prefix),
329 precache_delegate_(precache_delegate), 333 precache_delegate_(precache_delegate),
330 pool_(kMaxParallelFetches), 334 pool_(GetDefaultMaxParallelFetches()),
331 experiment_id_(experiment_id) { 335 experiment_id_(experiment_id) {
332 DCHECK(request_context_.get()); // Request context must be non-NULL. 336 DCHECK(request_context_.get()); // Request context must be non-NULL.
333 DCHECK(precache_delegate_); // Precache delegate must be non-NULL. 337 DCHECK(precache_delegate_); // Precache delegate must be non-NULL.
334 338
335 DCHECK_NE(GURL(), GetDefaultConfigURL()) 339 DCHECK_NE(GURL(), GetDefaultConfigURL())
336 << "Could not determine the precache config settings URL."; 340 << "Could not determine the precache config settings URL.";
337 DCHECK_NE(std::string(), GetDefaultManifestURLPrefix()) 341 DCHECK_NE(std::string(), GetDefaultManifestURLPrefix())
338 << "Could not determine the default precache manifest URL prefix."; 342 << "Could not determine the default precache manifest URL prefix.";
339 DCHECK(unfinished_work); 343 DCHECK(unfinished_work);
340 344
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 new Fetcher(request_context_.get(), resource_urls_to_fetch_.front(), 413 new Fetcher(request_context_.get(), resource_urls_to_fetch_.front(),
410 base::Bind(&PrecacheFetcher::OnResourceFetchComplete, 414 base::Bind(&PrecacheFetcher::OnResourceFetchComplete,
411 base::Unretained(this)), 415 base::Unretained(this)),
412 true /* is_resource_request */, max_bytes))); 416 true /* is_resource_request */, max_bytes)));
413 417
414 resource_urls_to_fetch_.pop_front(); 418 resource_urls_to_fetch_.pop_front();
415 } 419 }
416 } 420 }
417 421
418 void PrecacheFetcher::StartNextManifestFetch() { 422 void PrecacheFetcher::StartNextManifestFetch() {
419 if (manifest_urls_to_fetch_.empty()) 423 if (manifest_urls_to_fetch_.empty() || !pool_.IsAvailable())
420 return; 424 return;
421 425
422 // We only fetch one manifest at a time to keep the size of 426 // We only fetch one manifest at a time to keep the size of
423 // resource_urls_to_fetch_ as small as possible. 427 // resource_urls_to_fetch_ as small as possible.
424 DCHECK(pool_.IsAvailable())
425 << "There are no available parallel requests to fetch the next manifest. "
426 "Did you forget to call Delete?";
427 VLOG(3) << "Fetching " << manifest_urls_to_fetch_.front(); 428 VLOG(3) << "Fetching " << manifest_urls_to_fetch_.front();
428 pool_.Add(base::WrapUnique(new Fetcher( 429 pool_.Add(base::WrapUnique(new Fetcher(
429 request_context_.get(), manifest_urls_to_fetch_.front(), 430 request_context_.get(), manifest_urls_to_fetch_.front(),
430 base::Bind(&PrecacheFetcher::OnManifestFetchComplete, 431 base::Bind(&PrecacheFetcher::OnManifestFetchComplete,
431 base::Unretained(this)), 432 base::Unretained(this)),
432 false /* is_resource_request */, std::numeric_limits<int32_t>::max()))); 433 false /* is_resource_request */, std::numeric_limits<int32_t>::max())));
433 434
434 manifest_urls_to_fetch_.pop_front(); 435 manifest_urls_to_fetch_.pop_front();
435 } 436 }
436 437
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 562
562 void PrecacheFetcher::UpdateStats(int64_t response_bytes, 563 void PrecacheFetcher::UpdateStats(int64_t response_bytes,
563 int64_t network_response_bytes) { 564 int64_t network_response_bytes) {
564 unfinished_work_->set_total_bytes( 565 unfinished_work_->set_total_bytes(
565 unfinished_work_->total_bytes() + response_bytes); 566 unfinished_work_->total_bytes() + response_bytes);
566 unfinished_work_->set_network_bytes( 567 unfinished_work_->set_network_bytes(
567 unfinished_work_->network_bytes() + network_response_bytes); 568 unfinished_work_->network_bytes() + network_response_bytes);
568 } 569 }
569 570
570 } // namespace precache 571 } // namespace precache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698