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 f600474209e79d6a53f1f31e3462e89a25855216..148c380d79b4b5673ab0c2504cae4b2011c5e810 100644 |
| --- a/components/data_reduction_proxy/content/browser/content_lofi_decider.cc |
| +++ b/components/data_reduction_proxy/content/browser/content_lofi_decider.cc |
| @@ -43,7 +43,6 @@ bool ContentLoFiDecider::IsUsingLoFi(const net::URLRequest& request) const { |
| void ContentLoFiDecider::MaybeSetAcceptTransformHeader( |
| const net::URLRequest& request, |
| - bool are_previews_disabled, |
| net::HttpRequestHeaders* headers) const { |
| const content::ResourceRequestInfo* request_info = |
| content::ResourceRequestInfo::ForRequest(&request); |
| @@ -67,28 +66,16 @@ 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) |
| + // Do not add the Chrome-Proxy-Accept-Transform header if the request |
| + // has previews turned off. |
| + content::PreviewsState previews_state = request_info->GetPreviewsState(); |
| + if (previews_state & content::PREVIEWS_OFF) |
| return; |
| + // TODO(dougarnett): Remove once blink uses Off instead of NoTransform. |
| // 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; |
| // Lo-Fi is not allowed on the main frame, stylesheet, script, font resource, |
| @@ -104,32 +91,14 @@ void ContentLoFiDecider::MaybeSetAcceptTransformHeader( |
| // 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. |
| + // frame. |
| std::string accept_transform_value; |
| - if (lite_page_enabled_via_flags_or_field_trial && |
| + if ((previews_state & content::SERVER_LITE_PAGE_ON) && |
| resource_type == content::RESOURCE_TYPE_MAIN_FRAME) { |
| accept_transform_value = lite_page_directive(); |
| - |
| - // Since a Lite Page was not triggered client side, ask the server to |
| - // provide a Lite Page only if the page is otherwise data-heavy. |
| - if (!(request_info->GetPreviewsState() & content::SERVER_LITE_PAGE_ON)) |
| - accept_transform_value += base::StringPrintf(";%s", if_heavy_qualifier()); |
| - } else if (lofi_enabled_via_flags_or_field_trial && |
| - // Only use Lo-Fi if Lite Pages aren't enabled or fallback from |
| - // Lite Pages to Lo-Fi is enabled. |
| - (!lite_page_enabled_via_flags_or_field_trial || |
| - params::IsLitePageFallbackEnabled()) && |
| - resource_type_supports_empty_image && |
| - !(request_info->GetPreviewsState() & |
| - content::SERVER_LITE_PAGE_ON)) { |
| + } else if ((previews_state & content::SERVER_LOFI_ON) && |
| + resource_type_supports_empty_image) { |
| accept_transform_value = empty_image_directive(); |
| - |
| - // Since Lo-Fi was not triggered client side, ask the server to provide |
| - // Lo-Fi only if the page is otherwise data-heavy. |
| - if (!(request_info->GetPreviewsState() & content::SERVER_LOFI_ON)) |
| - accept_transform_value += base::StringPrintf(";%s", if_heavy_qualifier()); |
| } |
| if (accept_transform_value.empty()) |
| return; |
| @@ -180,23 +149,24 @@ void ContentLoFiDecider::RemoveAcceptTransformHeader( |
| headers->RemoveHeader(chrome_proxy_accept_transform_header()); |
| } |
| -void ContentLoFiDecider::MaybeSetIgnorePreviewsBlacklistDirective( |
| +void ContentLoFiDecider::MaybeSetForceLitePageDirective( |
| net::HttpRequestHeaders* headers) const { |
| + // Ensure lite page is requested in headers and enabled via flag. |
|
bengr
2017/05/01 16:53:13
This is very confusing. If lite pages are requeste
|
| if (!headers || !params::AreLitePagesEnabledViaFlags() || |
| !IsLitePagePreviewRequested(*headers)) { |
| return; |
| } |
| + |
| std::string chrome_proxy_header_value; |
| headers->GetHeader(chrome_proxy_header(), &chrome_proxy_header_value); |
| headers->RemoveHeader(chrome_proxy_header()); |
| if (!chrome_proxy_header_value.empty()) |
| chrome_proxy_header_value += ", "; |
| - chrome_proxy_header_value += |
| - chrome_proxy_lite_page_ignore_blacklist_directive(); |
| + chrome_proxy_header_value += chrome_proxy_force_lite_page_directive(); |
| headers->SetHeader(chrome_proxy_header(), chrome_proxy_header_value); |
| } |
| -bool ContentLoFiDecider::ShouldRecordLoFiUMA( |
| +bool ContentLoFiDecider::ShouldRecordPreviewsUMA( |
| const net::URLRequest& request) const { |
| const content::ResourceRequestInfo* request_info = |
| content::ResourceRequestInfo::ForRequest(&request); |