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

Side by Side Diff: chrome/browser/net/spdyproxy/data_reduction_proxy_settings.cc

Issue 111113006: Metrics fix for data reduction proxy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 11 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 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
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 base::ListValue& list_value, size_t index) { 59 int64 GetInt64PrefValue(const base::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
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();
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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 DataReductionProxySettings::ContentLengthList 343 DataReductionProxySettings::ContentLengthList
375 DataReductionProxySettings::GetDailyReceivedContentLengths() { 344 DataReductionProxySettings::GetDailyReceivedContentLengths() {
376 return GetDailyContentLengths(prefs::kDailyHttpReceivedContentLength); 345 return GetDailyContentLengths(prefs::kDailyHttpReceivedContentLength);
377 } 346 }
378 347
379 void DataReductionProxySettings::OnURLFetchComplete( 348 void DataReductionProxySettings::OnURLFetchComplete(
380 const net::URLFetcher* source) { 349 const net::URLFetcher* source) {
381 net::URLRequestStatus status = source->GetStatus(); 350 net::URLRequestStatus status = source->GetStatus();
382 if (status.status() == net::URLRequestStatus::FAILED && 351 if (status.status() == net::URLRequestStatus::FAILED &&
383 status.error() == net::ERR_INTERNET_DISCONNECTED) { 352 status.error() == net::ERR_INTERNET_DISCONNECTED) {
384 RecordProbeURLFetchResult(INTERNET_DISCONNECTED); 353 RecordProbeURLFetchResult(spdyproxy::INTERNET_DISCONNECTED);
385 return; 354 return;
386 } 355 }
387 356
388 std::string response; 357 std::string response;
389 source->GetResponseAsString(&response); 358 source->GetResponseAsString(&response);
390 359
391 if ("OK" == response.substr(0, 2)) { 360 if ("OK" == response.substr(0, 2)) {
392 DVLOG(1) << "The data reduction proxy is unrestricted."; 361 DVLOG(1) << "The data reduction proxy is unrestricted.";
393 362
394 if (enabled_by_user_) { 363 if (enabled_by_user_) {
395 if (restricted_by_carrier_) { 364 if (restricted_by_carrier_) {
396 // The user enabled the proxy, but sometime previously in the session, 365 // The user enabled the proxy, but sometime previously in the session,
397 // the network operator had blocked the canary and restricted the user. 366 // the network operator had blocked the canary and restricted the user.
398 // The current network doesn't block the canary, so don't restrict the 367 // The current network doesn't block the canary, so don't restrict the
399 // proxy configurations. 368 // proxy configurations.
400 SetProxyConfigs(true /* enabled */, 369 SetProxyConfigs(true /* enabled */,
401 false /* restricted */, 370 false /* restricted */,
402 false /* at_startup */); 371 false /* at_startup */);
403 RecordProbeURLFetchResult(SUCCEEDED_PROXY_ENABLED); 372 RecordProbeURLFetchResult(spdyproxy::SUCCEEDED_PROXY_ENABLED);
404 } else { 373 } else {
405 RecordProbeURLFetchResult(SUCCEEDED_PROXY_ALREADY_ENABLED); 374 RecordProbeURLFetchResult(spdyproxy::SUCCEEDED_PROXY_ALREADY_ENABLED);
406 } 375 }
407 } 376 }
408 restricted_by_carrier_ = false; 377 restricted_by_carrier_ = false;
409 return; 378 return;
410 } 379 }
411 DVLOG(1) << "The data reduction proxy is restricted to the configured " 380 DVLOG(1) << "The data reduction proxy is restricted to the configured "
412 << "fallback proxy."; 381 << "fallback proxy.";
413 382
414 if (enabled_by_user_) { 383 if (enabled_by_user_) {
415 if (!restricted_by_carrier_) { 384 if (!restricted_by_carrier_) {
416 // Restrict the proxy. 385 // Restrict the proxy.
417 SetProxyConfigs(true /* enabled */, 386 SetProxyConfigs(true /* enabled */,
418 true /* restricted */, 387 true /* restricted */,
419 false /* at_startup */); 388 false /* at_startup */);
420 RecordProbeURLFetchResult(FAILED_PROXY_DISABLED); 389 RecordProbeURLFetchResult(spdyproxy::FAILED_PROXY_DISABLED);
421 } else { 390 } else {
422 RecordProbeURLFetchResult(FAILED_PROXY_ALREADY_DISABLED); 391 RecordProbeURLFetchResult(spdyproxy::FAILED_PROXY_ALREADY_DISABLED);
423 } 392 }
424 } 393 }
425 restricted_by_carrier_ = true; 394 restricted_by_carrier_ = true;
426 } 395 }
427 396
428 void DataReductionProxySettings::OnIPAddressChanged() { 397 void DataReductionProxySettings::OnIPAddressChanged() {
429 if (enabled_by_user_) { 398 if (enabled_by_user_) {
430 DCHECK(IsDataReductionProxyAllowed()); 399 DCHECK(IsDataReductionProxyAllowed());
431 ProbeWhetherDataReductionProxyIsAvailable(); 400 ProbeWhetherDataReductionProxyIsAvailable();
432 } 401 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 dict->SetString("bypass_list", JoinString(bypass_rules_, ", ")); 515 dict->SetString("bypass_list", JoinString(bypass_rules_, ", "));
547 } else { 516 } else {
548 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_SYSTEM)); 517 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_SYSTEM));
549 dict->SetString("server", ""); 518 dict->SetString("server", "");
550 dict->SetString("bypass_list", ""); 519 dict->SetString("bypass_list", "");
551 } 520 }
552 } 521 }
553 522
554 // Metrics methods 523 // Metrics methods
555 void DataReductionProxySettings::RecordDataReductionInit() { 524 void DataReductionProxySettings::RecordDataReductionInit() {
556 ProxyStartupState state = PROXY_NOT_AVAILABLE; 525 ProxyStartupState state = spdyproxy::PROXY_NOT_AVAILABLE;
557 if (IsDataReductionProxyAllowed()) 526 if (IsDataReductionProxyAllowed()) {
558 state = IsDataReductionProxyEnabled() ? PROXY_ENABLED : PROXY_DISABLED; 527 if (IsDataReductionProxyEnabled())
528 state = spdyproxy::PROXY_ENABLED;
529 else
530 state = spdyproxy::PROXY_DISABLED;
531 }
532
533 RecordStartupState(state);
534 }
535
536 void DataReductionProxySettings::RecordProbeURLFetchResult(
537 ProbeURLFetchResult result) {
538 UMA_HISTOGRAM_ENUMERATION(kUMAProxyProbeURL,
539 result,
540 spdyproxy::PROBE_URL_FETCH_RESULT_COUNT);
541 }
542
543 void DataReductionProxySettings::RecordStartupState(ProxyStartupState state) {
559 UMA_HISTOGRAM_ENUMERATION(kUMAProxyStartupStateHistogram, 544 UMA_HISTOGRAM_ENUMERATION(kUMAProxyStartupStateHistogram,
560 state, 545 state,
561 PROXY_STARTUP_STATE_COUNT); 546 spdyproxy::PROXY_STARTUP_STATE_COUNT);
562 } 547 }
563 548
564 DataReductionProxySettings::ContentLengthList 549 DataReductionProxySettings::ContentLengthList
565 DataReductionProxySettings::GetDailyContentLengths(const char* pref_name) { 550 DataReductionProxySettings::GetDailyContentLengths(const char* pref_name) {
566 DataReductionProxySettings::ContentLengthList content_lengths; 551 DataReductionProxySettings::ContentLengthList content_lengths;
567 const base::ListValue* list_value = GetLocalStatePrefs()->GetList(pref_name); 552 const base::ListValue* list_value = GetLocalStatePrefs()->GetList(pref_name);
568 if (list_value->GetSize() == spdyproxy::kNumDaysInHistory) { 553 if (list_value->GetSize() == spdyproxy::kNumDaysInHistory) {
569 for (size_t i = 0; i < spdyproxy::kNumDaysInHistory; ++i) { 554 for (size_t i = 0; i < spdyproxy::kNumDaysInHistory; ++i) {
570 content_lengths.push_back(GetInt64PrefValue(*list_value, i)); 555 content_lengths.push_back(GetInt64PrefValue(*list_value, i));
571 } 556 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 } 664 }
680 665
681 void 666 void
682 DataReductionProxySettings::ProbeWhetherDataReductionProxyIsAvailable() { 667 DataReductionProxySettings::ProbeWhetherDataReductionProxyIsAvailable() {
683 net::URLFetcher* fetcher = GetURLFetcher(); 668 net::URLFetcher* fetcher = GetURLFetcher();
684 if (!fetcher) 669 if (!fetcher)
685 return; 670 return;
686 fetcher_.reset(fetcher); 671 fetcher_.reset(fetcher);
687 fetcher_->Start(); 672 fetcher_->Start();
688 } 673 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698