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

Side by Side Diff: components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.cc

Issue 568893002: Trigger data reduction proxy unreachable message via on proxy fall back. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed bengr's comments Created 6 years, 3 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_usage_sta ts.h" 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_usage_sta ts.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 10 matching lines...) Expand all
21 using net::HostPortPair; 21 using net::HostPortPair;
22 using net::ProxyServer; 22 using net::ProxyServer;
23 using net::ProxyService; 23 using net::ProxyService;
24 using net::NetworkChangeNotifier; 24 using net::NetworkChangeNotifier;
25 using net::URLRequest; 25 using net::URLRequest;
26 26
27 namespace data_reduction_proxy { 27 namespace data_reduction_proxy {
28 28
29 namespace { 29 namespace {
30 30
31 const int UNAVAILABLE_THRESHOLD_NUM_PROXY_NET_ERRORS = 0;
bengr 2014/09/19 21:28:12 Use chromium C++ style here and below: kUnavailabl
Not at Google. Contact bengr 2014/09/22 21:46:58 Done.
32 const int UNAVAILABLE_THRESHOLD_NUM_SUCCESSFUL_REQUESTS = 0;
33 const int RESET_THRESHOLD_NUM_SUCCESSFUL_REQUESTS = 3;
34
31 // Records a net error code that resulted in bypassing the data reduction 35 // Records a net error code that resulted in bypassing the data reduction
32 // proxy (|is_primary| is true) or the data reduction proxy fallback. 36 // proxy (|is_primary| is true) or the data reduction proxy fallback.
33 void RecordDataReductionProxyBypassOnNetworkError( 37 void RecordDataReductionProxyBypassOnNetworkError(
34 bool is_primary, 38 bool is_primary,
35 const ProxyServer& proxy_server, 39 const ProxyServer& proxy_server,
36 int net_error) { 40 int net_error) {
37 if (is_primary) { 41 if (is_primary) {
38 UMA_HISTOGRAM_SPARSE_SLOWLY( 42 UMA_HISTOGRAM_SPARSE_SLOWLY(
39 "DataReductionProxy.BypassOnNetworkErrorPrimary", 43 "DataReductionProxy.BypassOnNetworkErrorPrimary",
40 std::abs(net_error)); 44 std::abs(net_error));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 } 76 }
73 } 77 }
74 78
75 DataReductionProxyUsageStats::DataReductionProxyUsageStats( 79 DataReductionProxyUsageStats::DataReductionProxyUsageStats(
76 DataReductionProxyParams* params, 80 DataReductionProxyParams* params,
77 MessageLoopProxy* ui_thread_proxy) 81 MessageLoopProxy* ui_thread_proxy)
78 : data_reduction_proxy_params_(params), 82 : data_reduction_proxy_params_(params),
79 last_bypass_type_(BYPASS_EVENT_TYPE_MAX), 83 last_bypass_type_(BYPASS_EVENT_TYPE_MAX),
80 triggering_request_(true), 84 triggering_request_(true),
81 ui_thread_proxy_(ui_thread_proxy), 85 ui_thread_proxy_(ui_thread_proxy),
82 eligible_num_requests_through_proxy_(0), 86 num_successful_requests_through_proxy_(0),
83 actual_num_requests_through_proxy_(0), 87 num_proxy_net_errors_(0),
84 unavailable_(false) { 88 unavailable_(false) {
89 DCHECK(params);
90
85 NetworkChangeNotifier::AddNetworkChangeObserver(this); 91 NetworkChangeNotifier::AddNetworkChangeObserver(this);
86 }; 92 };
87 93
88 DataReductionProxyUsageStats::~DataReductionProxyUsageStats() { 94 DataReductionProxyUsageStats::~DataReductionProxyUsageStats() {
89 NetworkChangeNotifier::RemoveNetworkChangeObserver(this); 95 NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
90 }; 96 };
91 97
92 void DataReductionProxyUsageStats::OnUrlRequestCompleted( 98 void DataReductionProxyUsageStats::OnUrlRequestCompleted(
93 const net::URLRequest* request, bool started) { 99 const net::URLRequest* request, bool started) {
94 DCHECK(thread_checker_.CalledOnValidThread()); 100 DCHECK(thread_checker_.CalledOnValidThread());
95 101
96 if (request->status().status() == net::URLRequestStatus::SUCCESS) { 102 if (request->status().status() == net::URLRequestStatus::SUCCESS &&
97 if (data_reduction_proxy_params_->IsDataReductionProxyEligible(request)) { 103 data_reduction_proxy_params_->WasDataReductionProxyUsed(request, NULL)) {
98 bool was_received_via_proxy = 104 num_successful_requests_through_proxy_++;
99 data_reduction_proxy_params_->WasDataReductionProxyUsed( 105
100 request, NULL); 106 // To account for the case when the proxy is blocked for a little while
101 IncrementRequestCounts(was_received_via_proxy); 107 // and then works fine, we reset the counts when they exceed thresholds.
108 if (num_proxy_net_errors_ > UNAVAILABLE_THRESHOLD_NUM_PROXY_NET_ERRORS &&
109 num_successful_requests_through_proxy_ >
110 RESET_THRESHOLD_NUM_SUCCESSFUL_REQUESTS) {
111 ClearRequestCounts();
112 } else {
113 MaybeNotifyUnavailability();
102 } 114 }
103 } 115 }
104 } 116 }
105 117
106 void DataReductionProxyUsageStats::OnNetworkChanged( 118 void DataReductionProxyUsageStats::OnNetworkChanged(
107 NetworkChangeNotifier::ConnectionType type) { 119 NetworkChangeNotifier::ConnectionType type) {
108 DCHECK(thread_checker_.CalledOnValidThread()); 120 DCHECK(thread_checker_.CalledOnValidThread());
109 ClearRequestCounts(); 121 ClearRequestCounts();
110 } 122 }
111 123
112 void DataReductionProxyUsageStats::IncrementRequestCounts(
113 bool was_received_via_proxy) {
114 DCHECK(thread_checker_.CalledOnValidThread());
115 if (was_received_via_proxy) {
116 actual_num_requests_through_proxy_++;
117 }
118 eligible_num_requests_through_proxy_++;
119
120 // To account for the case when the proxy works for a little while and then
121 // gets blocked, we reset the counts occasionally.
122 if (eligible_num_requests_through_proxy_ > 50
123 && actual_num_requests_through_proxy_ > 0) {
124 ClearRequestCounts();
125 } else {
126 MaybeNotifyUnavailability();
127 }
128 }
129
130 void DataReductionProxyUsageStats::ClearRequestCounts() { 124 void DataReductionProxyUsageStats::ClearRequestCounts() {
131 DCHECK(thread_checker_.CalledOnValidThread()); 125 DCHECK(thread_checker_.CalledOnValidThread());
132 eligible_num_requests_through_proxy_ = 0; 126 num_successful_requests_through_proxy_ = 0;
133 actual_num_requests_through_proxy_ = 0; 127 num_proxy_net_errors_ = 0;
134 MaybeNotifyUnavailability(); 128 MaybeNotifyUnavailability();
135 } 129 }
136 130
137 void DataReductionProxyUsageStats::MaybeNotifyUnavailability() { 131 void DataReductionProxyUsageStats::MaybeNotifyUnavailability() {
138 bool prev_unavailable = unavailable_; 132 bool prev_unavailable = unavailable_;
139 unavailable_ = (eligible_num_requests_through_proxy_ > 0 && 133 unavailable_ =
140 actual_num_requests_through_proxy_ == 0); 134 (num_proxy_net_errors_ > UNAVAILABLE_THRESHOLD_NUM_PROXY_NET_ERRORS &&
135 num_successful_requests_through_proxy_ <=
136 UNAVAILABLE_THRESHOLD_NUM_SUCCESSFUL_REQUESTS);
141 if (prev_unavailable != unavailable_) { 137 if (prev_unavailable != unavailable_) {
142 ui_thread_proxy_->PostTask(FROM_HERE, base::Bind( 138 ui_thread_proxy_->PostTask(FROM_HERE, base::Bind(
143 &DataReductionProxyUsageStats::NotifyUnavailabilityOnUIThread, 139 &DataReductionProxyUsageStats::NotifyUnavailabilityOnUIThread,
144 base::Unretained(this), 140 base::Unretained(this),
145 unavailable_)); 141 unavailable_));
146 } 142 }
147 } 143 }
148 144
149 void DataReductionProxyUsageStats::NotifyUnavailabilityOnUIThread( 145 void DataReductionProxyUsageStats::NotifyUnavailabilityOnUIThread(
150 bool unavailable) { 146 bool unavailable) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 } 224 }
229 225
230 if (data_reduction_proxy_params_-> 226 if (data_reduction_proxy_params_->
231 AreDataReductionProxiesBypassed(request, NULL)) { 227 AreDataReductionProxiesBypassed(request, NULL)) {
232 RecordBypassedBytes(last_bypass_type_, 228 RecordBypassedBytes(last_bypass_type_,
233 DataReductionProxyUsageStats::NETWORK_ERROR, 229 DataReductionProxyUsageStats::NETWORK_ERROR,
234 content_length); 230 content_length);
235 } 231 }
236 } 232 }
237 233
238 void DataReductionProxyUsageStats::RecordBypassEventHistograms( 234 void DataReductionProxyUsageStats::OnProxyFallback(
239 const net::ProxyServer& bypassed_proxy, 235 const net::ProxyServer& bypassed_proxy,
240 int net_error) const { 236 int net_error) {
241 DataReductionProxyTypeInfo data_reduction_proxy_info; 237 DataReductionProxyTypeInfo data_reduction_proxy_info;
242 if (bypassed_proxy.is_valid() && !bypassed_proxy.is_direct() && 238 if (bypassed_proxy.is_valid() && !bypassed_proxy.is_direct() &&
243 data_reduction_proxy_params_->IsDataReductionProxy( 239 data_reduction_proxy_params_->IsDataReductionProxy(
244 bypassed_proxy.host_port_pair(), &data_reduction_proxy_info)) { 240 bypassed_proxy.host_port_pair(), &data_reduction_proxy_info)) {
245 if (data_reduction_proxy_info.is_ssl) 241 if (data_reduction_proxy_info.is_ssl)
246 return; 242 return;
243
244 num_proxy_net_errors_++;
245 MaybeNotifyUnavailability();
246
247 if (!data_reduction_proxy_info.is_fallback) { 247 if (!data_reduction_proxy_info.is_fallback) {
248 RecordDataReductionProxyBypassInfo( 248 RecordDataReductionProxyBypassInfo(
249 true, false, bypassed_proxy, BYPASS_EVENT_TYPE_NETWORK_ERROR); 249 true, false, bypassed_proxy, BYPASS_EVENT_TYPE_NETWORK_ERROR);
250 RecordDataReductionProxyBypassOnNetworkError( 250 RecordDataReductionProxyBypassOnNetworkError(
251 true, bypassed_proxy, net_error); 251 true, bypassed_proxy, net_error);
252 } else { 252 } else {
253 RecordDataReductionProxyBypassInfo( 253 RecordDataReductionProxyBypassInfo(
254 false, false, bypassed_proxy, BYPASS_EVENT_TYPE_NETWORK_ERROR); 254 false, false, bypassed_proxy, BYPASS_EVENT_TYPE_NETWORK_ERROR);
255 RecordDataReductionProxyBypassOnNetworkError( 255 RecordDataReductionProxyBypassOnNetworkError(
256 false, bypassed_proxy, net_error); 256 false, bypassed_proxy, net_error);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 default: 369 default:
370 break; 370 break;
371 } 371 }
372 break; 372 break;
373 } 373 }
374 } 374 }
375 375
376 } // namespace data_reduction_proxy 376 } // namespace data_reduction_proxy
377 377
378 378
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698