Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc |
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc |
index 465ec6cf16bb31ab35a54fef218ea4f3707994cb..645ff67fb4261f6a645508c778e330a2d48f8080 100644 |
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc |
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc |
@@ -43,6 +43,20 @@ namespace data_reduction_proxy { |
namespace { |
+// Values of the UMA DataReductionProxy.Protocol.AcceptTransform histogram |
+// defined in metrics/histograms/histograms.xml. This enum must remain |
+// synchronized with DataReductionProxyProtocolAcceptTransformEvent in |
+// tools/metrics/histograms/enums.xml. |
+enum AcceptTransformEvent { |
+ ACCEPT_LITE_PAGE_SENT = 0, |
+ TRANSFORM_LITE_PAGE_RECEIVED = 1, |
+ POLICY_EMPTY_IMAGE_RECEIVED = 2, |
+ ACCEPT_EMPTY_IMAGE_SENT = 3, |
+ TRANSFORM_EMPTY_IMAGE_RECEIVED = 4, |
+ ACCEPT_COMPRESSED_VIDEO_SENT = 5, |
+ ACCEPT_TRANSFORM_EVENT_BOUNDARY |
+}; |
+ |
// Records the occurrence of |sample| in |name| histogram. UMA macros are not |
// used because the |name| is not static. |
void RecordNewContentLengthHistogram(const std::string& name, int64_t sample) { |
@@ -165,6 +179,53 @@ void RecordContentLengthHistograms(bool lofi_low_header_added, |
received_content_length); |
} |
+void RecordAcceptTransformEvent(AcceptTransformEvent event) { |
+ UMA_HISTOGRAM_ENUMERATION("DataReductionProxy.Protocol.AcceptTransform", |
+ event, ACCEPT_TRANSFORM_EVENT_BOUNDARY); |
+} |
+ |
+void RecordAcceptTransformSentUMA( |
+ const net::HttpRequestHeaders& request_headers) { |
+ std::string accept_transform_header_value; |
+ if (request_headers.GetHeader(chrome_proxy_accept_transform_header(), |
+ &accept_transform_header_value)) { |
+ if (std::string::npos != |
+ accept_transform_header_value.find(lite_page_directive())) { |
bengr
2017/06/26 18:11:47
This is a very brittle way of finding directives i
dougarnett
2017/06/26 21:19:16
Added methods to parse headers into a single Trans
|
+ RecordAcceptTransformEvent(ACCEPT_LITE_PAGE_SENT); |
+ } else if (std::string::npos != |
+ accept_transform_header_value.find(empty_image_directive())) { |
+ RecordAcceptTransformEvent(ACCEPT_EMPTY_IMAGE_SENT); |
+ } else if (std::string::npos != accept_transform_header_value.find( |
+ compressed_video_directive())) { |
+ RecordAcceptTransformEvent(ACCEPT_COMPRESSED_VIDEO_SENT); |
+ } else { |
+ NOTREACHED() << "Unexpected accept transform: " |
+ << accept_transform_header_value; |
+ } |
+ } |
+} |
+ |
+void RecordAcceptTransformReceivedUMA(const net::URLRequest& request) { |
+ net::HttpResponseHeaders* response_headers = request.response_headers(); |
+ if (!response_headers) |
+ return; |
+ |
+ if (IsLitePagePreview(*response_headers)) { |
+ RecordAcceptTransformEvent(TRANSFORM_LITE_PAGE_RECEIVED); |
+ } else if (IsEmptyImagePreview(*response_headers)) { |
+ RecordAcceptTransformEvent(TRANSFORM_EMPTY_IMAGE_RECEIVED); |
+ } else { |
+ std::string chrome_proxy_header_value; |
+ if (response_headers->GetNormalizedHeader(chrome_proxy_header(), |
+ &chrome_proxy_header_value) && |
+ std::string::npos != |
+ chrome_proxy_header_value.find( |
+ chrome_proxy_page_policies_empty_image_directive())) { |
+ RecordAcceptTransformEvent(POLICY_EMPTY_IMAGE_RECEIVED); |
+ } |
+ } |
+} |
+ |
// Verifies that the chrome proxy related request headers are set correctly. |
// |via_chrome_proxy| is true if the request is being fetched via Chrome Data |
// Saver proxy. |
@@ -373,6 +434,7 @@ void DataReductionProxyNetworkDelegate::OnBeforeSendHeadersInternal( |
data_reduction_proxy_request_options_->AddRequestHeader(headers, page_id); |
VerifyHttpRequestHeaders(true, *headers); |
+ RecordAcceptTransformSentUMA(*headers); |
} |
void DataReductionProxyNetworkDelegate::OnBeforeRedirectInternal( |
@@ -456,6 +518,7 @@ void DataReductionProxyNetworkDelegate::OnCompletedInternal( |
CalculateAndRecordDataUsage(*request, request_type); |
RecordContentLength(*request, request_type, original_content_length); |
+ RecordAcceptTransformReceivedUMA(*request); |
} |
void DataReductionProxyNetworkDelegate::OnHeadersReceivedInternal( |