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

Side by Side Diff: components/data_reduction_proxy/browser/data_reduction_proxy_settings.cc

Issue 338723002: Add probe to warm data reduction proxy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/data_reduction_proxy/browser/data_reduction_proxy_settings. h" 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings. h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 297
298 DataReductionProxySettings::ContentLengthList 298 DataReductionProxySettings::ContentLengthList
299 DataReductionProxySettings::GetDailyReceivedContentLengths() { 299 DataReductionProxySettings::GetDailyReceivedContentLengths() {
300 DCHECK(thread_checker_.CalledOnValidThread()); 300 DCHECK(thread_checker_.CalledOnValidThread());
301 return GetDailyContentLengths(prefs::kDailyHttpReceivedContentLength); 301 return GetDailyContentLengths(prefs::kDailyHttpReceivedContentLength);
302 } 302 }
303 303
304 void DataReductionProxySettings::OnURLFetchComplete( 304 void DataReductionProxySettings::OnURLFetchComplete(
305 const net::URLFetcher* source) { 305 const net::URLFetcher* source) {
306 DCHECK(thread_checker_.CalledOnValidThread()); 306 DCHECK(thread_checker_.CalledOnValidThread());
307
308 // The purpose of sending a request for the warmup URL is to warm the
309 // connection to the data_reduction_proxy. The result is ignored.
310 if (source == warmup_fetcher_.get())
311 return;
312
313 DCHECK(source == fetcher_.get());
307 net::URLRequestStatus status = source->GetStatus(); 314 net::URLRequestStatus status = source->GetStatus();
308 if (status.status() == net::URLRequestStatus::FAILED && 315 if (status.status() == net::URLRequestStatus::FAILED &&
309 status.error() == net::ERR_INTERNET_DISCONNECTED) { 316 status.error() == net::ERR_INTERNET_DISCONNECTED) {
310 RecordProbeURLFetchResult(INTERNET_DISCONNECTED); 317 RecordProbeURLFetchResult(INTERNET_DISCONNECTED);
311 return; 318 return;
312 } 319 }
313 320
314 std::string response; 321 std::string response;
315 source->GetResponseAsString(&response); 322 source->GetResponseAsString(&response);
316 323
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 399
393 LOG(WARNING) << "SPDY proxy " << (enabled ? annotated_on : kOff) 400 LOG(WARNING) << "SPDY proxy " << (enabled ? annotated_on : kOff)
394 << " " << (at_startup ? kAtStartup : kByUser); 401 << " " << (at_startup ? kAtStartup : kByUser);
395 } 402 }
396 403
397 void DataReductionProxySettings::OnIPAddressChanged() { 404 void DataReductionProxySettings::OnIPAddressChanged() {
398 DCHECK(thread_checker_.CalledOnValidThread()); 405 DCHECK(thread_checker_.CalledOnValidThread());
399 if (enabled_by_user_) { 406 if (enabled_by_user_) {
400 DCHECK(params_->allowed()); 407 DCHECK(params_->allowed());
401 ProbeWhetherDataReductionProxyIsAvailable(); 408 ProbeWhetherDataReductionProxyIsAvailable();
409 WarmProxyConnection();
402 } 410 }
403 } 411 }
404 412
405 void DataReductionProxySettings::OnProxyEnabledPrefChange() { 413 void DataReductionProxySettings::OnProxyEnabledPrefChange() {
406 DCHECK(thread_checker_.CalledOnValidThread()); 414 DCHECK(thread_checker_.CalledOnValidThread());
407 if (!params_->allowed()) 415 if (!params_->allowed())
408 return; 416 return;
409 MaybeActivateDataReductionProxy(false); 417 MaybeActivateDataReductionProxy(false);
410 } 418 }
411 419
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 } 452 }
445 453
446 // Configure use of the data reduction proxy if it is enabled. 454 // Configure use of the data reduction proxy if it is enabled.
447 enabled_by_user_= IsDataReductionProxyEnabled(); 455 enabled_by_user_= IsDataReductionProxyEnabled();
448 SetProxyConfigs(enabled_by_user_, 456 SetProxyConfigs(enabled_by_user_,
449 IsDataReductionProxyAlternativeEnabled(), 457 IsDataReductionProxyAlternativeEnabled(),
450 restricted_by_carrier_, 458 restricted_by_carrier_,
451 at_startup); 459 at_startup);
452 460
453 // Check if the proxy has been restricted explicitly by the carrier. 461 // Check if the proxy has been restricted explicitly by the carrier.
454 if (enabled_by_user_) 462 if (enabled_by_user_) {
455 ProbeWhetherDataReductionProxyIsAvailable(); 463 ProbeWhetherDataReductionProxyIsAvailable();
464 WarmProxyConnection();
465 }
456 } 466 }
457 467
458 void DataReductionProxySettings::SetProxyConfigs(bool enabled, 468 void DataReductionProxySettings::SetProxyConfigs(bool enabled,
459 bool alternative_enabled, 469 bool alternative_enabled,
460 bool restricted, 470 bool restricted,
461 bool at_startup) { 471 bool at_startup) {
462 DCHECK(thread_checker_.CalledOnValidThread()); 472 DCHECK(thread_checker_.CalledOnValidThread());
463 LogProxyState(enabled, restricted, at_startup); 473 LogProxyState(enabled, restricted, at_startup);
464 // The alternative is only configured if the standard configuration is 474 // The alternative is only configured if the standard configuration is
465 // is enabled. 475 // is enabled.
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 int64 salt, 584 int64 salt,
575 const std::string& key) { 585 const std::string& key) {
576 std::string salted_key = 586 std::string salted_key =
577 base::StringPrintf("%lld%s%lld", 587 base::StringPrintf("%lld%s%lld",
578 static_cast<long long>(salt), 588 static_cast<long long>(salt),
579 key.c_str(), 589 key.c_str(),
580 static_cast<long long>(salt)); 590 static_cast<long long>(salt));
581 return base::UTF8ToUTF16(base::MD5String(salted_key)); 591 return base::UTF8ToUTF16(base::MD5String(salted_key));
582 } 592 }
583 593
584 net::URLFetcher* DataReductionProxySettings::GetURLFetcher() { 594 net::URLFetcher* DataReductionProxySettings::GetBaseURLFetcher(
585 DCHECK(url_request_context_getter_); 595 const GURL& gurl,
586 net::URLFetcher* fetcher = net::URLFetcher::Create(params_->probe_url(), 596 int load_flags) {
597
598 net::URLFetcher* fetcher = net::URLFetcher::Create(gurl,
587 net::URLFetcher::GET, 599 net::URLFetcher::GET,
588 this); 600 this);
589 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE | net::LOAD_BYPASS_PROXY); 601 fetcher->SetLoadFlags(load_flags);
602 DCHECK(url_request_context_getter_);
590 fetcher->SetRequestContext(url_request_context_getter_); 603 fetcher->SetRequestContext(url_request_context_getter_);
591 // Configure max retries to be at most kMaxRetries times for 5xx errors. 604 // Configure max retries to be at most kMaxRetries times for 5xx errors.
592 static const int kMaxRetries = 5; 605 static const int kMaxRetries = 5;
593 fetcher->SetMaxRetriesOn5xx(kMaxRetries); 606 fetcher->SetMaxRetriesOn5xx(kMaxRetries);
594 fetcher->SetAutomaticallyRetryOnNetworkChanges(kMaxRetries); 607 fetcher->SetAutomaticallyRetryOnNetworkChanges(kMaxRetries);
595 return fetcher; 608 return fetcher;
596 } 609 }
597 610
611
612 net::URLFetcher*
613 DataReductionProxySettings::GetURLFetcherForAvailabilityCheck() {
614 return GetBaseURLFetcher(params_->probe_url(),
615 net::LOAD_DISABLE_CACHE | net::LOAD_BYPASS_PROXY);
616 }
617
618
598 void DataReductionProxySettings::ProbeWhetherDataReductionProxyIsAvailable() { 619 void DataReductionProxySettings::ProbeWhetherDataReductionProxyIsAvailable() {
599 net::URLFetcher* fetcher = GetURLFetcher(); 620 net::URLFetcher* fetcher = GetURLFetcherForAvailabilityCheck();
600 if (!fetcher) 621 if (!fetcher)
601 return; 622 return;
602 fetcher_.reset(fetcher); 623 fetcher_.reset(fetcher);
603 fetcher_->Start(); 624 fetcher_->Start();
604 } 625 }
605 626
627 net::URLFetcher* DataReductionProxySettings::GetURLFetcherForWarmup() {
628 return GetBaseURLFetcher(params_->warmup_url(), net::LOAD_DISABLE_CACHE);
629 }
630
631 void DataReductionProxySettings::WarmProxyConnection() {
632 net::URLFetcher* fetcher = GetURLFetcherForWarmup();
633 if (!fetcher)
634 return;
635 warmup_fetcher_.reset(fetcher);
636 warmup_fetcher_->Start();
637 }
638
606 } // namespace data_reduction_proxy 639 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698