OLD | NEW |
---|---|
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 "base/metrics/histogram.h" | |
5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_usage_sta ts.h" | 6 #include "components/data_reduction_proxy/browser/data_reduction_proxy_usage_sta ts.h" |
7 #include "net/base/net_errors.h" | |
6 #include "net/proxy/proxy_retry_info.h" | 8 #include "net/proxy/proxy_retry_info.h" |
7 #include "net/proxy/proxy_server.h" | 9 #include "net/proxy/proxy_server.h" |
8 #include "net/proxy/proxy_service.h" | 10 #include "net/proxy/proxy_service.h" |
9 #include "net/url_request/url_request_context.h" | 11 #include "net/url_request/url_request_context.h" |
10 | 12 |
11 using base::MessageLoopProxy; | 13 using base::MessageLoopProxy; |
12 using net::HostPortPair; | 14 using net::HostPortPair; |
13 using net::ProxyServer; | 15 using net::ProxyServer; |
16 using net::ProxyService; | |
Alexei Svitkine (slow)
2014/07/15 18:20:07
Nit: You fully qualify this in some places below,
megjablon
2014/07/16 00:00:59
Done.
| |
14 using net::NetworkChangeNotifier; | 17 using net::NetworkChangeNotifier; |
15 | 18 |
16 namespace data_reduction_proxy { | 19 namespace data_reduction_proxy { |
17 | 20 |
18 DataReductionProxyUsageStats::DataReductionProxyUsageStats( | 21 DataReductionProxyUsageStats::DataReductionProxyUsageStats( |
19 DataReductionProxyParams* params, | 22 DataReductionProxyParams* params, |
20 MessageLoopProxy* ui_thread_proxy, | 23 MessageLoopProxy* ui_thread_proxy, |
21 MessageLoopProxy* io_thread_proxy) | 24 MessageLoopProxy* io_thread_proxy) |
22 : data_reduction_proxy_params_(params), | 25 : data_reduction_proxy_params_(params), |
26 bypass_type_(ProxyService::BYPASS_EVENT_TYPE_MAX), | |
27 triggering_request_(true), | |
23 ui_thread_proxy_(ui_thread_proxy), | 28 ui_thread_proxy_(ui_thread_proxy), |
24 io_thread_proxy_(io_thread_proxy), | 29 io_thread_proxy_(io_thread_proxy), |
25 eligible_num_requests_through_proxy_(0), | 30 eligible_num_requests_through_proxy_(0), |
26 actual_num_requests_through_proxy_(0) { | 31 actual_num_requests_through_proxy_(0) { |
27 NetworkChangeNotifier::AddNetworkChangeObserver(this); | 32 NetworkChangeNotifier::AddNetworkChangeObserver(this); |
28 }; | 33 }; |
29 | 34 |
30 DataReductionProxyUsageStats::~DataReductionProxyUsageStats() { | 35 DataReductionProxyUsageStats::~DataReductionProxyUsageStats() { |
31 NetworkChangeNotifier::RemoveNetworkChangeObserver(this); | 36 NetworkChangeNotifier::RemoveNetworkChangeObserver(this); |
32 }; | 37 }; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 ClearRequestCountsOnUiThread(); | 91 ClearRequestCountsOnUiThread(); |
87 } | 92 } |
88 } | 93 } |
89 | 94 |
90 void DataReductionProxyUsageStats::ClearRequestCountsOnUiThread() { | 95 void DataReductionProxyUsageStats::ClearRequestCountsOnUiThread() { |
91 DCHECK(ui_thread_proxy_->BelongsToCurrentThread()); | 96 DCHECK(ui_thread_proxy_->BelongsToCurrentThread()); |
92 eligible_num_requests_through_proxy_ = 0; | 97 eligible_num_requests_through_proxy_ = 0; |
93 actual_num_requests_through_proxy_ = 0; | 98 actual_num_requests_through_proxy_ = 0; |
94 } | 99 } |
95 | 100 |
101 void DataReductionProxyUsageStats::SetBypassType( | |
102 net::ProxyService::DataReductionProxyBypassType type) { | |
103 bypass_type_ = type; | |
104 triggering_request_ = true; | |
105 } | |
106 | |
107 void DataReductionProxyUsageStats::RecordBypassedBytesHistograms( | |
108 const int64 content_length, | |
109 const net::URLRequest* request, | |
110 const BooleanPrefMember* data_reduction_proxy_enabled) { | |
111 if (data_reduction_proxy_params_->WasDataReductionProxyUsed(request, NULL)) { | |
112 RecordBypassedBytes(bypass_type_, | |
113 DataReductionProxyUsageStats::NOT_BYPASSED, | |
114 content_length); | |
115 return; | |
116 } | |
117 | |
118 if (data_reduction_proxy_enabled && | |
119 data_reduction_proxy_enabled->GetValue() && | |
120 request->url().SchemeIs("https") && | |
Alexei Svitkine (slow)
2014/07/15 18:20:07
Nit: url::kHttpsScheme instead of "https"
megjablon
2014/07/16 00:00:59
Done.
| |
121 data_reduction_proxy_enabled->GetValue()) { | |
Alexei Svitkine (slow)
2014/07/15 18:20:07
This condition is repeated.
megjablon
2014/07/16 00:00:59
Done.
| |
122 RecordBypassedBytes(bypass_type_, | |
123 DataReductionProxyUsageStats::SSL, | |
124 content_length); | |
125 return; | |
126 } | |
127 | |
128 if (data_reduction_proxy_enabled && | |
129 data_reduction_proxy_enabled->GetValue() && | |
130 !data_reduction_proxy_params_->IsDataReductionProxyEligible(request)) { | |
131 RecordBypassedBytes(bypass_type_, | |
132 DataReductionProxyUsageStats::LOCAL_BYPASS_RULES, | |
133 content_length); | |
134 return; | |
135 } | |
136 | |
137 if (triggering_request_) { | |
138 RecordBypassedBytes(bypass_type_, | |
139 DataReductionProxyUsageStats::TRIGGERING_REQUEST, | |
140 content_length); | |
141 triggering_request_ = false; | |
142 } | |
143 | |
144 std::string mime_type; | |
145 request->GetMimeType(&mime_type); | |
146 // MIME types are named by <media-type>/<subtype>. We check to see if the | |
147 // media type is audio or video. | |
148 if((mime_type).find("audio/") != string::npos || | |
Alexei Svitkine (slow)
2014/07/15 18:20:08
Why the extra parens around mime_type? Also, add a
megjablon
2014/07/16 00:00:59
Done.
| |
149 (mime_type).find("video/") != string::npos) { | |
150 RecordBypassedBytes(bypass_type_, | |
151 DataReductionProxyUsageStats::AUDIO_VIDEO, | |
152 content_length); | |
153 } | |
154 | |
155 RecordBypassedBytes(bypass_type_, | |
156 DataReductionProxyUsageStats::BYPASSED_BYTES_TYPE_MAX, | |
157 content_length); | |
158 } | |
159 | |
160 void DataReductionProxyUsageStats::RecordBypassedBytes( | |
161 ProxyService::DataReductionProxyBypassType bypass_type, | |
162 DataReductionProxyUsageStats::DataReductionProxyBypassedBytesType | |
163 bypassed_bytes_type, | |
Alexei Svitkine (slow)
2014/07/15 18:20:08
Indent 4 more. Or find a way to not wrap this.
Fo
megjablon
2014/07/16 00:00:59
Done.
| |
164 int64 content_length) { | |
165 switch(bypassed_bytes_type) { | |
Alexei Svitkine (slow)
2014/07/15 18:20:07
Nit: Space after switch.
megjablon
2014/07/16 00:00:59
Done.
| |
166 case DataReductionProxyUsageStats::NOT_BYPASSED: | |
167 UMA_HISTOGRAM_COUNTS( | |
168 "DataReductionProxy.BypassedBytes.NotBypassed", content_length); | |
169 break; | |
170 case DataReductionProxyUsageStats::SSL: | |
171 UMA_HISTOGRAM_COUNTS( | |
172 "DataReductionProxy.BypassedBytes.SSL", content_length); | |
173 break; | |
174 case DataReductionProxyUsageStats::LOCAL_BYPASS_RULES: | |
175 UMA_HISTOGRAM_COUNTS( | |
176 "DataReductionProxy.BypassedBytes.LocalBypassRules", | |
177 content_length); | |
178 break; | |
179 case DataReductionProxyUsageStats::AUDIO_VIDEO: | |
180 if (bypass_type_ == ProxyService::SHORT_BYPASS) | |
181 UMA_HISTOGRAM_COUNTS( | |
182 "DataReductionProxy.BypassedBytes.ShortAudioVideo", | |
183 content_length); | |
184 break; | |
185 case DataReductionProxyUsageStats::TRIGGERING_REQUEST: | |
186 switch(bypass_type) { | |
187 case ProxyService::SHORT_BYPASS: | |
188 UMA_HISTOGRAM_COUNTS( | |
189 "DataReductionProxy.BypassedBytes.ShortTriggeringRequest", | |
190 content_length); | |
191 break; | |
192 case ProxyService::MEDIUM_BYPASS: | |
193 UMA_HISTOGRAM_COUNTS( | |
194 "DataReductionProxy.BypassedBytes.MediumTriggeringRequest", | |
195 content_length); | |
196 break; | |
197 case ProxyService::LONG_BYPASS: | |
198 UMA_HISTOGRAM_COUNTS( | |
199 "DataReductionProxy.BypassedBytes.LongTriggeringRequest", | |
200 content_length); | |
201 break; | |
202 default: | |
203 break; | |
204 } | |
205 break; | |
206 case DataReductionProxyUsageStats::BYPASSED_BYTES_TYPE_MAX: | |
207 switch(bypass_type) { | |
208 case ProxyService::CURRENT_BYPASS: | |
209 UMA_HISTOGRAM_COUNTS("DataReductionProxy.BypassedBytes.Current", | |
210 content_length); | |
211 break; | |
212 case ProxyService::SHORT_BYPASS: | |
213 UMA_HISTOGRAM_COUNTS("DataReductionProxy.BypassedBytes.ShortAll", | |
214 content_length); | |
215 break; | |
216 case ProxyService::MEDIUM_BYPASS: | |
217 UMA_HISTOGRAM_COUNTS("DataReductionProxy.BypassedBytes.MediumAll", | |
218 content_length); | |
219 break; | |
220 case ProxyService::LONG_BYPASS: | |
221 UMA_HISTOGRAM_COUNTS("DataReductionProxy.BypassedBytes.LongAll", | |
222 content_length); | |
223 break; | |
224 case ProxyService::MISSING_VIA_HEADER_4XX: | |
225 UMA_HISTOGRAM_COUNTS( | |
226 "DataReductionProxy.BypassedBytes.MissingViaHeader4xx", | |
227 content_length); | |
228 break; | |
229 case ProxyService::MISSING_VIA_HEADER_OTHER: | |
230 UMA_HISTOGRAM_COUNTS( | |
231 "DataReductionProxy.BypassedBytes.MissingViaHeaderOther", | |
232 content_length); | |
233 break; | |
234 case ProxyService::MALFORMED_407: | |
235 UMA_HISTOGRAM_COUNTS("DataReductionProxy.BypassedBytes.Malformed407", | |
236 content_length); | |
237 break; | |
238 case ProxyService::STATUS_500_HTTP_INTERNAL_SERVER_ERROR: | |
239 UMA_HISTOGRAM_COUNTS( | |
240 "DataReductionProxy.BypassedBytes." | |
241 "Status500HttpInternalServerError", | |
242 content_length); | |
243 break; | |
244 case ProxyService::STATUS_502_HTTP_BAD_GATEWAY: | |
245 UMA_HISTOGRAM_COUNTS( | |
246 "DataReductionProxy.BypassedBytes.Status502HttpBadGateway", | |
247 content_length); | |
248 break; | |
249 case ProxyService::STATUS_503_HTTP_SERVICE_UNAVAILABLE: | |
250 UMA_HISTOGRAM_COUNTS( | |
251 "DataReductionProxy.BypassedBytes." | |
252 "Status503HttpServiceUnavailable", | |
253 content_length); | |
254 break; | |
255 default: | |
256 UMA_HISTOGRAM_COUNTS( | |
257 "DataReductionProxy.BypassedBytes.NetworkErrorOther", | |
258 content_length); | |
259 break; | |
260 } | |
261 break; | |
262 } | |
263 } | |
264 | |
96 } // namespace data_reduction_proxy | 265 } // namespace data_reduction_proxy |
97 | 266 |
98 | 267 |
OLD | NEW |