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..ba7b3e0268c73fe805289d5d98efd2a3e89fdc72 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,183 @@ void DataReductionProxyUsageStats::ClearRequestCountsOnUiThread() { |
actual_num_requests_through_proxy_ = 0; |
} |
+void DataReductionProxyUsageStats::SetBypassType( |
+ ProxyService::DataReductionProxyBypassType type) { |
+ bypass_type_ = type; |
+ triggering_request_ = true; |
+} |
+ |
+void DataReductionProxyUsageStats::RecordBypassedBytesHistograms( |
+ int64 content_length, |
+ const net::URLRequest& request, |
+ const BooleanPrefMember* data_reduction_proxy_enabled) { |
bengr
2014/07/16 01:40:10
Why isn't this a const &? If you need to leave it
megjablon
2014/07/16 23:07:14
I do check to make sure it's not null whenever I u
bengr
2014/07/16 23:28:14
OK. Is it always non-NULL? Can you pass a const &?
megjablon
2014/07/17 02:41:40
No it is not always non-NULL. I can check in netwo
|
+ if (data_reduction_proxy_params_->WasDataReductionProxyUsed(&request, NULL)) { |
+ RecordBypassedBytes(bypass_type_, |
+ DataReductionProxyUsageStats::NOT_BYPASSED, |
+ content_length); |
+ return; |
+ } |
+ |
+ if (data_reduction_proxy_enabled && |
+ data_reduction_proxy_enabled->GetValue() && |
+ request.url().SchemeIs(url::kHttpsScheme)) { |
+ RecordBypassedBytes(bypass_type_, |
+ DataReductionProxyUsageStats::SSL, |
+ content_length); |
+ return; |
+ } |
+ |
+ if (data_reduction_proxy_enabled && |
+ data_reduction_proxy_enabled->GetValue() && |
+ !data_reduction_proxy_params_->IsDataReductionProxyEligible(&request)) { |
+ RecordBypassedBytes(bypass_type_, |
+ DataReductionProxyUsageStats::LOCAL_BYPASS_RULES, |
+ content_length); |
+ return; |
+ } |
+ |
+ if (triggering_request_) { |
+ RecordBypassedBytes(bypass_type_, |
+ DataReductionProxyUsageStats::TRIGGERING_REQUEST, |
+ content_length); |
+ triggering_request_ = false; |
+ } |
+ |
+ std::string mime_type; |
+ request.GetMimeType(&mime_type); |
+ // MIME types are named by <media-type>/<subtype>. We check to see if the |
+ // media type is audio or video. |
bengr
2014/07/16 01:40:10
Please check how the data reduction proxy decides
megjablon
2014/07/16 23:07:14
Where can I find this?
bengr
2014/07/16 23:28:14
ask piatek@
|
+ if (mime_type.find("audio/") != string::npos || |
+ mime_type.find("video/") != string::npos) { |
+ RecordBypassedBytes(bypass_type_, |
+ DataReductionProxyUsageStats::AUDIO_VIDEO, |
+ content_length); |
+ } |
+ |
+ if (bypass_type_ != ProxyService::BYPASS_EVENT_TYPE_MAX) { |
+ RecordBypassedBytes(bypass_type_, |
+ DataReductionProxyUsageStats::BYPASSED_BYTES_TYPE_MAX, |
+ content_length); |
+ return; |
+ } |
+ |
+ if (data_reduction_proxy_params_-> |
+ WereDataReductionProxiesBypassed(&request)) { |
+ RecordBypassedBytes(bypass_type_, |
+ DataReductionProxyUsageStats::NETWORK_ERROR, |
+ content_length); |
+ } |
+} |
+ |
+void DataReductionProxyUsageStats::RecordBypassedBytes( |
+ ProxyService::DataReductionProxyBypassType bypass_type, |
+ DataReductionProxyUsageStats::BypassedBytesType bypassed_bytes_type, |
+ int64 content_length) { |
+ switch(bypassed_bytes_type) { |
+ |
+ case DataReductionProxyUsageStats::NOT_BYPASSED: |
+ UMA_HISTOGRAM_COUNTS( |
+ "DataReductionProxy.BypassedBytes.NotBypassed", content_length); |
+ break; |
+ case DataReductionProxyUsageStats::SSL: |
+ UMA_HISTOGRAM_COUNTS( |
+ "DataReductionProxy.BypassedBytes.SSL", content_length); |
+ break; |
+ case DataReductionProxyUsageStats::LOCAL_BYPASS_RULES: |
+ UMA_HISTOGRAM_COUNTS( |
+ "DataReductionProxy.BypassedBytes.LocalBypassRules", |
+ content_length); |
+ break; |
+ case DataReductionProxyUsageStats::AUDIO_VIDEO: |
+ if (bypass_type_ == ProxyService::SHORT_BYPASS) |
+ UMA_HISTOGRAM_COUNTS( |
+ "DataReductionProxy.BypassedBytes.ShortAudioVideo", |
+ content_length); |
+ break; |
+ case DataReductionProxyUsageStats::TRIGGERING_REQUEST: |
+ switch(bypass_type) { |
+ |
+ case ProxyService::SHORT_BYPASS: |
+ UMA_HISTOGRAM_COUNTS( |
+ "DataReductionProxy.BypassedBytes.ShortTriggeringRequest", |
+ content_length); |
+ break; |
+ case ProxyService::MEDIUM_BYPASS: |
+ UMA_HISTOGRAM_COUNTS( |
+ "DataReductionProxy.BypassedBytes.MediumTriggeringRequest", |
+ content_length); |
+ break; |
+ case ProxyService::LONG_BYPASS: |
+ UMA_HISTOGRAM_COUNTS( |
+ "DataReductionProxy.BypassedBytes.LongTriggeringRequest", |
+ content_length); |
+ break; |
+ default: |
+ break; |
+ } |
+ break; |
+ case DataReductionProxyUsageStats::NETWORK_ERROR: |
+ UMA_HISTOGRAM_COUNTS( |
+ "DataReductionProxy.BypassedBytes.NetworkErrorOther", |
+ content_length); |
+ break; |
+ case DataReductionProxyUsageStats::BYPASSED_BYTES_TYPE_MAX: |
+ switch(bypass_type) { |
+ |
+ case ProxyService::CURRENT_BYPASS: |
+ UMA_HISTOGRAM_COUNTS("DataReductionProxy.BypassedBytes.Current", |
+ content_length); |
+ break; |
+ case ProxyService::SHORT_BYPASS: |
+ UMA_HISTOGRAM_COUNTS("DataReductionProxy.BypassedBytes.ShortAll", |
+ content_length); |
+ break; |
+ case ProxyService::MEDIUM_BYPASS: |
+ UMA_HISTOGRAM_COUNTS("DataReductionProxy.BypassedBytes.MediumAll", |
+ content_length); |
+ break; |
+ case ProxyService::LONG_BYPASS: |
+ UMA_HISTOGRAM_COUNTS("DataReductionProxy.BypassedBytes.LongAll", |
+ content_length); |
+ break; |
+ case ProxyService::MISSING_VIA_HEADER_4XX: |
+ UMA_HISTOGRAM_COUNTS( |
+ "DataReductionProxy.BypassedBytes.MissingViaHeader4xx", |
+ content_length); |
+ break; |
+ case ProxyService::MISSING_VIA_HEADER_OTHER: |
+ UMA_HISTOGRAM_COUNTS( |
+ "DataReductionProxy.BypassedBytes.MissingViaHeaderOther", |
+ content_length); |
+ break; |
+ case ProxyService::MALFORMED_407: |
+ UMA_HISTOGRAM_COUNTS("DataReductionProxy.BypassedBytes.Malformed407", |
+ content_length); |
+ break; |
+ case ProxyService::STATUS_500_HTTP_INTERNAL_SERVER_ERROR: |
+ UMA_HISTOGRAM_COUNTS( |
+ "DataReductionProxy.BypassedBytes." |
+ "Status500HttpInternalServerError", |
+ content_length); |
+ break; |
+ case ProxyService::STATUS_502_HTTP_BAD_GATEWAY: |
+ UMA_HISTOGRAM_COUNTS( |
+ "DataReductionProxy.BypassedBytes.Status502HttpBadGateway", |
+ content_length); |
+ break; |
+ case ProxyService::STATUS_503_HTTP_SERVICE_UNAVAILABLE: |
+ UMA_HISTOGRAM_COUNTS( |
+ "DataReductionProxy.BypassedBytes." |
+ "Status503HttpServiceUnavailable", |
+ content_length); |
+ break; |
+ default: |
+ break; |
+ } |
+ break; |
+ } |
+} |
+ |
} // namespace data_reduction_proxy |