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

Unified Diff: components/data_reduction_proxy/content/browser/content_lofi_decider.cc

Issue 2424263002: Added support for heavy page previews transformations (Closed)
Patch Set: Addressed comments Created 4 years, 2 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/content/browser/content_lofi_decider.cc
diff --git a/components/data_reduction_proxy/content/browser/content_lofi_decider.cc b/components/data_reduction_proxy/content/browser/content_lofi_decider.cc
index db658528852bd6d90293832d4622c779259addc5..c5e2b4daa0920501f6c7c13ed95d9d1665bd4a3c 100644
--- a/components/data_reduction_proxy/content/browser/content_lofi_decider.cc
+++ b/components/data_reduction_proxy/content/browser/content_lofi_decider.cc
@@ -8,6 +8,7 @@
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
+#include "base/strings/stringprintf.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
#include "content/public/browser/resource_request_info.h"
@@ -38,6 +39,7 @@ bool ContentLoFiDecider::IsUsingLoFiMode(const net::URLRequest& request) const {
void ContentLoFiDecider::MaybeSetAcceptTransformHeader(
const net::URLRequest& request,
+ bool is_previews_disabled,
net::HttpRequestHeaders* headers) const {
const content::ResourceRequestInfo* request_info =
content::ResourceRequestInfo::ForRequest(&request);
@@ -45,17 +47,6 @@ void ContentLoFiDecider::MaybeSetAcceptTransformHeader(
if (!request_info)
return;
- content::ResourceType resource_type = request_info->GetResourceType();
-
- // The Lo-Fi and Lite Page directives should not be added for users in the
- // Lo-Fi field trial "Control" group.
- bool lofi_enabled_via_flag_or_field_trial =
- params::IsLoFiOnViaFlags() || params::IsIncludedInLoFiEnabledFieldTrial();
-
- bool lite_page_via_flag_or_field_trial =
- params::AreLitePagesEnabledViaFlags() ||
- params::IsIncludedInLitePageFieldTrial();
-
// Previews only operate on HTTP.
if (!request.url().SchemeIs("http"))
return;
@@ -64,14 +55,31 @@ void ContentLoFiDecider::MaybeSetAcceptTransformHeader(
if (headers->HasHeader(chrome_proxy_accept_transform_header()))
return;
+ content::ResourceType resource_type = request_info->GetResourceType();
+
if (resource_type == content::RESOURCE_TYPE_MEDIA) {
headers->SetHeader(chrome_proxy_accept_transform_header(),
compressed_video_directive());
return;
}
- // User is not using Lo-Fi or is part of the "Control" group.
- if (!request_info->IsUsingLoFi() || !lofi_enabled_via_flag_or_field_trial)
+ // The Lo-Fi and Lite Page directives should not be added for users in the
+ // Lo-Fi field trial "Control" group.
+ bool lofi_enabled_via_flags_or_field_trial =
+ params::IsLoFiOnViaFlags() || params::IsIncludedInLoFiEnabledFieldTrial();
+
+ bool lite_page_enabled_via_flags_or_field_trial =
+ (params::IsLoFiOnViaFlags() && params::AreLitePagesEnabledViaFlags()) ||
+ params::IsIncludedInLitePageFieldTrial();
+
+ // User does not have previews enabled.
+ if (!lofi_enabled_via_flags_or_field_trial &&
+ !lite_page_enabled_via_flags_or_field_trial) {
+ return;
+ }
+
+ // Previews has been disabled.
+ if (is_previews_disabled)
return;
// LoFi is not allowed on the main frame, stylesheet, script, font resource,
@@ -84,20 +92,25 @@ void ContentLoFiDecider::MaybeSetAcceptTransformHeader(
resource_type == content::RESOURCE_TYPE_MEDIA ||
resource_type == content::RESOURCE_TYPE_CSP_REPORT);
- // If in the preview field trial or the preview flag is enabled, only add the
- // "lite-page" directive on main frame requests. Do not add "empty-image"
+ // If in the lite page field trial or the lite page flag is enabled, only add
+ // the "lite-page" directive on main frame requests. Do not add "empty-image"
// directives to other requests when Lite Page previews are enabled.
+ // Add the "if-heavy" qualifier to allow the server to provide a preview when
+ // the page is data heavy on if a preview was not otherwise triggered.
std::string accept_transform_value;
- if (lite_page_via_flag_or_field_trial) {
+ if (lite_page_enabled_via_flags_or_field_trial) {
if (resource_type == content::RESOURCE_TYPE_MAIN_FRAME)
accept_transform_value = lite_page_directive();
- } else if (resource_type_supports_empty_image) {
- accept_transform_value = empty_image_directive();
+ } else if (lofi_enabled_via_flags_or_field_trial) {
+ if (resource_type_supports_empty_image)
+ accept_transform_value = empty_image_directive();
}
-
if (accept_transform_value.empty())
return;
+ if (!request_info->IsUsingLoFi())
+ accept_transform_value += base::StringPrintf(";%s", if_heavy_qualifier());
+
headers->SetHeader(chrome_proxy_accept_transform_header(),
accept_transform_value);
}

Powered by Google App Engine
This is Rietveld 408576698