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

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: Updates from Ben's feedback 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 52cf1328dd087e952e599e1df148d8ee8fb3c09a..473bebd0452260e0b7e3e4469d86f45c92663cf0 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
@@ -42,6 +42,7 @@ const char kEmptyImageDirective[] = "empty-image";
const char kLitePageDirective[] = "lite-page";
const char kCompressedVideoDirective[] = "compressed-video";
const char kIdentityDirective[] = "identity";
+const char kChromeProxyPagePoliciesDirective[] = "page-policies";
// The legacy Chrome-Proxy response header directive for LoFi images.
const char kLegacyChromeProxyLoFiResponseDirective[] = "q=low";
@@ -120,6 +121,30 @@ bool HasURLRedirectCycle(const std::vector<GURL>& url_chain) {
url_chain.back()) != url_chain.rend();
}
+data_reduction_proxy::TransformType 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,
bengr 2017/06/28 16:45:51 So you split and return the first one you find. Wo
dougarnett 2017/06/28 22:12:38 I don't think we should support multiple types her
+ 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 {
@@ -168,6 +193,50 @@ const char* if_heavy_qualifier() {
return kIfHeavyQualifier;
}
+TransformType 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_COMPRESS_VIDEO;
+ } else {
+ return TRANSFORM_NONE;
+ }
+}
+
+TransformType 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,

Powered by Google App Engine
This is Rietveld 408576698