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" | |
bengr
2014/07/21 22:23:58
This should go above line 7 with a blank line abov
megjablon
2014/07/22 02:11:30
Done.
| |
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; | |
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 ProxyService::DataReductionProxyBypassType type) { | |
103 bypass_type_ = type; | |
104 triggering_request_ = true; | |
105 } | |
106 | |
107 void DataReductionProxyUsageStats::RecordBypassedBytesHistograms( | |
108 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.GetValue() && | |
119 request.url().SchemeIs(url::kHttpsScheme)) { | |
120 RecordBypassedBytes(bypass_type_, | |
121 DataReductionProxyUsageStats::SSL, | |
122 content_length); | |
123 return; | |
124 } | |
125 | |
126 if (data_reduction_proxy_enabled.GetValue() && | |
127 !data_reduction_proxy_params_->IsDataReductionProxyEligible(&request)) { | |
128 RecordBypassedBytes(bypass_type_, | |
129 DataReductionProxyUsageStats::LOCAL_BYPASS_RULES, | |
130 content_length); | |
131 return; | |
132 } | |
133 | |
134 if (triggering_request_) { | |
135 RecordBypassedBytes(bypass_type_, | |
136 DataReductionProxyUsageStats::TRIGGERING_REQUEST, | |
137 content_length); | |
138 triggering_request_ = false; | |
139 } | |
140 | |
141 std::string mime_type; | |
142 request.GetMimeType(&mime_type); | |
143 // MIME types are named by <media-type>/<subtype>. We check to see if the | |
144 // media type is audio or video. | |
145 if (mime_type.find("audio/") != string::npos || | |
bengr
2014/07/21 22:23:58
using string::compare is probably more efficient (
megjablon
2014/07/22 02:11:30
Done.
| |
146 mime_type.find("video/") != string::npos) { | |
147 RecordBypassedBytes(bypass_type_, | |
148 DataReductionProxyUsageStats::AUDIO_VIDEO, | |
149 content_length); | |
150 } | |
151 | |
152 if (bypass_type_ != ProxyService::BYPASS_EVENT_TYPE_MAX) { | |
153 RecordBypassedBytes(bypass_type_, | |
154 DataReductionProxyUsageStats::BYPASSED_BYTES_TYPE_MAX, | |
155 content_length); | |
156 return; | |
157 } | |
158 | |
159 if (data_reduction_proxy_params_-> | |
160 AreDataReductionProxiesBypassed(request, NULL)) { | |
161 RecordBypassedBytes(bypass_type_, | |
162 DataReductionProxyUsageStats::NETWORK_ERROR, | |
163 content_length); | |
164 } | |
165 } | |
166 | |
167 void DataReductionProxyUsageStats::RecordBypassedBytes( | |
168 ProxyService::DataReductionProxyBypassType bypass_type, | |
169 DataReductionProxyUsageStats::BypassedBytesType bypassed_bytes_type, | |
170 int64 content_length) { | |
171 switch (bypassed_bytes_type) { | |
172 case DataReductionProxyUsageStats::NOT_BYPASSED: | |
173 UMA_HISTOGRAM_COUNTS( | |
174 "DataReductionProxy.BypassedBytes.NotBypassed", content_length); | |
175 break; | |
176 case DataReductionProxyUsageStats::SSL: | |
177 UMA_HISTOGRAM_COUNTS( | |
178 "DataReductionProxy.BypassedBytes.SSL", content_length); | |
179 break; | |
180 case DataReductionProxyUsageStats::LOCAL_BYPASS_RULES: | |
181 UMA_HISTOGRAM_COUNTS( | |
182 "DataReductionProxy.BypassedBytes.LocalBypassRules", | |
183 content_length); | |
184 break; | |
185 case DataReductionProxyUsageStats::AUDIO_VIDEO: | |
186 if (bypass_type_ == ProxyService::SHORT_BYPASS) | |
bengr
2014/07/21 22:23:57
Add curly braces
megjablon
2014/07/22 02:11:30
Done.
| |
187 UMA_HISTOGRAM_COUNTS( | |
188 "DataReductionProxy.BypassedBytes.ShortAudioVideo", | |
189 content_length); | |
190 break; | |
191 case DataReductionProxyUsageStats::TRIGGERING_REQUEST: | |
192 switch (bypass_type) { | |
193 case ProxyService::SHORT_BYPASS: | |
194 UMA_HISTOGRAM_COUNTS( | |
195 "DataReductionProxy.BypassedBytes.ShortTriggeringRequest", | |
196 content_length); | |
197 break; | |
198 case ProxyService::MEDIUM_BYPASS: | |
199 UMA_HISTOGRAM_COUNTS( | |
200 "DataReductionProxy.BypassedBytes.MediumTriggeringRequest", | |
201 content_length); | |
202 break; | |
203 case ProxyService::LONG_BYPASS: | |
204 UMA_HISTOGRAM_COUNTS( | |
205 "DataReductionProxy.BypassedBytes.LongTriggeringRequest", | |
206 content_length); | |
207 break; | |
208 default: | |
209 break; | |
210 } | |
211 break; | |
212 case DataReductionProxyUsageStats::NETWORK_ERROR: | |
213 UMA_HISTOGRAM_COUNTS( | |
214 "DataReductionProxy.BypassedBytes.NetworkErrorOther", | |
215 content_length); | |
216 break; | |
217 case DataReductionProxyUsageStats::BYPASSED_BYTES_TYPE_MAX: | |
218 switch (bypass_type) { | |
219 case ProxyService::CURRENT_BYPASS: | |
220 UMA_HISTOGRAM_COUNTS("DataReductionProxy.BypassedBytes.Current", | |
221 content_length); | |
222 break; | |
223 case ProxyService::SHORT_BYPASS: | |
224 UMA_HISTOGRAM_COUNTS("DataReductionProxy.BypassedBytes.ShortAll", | |
225 content_length); | |
226 break; | |
227 case ProxyService::MEDIUM_BYPASS: | |
228 UMA_HISTOGRAM_COUNTS("DataReductionProxy.BypassedBytes.MediumAll", | |
229 content_length); | |
230 break; | |
231 case ProxyService::LONG_BYPASS: | |
232 UMA_HISTOGRAM_COUNTS("DataReductionProxy.BypassedBytes.LongAll", | |
233 content_length); | |
234 break; | |
235 case ProxyService::MISSING_VIA_HEADER_4XX: | |
236 UMA_HISTOGRAM_COUNTS( | |
237 "DataReductionProxy.BypassedBytes.MissingViaHeader4xx", | |
238 content_length); | |
239 break; | |
240 case ProxyService::MISSING_VIA_HEADER_OTHER: | |
241 UMA_HISTOGRAM_COUNTS( | |
242 "DataReductionProxy.BypassedBytes.MissingViaHeaderOther", | |
243 content_length); | |
244 break; | |
245 case ProxyService::MALFORMED_407: | |
246 UMA_HISTOGRAM_COUNTS("DataReductionProxy.BypassedBytes.Malformed407", | |
247 content_length); | |
248 break; | |
249 case ProxyService::STATUS_500_HTTP_INTERNAL_SERVER_ERROR: | |
250 UMA_HISTOGRAM_COUNTS( | |
251 "DataReductionProxy.BypassedBytes." | |
252 "Status500HttpInternalServerError", | |
253 content_length); | |
254 break; | |
255 case ProxyService::STATUS_502_HTTP_BAD_GATEWAY: | |
256 UMA_HISTOGRAM_COUNTS( | |
257 "DataReductionProxy.BypassedBytes.Status502HttpBadGateway", | |
258 content_length); | |
259 break; | |
260 case ProxyService::STATUS_503_HTTP_SERVICE_UNAVAILABLE: | |
261 UMA_HISTOGRAM_COUNTS( | |
262 "DataReductionProxy.BypassedBytes." | |
263 "Status503HttpServiceUnavailable", | |
264 content_length); | |
265 break; | |
266 default: | |
267 break; | |
268 } | |
269 break; | |
270 } | |
271 } | |
272 | |
96 } // namespace data_reduction_proxy | 273 } // namespace data_reduction_proxy |
97 | 274 |
98 | 275 |
OLD | NEW |