Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 | |
|
marq (ping after 24h)
2014/06/16 17:23:35
DCHECK(source == fetcher_.get()), so that adding a
bengr
2014/06/17 03:42:09
Done.
| |
| 307 net::URLRequestStatus status = source->GetStatus(); | 313 net::URLRequestStatus status = source->GetStatus(); |
| 308 if (status.status() == net::URLRequestStatus::FAILED && | 314 if (status.status() == net::URLRequestStatus::FAILED && |
| 309 status.error() == net::ERR_INTERNET_DISCONNECTED) { | 315 status.error() == net::ERR_INTERNET_DISCONNECTED) { |
| 310 RecordProbeURLFetchResult(INTERNET_DISCONNECTED); | 316 RecordProbeURLFetchResult(INTERNET_DISCONNECTED); |
| 311 return; | 317 return; |
| 312 } | 318 } |
| 313 | 319 |
| 314 std::string response; | 320 std::string response; |
| 315 source->GetResponseAsString(&response); | 321 source->GetResponseAsString(&response); |
| 316 | 322 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 | 398 |
| 393 LOG(WARNING) << "SPDY proxy " << (enabled ? annotated_on : kOff) | 399 LOG(WARNING) << "SPDY proxy " << (enabled ? annotated_on : kOff) |
| 394 << " " << (at_startup ? kAtStartup : kByUser); | 400 << " " << (at_startup ? kAtStartup : kByUser); |
| 395 } | 401 } |
| 396 | 402 |
| 397 void DataReductionProxySettings::OnIPAddressChanged() { | 403 void DataReductionProxySettings::OnIPAddressChanged() { |
| 398 DCHECK(thread_checker_.CalledOnValidThread()); | 404 DCHECK(thread_checker_.CalledOnValidThread()); |
| 399 if (enabled_by_user_) { | 405 if (enabled_by_user_) { |
| 400 DCHECK(params_->allowed()); | 406 DCHECK(params_->allowed()); |
| 401 ProbeWhetherDataReductionProxyIsAvailable(); | 407 ProbeWhetherDataReductionProxyIsAvailable(); |
| 408 WarmProxyConnection(); | |
| 402 } | 409 } |
| 403 } | 410 } |
| 404 | 411 |
| 405 void DataReductionProxySettings::OnProxyEnabledPrefChange() { | 412 void DataReductionProxySettings::OnProxyEnabledPrefChange() { |
| 406 DCHECK(thread_checker_.CalledOnValidThread()); | 413 DCHECK(thread_checker_.CalledOnValidThread()); |
| 407 if (!params_->allowed()) | 414 if (!params_->allowed()) |
| 408 return; | 415 return; |
| 409 MaybeActivateDataReductionProxy(false); | 416 MaybeActivateDataReductionProxy(false); |
| 410 } | 417 } |
| 411 | 418 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 444 } | 451 } |
| 445 | 452 |
| 446 // Configure use of the data reduction proxy if it is enabled. | 453 // Configure use of the data reduction proxy if it is enabled. |
| 447 enabled_by_user_= IsDataReductionProxyEnabled(); | 454 enabled_by_user_= IsDataReductionProxyEnabled(); |
| 448 SetProxyConfigs(enabled_by_user_, | 455 SetProxyConfigs(enabled_by_user_, |
| 449 IsDataReductionProxyAlternativeEnabled(), | 456 IsDataReductionProxyAlternativeEnabled(), |
| 450 restricted_by_carrier_, | 457 restricted_by_carrier_, |
| 451 at_startup); | 458 at_startup); |
| 452 | 459 |
| 453 // Check if the proxy has been restricted explicitly by the carrier. | 460 // Check if the proxy has been restricted explicitly by the carrier. |
| 454 if (enabled_by_user_) | 461 if (enabled_by_user_) { |
| 455 ProbeWhetherDataReductionProxyIsAvailable(); | 462 ProbeWhetherDataReductionProxyIsAvailable(); |
| 463 WarmProxyConnection(); | |
| 464 } | |
| 456 } | 465 } |
| 457 | 466 |
| 458 void DataReductionProxySettings::SetProxyConfigs(bool enabled, | 467 void DataReductionProxySettings::SetProxyConfigs(bool enabled, |
| 459 bool alternative_enabled, | 468 bool alternative_enabled, |
| 460 bool restricted, | 469 bool restricted, |
| 461 bool at_startup) { | 470 bool at_startup) { |
| 462 DCHECK(thread_checker_.CalledOnValidThread()); | 471 DCHECK(thread_checker_.CalledOnValidThread()); |
| 463 LogProxyState(enabled, restricted, at_startup); | 472 LogProxyState(enabled, restricted, at_startup); |
| 464 // The alternative is only configured if the standard configuration is | 473 // The alternative is only configured if the standard configuration is |
| 465 // is enabled. | 474 // is enabled. |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 574 int64 salt, | 583 int64 salt, |
| 575 const std::string& key) { | 584 const std::string& key) { |
| 576 std::string salted_key = | 585 std::string salted_key = |
| 577 base::StringPrintf("%lld%s%lld", | 586 base::StringPrintf("%lld%s%lld", |
| 578 static_cast<long long>(salt), | 587 static_cast<long long>(salt), |
| 579 key.c_str(), | 588 key.c_str(), |
| 580 static_cast<long long>(salt)); | 589 static_cast<long long>(salt)); |
| 581 return base::UTF8ToUTF16(base::MD5String(salted_key)); | 590 return base::UTF8ToUTF16(base::MD5String(salted_key)); |
| 582 } | 591 } |
| 583 | 592 |
| 584 net::URLFetcher* DataReductionProxySettings::GetURLFetcher() { | 593 net::URLFetcher* DataReductionProxySettings::GetBaseURLFetcher( |
| 585 DCHECK(url_request_context_getter_); | 594 const GURL& gurl, |
| 586 net::URLFetcher* fetcher = net::URLFetcher::Create(params_->probe_url(), | 595 int load_flags) { |
| 596 | |
| 597 net::URLFetcher* fetcher = net::URLFetcher::Create(gurl, | |
| 587 net::URLFetcher::GET, | 598 net::URLFetcher::GET, |
| 588 this); | 599 this); |
| 589 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE | net::LOAD_BYPASS_PROXY); | 600 fetcher->SetLoadFlags(load_flags); |
| 601 DCHECK(url_request_context_getter_); | |
| 590 fetcher->SetRequestContext(url_request_context_getter_); | 602 fetcher->SetRequestContext(url_request_context_getter_); |
| 591 // Configure max retries to be at most kMaxRetries times for 5xx errors. | 603 // Configure max retries to be at most kMaxRetries times for 5xx errors. |
| 592 static const int kMaxRetries = 5; | 604 static const int kMaxRetries = 5; |
| 593 fetcher->SetMaxRetriesOn5xx(kMaxRetries); | 605 fetcher->SetMaxRetriesOn5xx(kMaxRetries); |
| 594 fetcher->SetAutomaticallyRetryOnNetworkChanges(kMaxRetries); | 606 fetcher->SetAutomaticallyRetryOnNetworkChanges(kMaxRetries); |
| 595 return fetcher; | 607 return fetcher; |
| 596 } | 608 } |
| 597 | 609 |
| 610 | |
| 611 net::URLFetcher* DataReductionProxySettings::GetURLFetcher() { | |
|
marq (ping after 24h)
2014/06/16 17:23:34
I think you can tighten things up a bit and roll t
bengr
2014/06/17 03:42:09
This is the way it is to make testing easier.
| |
| 612 return GetBaseURLFetcher(params_->probe_url(), | |
| 613 net::LOAD_DISABLE_CACHE | net::LOAD_BYPASS_PROXY); | |
| 614 } | |
| 615 | |
| 616 | |
| 598 void DataReductionProxySettings::ProbeWhetherDataReductionProxyIsAvailable() { | 617 void DataReductionProxySettings::ProbeWhetherDataReductionProxyIsAvailable() { |
| 599 net::URLFetcher* fetcher = GetURLFetcher(); | 618 net::URLFetcher* fetcher = GetURLFetcher(); |
| 600 if (!fetcher) | 619 if (!fetcher) |
| 601 return; | 620 return; |
| 602 fetcher_.reset(fetcher); | 621 fetcher_.reset(fetcher); |
| 603 fetcher_->Start(); | 622 fetcher_->Start(); |
| 604 } | 623 } |
| 605 | 624 |
| 625 net::URLFetcher* DataReductionProxySettings::GetURLFetcherForWarmup() { | |
| 626 return GetBaseURLFetcher(params_->warmup_url(), | |
| 627 net::LOAD_DISABLE_CACHE); | |
|
marq (ping after 24h)
2014/06/16 17:23:35
This will fit on one line.
bengr
2014/06/17 03:42:09
Done.
| |
| 628 } | |
| 629 | |
| 630 void DataReductionProxySettings::WarmProxyConnection() { | |
| 631 net::URLFetcher* fetcher = GetURLFetcherForWarmup(); | |
| 632 if (!fetcher) | |
| 633 return; | |
| 634 warmup_fetcher_.reset(fetcher); | |
| 635 warmup_fetcher_->Start(); | |
| 636 } | |
| 637 | |
| 606 } // namespace data_reduction_proxy | 638 } // namespace data_reduction_proxy |
| OLD | NEW |