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