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 db658528852bd6d90293832d4622c779259addc5..aa6432c438dfbdbc01195926baf38ea98d7b227c 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" |
| @@ -45,17 +46,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,15 +54,28 @@ 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()) || |
|
RyanSturm
2016/10/19 18:58:56
Is lofi being on via flags a requirement for lite
bengr
2016/10/19 23:34:28
Yes, unfortunately.
RyanSturm
2016/10/19 23:43:12
Acknowledged.
|
| + 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; |
| + } |
| // LoFi is not allowed on the main frame, stylesheet, script, font resource, |
| // media, service worker, or CSP report. |
| @@ -87,17 +90,23 @@ void ContentLoFiDecider::MaybeSetAcceptTransformHeader( |
| // If in the preview field trial or the preview flag is enabled, only add the |
|
RyanSturm
2016/10/19 18:58:56
s/preview/lite page/
RyanSturm
2016/10/19 23:43:12
Done.
|
| // "lite-page" directive on main frame requests. Do not add "empty-image" |
| // directives to other requests when Lite Page previews are enabled. |
| + // If a preview was not triggered due to the network being slow, add the |
|
RyanSturm
2016/10/19 18:58:56
This comment is somewhat confusing with the "not".
RyanSturm
2016/10/19 18:58:56
nit: s/preview/server-side preview/ ?
bengr
2016/10/19 23:34:28
Redundant imho. Headers only go to servers.
bengr
2016/10/19 23:34:28
Done.
|
| + // "if-heavy" qualifier to allow the server to provide a preview when the |
| + // page is data heavy. |
| 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()) |
|
RyanSturm
2016/10/19 18:58:56
Just to verify, "if-heavy" is applied to lofi imag
bengr
2016/10/19 23:34:28
Yes. To both LoFi and Lite Page previews, and only
RyanSturm
2016/10/19 23:43:12
Acknowledged.
|
| + accept_transform_value += base::StringPrintf(";%s", if_heavy_qualifier()); |
| + |
| headers->SetHeader(chrome_proxy_accept_transform_header(), |
| accept_transform_value); |
| } |