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

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: 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/metrics/user_metrics.h"
11 #include "base/prefs/pref_member.h" 12 #include "base/prefs/pref_member.h"
12 #include "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
13 #include "base/prefs/scoped_user_pref_update.h" 14 #include "base/prefs/scoped_user_pref_update.h"
14 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
16 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
17 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.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_auth_requ est_handler.h"
19 #include "components/data_reduction_proxy/browser/data_reduction_proxy_configura tor.h" 20 #include "components/data_reduction_proxy/browser/data_reduction_proxy_configura tor.h"
20 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" 21 #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" 22 #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" 23 #include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names .h"
23 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h " 24 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h "
24 #include "net/base/host_port_pair.h" 25 #include "net/base/host_port_pair.h"
25 #include "net/base/load_flags.h" 26 #include "net/base/load_flags.h"
26 #include "net/base/net_errors.h" 27 #include "net/base/net_errors.h"
28 #include "net/base/net_util.h"
27 #include "net/http/http_network_session.h" 29 #include "net/http/http_network_session.h"
28 #include "net/http/http_response_headers.h" 30 #include "net/http/http_response_headers.h"
29 #include "net/url_request/url_fetcher.h" 31 #include "net/url_request/url_fetcher.h"
30 #include "net/url_request/url_fetcher_delegate.h" 32 #include "net/url_request/url_fetcher_delegate.h"
31 #include "net/url_request/url_request_context_getter.h" 33 #include "net/url_request/url_request_context_getter.h"
32 #include "net/url_request/url_request_status.h" 34 #include "net/url_request/url_request_status.h"
33 #include "url/gurl.h" 35 #include "url/gurl.h"
34 36
35 37
36 using base::StringPrintf; 38 using base::StringPrintf;
(...skipping 26 matching lines...) Expand all
63 } 65 }
64 66
65 } // namespace 67 } // namespace
66 68
67 namespace data_reduction_proxy { 69 namespace data_reduction_proxy {
68 70
69 DataReductionProxySettings::DataReductionProxySettings( 71 DataReductionProxySettings::DataReductionProxySettings(
70 DataReductionProxyParams* params) 72 DataReductionProxyParams* params)
71 : restricted_by_carrier_(false), 73 : restricted_by_carrier_(false),
72 enabled_by_user_(false), 74 enabled_by_user_(false),
75 disabled_on_vpn_(false),
73 prefs_(NULL), 76 prefs_(NULL),
74 local_state_prefs_(NULL), 77 local_state_prefs_(NULL),
75 url_request_context_getter_(NULL) { 78 url_request_context_getter_(NULL),
79 usage_stats_(NULL) {
76 DCHECK(params); 80 DCHECK(params);
77 params_.reset(params); 81 params_.reset(params);
78 } 82 }
79 83
80 DataReductionProxySettings::~DataReductionProxySettings() { 84 DataReductionProxySettings::~DataReductionProxySettings() {
81 if (params_->allowed()) 85 if (params_->allowed())
82 spdy_proxy_auth_enabled_.Destroy(); 86 spdy_proxy_auth_enabled_.Destroy();
83 } 87 }
84 88
85 void DataReductionProxySettings::InitPrefMembers() { 89 void DataReductionProxySettings::InitPrefMembers() {
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 kOn + std::string(" ") + (restricted ? kRestricted : kUnrestricted); 308 kOn + std::string(" ") + (restricted ? kRestricted : kUnrestricted);
305 309
306 LOG(WARNING) << "SPDY proxy " << (enabled ? annotated_on : kOff) 310 LOG(WARNING) << "SPDY proxy " << (enabled ? annotated_on : kOff)
307 << " " << (at_startup ? kAtStartup : kByUser); 311 << " " << (at_startup ? kAtStartup : kByUser);
308 } 312 }
309 313
310 void DataReductionProxySettings::OnIPAddressChanged() { 314 void DataReductionProxySettings::OnIPAddressChanged() {
311 DCHECK(thread_checker_.CalledOnValidThread()); 315 DCHECK(thread_checker_.CalledOnValidThread());
312 if (enabled_by_user_) { 316 if (enabled_by_user_) {
313 DCHECK(params_->allowed()); 317 DCHECK(params_->allowed());
318 base::RecordAction(
319 base::UserMetricsAction("DataReductionProxy_IPAddressChanged"));
320 if (DisableIfVPN())
321 return;
314 ProbeWhetherDataReductionProxyIsAvailable(); 322 ProbeWhetherDataReductionProxyIsAvailable();
315 WarmProxyConnection(); 323 WarmProxyConnection();
316 } 324 }
317 } 325 }
318 326
319 void DataReductionProxySettings::OnProxyEnabledPrefChange() { 327 void DataReductionProxySettings::OnProxyEnabledPrefChange() {
320 DCHECK(thread_checker_.CalledOnValidThread()); 328 DCHECK(thread_checker_.CalledOnValidThread());
321 if (!params_->allowed()) 329 if (!params_->allowed())
322 return; 330 return;
323 MaybeActivateDataReductionProxy(false); 331 MaybeActivateDataReductionProxy(false);
(...skipping 28 matching lines...) Expand all
352 // TODO(marq): Consider moving this so stats are wiped the first time the 360 // TODO(marq): Consider moving this so stats are wiped the first time the
353 // proxy settings are actually (not maybe) turned on. 361 // proxy settings are actually (not maybe) turned on.
354 if (spdy_proxy_auth_enabled_.GetValue() && 362 if (spdy_proxy_auth_enabled_.GetValue() &&
355 !prefs->GetBoolean(prefs::kDataReductionProxyWasEnabledBefore)) { 363 !prefs->GetBoolean(prefs::kDataReductionProxyWasEnabledBefore)) {
356 prefs->SetBoolean(prefs::kDataReductionProxyWasEnabledBefore, true); 364 prefs->SetBoolean(prefs::kDataReductionProxyWasEnabledBefore, true);
357 ResetDataReductionStatistics(); 365 ResetDataReductionStatistics();
358 } 366 }
359 367
360 // Configure use of the data reduction proxy if it is enabled. 368 // Configure use of the data reduction proxy if it is enabled.
361 enabled_by_user_= IsDataReductionProxyEnabled(); 369 enabled_by_user_= IsDataReductionProxyEnabled();
362 SetProxyConfigs(enabled_by_user_, 370 SetProxyConfigs(enabled_by_user_ && !disabled_on_vpn_,
363 IsDataReductionProxyAlternativeEnabled(), 371 IsDataReductionProxyAlternativeEnabled(),
364 restricted_by_carrier_, 372 restricted_by_carrier_,
365 at_startup); 373 at_startup);
366 374
367 // Check if the proxy has been restricted explicitly by the carrier. 375 // Check if the proxy has been restricted explicitly by the carrier.
368 if (enabled_by_user_) { 376 if (enabled_by_user_ && !disabled_on_vpn_) {
369 ProbeWhetherDataReductionProxyIsAvailable(); 377 ProbeWhetherDataReductionProxyIsAvailable();
370 WarmProxyConnection(); 378 WarmProxyConnection();
371 } 379 }
372 } 380 }
373 381
374 void DataReductionProxySettings::SetProxyConfigs(bool enabled, 382 void DataReductionProxySettings::SetProxyConfigs(bool enabled,
375 bool alternative_enabled, 383 bool alternative_enabled,
376 bool restricted, 384 bool restricted,
377 bool at_startup) { 385 bool at_startup) {
378 DCHECK(thread_checker_.CalledOnValidThread()); 386 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 result, 426 result,
419 PROBE_URL_FETCH_RESULT_COUNT); 427 PROBE_URL_FETCH_RESULT_COUNT);
420 } 428 }
421 429
422 void DataReductionProxySettings::RecordStartupState(ProxyStartupState state) { 430 void DataReductionProxySettings::RecordStartupState(ProxyStartupState state) {
423 UMA_HISTOGRAM_ENUMERATION(kUMAProxyStartupStateHistogram, 431 UMA_HISTOGRAM_ENUMERATION(kUMAProxyStartupStateHistogram,
424 state, 432 state,
425 PROXY_STARTUP_STATE_COUNT); 433 PROXY_STARTUP_STATE_COUNT);
426 } 434 }
427 435
436 void DataReductionProxySettings::GetNetworkList(
437 net::NetworkInterfaceList* interfaces,
438 int policy) {
439 net::GetNetworkList(interfaces, policy);
440
441 }
442
428 void DataReductionProxySettings::ResetParamsForTest( 443 void DataReductionProxySettings::ResetParamsForTest(
429 DataReductionProxyParams* params) { 444 DataReductionProxyParams* params) {
430 params_.reset(params); 445 params_.reset(params);
431 } 446 }
432 447
433 DataReductionProxySettings::ContentLengthList 448 DataReductionProxySettings::ContentLengthList
434 DataReductionProxySettings::GetDailyContentLengths(const char* pref_name) { 449 DataReductionProxySettings::GetDailyContentLengths(const char* pref_name) {
435 DCHECK(thread_checker_.CalledOnValidThread()); 450 DCHECK(thread_checker_.CalledOnValidThread());
436 DataReductionProxySettings::ContentLengthList content_lengths; 451 DataReductionProxySettings::ContentLengthList content_lengths;
437 const base::ListValue* list_value = GetLocalStatePrefs()->GetList(pref_name); 452 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) { 493 i < kNumDaysInHistory; ++i) {
479 orig += GetInt64PrefValue(*original_list, i); 494 orig += GetInt64PrefValue(*original_list, i);
480 recv += GetInt64PrefValue(*received_list, i); 495 recv += GetInt64PrefValue(*received_list, i);
481 } 496 }
482 *original_content_length = orig; 497 *original_content_length = orig;
483 *received_content_length = recv; 498 *received_content_length = recv;
484 *last_update_time = 499 *last_update_time =
485 local_state->GetInt64(prefs::kDailyHttpContentLengthLastUpdateDate); 500 local_state->GetInt64(prefs::kDailyHttpContentLengthLastUpdateDate);
486 } 501 }
487 502
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( 503 net::URLFetcher* DataReductionProxySettings::GetBaseURLFetcher(
501 const GURL& gurl, 504 const GURL& gurl,
502 int load_flags) { 505 int load_flags) {
503 506
504 net::URLFetcher* fetcher = net::URLFetcher::Create(gurl, 507 net::URLFetcher* fetcher = net::URLFetcher::Create(gurl,
505 net::URLFetcher::GET, 508 net::URLFetcher::GET,
506 this); 509 this);
507 fetcher->SetLoadFlags(load_flags); 510 fetcher->SetLoadFlags(load_flags);
508 DCHECK(url_request_context_getter_); 511 DCHECK(url_request_context_getter_);
509 fetcher->SetRequestContext(url_request_context_getter_); 512 fetcher->SetRequestContext(url_request_context_getter_);
(...skipping 25 matching lines...) Expand all
535 } 538 }
536 539
537 void DataReductionProxySettings::WarmProxyConnection() { 540 void DataReductionProxySettings::WarmProxyConnection() {
538 net::URLFetcher* fetcher = GetURLFetcherForWarmup(); 541 net::URLFetcher* fetcher = GetURLFetcherForWarmup();
539 if (!fetcher) 542 if (!fetcher)
540 return; 543 return;
541 warmup_fetcher_.reset(fetcher); 544 warmup_fetcher_.reset(fetcher);
542 warmup_fetcher_->Start(); 545 warmup_fetcher_->Start();
543 } 546 }
544 547
548 bool DataReductionProxySettings::DisableIfVPN() {
549 net::NetworkInterfaceList network_interfaces;
550 GetNetworkList(&network_interfaces, 0);
551 const std::string vpn_interface_name_prefix = "tun";
552 for (size_t i = 0; i < network_interfaces.size(); ++i) {
553 std::string interface_name = network_interfaces[i].name;
554 if (LowerCaseEqualsASCII(
555 interface_name.begin(),
556 interface_name.begin() + vpn_interface_name_prefix.size(),
557 vpn_interface_name_prefix.c_str())) {
558 SetProxyConfigs(false,
559 IsDataReductionProxyAlternativeEnabled(),
560 false,
561 false);
562 disabled_on_vpn_ = true;
563 base::RecordAction(
564 base::UserMetricsAction("DataReductionProxy_DisabledOnVPN"));
565 return true;
566 }
567 }
568 disabled_on_vpn_ = false;
569 return false;
570 }
571
545 } // namespace data_reduction_proxy 572 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698