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