Chromium Code Reviews| Index: components/data_reduction_proxy/browser/data_reduction_proxy_settings.cc |
| diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_settings.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_settings.cc |
| index cc575c94c3f6ef5e5cabd93855ed99cb89d94dd7..db8f40fd0da3c64d07e1cc6600adf8b0e7e6cbe8 100644 |
| --- a/components/data_reduction_proxy/browser/data_reduction_proxy_settings.cc |
| +++ b/components/data_reduction_proxy/browser/data_reduction_proxy_settings.cc |
| @@ -24,6 +24,7 @@ |
| #include "net/base/host_port_pair.h" |
| #include "net/base/load_flags.h" |
| #include "net/base/net_errors.h" |
| +#include "net/base/net_util.h" |
| #include "net/http/http_network_session.h" |
| #include "net/http/http_response_headers.h" |
| #include "net/url_request/url_fetcher.h" |
| @@ -36,6 +37,19 @@ |
| using base::StringPrintf; |
| namespace { |
| +// Values of the UMA DataReductionProxy.NetworkChangeEvents histograms. |
| +// This enum must remain synchronized with the enum of the same |
| +// name in metrics/histograms/histograms.xml. |
| +enum DataReductionProxyNetworkChangeEvents { |
| + // The client IP address changed. |
|
marq (ping after 24h)
2014/07/11 16:31:56
Use a more vertically-compact formatting:
IP
bengr
2014/07/11 22:49:15
Done.
|
| + IP_CHANGED = 0, |
| + |
| + // The proxy is disabled because a VPN is running. |
| + DISABLED_ON_VPN = 1, |
| + |
| + // This must always be last. |
| + CHANGE_EVENT_TYPE_MAX =2 |
|
Ilya Sherman
2014/07/11 03:45:52
nit: Please add a space after the '=' sign.
bengr
2014/07/11 22:49:15
Done.
|
| +}; |
| // Key of the UMA DataReductionProxy.StartupState histogram. |
| const char kUMAProxyStartupStateHistogram[] = |
| @@ -70,9 +84,11 @@ DataReductionProxySettings::DataReductionProxySettings( |
| DataReductionProxyParams* params) |
| : restricted_by_carrier_(false), |
| enabled_by_user_(false), |
| + disabled_on_vpn_(false), |
| prefs_(NULL), |
| local_state_prefs_(NULL), |
| - url_request_context_getter_(NULL) { |
| + url_request_context_getter_(NULL), |
| + usage_stats_(NULL) { |
| DCHECK(params); |
| params_.reset(params); |
| } |
| @@ -311,6 +327,11 @@ void DataReductionProxySettings::OnIPAddressChanged() { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| if (enabled_by_user_) { |
| DCHECK(params_->allowed()); |
| + UMA_HISTOGRAM_ENUMERATION("DataReductionProxy.NetworkChangeEvents", |
| + IP_CHANGED, |
| + CHANGE_EVENT_TYPE_MAX); |
| + if (DisableIfVPN()) |
| + return; |
| ProbeWhetherDataReductionProxyIsAvailable(); |
| WarmProxyConnection(); |
| } |
| @@ -359,13 +380,13 @@ void DataReductionProxySettings::MaybeActivateDataReductionProxy( |
| // Configure use of the data reduction proxy if it is enabled. |
| enabled_by_user_= IsDataReductionProxyEnabled(); |
| - SetProxyConfigs(enabled_by_user_, |
| + SetProxyConfigs(enabled_by_user_ && !disabled_on_vpn_, |
| IsDataReductionProxyAlternativeEnabled(), |
| restricted_by_carrier_, |
| at_startup); |
| // Check if the proxy has been restricted explicitly by the carrier. |
| - if (enabled_by_user_) { |
| + if (enabled_by_user_ && !disabled_on_vpn_) { |
| ProbeWhetherDataReductionProxyIsAvailable(); |
| WarmProxyConnection(); |
| } |
| @@ -425,6 +446,13 @@ void DataReductionProxySettings::RecordStartupState(ProxyStartupState state) { |
| PROXY_STARTUP_STATE_COUNT); |
| } |
| +void DataReductionProxySettings::GetNetworkList( |
| + net::NetworkInterfaceList* interfaces, |
| + int policy) { |
| + net::GetNetworkList(interfaces, policy); |
| + |
|
marq (ping after 24h)
2014/07/11 16:31:56
Extra line.
bengr
2014/07/11 22:49:16
Done.
|
| +} |
| + |
| void DataReductionProxySettings::ResetParamsForTest( |
| DataReductionProxyParams* params) { |
| params_.reset(params); |
| @@ -485,18 +513,6 @@ void DataReductionProxySettings::GetContentLengths( |
| local_state->GetInt64(prefs::kDailyHttpContentLengthLastUpdateDate); |
| } |
| -// static |
| -base::string16 DataReductionProxySettings::AuthHashForSalt( |
| - int64 salt, |
| - const std::string& key) { |
| - std::string salted_key = |
| - base::StringPrintf("%lld%s%lld", |
| - static_cast<long long>(salt), |
| - key.c_str(), |
| - static_cast<long long>(salt)); |
| - return base::UTF8ToUTF16(base::MD5String(salted_key)); |
| -} |
| - |
| net::URLFetcher* DataReductionProxySettings::GetBaseURLFetcher( |
| const GURL& gurl, |
| int load_flags) { |
| @@ -542,4 +558,29 @@ void DataReductionProxySettings::WarmProxyConnection() { |
| warmup_fetcher_->Start(); |
| } |
| +bool DataReductionProxySettings::DisableIfVPN() { |
| + net::NetworkInterfaceList network_interfaces; |
| + GetNetworkList(&network_interfaces, 0); |
| + const std::string vpn_interface_name_prefix = "tun"; |
|
marq (ping after 24h)
2014/07/11 16:31:56
Please add some comments explaining how this logic
bengr
2014/07/11 22:49:15
I added a comment. This will work on all Unix-deri
|
| + for (size_t i = 0; i < network_interfaces.size(); ++i) { |
| + std::string interface_name = network_interfaces[i].name; |
| + if (LowerCaseEqualsASCII( |
| + interface_name.begin(), |
| + interface_name.begin() + vpn_interface_name_prefix.size(), |
| + vpn_interface_name_prefix.c_str())) { |
| + SetProxyConfigs(false, |
| + IsDataReductionProxyAlternativeEnabled(), |
| + false, |
| + false); |
| + disabled_on_vpn_ = true; |
| + UMA_HISTOGRAM_ENUMERATION("DataReductionProxy.NetworkChangeEvents", |
| + DISABLED_ON_VPN, |
| + CHANGE_EVENT_TYPE_MAX); |
|
Ilya Sherman
2014/07/11 03:45:53
nit: Please factor out a method for emitting to th
marq (ping after 24h)
2014/07/11 16:31:56
Or at least factor the UMA name into a constant.
bengr
2014/07/11 22:49:15
Done.
bengr
2014/07/11 22:49:15
Done.
|
| + return true; |
| + } |
| + } |
| + disabled_on_vpn_ = false; |
| + return false; |
| +} |
| + |
| } // namespace data_reduction_proxy |