Chromium Code Reviews| 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, | |
|
Alexei Svitkine (slow)
2014/07/22 18:50:18
Nit: Remove this param and make it a local variabl
megjablon
2014/07/22 21:41:45
Done.
| |
| 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 // Individual histograms are needed to count the bypassed bytes for each | |
| 173 // bypass type so that we can see the size of requests. This helps us | |
| 174 // remove outliers that would skew the sum of bypassed bytes for each type. | |
| 175 switch (bypassed_bytes_type) { | |
| 176 case DataReductionProxyUsageStats::NOT_BYPASSED: | |
| 177 UMA_HISTOGRAM_COUNTS( | |
| 178 "DataReductionProxy.BypassedBytes.NotBypassed", content_length); | |
| 179 break; | |
| 180 case DataReductionProxyUsageStats::SSL: | |
| 181 UMA_HISTOGRAM_COUNTS( | |
| 182 "DataReductionProxy.BypassedBytes.SSL", content_length); | |
| 183 break; | |
| 184 case DataReductionProxyUsageStats::LOCAL_BYPASS_RULES: | |
| 185 UMA_HISTOGRAM_COUNTS( | |
| 186 "DataReductionProxy.BypassedBytes.LocalBypassRules", | |
| 187 content_length); | |
| 188 break; | |
| 189 case DataReductionProxyUsageStats::AUDIO_VIDEO: | |
| 190 if (last_bypass_type_ == ProxyService::SHORT_BYPASS) { | |
| 191 UMA_HISTOGRAM_COUNTS( | |
| 192 "DataReductionProxy.BypassedBytes.ShortAudioVideo", | |
| 193 content_length); | |
| 194 } | |
| 195 break; | |
| 196 case DataReductionProxyUsageStats::TRIGGERING_REQUEST: | |
| 197 switch (bypass_type) { | |
| 198 case ProxyService::SHORT_BYPASS: | |
| 199 UMA_HISTOGRAM_COUNTS( | |
| 200 "DataReductionProxy.BypassedBytes.ShortTriggeringRequest", | |
| 201 content_length); | |
| 202 break; | |
| 203 case ProxyService::MEDIUM_BYPASS: | |
| 204 UMA_HISTOGRAM_COUNTS( | |
| 205 "DataReductionProxy.BypassedBytes.MediumTriggeringRequest", | |
| 206 content_length); | |
| 207 break; | |
| 208 case ProxyService::LONG_BYPASS: | |
| 209 UMA_HISTOGRAM_COUNTS( | |
| 210 "DataReductionProxy.BypassedBytes.LongTriggeringRequest", | |
| 211 content_length); | |
| 212 break; | |
| 213 default: | |
| 214 break; | |
| 215 } | |
| 216 break; | |
| 217 case DataReductionProxyUsageStats::NETWORK_ERROR: | |
| 218 UMA_HISTOGRAM_COUNTS( | |
| 219 "DataReductionProxy.BypassedBytes.NetworkErrorOther", | |
| 220 content_length); | |
| 221 break; | |
| 222 case DataReductionProxyUsageStats::BYPASSED_BYTES_TYPE_MAX: | |
| 223 switch (bypass_type) { | |
| 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 |