Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Unified Diff: components/data_reduction_proxy/core/common/data_reduction_proxy_headers.cc

Issue 2956703002: Adds Server Previews protocol UMA plus UMA for not accepting previews (Closed)
Patch Set: Fix merge issue for unittest wrt AlwaysOn and PreviewsDecider Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/data_reduction_proxy/core/common/data_reduction_proxy_headers.cc
diff --git a/components/data_reduction_proxy/core/common/data_reduction_proxy_headers.cc b/components/data_reduction_proxy/core/common/data_reduction_proxy_headers.cc
index ef1e77faa3d285d7bf8659c86e794643d9dfe712..fe139ab1121e5d3cc1ebfcf990d717e82a748317 100644
--- a/components/data_reduction_proxy/core/common/data_reduction_proxy_headers.cc
+++ b/components/data_reduction_proxy/core/common/data_reduction_proxy_headers.cc
@@ -43,6 +43,7 @@ const char kActionValueDelimiter = '=';
const char kEmptyImageDirective[] = "empty-image";
const char kLitePageDirective[] = "lite-page";
const char kCompressedVideoDirective[] = "compressed-video";
+const char kChromeProxyPagePoliciesDirective[] = "page-policies";
// The legacy Chrome-Proxy response header directive for LoFi images.
const char kLegacyChromeProxyLoFiResponseDirective[] = "q=low";
@@ -121,6 +122,30 @@ bool HasURLRedirectCycle(const std::vector<GURL>& url_chain) {
url_chain.back()) != url_chain.rend();
}
+data_reduction_proxy::TransformDirective ParsePagePolicyDirective(
+ const std::string chrome_proxy_header_value) {
+ for (const auto& directive : base::SplitStringPiece(
+ chrome_proxy_header_value, ",", base::TRIM_WHITESPACE,
+ base::SPLIT_WANT_NONEMPTY)) {
+ if (!base::StartsWith(directive, kChromeProxyPagePoliciesDirective,
+ base::CompareCase::INSENSITIVE_ASCII)) {
+ continue;
+ }
+
+ // Check policy directive for empty-image entry.
+ base::StringPiece page_policies_value = base::StringPiece(directive).substr(
+ arraysize(kChromeProxyPagePoliciesDirective));
+ for (const auto& policy :
+ base::SplitStringPiece(page_policies_value, "|", base::TRIM_WHITESPACE,
+ base::SPLIT_WANT_NONEMPTY)) {
+ if (base::LowerCaseEqualsASCII(policy, kEmptyImageDirective)) {
+ return data_reduction_proxy::TRANSFORM_PAGE_POLICIES_EMPTY_IMAGE;
+ }
+ }
+ }
+ return data_reduction_proxy::TRANSFORM_NONE;
+}
+
} // namespace
namespace data_reduction_proxy {
@@ -169,6 +194,52 @@ const char* if_heavy_qualifier() {
return kIfHeavyQualifier;
}
+TransformDirective ParseRequestTransform(
+ const net::HttpRequestHeaders& headers) {
+ std::string accept_transform_value;
+ if (!headers.GetHeader(chrome_proxy_accept_transform_header(),
+ &accept_transform_value)) {
+ return TRANSFORM_NONE;
+ }
+
+ if (base::LowerCaseEqualsASCII(accept_transform_value,
+ lite_page_directive())) {
+ return TRANSFORM_LITE_PAGE;
+ } else if (base::LowerCaseEqualsASCII(accept_transform_value,
+ empty_image_directive())) {
+ return TRANSFORM_EMPTY_IMAGE;
+ } else if (base::LowerCaseEqualsASCII(accept_transform_value,
+ compressed_video_directive())) {
+ return TRANSFORM_COMPRESSED_VIDEO;
+ } else {
+ return TRANSFORM_NONE;
+ }
+}
+
+TransformDirective ParseResponseTransform(
+ const net::HttpResponseHeaders& headers) {
+ std::string content_transform_value;
+ if (!headers.GetNormalizedHeader(chrome_proxy_content_transform_header(),
+ &content_transform_value)) {
+ // No content-transform so check for page-policies in chrome-proxy header.
+ std::string chrome_proxy_header_value;
+ if (headers.GetNormalizedHeader(chrome_proxy_header(),
+ &chrome_proxy_header_value)) {
+ return ParsePagePolicyDirective(chrome_proxy_header_value);
+ }
+ } else if (base::LowerCaseEqualsASCII(content_transform_value,
+ lite_page_directive())) {
+ return TRANSFORM_LITE_PAGE;
+ } else if (base::LowerCaseEqualsASCII(content_transform_value,
+ empty_image_directive())) {
+ return TRANSFORM_EMPTY_IMAGE;
+ } else {
+ NOTREACHED() << "Unexpected content transform header: "
+ << content_transform_value;
+ }
+ return TRANSFORM_NONE;
+}
+
bool IsEmptyImagePreview(const net::HttpResponseHeaders& headers) {
return IsPreviewType(headers, kEmptyImageDirective) ||
headers.HasHeaderValue(kChromeProxyHeader,
« no previous file with comments | « components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h ('k') | tools/metrics/histograms/enums.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698