Chromium Code Reviews| 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 4f98e4eea1b944c2b0e38617618007e909bf3065..6b4799ff7582d53bbdd90ac1ee39af4c1e839101 100644 |
| --- a/components/data_reduction_proxy/content/browser/content_lofi_decider.cc |
| +++ b/components/data_reduction_proxy/content/browser/content_lofi_decider.cc |
| @@ -6,9 +6,11 @@ |
| #include <string> |
| +#include "base/feature_list.h" |
| #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 +69,47 @@ 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; |
| + content::PreviewsState previews_state = request_info->GetPreviewsState(); |
|
megjablon
2017/06/01 00:06:21
Replace request_info->GetPreviewsState() calls bel
dougarnett
2017/06/01 18:16:47
Done.
|
| // 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) |
| + if (previews_state & content::PREVIEWS_NO_TRANSFORM) { |
| return; |
| + } |
| + |
| + // For the proxy-decides-transform feature, the header is set based only |
| + // on the request's PreviewsState (no checking of previews flags). |
| + // 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 check_previews_flags = !base::FeatureList::IsEnabled( |
| + features::kDataReductionProxyDecidesTransform); |
| + |
| + bool lofi_enabled_via_flags_or_field_trial = false; |
| + bool lite_page_enabled_via_flags_or_field_trial = false; |
| + if (check_previews_flags) { |
| + // 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. |
|
megjablon
2017/06/01 00:06:21
nit: Previews have?
dougarnett
2017/06/01 18:16:48
Done.
|
| + 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 +121,28 @@ 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 (!check_previews_flags) { |
| + // 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) { |
| + accept_transform_value = lite_page_directive(); |
| + } else if ((previews_state & content::SERVER_LOFI_ON) && |
| + resource_type_supports_empty_image) { |
| + // Note that for subresource requests, the Lo-Fi bit should only be set |
| + // if the main frame response provided the "empty-image" directive (for |
| + // the client to echo back to the server here for any image resources). |
| + 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 |