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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 DataReductionProxySettings::ContentLengthList | 233 DataReductionProxySettings::ContentLengthList |
234 DataReductionProxySettings::GetDailyReceivedContentLengths() { | 234 DataReductionProxySettings::GetDailyReceivedContentLengths() { |
235 DCHECK(thread_checker_.CalledOnValidThread()); | 235 DCHECK(thread_checker_.CalledOnValidThread()); |
236 return GetDailyContentLengths(prefs::kDailyHttpReceivedContentLength); | 236 return GetDailyContentLengths(prefs::kDailyHttpReceivedContentLength); |
237 } | 237 } |
238 | 238 |
239 void DataReductionProxySettings::OnURLFetchComplete( | 239 void DataReductionProxySettings::OnURLFetchComplete( |
240 const net::URLFetcher* source) { | 240 const net::URLFetcher* source) { |
241 DCHECK(thread_checker_.CalledOnValidThread()); | 241 DCHECK(thread_checker_.CalledOnValidThread()); |
242 | 242 |
243 // The purpose of sending a request for the warmup URL is to warm the | |
244 // connection to the data_reduction_proxy. The result is ignored. | |
245 if (source == warmup_fetcher_.get()) | |
246 return; | |
247 | |
248 DCHECK(source == fetcher_.get()); | 243 DCHECK(source == fetcher_.get()); |
249 net::URLRequestStatus status = source->GetStatus(); | 244 net::URLRequestStatus status = source->GetStatus(); |
250 if (status.status() == net::URLRequestStatus::FAILED) { | 245 if (status.status() == net::URLRequestStatus::FAILED) { |
251 if (status.error() == net::ERR_INTERNET_DISCONNECTED) { | 246 if (status.error() == net::ERR_INTERNET_DISCONNECTED) { |
252 RecordProbeURLFetchResult(INTERNET_DISCONNECTED); | 247 RecordProbeURLFetchResult(INTERNET_DISCONNECTED); |
253 return; | 248 return; |
254 } | 249 } |
255 // TODO(bengr): Remove once we understand the reasons probes are failing. | 250 // TODO(bengr): Remove once we understand the reasons probes are failing. |
256 // Probe errors are either due to fetcher-level errors or modified | 251 // Probe errors are either due to fetcher-level errors or modified |
257 // responses. This only tracks the former. | 252 // responses. This only tracks the former. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 } | 339 } |
345 | 340 |
346 void DataReductionProxySettings::OnIPAddressChanged() { | 341 void DataReductionProxySettings::OnIPAddressChanged() { |
347 DCHECK(thread_checker_.CalledOnValidThread()); | 342 DCHECK(thread_checker_.CalledOnValidThread()); |
348 if (enabled_by_user_) { | 343 if (enabled_by_user_) { |
349 DCHECK(params_->allowed()); | 344 DCHECK(params_->allowed()); |
350 RecordNetworkChangeEvent(IP_CHANGED); | 345 RecordNetworkChangeEvent(IP_CHANGED); |
351 if (DisableIfVPN()) | 346 if (DisableIfVPN()) |
352 return; | 347 return; |
353 ProbeWhetherDataReductionProxyIsAvailable(); | 348 ProbeWhetherDataReductionProxyIsAvailable(); |
354 WarmProxyConnection(); | |
355 } | 349 } |
356 } | 350 } |
357 | 351 |
358 void DataReductionProxySettings::OnProxyEnabledPrefChange() { | 352 void DataReductionProxySettings::OnProxyEnabledPrefChange() { |
359 DCHECK(thread_checker_.CalledOnValidThread()); | 353 DCHECK(thread_checker_.CalledOnValidThread()); |
360 if (!on_data_reduction_proxy_enabled_.is_null()) | 354 if (!on_data_reduction_proxy_enabled_.is_null()) |
361 on_data_reduction_proxy_enabled_.Run(IsDataReductionProxyEnabled()); | 355 on_data_reduction_proxy_enabled_.Run(IsDataReductionProxyEnabled()); |
362 if (!params_->allowed()) | 356 if (!params_->allowed()) |
363 return; | 357 return; |
364 MaybeActivateDataReductionProxy(false); | 358 MaybeActivateDataReductionProxy(false); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 // Configure use of the data reduction proxy if it is enabled. | 394 // Configure use of the data reduction proxy if it is enabled. |
401 enabled_by_user_= IsDataReductionProxyEnabled(); | 395 enabled_by_user_= IsDataReductionProxyEnabled(); |
402 SetProxyConfigs(enabled_by_user_ && !disabled_on_vpn_, | 396 SetProxyConfigs(enabled_by_user_ && !disabled_on_vpn_, |
403 IsDataReductionProxyAlternativeEnabled(), | 397 IsDataReductionProxyAlternativeEnabled(), |
404 restricted_by_carrier_, | 398 restricted_by_carrier_, |
405 at_startup); | 399 at_startup); |
406 | 400 |
407 // Check if the proxy has been restricted explicitly by the carrier. | 401 // Check if the proxy has been restricted explicitly by the carrier. |
408 if (enabled_by_user_ && !disabled_on_vpn_) { | 402 if (enabled_by_user_ && !disabled_on_vpn_) { |
409 ProbeWhetherDataReductionProxyIsAvailable(); | 403 ProbeWhetherDataReductionProxyIsAvailable(); |
410 WarmProxyConnection(); | |
411 } | 404 } |
412 } | 405 } |
413 | 406 |
414 void DataReductionProxySettings::SetProxyConfigs(bool enabled, | 407 void DataReductionProxySettings::SetProxyConfigs(bool enabled, |
415 bool alternative_enabled, | 408 bool alternative_enabled, |
416 bool restricted, | 409 bool restricted, |
417 bool at_startup) { | 410 bool at_startup) { |
418 DCHECK(thread_checker_.CalledOnValidThread()); | 411 DCHECK(thread_checker_.CalledOnValidThread()); |
419 DCHECK(configurator_); | 412 DCHECK(configurator_); |
420 | 413 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 | 552 |
560 | 553 |
561 void DataReductionProxySettings::ProbeWhetherDataReductionProxyIsAvailable() { | 554 void DataReductionProxySettings::ProbeWhetherDataReductionProxyIsAvailable() { |
562 net::URLFetcher* fetcher = GetURLFetcherForAvailabilityCheck(); | 555 net::URLFetcher* fetcher = GetURLFetcherForAvailabilityCheck(); |
563 if (!fetcher) | 556 if (!fetcher) |
564 return; | 557 return; |
565 fetcher_.reset(fetcher); | 558 fetcher_.reset(fetcher); |
566 fetcher_->Start(); | 559 fetcher_->Start(); |
567 } | 560 } |
568 | 561 |
569 net::URLFetcher* DataReductionProxySettings::GetURLFetcherForWarmup() { | |
570 return GetBaseURLFetcher(params_->warmup_url(), net::LOAD_DISABLE_CACHE); | |
571 } | |
572 | |
573 void DataReductionProxySettings::WarmProxyConnection() { | |
574 net::URLFetcher* fetcher = GetURLFetcherForWarmup(); | |
575 if (!fetcher) | |
576 return; | |
577 warmup_fetcher_.reset(fetcher); | |
578 warmup_fetcher_->Start(); | |
579 } | |
580 | |
581 bool DataReductionProxySettings::DisableIfVPN() { | 562 bool DataReductionProxySettings::DisableIfVPN() { |
582 net::NetworkInterfaceList network_interfaces; | 563 net::NetworkInterfaceList network_interfaces; |
583 GetNetworkList(&network_interfaces, 0); | 564 GetNetworkList(&network_interfaces, 0); |
584 // VPNs use a "tun" interface, so the presence of a "tun" interface indicates | 565 // VPNs use a "tun" interface, so the presence of a "tun" interface indicates |
585 // a VPN is in use. | 566 // a VPN is in use. |
586 // TODO(kundaji): Verify this works on Windows. | 567 // TODO(kundaji): Verify this works on Windows. |
587 const std::string vpn_interface_name_prefix = "tun"; | 568 const std::string vpn_interface_name_prefix = "tun"; |
588 for (size_t i = 0; i < network_interfaces.size(); ++i) { | 569 for (size_t i = 0; i < network_interfaces.size(); ++i) { |
589 std::string interface_name = network_interfaces[i].name; | 570 std::string interface_name = network_interfaces[i].name; |
590 if (LowerCaseEqualsASCII( | 571 if (LowerCaseEqualsASCII( |
(...skipping 13 matching lines...) Expand all Loading... |
604 SetProxyConfigs(enabled_by_user_, | 585 SetProxyConfigs(enabled_by_user_, |
605 IsDataReductionProxyAlternativeEnabled(), | 586 IsDataReductionProxyAlternativeEnabled(), |
606 restricted_by_carrier_, | 587 restricted_by_carrier_, |
607 false); | 588 false); |
608 } | 589 } |
609 disabled_on_vpn_ = false; | 590 disabled_on_vpn_ = false; |
610 return false; | 591 return false; |
611 } | 592 } |
612 | 593 |
613 } // namespace data_reduction_proxy | 594 } // namespace data_reduction_proxy |
OLD | NEW |