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

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

Issue 2911673002: New CPAT support in ContentLoFiDecider guarded by feature flag. (Closed)
Patch Set: FIxed a comment Created 3 years, 7 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 ac9452408650d0d10faad044a1f504a280c32253..2d2b7048358bda6f70a442a70a3eeb3368640926 100644
--- a/components/data_reduction_proxy/content/browser/content_lofi_decider.cc
+++ b/components/data_reduction_proxy/content/browser/content_lofi_decider.cc
@@ -9,6 +9,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_features.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"
@@ -67,29 +68,46 @@ void ContentLoFiDecider::MaybeSetAcceptTransformHeader(
return;
}
- // 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 (are_previews_disabled)
- return;
-
// Do not add the Chrome-Proxy-Accept-Transform header when the page load
// explicitly forbids previews transformations.
- if (request_info->GetPreviewsState() & content::PREVIEWS_NO_TRANSFORM)
+ content::PreviewsState previews_state = request_info->GetPreviewsState();
megjablon 2017/05/30 18:38:53 I'd move this line above the comment.
dougarnett 2017/05/30 22:15:48 Done.
+ if (previews_state & content::PREVIEWS_NO_TRANSFORM) {
megjablon 2017/05/30 18:38:53 If you want, you can remove the brackets here.
dougarnett 2017/05/30 22:15:48 Acknowledged.
return;
+ }
+
+ // For the proxy-decides-transform feature, we determine whether to set
megjablon 2017/05/30 18:38:53 Don't use we. "the header is set based only on the
dougarnett 2017/05/30 22:15:48 Done.
+ // header by the request's PreviewsState (no further flag checks here).
+ // This is for a newer version of the proxy server protocol where the
+ // server makes the transform decision and client simply advertises
+ // if is accepts transforms for the resource type (determined here from
+ // previously set previews state bits). The previous logic in this method
+ // that checks various flags will be deprecated.
+ bool decide_by_previews_state = base::FeatureList::IsEnabled(
megjablon 2017/05/30 18:38:53 Maybe call this check_previews_flags and use the i
dougarnett 2017/05/30 22:15:48 Done.
+ features::kDataReductionProxyDecidesTransform);
+
+ bool lofi_enabled_via_flags_or_field_trial = false;
+ bool lite_page_enabled_via_flags_or_field_trial = false;
+ if (!decide_by_previews_state) {
+ // The Lo-Fi and Lite Page directives should not be added for users in the
+ // Lo-Fi field trial "Control" group.
+ lofi_enabled_via_flags_or_field_trial =
+ params::IsLoFiOnViaFlags() ||
+ params::IsIncludedInLoFiEnabledFieldTrial();
+
+ lite_page_enabled_via_flags_or_field_trial =
+ (params::IsLoFiOnViaFlags() && params::AreLitePagesEnabledViaFlags()) ||
+ params::IsIncludedInLitePageFieldTrial();
+
+ // Previews has been disabled.
+ if (are_previews_disabled)
+ return;
+
+ // User does not have previews enabled.
+ if (!lofi_enabled_via_flags_or_field_trial &&
+ !lite_page_enabled_via_flags_or_field_trial) {
+ return;
+ }
+ }
// Lo-Fi is not allowed on the main frame, stylesheet, script, font resource,
// media, service worker, or CSP report.
@@ -101,15 +119,25 @@ void ContentLoFiDecider::MaybeSetAcceptTransformHeader(
resource_type == content::RESOURCE_TYPE_MEDIA ||
resource_type == content::RESOURCE_TYPE_CSP_REPORT);
- // If the Lite Page field trial or flag is enabled, only add the "lite-page"
- // directive on main frame requests. Only add "empty-image" directives to
- // other requests when Lite Page previews are not enabled after the main
- // frame. 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_enabled_via_flags_or_field_trial &&
- resource_type == content::RESOURCE_TYPE_MAIN_FRAME) {
+ if (decide_by_previews_state) {
+ // For the proxy-decides-transform feature, check PreviewsState bits and
+ // type of resource to determine which, if any, transformation to accept.
+ if ((previews_state & content::SERVER_LITE_PAGE_ON) &&
+ resource_type == content::RESOURCE_TYPE_MAIN_FRAME) {
megjablon 2017/05/30 18:38:53 Do we want: if (previews_state & content::SERVER_
dougarnett 2017/05/30 22:15:48 Discussed in person. I favor the client not wiring
+ accept_transform_value = lite_page_directive();
+ } else if ((previews_state & content::SERVER_LOFI_ON) &&
+ resource_type_supports_empty_image) {
+ accept_transform_value = empty_image_directive();
+ }
+ } else if (lite_page_enabled_via_flags_or_field_trial &&
+ resource_type == content::RESOURCE_TYPE_MAIN_FRAME) {
+ // If the Lite Page field trial or flag is enabled, only add the "lite-page"
+ // directive on main frame requests. Only add "empty-image" directives to
+ // other requests when Lite Page previews are not enabled after the main
+ // frame. 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.
accept_transform_value = lite_page_directive();
// Since a Lite Page was not triggered client side, ask the server to

Powered by Google App Engine
This is Rietveld 408576698