Chromium Code Reviews| Index: components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.cc |
| diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.cc |
| index 61a26f2cfd7dcf2cc39ef58da66b5ce04fbda096..8a62ed62c9f8a963966444016754d01c03910012 100644 |
| --- a/components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.cc |
| +++ b/components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.cc |
| @@ -2,7 +2,9 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include "base/metrics/histogram.h" |
| #include "components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.h" |
| +#include "net/base/net_errors.h" |
| #include "net/proxy/proxy_retry_info.h" |
| #include "net/proxy/proxy_server.h" |
| #include "net/proxy/proxy_service.h" |
| @@ -11,6 +13,7 @@ |
| using base::MessageLoopProxy; |
| using net::HostPortPair; |
| using net::ProxyServer; |
| +using net::ProxyService; |
| using net::NetworkChangeNotifier; |
| namespace data_reduction_proxy { |
| @@ -20,6 +23,8 @@ DataReductionProxyUsageStats::DataReductionProxyUsageStats( |
| MessageLoopProxy* ui_thread_proxy, |
| MessageLoopProxy* io_thread_proxy) |
| : data_reduction_proxy_params_(params), |
| + bypass_type_(ProxyService::BYPASS_EVENT_TYPE_MAX), |
| + triggering_request_(true), |
| ui_thread_proxy_(ui_thread_proxy), |
| io_thread_proxy_(io_thread_proxy), |
| eligible_num_requests_through_proxy_(0), |
| @@ -93,6 +98,137 @@ void DataReductionProxyUsageStats::ClearRequestCountsOnUiThread() { |
| actual_num_requests_through_proxy_ = 0; |
| } |
| +void DataReductionProxyUsageStats::SetBypassType( |
| + net::ProxyService::DataReductionProxyBypassType type) { |
| + bypass_type_ = type; |
| + triggering_request_ = true; |
| +} |
| + |
| +void DataReductionProxyUsageStats::RecordBypassedBytesHistograms( |
| + const int64 content_length, |
| + const net::URLRequest* request) { |
| + if (data_reduction_proxy_params_->WasDataReductionProxyUsed(request, NULL)) { |
| + UMA_HISTOGRAM_COUNTS( |
| + "DataReductionProxy.BypassedBytes.NotBypassed", content_length); |
| + return; |
| + } |
| + |
| + if (request->url().SchemeIs("https")) { |
| + UMA_HISTOGRAM_COUNTS( |
| + "DataReductionProxy.BypassedBytes.SSL", content_length); |
| + return; |
| + } |
| + |
| + LOG(WARNING) << "Data Reduction Eligible: " |
|
bengr
2014/07/12 00:11:59
Remove this logging.
megjablon
2014/07/14 19:06:41
Done.
|
| + << data_reduction_proxy_params_->IsDataReductionProxyEligible(request); |
| + if (!data_reduction_proxy_params_->IsDataReductionProxyEligible(request)) { |
| + UMA_HISTOGRAM_COUNTS( |
|
bengr
2014/07/14 17:44:03
Can you move all of your UMA into RecordBypassedBy
megjablon
2014/07/14 19:06:41
Should I do this by adding parameter bool is_local
bengr
2014/07/14 22:04:29
I was thinking the former, I think. The RecordBypa
|
| + "DataReductionProxy.BypassedBytes.LocalBypassRules", content_length); |
| + return; |
| + } |
| + |
| + if (triggering_request_) { |
| + RecordTriggeringRequestBypassedBytes(bypass_type_, content_length); |
| + triggering_request_ = false; |
| + } |
| + |
| + if (bypass_type_ == |
| + ProxyService::DataReductionProxyBypassType::SHORT_BYPASS) { |
| + string* mime_type = new string(); |
|
bengr
2014/07/12 00:11:59
std::string and don't new().
std::string mime_typ
megjablon
2014/07/14 19:06:41
Done.
|
| + request->GetMimeType(mime_type); |
| + if((*mime_type).find("audio/") != string::npos || |
|
bengr
2014/07/12 00:11:59
Add comment that describes how you know that audio
megjablon
2014/07/14 19:06:41
Done.
|
| + (*mime_type).find("video/") != string::npos) { |
| + UMA_HISTOGRAM_COUNTS("DataReductionProxy.BypassedBytes.ShortAudioVideo", |
|
bengr
2014/07/14 17:44:03
Can you move all of your UMA into RecordBypassedBy
|
| + content_length); |
| + } |
| + } |
| + |
| + RecordBypassedBytes(bypass_type_, content_length); |
| +} |
| + |
| +void DataReductionProxyUsageStats::RecordTriggeringRequestBypassedBytes( |
|
bengr
2014/07/14 17:44:03
Can you move all of your UMA into RecordBypassedBy
|
| + ProxyService::DataReductionProxyBypassType bypass_type, |
| + int64 content_length) { |
| + switch(bypass_type) { |
| + case ProxyService::DataReductionProxyBypassType::SHORT_BYPASS: |
| + UMA_HISTOGRAM_COUNTS( |
| + "DataReductionProxy.BypassedBytes.ShortTriggeringRequest", |
| + content_length); |
| + break; |
| + case ProxyService::DataReductionProxyBypassType::MEDIUM_BYPASS: |
| + UMA_HISTOGRAM_COUNTS( |
| + "DataReductionProxy.BypassedBytes.MediumTriggeringRequest", |
| + content_length); |
| + break; |
| + case ProxyService::DataReductionProxyBypassType::LONG_BYPASS: |
| + UMA_HISTOGRAM_COUNTS( |
| + "DataReductionProxy.BypassedBytes.LongTriggeringRequest", |
| + content_length); |
| + break; |
| + default: |
| + break; |
| + } |
| +} |
| + |
| +void DataReductionProxyUsageStats::RecordBypassedBytes( |
| + ProxyService::DataReductionProxyBypassType bypass_type, |
| + int64 content_length) { |
| + switch(bypass_type) { |
| + case ProxyService::DataReductionProxyBypassType::CURRENT_BYPASS: |
| + UMA_HISTOGRAM_COUNTS("DataReductionProxy.BypassedBytes.Current", |
| + content_length); |
| + break; |
| + case ProxyService::DataReductionProxyBypassType::SHORT_BYPASS: |
| + UMA_HISTOGRAM_COUNTS("DataReductionProxy.BypassedBytes.ShortAll", |
| + content_length); |
| + break; |
| + case ProxyService::DataReductionProxyBypassType::MEDIUM_BYPASS: |
| + UMA_HISTOGRAM_COUNTS("DataReductionProxy.BypassedBytes.MediumAll", |
| + content_length); |
| + break; |
| + case ProxyService::DataReductionProxyBypassType::LONG_BYPASS: |
| + UMA_HISTOGRAM_COUNTS("DataReductionProxy.BypassedBytes.LongAll", |
| + content_length); |
| + break; |
| + case ProxyService::DataReductionProxyBypassType::MISSING_VIA_HEADER_4XX: |
| + UMA_HISTOGRAM_COUNTS( |
| + "DataReductionProxy.BypassedBytes.MissingViaHeader4xx", |
| + content_length); |
| + break; |
| + case ProxyService::DataReductionProxyBypassType::MISSING_VIA_HEADER_OTHER: |
| + UMA_HISTOGRAM_COUNTS( |
| + "DataReductionProxy.BypassedBytes.MissingViaHeaderOther", |
| + content_length); |
| + break; |
| + case ProxyService::DataReductionProxyBypassType::MALFORMED_407: |
| + UMA_HISTOGRAM_COUNTS("DataReductionProxy.BypassedBytes.Malformed407", |
| + content_length); |
| + break; |
| + case ProxyService::DataReductionProxyBypassType |
| + ::STATUS_500_HTTP_INTERNAL_SERVER_ERROR: |
| + UMA_HISTOGRAM_COUNTS( |
| + "DataReductionProxy.BypassedBytes.Status500HTTPInternalServerError", |
| + content_length); |
| + break; |
| + case ProxyService::DataReductionProxyBypassType |
| + ::STATUS_502_HTTP_BAD_GATEWAY: |
| + UMA_HISTOGRAM_COUNTS( |
| + "DataReductionProxy.BypassedBytes.Status502HTTPBadGateway", |
| + content_length); |
| + break; |
| + case ProxyService::DataReductionProxyBypassType |
| + ::STATUS_503_HTTP_SERVICE_UNAVAILABLE: |
| + UMA_HISTOGRAM_COUNTS( |
| + "DataReductionProxy.BypassedBytes.Status503HTTPServiceUnavailable", |
| + content_length); |
| + break; |
| + default: |
| + UMA_HISTOGRAM_COUNTS( |
| + "DataReductionProxy.BypassedBytes.NetworkErrorOther", |
| + content_length); |
| + } |
| +} |
| + |
| } // namespace data_reduction_proxy |