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 net::ProxyService::DataReductionProxyBypassType type) { | |
| 103 bypass_type_ = type; | |
| 104 triggering_request_ = true; | |
| 105 } | |
| 106 | |
| 107 void DataReductionProxyUsageStats::RecordBypassedBytesHistograms( | |
| 108 const int64 content_length, | |
| 109 const net::URLRequest* request) { | |
| 110 if (data_reduction_proxy_params_->WasDataReductionProxyUsed(request, NULL)) { | |
| 111 UMA_HISTOGRAM_COUNTS( | |
| 112 "DataReductionProxy.BypassedBytes.NotBypassed", content_length); | |
| 113 return; | |
| 114 } | |
| 115 | |
| 116 if (request->url().SchemeIs("https")) { | |
| 117 UMA_HISTOGRAM_COUNTS( | |
| 118 "DataReductionProxy.BypassedBytes.SSL", content_length); | |
| 119 return; | |
| 120 } | |
| 121 | |
| 122 LOG(WARNING) << "Data Reduction Eligible: " | |
| 123 << data_reduction_proxy_params_->IsDataReductionProxyEligible(request); | |
| 124 if (!data_reduction_proxy_params_->IsDataReductionProxyEligible(request)) { | |
| 125 UMA_HISTOGRAM_COUNTS( | |
| 126 "DataReductionProxy.BypassedBytes.LocalBypassRules", content_length); | |
| 127 return; | |
| 128 } | |
| 129 | |
| 130 if (triggering_request_) { | |
| 131 RecordTriggeringRequestBypassedBytes(bypass_type_, content_length); | |
| 132 triggering_request_ = false; | |
| 133 } | |
| 134 | |
| 135 if (bypass_type_ == | |
| 136 ProxyService::DataReductionProxyBypassType::SHORT_BYPASS) { | |
| 137 std::string mime_type; | |
| 138 request->GetMimeType(&mime_type); | |
| 139 // MIME types are named by <media-type>/<subtype>. We check to see if the | |
| 140 // media type is audio or video. | |
| 141 if((mime_type).find("audio/") != string::npos || | |
| 142 (mime_type).find("video/") != string::npos) { | |
| 143 UMA_HISTOGRAM_COUNTS("DataReductionProxy.BypassedBytes.ShortAudioVideo", | |
| 144 content_length); | |
| 145 } | |
| 146 } | |
| 147 | |
| 148 RecordBypassedBytes(bypass_type_, content_length); | |
| 149 } | |
| 150 | |
| 151 void DataReductionProxyUsageStats::RecordTriggeringRequestBypassedBytes( | |
| 152 ProxyService::DataReductionProxyBypassType bypass_type, | |
| 153 int64 content_length) { | |
| 154 switch(bypass_type) { | |
| 155 case ProxyService::DataReductionProxyBypassType::SHORT_BYPASS: | |
| 156 UMA_HISTOGRAM_COUNTS( | |
| 157 "DataReductionProxy.BypassedBytes.ShortTriggeringRequest", | |
| 158 content_length); | |
| 159 break; | |
| 160 case ProxyService::DataReductionProxyBypassType::MEDIUM_BYPASS: | |
| 161 UMA_HISTOGRAM_COUNTS( | |
| 162 "DataReductionProxy.BypassedBytes.MediumTriggeringRequest", | |
| 163 content_length); | |
| 164 break; | |
| 165 case ProxyService::DataReductionProxyBypassType::LONG_BYPASS: | |
| 166 UMA_HISTOGRAM_COUNTS( | |
| 167 "DataReductionProxy.BypassedBytes.LongTriggeringRequest", | |
| 168 content_length); | |
| 169 break; | |
| 170 default: | |
| 171 break; | |
| 172 } | |
| 173 } | |
| 174 | |
| 175 void DataReductionProxyUsageStats::RecordBypassedBytes( | |
| 176 ProxyService::DataReductionProxyBypassType bypass_type, | |
| 177 int64 content_length) { | |
| 178 switch(bypass_type) { | |
| 179 case ProxyService::DataReductionProxyBypassType::CURRENT_BYPASS: | |
| 180 UMA_HISTOGRAM_COUNTS("DataReductionProxy.BypassedBytes.Current", | |
|
bengr
2014/07/14 22:04:30
Why did you shift all of these?
megjablon
2014/07/15 18:02:50
That was not intentional. I have no idea how that
| |
| 181 content_length); | |
| 182 break; | |
| 183 case ProxyService::DataReductionProxyBypassType::SHORT_BYPASS: | |
| 184 UMA_HISTOGRAM_COUNTS("DataReductionProxy.BypassedBytes.ShortAll", | |
| 185 content_length); | |
| 186 break; | |
| 187 case ProxyService::DataReductionProxyBypassType::MEDIUM_BYPASS: | |
| 188 UMA_HISTOGRAM_COUNTS("DataReductionProxy.BypassedBytes.MediumAll", | |
| 189 content_length); | |
| 190 break; | |
| 191 case ProxyService::DataReductionProxyBypassType::LONG_BYPASS: | |
| 192 UMA_HISTOGRAM_COUNTS("DataReductionProxy.BypassedBytes.LongAll", | |
| 193 content_length); | |
| 194 break; | |
| 195 case ProxyService::DataReductionProxyBypassType::MISSING_VIA_HEADER_4XX: | |
| 196 UMA_HISTOGRAM_COUNTS( | |
| 197 "DataReductionProxy.BypassedBytes.MissingViaHeader4xx", | |
| 198 content_length); | |
| 199 break; | |
| 200 case ProxyService::DataReductionProxyBypassType | |
| 201 ::MISSING_VIA_HEADER_OTHER: | |
| 202 UMA_HISTOGRAM_COUNTS( | |
| 203 "DataReductionProxy.BypassedBytes.MissingViaHeaderOther", | |
| 204 content_length); | |
| 205 break; | |
| 206 case ProxyService::DataReductionProxyBypassType::MALFORMED_407: | |
| 207 UMA_HISTOGRAM_COUNTS("DataReductionProxy.BypassedBytes.Malformed407", | |
| 208 content_length); | |
| 209 break; | |
| 210 case ProxyService::DataReductionProxyBypassType | |
| 211 ::STATUS_500_HTTP_INTERNAL_SERVER_ERROR: | |
| 212 UMA_HISTOGRAM_COUNTS( | |
| 213 "DataReductionProxy.BypassedBytes." | |
| 214 "Status500HttpInternalServerError", | |
| 215 content_length); | |
| 216 break; | |
| 217 case ProxyService::DataReductionProxyBypassType | |
| 218 ::STATUS_502_HTTP_BAD_GATEWAY: | |
| 219 UMA_HISTOGRAM_COUNTS( | |
| 220 "DataReductionProxy.BypassedBytes.Status502HttpBadGateway", | |
| 221 content_length); | |
| 222 break; | |
| 223 case ProxyService::DataReductionProxyBypassType | |
| 224 ::STATUS_503_HTTP_SERVICE_UNAVAILABLE: | |
| 225 UMA_HISTOGRAM_COUNTS( | |
| 226 "DataReductionProxy.BypassedBytes." | |
| 227 "Status503HttpServiceUnavailable", | |
| 228 content_length); | |
| 229 break; | |
| 230 default: | |
| 231 UMA_HISTOGRAM_COUNTS( | |
| 232 "DataReductionProxy.BypassedBytes.NetworkErrorOther", | |
| 233 content_length); | |
| 234 break; | |
| 235 } | |
| 236 } | |
| 237 | |
| 96 } // namespace data_reduction_proxy | 238 } // namespace data_reduction_proxy |
| 97 | 239 |
| 98 | 240 |
| OLD | NEW |