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