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

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: Changed to a histogram 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 DataReductionProxyNetworkChangeEvents {
44 // 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.
45 IP_CHANGED = 0,
46
47 // The proxy is disabled because a VPN is running.
48 DISABLED_ON_VPN = 1,
49
50 // This must always be last.
51 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.
52 };
39 53
40 // Key of the UMA DataReductionProxy.StartupState histogram. 54 // Key of the UMA DataReductionProxy.StartupState histogram.
41 const char kUMAProxyStartupStateHistogram[] = 55 const char kUMAProxyStartupStateHistogram[] =
42 "DataReductionProxy.StartupState"; 56 "DataReductionProxy.StartupState";
43 57
44 // Key of the UMA DataReductionProxy.ProbeURL histogram. 58 // Key of the UMA DataReductionProxy.ProbeURL histogram.
45 const char kUMAProxyProbeURL[] = "DataReductionProxy.ProbeURL"; 59 const char kUMAProxyProbeURL[] = "DataReductionProxy.ProbeURL";
46 60
47 int64 GetInt64PrefValue(const base::ListValue& list_value, size_t index) { 61 int64 GetInt64PrefValue(const base::ListValue& list_value, size_t index) {
48 int64 val = 0; 62 int64 val = 0;
(...skipping 14 matching lines...) Expand all
63 } 77 }
64 78
65 } // namespace 79 } // namespace
66 80
67 namespace data_reduction_proxy { 81 namespace data_reduction_proxy {
68 82
69 DataReductionProxySettings::DataReductionProxySettings( 83 DataReductionProxySettings::DataReductionProxySettings(
70 DataReductionProxyParams* params) 84 DataReductionProxyParams* params)
71 : restricted_by_carrier_(false), 85 : restricted_by_carrier_(false),
72 enabled_by_user_(false), 86 enabled_by_user_(false),
87 disabled_on_vpn_(false),
73 prefs_(NULL), 88 prefs_(NULL),
74 local_state_prefs_(NULL), 89 local_state_prefs_(NULL),
75 url_request_context_getter_(NULL) { 90 url_request_context_getter_(NULL),
91 usage_stats_(NULL) {
76 DCHECK(params); 92 DCHECK(params);
77 params_.reset(params); 93 params_.reset(params);
78 } 94 }
79 95
80 DataReductionProxySettings::~DataReductionProxySettings() { 96 DataReductionProxySettings::~DataReductionProxySettings() {
81 if (params_->allowed()) 97 if (params_->allowed())
82 spdy_proxy_auth_enabled_.Destroy(); 98 spdy_proxy_auth_enabled_.Destroy();
83 } 99 }
84 100
85 void DataReductionProxySettings::InitPrefMembers() { 101 void DataReductionProxySettings::InitPrefMembers() {
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 kOn + std::string(" ") + (restricted ? kRestricted : kUnrestricted); 320 kOn + std::string(" ") + (restricted ? kRestricted : kUnrestricted);
305 321
306 LOG(WARNING) << "SPDY proxy " << (enabled ? annotated_on : kOff) 322 LOG(WARNING) << "SPDY proxy " << (enabled ? annotated_on : kOff)
307 << " " << (at_startup ? kAtStartup : kByUser); 323 << " " << (at_startup ? kAtStartup : kByUser);
308 } 324 }
309 325
310 void DataReductionProxySettings::OnIPAddressChanged() { 326 void DataReductionProxySettings::OnIPAddressChanged() {
311 DCHECK(thread_checker_.CalledOnValidThread()); 327 DCHECK(thread_checker_.CalledOnValidThread());
312 if (enabled_by_user_) { 328 if (enabled_by_user_) {
313 DCHECK(params_->allowed()); 329 DCHECK(params_->allowed());
330 UMA_HISTOGRAM_ENUMERATION("DataReductionProxy.NetworkChangeEvents",
331 IP_CHANGED,
332 CHANGE_EVENT_TYPE_MAX);
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
marq (ping after 24h) 2014/07/11 16:31:56 Extra line.
bengr 2014/07/11 22:49:16 Done.
454 }
455
428 void DataReductionProxySettings::ResetParamsForTest( 456 void DataReductionProxySettings::ResetParamsForTest(
429 DataReductionProxyParams* params) { 457 DataReductionProxyParams* params) {
430 params_.reset(params); 458 params_.reset(params);
431 } 459 }
432 460
433 DataReductionProxySettings::ContentLengthList 461 DataReductionProxySettings::ContentLengthList
434 DataReductionProxySettings::GetDailyContentLengths(const char* pref_name) { 462 DataReductionProxySettings::GetDailyContentLengths(const char* pref_name) {
435 DCHECK(thread_checker_.CalledOnValidThread()); 463 DCHECK(thread_checker_.CalledOnValidThread());
436 DataReductionProxySettings::ContentLengthList content_lengths; 464 DataReductionProxySettings::ContentLengthList content_lengths;
437 const base::ListValue* list_value = GetLocalStatePrefs()->GetList(pref_name); 465 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) { 506 i < kNumDaysInHistory; ++i) {
479 orig += GetInt64PrefValue(*original_list, i); 507 orig += GetInt64PrefValue(*original_list, i);
480 recv += GetInt64PrefValue(*received_list, i); 508 recv += GetInt64PrefValue(*received_list, i);
481 } 509 }
482 *original_content_length = orig; 510 *original_content_length = orig;
483 *received_content_length = recv; 511 *received_content_length = recv;
484 *last_update_time = 512 *last_update_time =
485 local_state->GetInt64(prefs::kDailyHttpContentLengthLastUpdateDate); 513 local_state->GetInt64(prefs::kDailyHttpContentLengthLastUpdateDate);
486 } 514 }
487 515
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( 516 net::URLFetcher* DataReductionProxySettings::GetBaseURLFetcher(
501 const GURL& gurl, 517 const GURL& gurl,
502 int load_flags) { 518 int load_flags) {
503 519
504 net::URLFetcher* fetcher = net::URLFetcher::Create(gurl, 520 net::URLFetcher* fetcher = net::URLFetcher::Create(gurl,
505 net::URLFetcher::GET, 521 net::URLFetcher::GET,
506 this); 522 this);
507 fetcher->SetLoadFlags(load_flags); 523 fetcher->SetLoadFlags(load_flags);
508 DCHECK(url_request_context_getter_); 524 DCHECK(url_request_context_getter_);
509 fetcher->SetRequestContext(url_request_context_getter_); 525 fetcher->SetRequestContext(url_request_context_getter_);
(...skipping 25 matching lines...) Expand all
535 } 551 }
536 552
537 void DataReductionProxySettings::WarmProxyConnection() { 553 void DataReductionProxySettings::WarmProxyConnection() {
538 net::URLFetcher* fetcher = GetURLFetcherForWarmup(); 554 net::URLFetcher* fetcher = GetURLFetcherForWarmup();
539 if (!fetcher) 555 if (!fetcher)
540 return; 556 return;
541 warmup_fetcher_.reset(fetcher); 557 warmup_fetcher_.reset(fetcher);
542 warmup_fetcher_->Start(); 558 warmup_fetcher_->Start();
543 } 559 }
544 560
561 bool DataReductionProxySettings::DisableIfVPN() {
562 net::NetworkInterfaceList network_interfaces;
563 GetNetworkList(&network_interfaces, 0);
564 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
565 for (size_t i = 0; i < network_interfaces.size(); ++i) {
566 std::string interface_name = network_interfaces[i].name;
567 if (LowerCaseEqualsASCII(
568 interface_name.begin(),
569 interface_name.begin() + vpn_interface_name_prefix.size(),
570 vpn_interface_name_prefix.c_str())) {
571 SetProxyConfigs(false,
572 IsDataReductionProxyAlternativeEnabled(),
573 false,
574 false);
575 disabled_on_vpn_ = true;
576 UMA_HISTOGRAM_ENUMERATION("DataReductionProxy.NetworkChangeEvents",
577 DISABLED_ON_VPN,
578 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.
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