OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/net/spdyproxy/data_reduction_proxy_settings.h" | 5 #include "chrome/browser/net/spdyproxy/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" |
(...skipping 19 matching lines...) Expand all Loading... | |
30 #include "net/http/http_auth_cache.h" | 30 #include "net/http/http_auth_cache.h" |
31 #include "net/http/http_network_session.h" | 31 #include "net/http/http_network_session.h" |
32 #include "net/http/http_response_headers.h" | 32 #include "net/http/http_response_headers.h" |
33 #include "net/url_request/url_fetcher.h" | 33 #include "net/url_request/url_fetcher.h" |
34 #include "net/url_request/url_fetcher_delegate.h" | 34 #include "net/url_request/url_fetcher_delegate.h" |
35 #include "net/url_request/url_request_status.h" | 35 #include "net/url_request/url_request_status.h" |
36 #include "url/gurl.h" | 36 #include "url/gurl.h" |
37 | 37 |
38 using base::FieldTrialList; | 38 using base::FieldTrialList; |
39 using base::StringPrintf; | 39 using base::StringPrintf; |
40 using spdyproxy::ProbeURLFetchResult; | |
41 using spdyproxy::ProxyStartupState; | |
40 | 42 |
41 namespace { | 43 namespace { |
42 | 44 |
43 // Key of the UMA DataReductionProxy.StartupState histogram. | 45 // Key of the UMA DataReductionProxy.StartupState histogram. |
44 const char kUMAProxyStartupStateHistogram[] = | 46 const char kUMAProxyStartupStateHistogram[] = |
45 "DataReductionProxy.StartupState"; | 47 "DataReductionProxy.StartupState"; |
46 // Values of the UMA DataReductionProxy.StartupState histogram. | |
47 enum ProxyStartupState { | |
48 PROXY_NOT_AVAILABLE = 0, | |
49 PROXY_DISABLED, | |
50 PROXY_ENABLED, | |
51 PROXY_STARTUP_STATE_COUNT, | |
52 }; | |
53 | 48 |
54 // Key of the UMA DataReductionProxy.ProbeURL histogram. | 49 // Key of the UMA DataReductionProxy.ProbeURL histogram. |
55 const char kUMAProxyProbeURL[] = "DataReductionProxy.ProbeURL"; | 50 const char kUMAProxyProbeURL[] = "DataReductionProxy.ProbeURL"; |
56 // Values of the UMA DataReductionProxy.ProbeURL histogram. | |
57 // This enum must remain synchronized with DataReductionProxyProbeURLFetchResult | |
58 // in metrics/histograms/histograms.xml. | |
59 enum ProbeURLFetchResult { | |
60 // The probe failed because the internet was disconnected. | |
61 INTERNET_DISCONNECTED = 0, | |
62 | 51 |
63 // The probe failed for any other reason, and as a result, the proxy was | |
64 // disabled. | |
65 FAILED_PROXY_DISABLED, | |
66 | |
67 // The probe failed, but the proxy was already disabled. | |
68 FAILED_PROXY_ALREADY_DISABLED, | |
69 | |
70 // THe probe succeeded, and as a result the proxy was enabled. | |
71 SUCCEEDED_PROXY_ENABLED, | |
72 | |
73 // The probe succeeded, but the proxy was already enabled. | |
74 SUCCEEDED_PROXY_ALREADY_ENABLED, | |
75 | |
76 // This must always be last. | |
77 FETCH_RESULT_COUNT | |
78 }; | |
79 | |
80 void RecordProbeURLFetchResult(ProbeURLFetchResult result) { | |
81 UMA_HISTOGRAM_ENUMERATION(kUMAProxyProbeURL, result, FETCH_RESULT_COUNT); | |
82 } | |
83 | 52 |
84 const char kEnabled[] = "Enabled"; | 53 const char kEnabled[] = "Enabled"; |
85 | 54 |
86 // TODO(marq): Factor this string out into a constant here and in | 55 // TODO(marq): Factor this string out into a constant here and in |
87 // http_auth_handler_spdyproxy. | 56 // http_auth_handler_spdyproxy. |
88 const char kAuthenticationRealmName[] = "SpdyProxy"; | 57 const char kAuthenticationRealmName[] = "SpdyProxy"; |
89 | 58 |
90 int64 GetInt64PrefValue(const ListValue& list_value, size_t index) { | 59 int64 GetInt64PrefValue(const ListValue& list_value, size_t index) { |
91 int64 val = 0; | 60 int64 val = 0; |
92 std::string pref_value; | 61 std::string pref_value; |
(...skipping 26 matching lines...) Expand all Loading... | |
119 void DataReductionProxySettings::InitPrefMembers() { | 88 void DataReductionProxySettings::InitPrefMembers() { |
120 spdy_proxy_auth_enabled_.Init( | 89 spdy_proxy_auth_enabled_.Init( |
121 prefs::kSpdyProxyAuthEnabled, | 90 prefs::kSpdyProxyAuthEnabled, |
122 GetOriginalProfilePrefs(), | 91 GetOriginalProfilePrefs(), |
123 base::Bind(&DataReductionProxySettings::OnProxyEnabledPrefChange, | 92 base::Bind(&DataReductionProxySettings::OnProxyEnabledPrefChange, |
124 base::Unretained(this))); | 93 base::Unretained(this))); |
125 } | 94 } |
126 | 95 |
127 void DataReductionProxySettings::InitDataReductionProxySettings() { | 96 void DataReductionProxySettings::InitDataReductionProxySettings() { |
128 InitPrefMembers(); | 97 InitPrefMembers(); |
98 RecordDataReductionInit(); | |
bengr
2014/01/02 17:30:40
Did you move this here so we record something even
marq (ping after 24h)
2014/01/02 20:45:47
No, because this code only exists for the mobile p
| |
129 | 99 |
130 // Disable the proxy if it is not allowed to be used. | 100 // Disable the proxy if it is not allowed to be used. |
131 if (!IsDataReductionProxyAllowed()) | 101 if (!IsDataReductionProxyAllowed()) |
132 return; | 102 return; |
133 | 103 |
134 AddDefaultProxyBypassRules(); | 104 AddDefaultProxyBypassRules(); |
135 net::NetworkChangeNotifier::AddIPAddressObserver(this); | 105 net::NetworkChangeNotifier::AddIPAddressObserver(this); |
136 | 106 |
137 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 107 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
138 | 108 |
139 // Setting the kEnableSpdyProxyAuth switch has the same effect as enabling | 109 // Setting the kEnableSpdyProxyAuth switch has the same effect as enabling |
140 // the feature via settings, in that once set, the preference will be sticky | 110 // the feature via settings, in that once set, the preference will be sticky |
141 // across instances of Chrome. Disabling the feature can only be done through | 111 // across instances of Chrome. Disabling the feature can only be done through |
142 // the settings menu. | 112 // the settings menu. |
143 RecordDataReductionInit(); | |
144 if (spdy_proxy_auth_enabled_.GetValue() || | 113 if (spdy_proxy_auth_enabled_.GetValue() || |
145 command_line.HasSwitch(switches::kEnableSpdyProxyAuth)) { | 114 command_line.HasSwitch(switches::kEnableSpdyProxyAuth)) { |
146 MaybeActivateDataReductionProxy(true); | 115 MaybeActivateDataReductionProxy(true); |
147 } else { | 116 } else { |
148 // This is logged so we can use this information in user feedback. | 117 // This is logged so we can use this information in user feedback. |
149 LogProxyState(false /* enabled */, | 118 LogProxyState(false /* enabled */, |
150 false /* restricted */, | 119 false /* restricted */, |
151 true /* at startup */); | 120 true /* at startup */); |
152 } | 121 } |
153 } | 122 } |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
372 DataReductionProxySettings::ContentLengthList | 341 DataReductionProxySettings::ContentLengthList |
373 DataReductionProxySettings::GetDailyReceivedContentLengths() { | 342 DataReductionProxySettings::GetDailyReceivedContentLengths() { |
374 return GetDailyContentLengths(prefs::kDailyHttpReceivedContentLength); | 343 return GetDailyContentLengths(prefs::kDailyHttpReceivedContentLength); |
375 } | 344 } |
376 | 345 |
377 void DataReductionProxySettings::OnURLFetchComplete( | 346 void DataReductionProxySettings::OnURLFetchComplete( |
378 const net::URLFetcher* source) { | 347 const net::URLFetcher* source) { |
379 net::URLRequestStatus status = source->GetStatus(); | 348 net::URLRequestStatus status = source->GetStatus(); |
380 if (status.status() == net::URLRequestStatus::FAILED && | 349 if (status.status() == net::URLRequestStatus::FAILED && |
381 status.error() == net::ERR_INTERNET_DISCONNECTED) { | 350 status.error() == net::ERR_INTERNET_DISCONNECTED) { |
382 RecordProbeURLFetchResult(INTERNET_DISCONNECTED); | 351 RecordProbeURLFetchResult(spdyproxy::INTERNET_DISCONNECTED); |
383 return; | 352 return; |
384 } | 353 } |
385 | 354 |
386 std::string response; | 355 std::string response; |
387 source->GetResponseAsString(&response); | 356 source->GetResponseAsString(&response); |
388 | 357 |
389 if ("OK" == response.substr(0, 2)) { | 358 if ("OK" == response.substr(0, 2)) { |
390 DVLOG(1) << "The data reduction proxy is unrestricted."; | 359 DVLOG(1) << "The data reduction proxy is unrestricted."; |
391 | 360 |
392 if (enabled_by_user_) { | 361 if (enabled_by_user_) { |
393 if (restricted_by_carrier_) { | 362 if (restricted_by_carrier_) { |
394 // The user enabled the proxy, but sometime previously in the session, | 363 // The user enabled the proxy, but sometime previously in the session, |
395 // the network operator had blocked the canary and restricted the user. | 364 // the network operator had blocked the canary and restricted the user. |
396 // The current network doesn't block the canary, so don't restrict the | 365 // The current network doesn't block the canary, so don't restrict the |
397 // proxy configurations. | 366 // proxy configurations. |
398 SetProxyConfigs(true /* enabled */, | 367 SetProxyConfigs(true /* enabled */, |
399 false /* restricted */, | 368 false /* restricted */, |
400 false /* at_startup */); | 369 false /* at_startup */); |
401 RecordProbeURLFetchResult(SUCCEEDED_PROXY_ENABLED); | 370 RecordProbeURLFetchResult(spdyproxy::SUCCEEDED_PROXY_ENABLED); |
402 } else { | 371 } else { |
403 RecordProbeURLFetchResult(SUCCEEDED_PROXY_ALREADY_ENABLED); | 372 RecordProbeURLFetchResult(spdyproxy::SUCCEEDED_PROXY_ALREADY_ENABLED); |
404 } | 373 } |
405 } | 374 } |
406 restricted_by_carrier_ = false; | 375 restricted_by_carrier_ = false; |
407 return; | 376 return; |
408 } | 377 } |
409 DVLOG(1) << "The data reduction proxy is restricted to the configured " | 378 DVLOG(1) << "The data reduction proxy is restricted to the configured " |
410 << "fallback proxy."; | 379 << "fallback proxy."; |
411 | 380 |
412 if (enabled_by_user_) { | 381 if (enabled_by_user_) { |
413 if (!restricted_by_carrier_) { | 382 if (!restricted_by_carrier_) { |
414 // Restrict the proxy. | 383 // Restrict the proxy. |
415 SetProxyConfigs(true /* enabled */, | 384 SetProxyConfigs(true /* enabled */, |
416 true /* restricted */, | 385 true /* restricted */, |
417 false /* at_startup */); | 386 false /* at_startup */); |
418 RecordProbeURLFetchResult(FAILED_PROXY_DISABLED); | 387 RecordProbeURLFetchResult(spdyproxy::FAILED_PROXY_DISABLED); |
419 } else { | 388 } else { |
420 RecordProbeURLFetchResult(FAILED_PROXY_ALREADY_DISABLED); | 389 RecordProbeURLFetchResult(spdyproxy::FAILED_PROXY_ALREADY_DISABLED); |
421 } | 390 } |
422 } | 391 } |
423 restricted_by_carrier_ = true; | 392 restricted_by_carrier_ = true; |
424 } | 393 } |
425 | 394 |
426 void DataReductionProxySettings::OnIPAddressChanged() { | 395 void DataReductionProxySettings::OnIPAddressChanged() { |
427 if (enabled_by_user_) { | 396 if (enabled_by_user_) { |
428 DCHECK(IsDataReductionProxyAllowed()); | 397 DCHECK(IsDataReductionProxyAllowed()); |
429 ProbeWhetherDataReductionProxyIsAvailable(); | 398 ProbeWhetherDataReductionProxyIsAvailable(); |
430 } | 399 } |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
544 dict->SetString("bypass_list", JoinString(bypass_rules_, ", ")); | 513 dict->SetString("bypass_list", JoinString(bypass_rules_, ", ")); |
545 } else { | 514 } else { |
546 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_SYSTEM)); | 515 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_SYSTEM)); |
547 dict->SetString("server", ""); | 516 dict->SetString("server", ""); |
548 dict->SetString("bypass_list", ""); | 517 dict->SetString("bypass_list", ""); |
549 } | 518 } |
550 } | 519 } |
551 | 520 |
552 // Metrics methods | 521 // Metrics methods |
553 void DataReductionProxySettings::RecordDataReductionInit() { | 522 void DataReductionProxySettings::RecordDataReductionInit() { |
554 ProxyStartupState state = PROXY_NOT_AVAILABLE; | 523 ProxyStartupState state = spdyproxy::PROXY_NOT_AVAILABLE; |
555 if (IsDataReductionProxyAllowed()) | 524 if (IsDataReductionProxyAllowed()) |
556 state = IsDataReductionProxyEnabled() ? PROXY_ENABLED : PROXY_DISABLED; | 525 state = IsDataReductionProxyEnabled() ? spdyproxy::PROXY_ENABLED |
bengr
2014/01/02 17:30:40
It's probably cleaner now to write this as:
if (I
marq (ping after 24h)
2014/01/02 20:45:47
Done.
| |
526 : spdyproxy::PROXY_DISABLED; | |
527 RecordStartupState(state); | |
528 } | |
529 | |
530 void DataReductionProxySettings::RecordProbeURLFetchResult( | |
531 ProbeURLFetchResult result) { | |
bengr
2014/01/02 17:30:40
Can this fit on the line above?
marq (ping after 24h)
2014/01/02 20:45:47
Not by nine characters.
| |
532 UMA_HISTOGRAM_ENUMERATION(kUMAProxyProbeURL, | |
533 result, | |
534 spdyproxy::FETCH_RESULT_COUNT); | |
535 } | |
536 | |
537 void DataReductionProxySettings::RecordStartupState(ProxyStartupState state) { | |
557 UMA_HISTOGRAM_ENUMERATION(kUMAProxyStartupStateHistogram, | 538 UMA_HISTOGRAM_ENUMERATION(kUMAProxyStartupStateHistogram, |
558 state, | 539 state, |
559 PROXY_STARTUP_STATE_COUNT); | 540 spdyproxy::PROXY_STARTUP_STATE_COUNT); |
560 } | 541 } |
561 | 542 |
562 DataReductionProxySettings::ContentLengthList | 543 DataReductionProxySettings::ContentLengthList |
563 DataReductionProxySettings::GetDailyContentLengths(const char* pref_name) { | 544 DataReductionProxySettings::GetDailyContentLengths(const char* pref_name) { |
564 DataReductionProxySettings::ContentLengthList content_lengths; | 545 DataReductionProxySettings::ContentLengthList content_lengths; |
565 const ListValue* list_value = GetLocalStatePrefs()->GetList(pref_name); | 546 const ListValue* list_value = GetLocalStatePrefs()->GetList(pref_name); |
566 if (list_value->GetSize() == spdyproxy::kNumDaysInHistory) { | 547 if (list_value->GetSize() == spdyproxy::kNumDaysInHistory) { |
567 for (size_t i = 0; i < spdyproxy::kNumDaysInHistory; ++i) { | 548 for (size_t i = 0; i < spdyproxy::kNumDaysInHistory; ++i) { |
568 content_lengths.push_back(GetInt64PrefValue(*list_value, i)); | 549 content_lengths.push_back(GetInt64PrefValue(*list_value, i)); |
569 } | 550 } |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
677 } | 658 } |
678 | 659 |
679 void | 660 void |
680 DataReductionProxySettings::ProbeWhetherDataReductionProxyIsAvailable() { | 661 DataReductionProxySettings::ProbeWhetherDataReductionProxyIsAvailable() { |
681 net::URLFetcher* fetcher = GetURLFetcher(); | 662 net::URLFetcher* fetcher = GetURLFetcher(); |
682 if (!fetcher) | 663 if (!fetcher) |
683 return; | 664 return; |
684 fetcher_.reset(fetcher); | 665 fetcher_.reset(fetcher); |
685 fetcher_->Start(); | 666 fetcher_->Start(); |
686 } | 667 } |
OLD | NEW |