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 "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.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 || | |
| 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 WereDataReductionProxiesBypassed(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 | |
| 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 (bypass_type_ == ProxyService::SHORT_BYPASS) | |
| 188 UMA_HISTOGRAM_COUNTS( | |
| 189 "DataReductionProxy.BypassedBytes.ShortAudioVideo", | |
| 190 content_length); | |
| 191 break; | |
| 192 case DataReductionProxyUsageStats::TRIGGERING_REQUEST: | |
| 193 switch(bypass_type) { | |
| 194 | |
| 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 | |
|
bengr
2014/07/19 00:13:01
remove blank line
megjablon
2014/07/21 19:44:45
Done.
| |
| 222 case ProxyService::CURRENT_BYPASS: | |
| 223 UMA_HISTOGRAM_COUNTS("DataReductionProxy.BypassedBytes.Current", | |
| 224 content_length); | |
| 225 break; | |
| 226 case ProxyService::SHORT_BYPASS: | |
| 227 UMA_HISTOGRAM_COUNTS("DataReductionProxy.BypassedBytes.ShortAll", | |
| 228 content_length); | |
| 229 break; | |
| 230 case ProxyService::MEDIUM_BYPASS: | |
| 231 UMA_HISTOGRAM_COUNTS("DataReductionProxy.BypassedBytes.MediumAll", | |
| 232 content_length); | |
| 233 break; | |
| 234 case ProxyService::LONG_BYPASS: | |
| 235 UMA_HISTOGRAM_COUNTS("DataReductionProxy.BypassedBytes.LongAll", | |
| 236 content_length); | |
| 237 break; | |
| 238 case ProxyService::MISSING_VIA_HEADER_4XX: | |
| 239 UMA_HISTOGRAM_COUNTS( | |
| 240 "DataReductionProxy.BypassedBytes.MissingViaHeader4xx", | |
| 241 content_length); | |
| 242 break; | |
| 243 case ProxyService::MISSING_VIA_HEADER_OTHER: | |
| 244 UMA_HISTOGRAM_COUNTS( | |
| 245 "DataReductionProxy.BypassedBytes.MissingViaHeaderOther", | |
| 246 content_length); | |
| 247 break; | |
| 248 case ProxyService::MALFORMED_407: | |
| 249 UMA_HISTOGRAM_COUNTS("DataReductionProxy.BypassedBytes.Malformed407", | |
| 250 content_length); | |
| 251 break; | |
| 252 case ProxyService::STATUS_500_HTTP_INTERNAL_SERVER_ERROR: | |
| 253 UMA_HISTOGRAM_COUNTS( | |
| 254 "DataReductionProxy.BypassedBytes." | |
| 255 "Status500HttpInternalServerError", | |
| 256 content_length); | |
| 257 break; | |
| 258 case ProxyService::STATUS_502_HTTP_BAD_GATEWAY: | |
| 259 UMA_HISTOGRAM_COUNTS( | |
| 260 "DataReductionProxy.BypassedBytes.Status502HttpBadGateway", | |
| 261 content_length); | |
| 262 break; | |
| 263 case ProxyService::STATUS_503_HTTP_SERVICE_UNAVAILABLE: | |
| 264 UMA_HISTOGRAM_COUNTS( | |
| 265 "DataReductionProxy.BypassedBytes." | |
| 266 "Status503HttpServiceUnavailable", | |
| 267 content_length); | |
| 268 break; | |
| 269 default: | |
| 270 break; | |
| 271 } | |
| 272 break; | |
| 273 } | |
| 274 } | |
| 275 | |
| 96 } // namespace data_reduction_proxy | 276 } // namespace data_reduction_proxy |
| 97 | 277 |
| 98 | 278 |
| OLD | NEW |