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

Unified Diff: components/data_reduction_proxy/browser/data_reduction_proxy_settings.cc

Issue 373153003: Bypass data reduction proxy when using VPN (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
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 b4299655cc85e30a93f0d9a0960453d96046b4d3..1d1d70f6abbae11a3f675039a8c0eb5a8e8cabfe 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,14 @@
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 DataReductionProxyNetworkChangeEvent {
+ IP_CHANGED = 0, // The client IP address changed.
+ DISABLED_ON_VPN = 1, // The proxy is disabled because a VPN is running.
+ CHANGE_EVENT_COUNT = 2 // This must always be last.
+};
// Key of the UMA DataReductionProxy.StartupState histogram.
const char kUMAProxyStartupStateHistogram[] =
@@ -44,6 +53,13 @@ const char kUMAProxyStartupStateHistogram[] =
// Key of the UMA DataReductionProxy.ProbeURL histogram.
const char kUMAProxyProbeURL[] = "DataReductionProxy.ProbeURL";
+// Record a network change event.
+void RecordNetworkChangeEvent(DataReductionProxyNetworkChangeEvent event) {
+ UMA_HISTOGRAM_ENUMERATION("DataReductionProxy.NetworkChangeEvents",
+ event,
+ CHANGE_EVENT_COUNT);
+}
+
int64 GetInt64PrefValue(const base::ListValue& list_value, size_t index) {
int64 val = 0;
std::string pref_value;
@@ -70,10 +86,10 @@ 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),
- usage_stats_(NULL) {
+ url_request_context_getter_(NULL) {
DCHECK(params);
params_.reset(params);
}
@@ -312,6 +328,9 @@ void DataReductionProxySettings::OnIPAddressChanged() {
DCHECK(thread_checker_.CalledOnValidThread());
if (enabled_by_user_) {
DCHECK(params_->allowed());
+ RecordNetworkChangeEvent(IP_CHANGED);
+ if (DisableIfVPN())
+ return;
ProbeWhetherDataReductionProxyIsAvailable();
WarmProxyConnection();
}
@@ -360,13 +379,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();
}
@@ -426,6 +445,12 @@ void DataReductionProxySettings::RecordStartupState(ProxyStartupState state) {
PROXY_STARTUP_STATE_COUNT);
}
+void DataReductionProxySettings::GetNetworkList(
+ net::NetworkInterfaceList* interfaces,
+ int policy) {
+ net::GetNetworkList(interfaces, policy);
+}
+
void DataReductionProxySettings::ResetParamsForTest(
DataReductionProxyParams* params) {
params_.reset(params);
@@ -486,18 +511,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) {
@@ -543,4 +556,36 @@ void DataReductionProxySettings::WarmProxyConnection() {
warmup_fetcher_->Start();
}
+bool DataReductionProxySettings::DisableIfVPN() {
+ net::NetworkInterfaceList network_interfaces;
+ GetNetworkList(&network_interfaces, 0);
+ // VPNs use a "tun" interface, so the presence of a "tun" interface indicates
+ // a VPN is in use.
+ // TODO(kundaji): Verify this works on Windows.
+ const std::string vpn_interface_name_prefix = "tun";
+ 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;
+ RecordNetworkChangeEvent(DISABLED_ON_VPN);
+ return true;
+ }
+ }
+ if (disabled_on_vpn_) {
+ SetProxyConfigs(enabled_by_user_,
+ IsDataReductionProxyAlternativeEnabled(),
+ restricted_by_carrier_,
+ false);
+ }
+ disabled_on_vpn_ = false;
+ return false;
+}
+
} // namespace data_reduction_proxy

Powered by Google App Engine
This is Rietveld 408576698