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

Side by Side 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: Addressed comments from marq and Ilya 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 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"
11 #include "base/prefs/pref_member.h" 11 #include "base/prefs/pref_member.h"
12 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
13 #include "base/prefs/scoped_user_pref_update.h" 13 #include "base/prefs/scoped_user_pref_update.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "components/data_reduction_proxy/browser/data_reduction_proxy_auth_requ est_handler.h" 18 #include "components/data_reduction_proxy/browser/data_reduction_proxy_auth_requ est_handler.h"
19 #include "components/data_reduction_proxy/browser/data_reduction_proxy_configura tor.h" 19 #include "components/data_reduction_proxy/browser/data_reduction_proxy_configura tor.h"
20 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" 20 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
21 #include "components/data_reduction_proxy/browser/data_reduction_proxy_usage_sta ts.h" 21 #include "components/data_reduction_proxy/browser/data_reduction_proxy_usage_sta ts.h"
22 #include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names .h" 22 #include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names .h"
23 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h " 23 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h "
24 #include "net/base/host_port_pair.h" 24 #include "net/base/host_port_pair.h"
25 #include "net/base/load_flags.h" 25 #include "net/base/load_flags.h"
26 #include "net/base/net_errors.h" 26 #include "net/base/net_errors.h"
27 #include "net/base/net_util.h"
27 #include "net/http/http_network_session.h" 28 #include "net/http/http_network_session.h"
28 #include "net/http/http_response_headers.h" 29 #include "net/http/http_response_headers.h"
29 #include "net/url_request/url_fetcher.h" 30 #include "net/url_request/url_fetcher.h"
30 #include "net/url_request/url_fetcher_delegate.h" 31 #include "net/url_request/url_fetcher_delegate.h"
31 #include "net/url_request/url_request_context_getter.h" 32 #include "net/url_request/url_request_context_getter.h"
32 #include "net/url_request/url_request_status.h" 33 #include "net/url_request/url_request_status.h"
33 #include "url/gurl.h" 34 #include "url/gurl.h"
34 35
35 36
36 using base::StringPrintf; 37 using base::StringPrintf;
37 38
38 namespace { 39 namespace {
40 // Values of the UMA DataReductionProxy.NetworkChangeEvents histograms.
41 // This enum must remain synchronized with the enum of the same
42 // name in metrics/histograms/histograms.xml.
43 enum DataReductionProxyNetworkChangeEvent {
44 IP_CHANGED = 0, // The client IP address changed.
45 DISABLED_ON_VPN = 1, // The proxy is disabled because a VPN is running.
46 CHANGE_EVENT_COUNT = 2 // This must always be last.
47 };
39 48
40 // Key of the UMA DataReductionProxy.StartupState histogram. 49 // Key of the UMA DataReductionProxy.StartupState histogram.
41 const char kUMAProxyStartupStateHistogram[] = 50 const char kUMAProxyStartupStateHistogram[] =
42 "DataReductionProxy.StartupState"; 51 "DataReductionProxy.StartupState";
43 52
44 // Key of the UMA DataReductionProxy.ProbeURL histogram. 53 // Key of the UMA DataReductionProxy.ProbeURL histogram.
45 const char kUMAProxyProbeURL[] = "DataReductionProxy.ProbeURL"; 54 const char kUMAProxyProbeURL[] = "DataReductionProxy.ProbeURL";
46 55
56 // Record a network change event.
57 void RecordNetworkChangeEvent(DataReductionProxyNetworkChangeEvent event) {
58 UMA_HISTOGRAM_ENUMERATION("DataReductionProxy.NetworkChangeEvents",
59 event,
60 CHANGE_EVENT_COUNT);
61 }
62
47 int64 GetInt64PrefValue(const base::ListValue& list_value, size_t index) { 63 int64 GetInt64PrefValue(const base::ListValue& list_value, size_t index) {
48 int64 val = 0; 64 int64 val = 0;
49 std::string pref_value; 65 std::string pref_value;
50 bool rv = list_value.GetString(index, &pref_value); 66 bool rv = list_value.GetString(index, &pref_value);
51 DCHECK(rv); 67 DCHECK(rv);
52 if (rv) { 68 if (rv) {
53 rv = base::StringToInt64(pref_value, &val); 69 rv = base::StringToInt64(pref_value, &val);
54 DCHECK(rv); 70 DCHECK(rv);
55 } 71 }
56 return val; 72 return val;
57 } 73 }
58 74
59 bool IsEnabledOnCommandLine() { 75 bool IsEnabledOnCommandLine() {
60 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 76 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
61 return command_line.HasSwitch( 77 return command_line.HasSwitch(
62 data_reduction_proxy::switches::kEnableDataReductionProxy); 78 data_reduction_proxy::switches::kEnableDataReductionProxy);
63 } 79 }
64 80
65 } // namespace 81 } // namespace
66 82
67 namespace data_reduction_proxy { 83 namespace data_reduction_proxy {
68 84
69 DataReductionProxySettings::DataReductionProxySettings( 85 DataReductionProxySettings::DataReductionProxySettings(
70 DataReductionProxyParams* params) 86 DataReductionProxyParams* params)
71 : restricted_by_carrier_(false), 87 : restricted_by_carrier_(false),
72 enabled_by_user_(false), 88 enabled_by_user_(false),
89 disabled_on_vpn_(false),
73 prefs_(NULL), 90 prefs_(NULL),
74 local_state_prefs_(NULL), 91 local_state_prefs_(NULL),
75 url_request_context_getter_(NULL) { 92 url_request_context_getter_(NULL),
93 usage_stats_(NULL) {
76 DCHECK(params); 94 DCHECK(params);
77 params_.reset(params); 95 params_.reset(params);
78 } 96 }
79 97
80 DataReductionProxySettings::~DataReductionProxySettings() { 98 DataReductionProxySettings::~DataReductionProxySettings() {
81 if (params_->allowed()) 99 if (params_->allowed())
82 spdy_proxy_auth_enabled_.Destroy(); 100 spdy_proxy_auth_enabled_.Destroy();
83 } 101 }
84 102
85 void DataReductionProxySettings::InitPrefMembers() { 103 void DataReductionProxySettings::InitPrefMembers() {
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 kOn + std::string(" ") + (restricted ? kRestricted : kUnrestricted); 322 kOn + std::string(" ") + (restricted ? kRestricted : kUnrestricted);
305 323
306 LOG(WARNING) << "SPDY proxy " << (enabled ? annotated_on : kOff) 324 LOG(WARNING) << "SPDY proxy " << (enabled ? annotated_on : kOff)
307 << " " << (at_startup ? kAtStartup : kByUser); 325 << " " << (at_startup ? kAtStartup : kByUser);
308 } 326 }
309 327
310 void DataReductionProxySettings::OnIPAddressChanged() { 328 void DataReductionProxySettings::OnIPAddressChanged() {
311 DCHECK(thread_checker_.CalledOnValidThread()); 329 DCHECK(thread_checker_.CalledOnValidThread());
312 if (enabled_by_user_) { 330 if (enabled_by_user_) {
313 DCHECK(params_->allowed()); 331 DCHECK(params_->allowed());
332 RecordNetworkChangeEvent(IP_CHANGED);
333 if (DisableIfVPN())
334 return;
314 ProbeWhetherDataReductionProxyIsAvailable(); 335 ProbeWhetherDataReductionProxyIsAvailable();
315 WarmProxyConnection(); 336 WarmProxyConnection();
316 } 337 }
317 } 338 }
318 339
319 void DataReductionProxySettings::OnProxyEnabledPrefChange() { 340 void DataReductionProxySettings::OnProxyEnabledPrefChange() {
320 DCHECK(thread_checker_.CalledOnValidThread()); 341 DCHECK(thread_checker_.CalledOnValidThread());
321 if (!params_->allowed()) 342 if (!params_->allowed())
322 return; 343 return;
323 MaybeActivateDataReductionProxy(false); 344 MaybeActivateDataReductionProxy(false);
(...skipping 28 matching lines...) Expand all
352 // TODO(marq): Consider moving this so stats are wiped the first time the 373 // TODO(marq): Consider moving this so stats are wiped the first time the
353 // proxy settings are actually (not maybe) turned on. 374 // proxy settings are actually (not maybe) turned on.
354 if (spdy_proxy_auth_enabled_.GetValue() && 375 if (spdy_proxy_auth_enabled_.GetValue() &&
355 !prefs->GetBoolean(prefs::kDataReductionProxyWasEnabledBefore)) { 376 !prefs->GetBoolean(prefs::kDataReductionProxyWasEnabledBefore)) {
356 prefs->SetBoolean(prefs::kDataReductionProxyWasEnabledBefore, true); 377 prefs->SetBoolean(prefs::kDataReductionProxyWasEnabledBefore, true);
357 ResetDataReductionStatistics(); 378 ResetDataReductionStatistics();
358 } 379 }
359 380
360 // Configure use of the data reduction proxy if it is enabled. 381 // Configure use of the data reduction proxy if it is enabled.
361 enabled_by_user_= IsDataReductionProxyEnabled(); 382 enabled_by_user_= IsDataReductionProxyEnabled();
362 SetProxyConfigs(enabled_by_user_, 383 SetProxyConfigs(enabled_by_user_ && !disabled_on_vpn_,
363 IsDataReductionProxyAlternativeEnabled(), 384 IsDataReductionProxyAlternativeEnabled(),
364 restricted_by_carrier_, 385 restricted_by_carrier_,
365 at_startup); 386 at_startup);
366 387
367 // Check if the proxy has been restricted explicitly by the carrier. 388 // Check if the proxy has been restricted explicitly by the carrier.
368 if (enabled_by_user_) { 389 if (enabled_by_user_ && !disabled_on_vpn_) {
369 ProbeWhetherDataReductionProxyIsAvailable(); 390 ProbeWhetherDataReductionProxyIsAvailable();
370 WarmProxyConnection(); 391 WarmProxyConnection();
371 } 392 }
372 } 393 }
373 394
374 void DataReductionProxySettings::SetProxyConfigs(bool enabled, 395 void DataReductionProxySettings::SetProxyConfigs(bool enabled,
375 bool alternative_enabled, 396 bool alternative_enabled,
376 bool restricted, 397 bool restricted,
377 bool at_startup) { 398 bool at_startup) {
378 DCHECK(thread_checker_.CalledOnValidThread()); 399 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 result, 439 result,
419 PROBE_URL_FETCH_RESULT_COUNT); 440 PROBE_URL_FETCH_RESULT_COUNT);
420 } 441 }
421 442
422 void DataReductionProxySettings::RecordStartupState(ProxyStartupState state) { 443 void DataReductionProxySettings::RecordStartupState(ProxyStartupState state) {
423 UMA_HISTOGRAM_ENUMERATION(kUMAProxyStartupStateHistogram, 444 UMA_HISTOGRAM_ENUMERATION(kUMAProxyStartupStateHistogram,
424 state, 445 state,
425 PROXY_STARTUP_STATE_COUNT); 446 PROXY_STARTUP_STATE_COUNT);
426 } 447 }
427 448
449 void DataReductionProxySettings::GetNetworkList(
450 net::NetworkInterfaceList* interfaces,
451 int policy) {
452 net::GetNetworkList(interfaces, policy);
453 }
454
428 void DataReductionProxySettings::ResetParamsForTest( 455 void DataReductionProxySettings::ResetParamsForTest(
429 DataReductionProxyParams* params) { 456 DataReductionProxyParams* params) {
430 params_.reset(params); 457 params_.reset(params);
431 } 458 }
432 459
433 DataReductionProxySettings::ContentLengthList 460 DataReductionProxySettings::ContentLengthList
434 DataReductionProxySettings::GetDailyContentLengths(const char* pref_name) { 461 DataReductionProxySettings::GetDailyContentLengths(const char* pref_name) {
435 DCHECK(thread_checker_.CalledOnValidThread()); 462 DCHECK(thread_checker_.CalledOnValidThread());
436 DataReductionProxySettings::ContentLengthList content_lengths; 463 DataReductionProxySettings::ContentLengthList content_lengths;
437 const base::ListValue* list_value = GetLocalStatePrefs()->GetList(pref_name); 464 const base::ListValue* list_value = GetLocalStatePrefs()->GetList(pref_name);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 i < kNumDaysInHistory; ++i) { 505 i < kNumDaysInHistory; ++i) {
479 orig += GetInt64PrefValue(*original_list, i); 506 orig += GetInt64PrefValue(*original_list, i);
480 recv += GetInt64PrefValue(*received_list, i); 507 recv += GetInt64PrefValue(*received_list, i);
481 } 508 }
482 *original_content_length = orig; 509 *original_content_length = orig;
483 *received_content_length = recv; 510 *received_content_length = recv;
484 *last_update_time = 511 *last_update_time =
485 local_state->GetInt64(prefs::kDailyHttpContentLengthLastUpdateDate); 512 local_state->GetInt64(prefs::kDailyHttpContentLengthLastUpdateDate);
486 } 513 }
487 514
488 // static
489 base::string16 DataReductionProxySettings::AuthHashForSalt(
490 int64 salt,
491 const std::string& key) {
492 std::string salted_key =
493 base::StringPrintf("%lld%s%lld",
494 static_cast<long long>(salt),
495 key.c_str(),
496 static_cast<long long>(salt));
497 return base::UTF8ToUTF16(base::MD5String(salted_key));
498 }
499
500 net::URLFetcher* DataReductionProxySettings::GetBaseURLFetcher( 515 net::URLFetcher* DataReductionProxySettings::GetBaseURLFetcher(
501 const GURL& gurl, 516 const GURL& gurl,
502 int load_flags) { 517 int load_flags) {
503 518
504 net::URLFetcher* fetcher = net::URLFetcher::Create(gurl, 519 net::URLFetcher* fetcher = net::URLFetcher::Create(gurl,
505 net::URLFetcher::GET, 520 net::URLFetcher::GET,
506 this); 521 this);
507 fetcher->SetLoadFlags(load_flags); 522 fetcher->SetLoadFlags(load_flags);
508 DCHECK(url_request_context_getter_); 523 DCHECK(url_request_context_getter_);
509 fetcher->SetRequestContext(url_request_context_getter_); 524 fetcher->SetRequestContext(url_request_context_getter_);
(...skipping 25 matching lines...) Expand all
535 } 550 }
536 551
537 void DataReductionProxySettings::WarmProxyConnection() { 552 void DataReductionProxySettings::WarmProxyConnection() {
538 net::URLFetcher* fetcher = GetURLFetcherForWarmup(); 553 net::URLFetcher* fetcher = GetURLFetcherForWarmup();
539 if (!fetcher) 554 if (!fetcher)
540 return; 555 return;
541 warmup_fetcher_.reset(fetcher); 556 warmup_fetcher_.reset(fetcher);
542 warmup_fetcher_->Start(); 557 warmup_fetcher_->Start();
543 } 558 }
544 559
560 bool DataReductionProxySettings::DisableIfVPN() {
561 net::NetworkInterfaceList network_interfaces;
562 GetNetworkList(&network_interfaces, 0);
563 // VPNs use a "tun" interface, so the presence of a "tun" interface indicates
564 // a VPN is in use.
565 // TODO(kundaji): Verify this works on Windows.
566 const std::string vpn_interface_name_prefix = "tun";
567 for (size_t i = 0; i < network_interfaces.size(); ++i) {
568 std::string interface_name = network_interfaces[i].name;
569 if (LowerCaseEqualsASCII(
570 interface_name.begin(),
571 interface_name.begin() + vpn_interface_name_prefix.size(),
572 vpn_interface_name_prefix.c_str())) {
573 SetProxyConfigs(false,
574 IsDataReductionProxyAlternativeEnabled(),
575 false,
576 false);
577 disabled_on_vpn_ = true;
578 RecordNetworkChangeEvent(DISABLED_ON_VPN);
579 return true;
580 }
581 }
582 disabled_on_vpn_ = false;
583 return false;
584 }
585
545 } // namespace data_reduction_proxy 586 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698