Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/data_reduction_proxy/content/browser/content_lofi_decider.h " | 5 #include "components/data_reduction_proxy/content/browser/content_lofi_decider.h " |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/feature_list.h" | |
| 9 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| 10 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 11 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_featu res.h" | |
| 12 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h" | 14 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h" |
| 13 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" | 15 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" |
| 14 #include "content/public/browser/resource_request_info.h" | 16 #include "content/public/browser/resource_request_info.h" |
| 15 #include "content/public/common/previews_state.h" | 17 #include "content/public/common/previews_state.h" |
| 16 #include "content/public/common/resource_type.h" | 18 #include "content/public/common/resource_type.h" |
| 17 #include "net/base/load_flags.h" | 19 #include "net/base/load_flags.h" |
| 18 #include "net/http/http_request_headers.h" | 20 #include "net/http/http_request_headers.h" |
| 19 #include "net/url_request/url_request.h" | 21 #include "net/url_request/url_request.h" |
| 20 | 22 |
| 21 namespace data_reduction_proxy { | 23 namespace data_reduction_proxy { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 return; | 62 return; |
| 61 | 63 |
| 62 content::ResourceType resource_type = request_info->GetResourceType(); | 64 content::ResourceType resource_type = request_info->GetResourceType(); |
| 63 | 65 |
| 64 if (resource_type == content::RESOURCE_TYPE_MEDIA) { | 66 if (resource_type == content::RESOURCE_TYPE_MEDIA) { |
| 65 headers->SetHeader(chrome_proxy_accept_transform_header(), | 67 headers->SetHeader(chrome_proxy_accept_transform_header(), |
| 66 compressed_video_directive()); | 68 compressed_video_directive()); |
| 67 return; | 69 return; |
| 68 } | 70 } |
| 69 | 71 |
| 70 // The Lo-Fi and Lite Page directives should not be added for users in the | 72 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.
| |
| 71 // Lo-Fi field trial "Control" group. | |
| 72 bool lofi_enabled_via_flags_or_field_trial = | |
| 73 params::IsLoFiOnViaFlags() || params::IsIncludedInLoFiEnabledFieldTrial(); | |
| 74 | 73 |
| 75 bool lite_page_enabled_via_flags_or_field_trial = | 74 // Do not add the Chrome-Proxy-Accept-Transform header when the page load |
| 76 (params::IsLoFiOnViaFlags() && params::AreLitePagesEnabledViaFlags()) || | 75 // explicitly forbids previews transformations. |
| 77 params::IsIncludedInLitePageFieldTrial(); | 76 if (previews_state & content::PREVIEWS_NO_TRANSFORM) { |
| 78 | |
| 79 // User does not have previews enabled. | |
| 80 if (!lofi_enabled_via_flags_or_field_trial && | |
| 81 !lite_page_enabled_via_flags_or_field_trial) { | |
| 82 return; | 77 return; |
| 83 } | 78 } |
| 84 | 79 |
| 85 // Previews has been disabled. | 80 // For the proxy-decides-transform feature, the header is set based only |
| 86 if (are_previews_disabled) | 81 // on the request's PreviewsState (no checking of previews flags). |
| 87 return; | 82 // This is for a newer version of the proxy server protocol where the |
| 83 // server makes the transform decision and client simply advertises | |
| 84 // if is accepts transforms for the resource type (determined here from | |
| 85 // previously set previews state bits). The previous logic in this method | |
| 86 // that checks various flags will be deprecated. | |
| 87 bool check_previews_flags = !base::FeatureList::IsEnabled( | |
| 88 features::kDataReductionProxyDecidesTransform); | |
| 88 | 89 |
| 89 // Do not add the Chrome-Proxy-Accept-Transform header when the page load | 90 bool lofi_enabled_via_flags_or_field_trial = false; |
| 90 // explicitly forbids previews transformations. | 91 bool lite_page_enabled_via_flags_or_field_trial = false; |
| 91 if (request_info->GetPreviewsState() & content::PREVIEWS_NO_TRANSFORM) | 92 if (check_previews_flags) { |
| 92 return; | 93 // The Lo-Fi and Lite Page directives should not be added for users in the |
| 94 // Lo-Fi field trial "Control" group. | |
| 95 lofi_enabled_via_flags_or_field_trial = | |
| 96 params::IsLoFiOnViaFlags() || | |
| 97 params::IsIncludedInLoFiEnabledFieldTrial(); | |
| 98 | |
| 99 lite_page_enabled_via_flags_or_field_trial = | |
| 100 (params::IsLoFiOnViaFlags() && params::AreLitePagesEnabledViaFlags()) || | |
| 101 params::IsIncludedInLitePageFieldTrial(); | |
| 102 | |
| 103 // Previews has been disabled. | |
|
megjablon
2017/06/01 00:06:21
nit: Previews have?
dougarnett
2017/06/01 18:16:48
Done.
| |
| 104 if (are_previews_disabled) | |
| 105 return; | |
| 106 | |
| 107 // User does not have previews enabled. | |
| 108 if (!lofi_enabled_via_flags_or_field_trial && | |
| 109 !lite_page_enabled_via_flags_or_field_trial) { | |
| 110 return; | |
| 111 } | |
| 112 } | |
| 93 | 113 |
| 94 // Lo-Fi is not allowed on the main frame, stylesheet, script, font resource, | 114 // Lo-Fi is not allowed on the main frame, stylesheet, script, font resource, |
| 95 // media, service worker, or CSP report. | 115 // media, service worker, or CSP report. |
| 96 bool resource_type_supports_empty_image = | 116 bool resource_type_supports_empty_image = |
| 97 !(resource_type == content::RESOURCE_TYPE_MAIN_FRAME || | 117 !(resource_type == content::RESOURCE_TYPE_MAIN_FRAME || |
| 98 resource_type == content::RESOURCE_TYPE_STYLESHEET || | 118 resource_type == content::RESOURCE_TYPE_STYLESHEET || |
| 99 resource_type == content::RESOURCE_TYPE_SCRIPT || | 119 resource_type == content::RESOURCE_TYPE_SCRIPT || |
| 100 resource_type == content::RESOURCE_TYPE_FONT_RESOURCE || | 120 resource_type == content::RESOURCE_TYPE_FONT_RESOURCE || |
| 101 resource_type == content::RESOURCE_TYPE_MEDIA || | 121 resource_type == content::RESOURCE_TYPE_MEDIA || |
| 102 resource_type == content::RESOURCE_TYPE_CSP_REPORT); | 122 resource_type == content::RESOURCE_TYPE_CSP_REPORT); |
| 103 | 123 |
| 104 // If the Lite Page field trial or flag is enabled, only add the "lite-page" | |
| 105 // directive on main frame requests. Only add "empty-image" directives to | |
| 106 // other requests when Lite Page previews are not enabled after the main | |
| 107 // frame. Add the "if-heavy" qualifier to allow the server to provide a | |
| 108 // preview when the page is data heavy on if a preview was not otherwise | |
| 109 // triggered. | |
| 110 std::string accept_transform_value; | 124 std::string accept_transform_value; |
| 111 if (lite_page_enabled_via_flags_or_field_trial && | 125 if (!check_previews_flags) { |
| 112 resource_type == content::RESOURCE_TYPE_MAIN_FRAME) { | 126 // For the proxy-decides-transform feature, check PreviewsState bits and |
| 127 // type of resource to determine which, if any, transformation to accept. | |
| 128 if ((previews_state & content::SERVER_LITE_PAGE_ON) && | |
| 129 resource_type == content::RESOURCE_TYPE_MAIN_FRAME) { | |
| 130 accept_transform_value = lite_page_directive(); | |
| 131 } else if ((previews_state & content::SERVER_LOFI_ON) && | |
| 132 resource_type_supports_empty_image) { | |
| 133 // Note that for subresource requests, the Lo-Fi bit should only be set | |
| 134 // if the main frame response provided the "empty-image" directive (for | |
| 135 // the client to echo back to the server here for any image resources). | |
| 136 accept_transform_value = empty_image_directive(); | |
| 137 } | |
| 138 } else if (lite_page_enabled_via_flags_or_field_trial && | |
| 139 resource_type == content::RESOURCE_TYPE_MAIN_FRAME) { | |
| 140 // If the Lite Page field trial or flag is enabled, only add the "lite-page" | |
| 141 // directive on main frame requests. Only add "empty-image" directives to | |
| 142 // other requests when Lite Page previews are not enabled after the main | |
| 143 // frame. Add the "if-heavy" qualifier to allow the server to provide a | |
| 144 // preview when the page is data heavy on if a preview was not otherwise | |
| 145 // triggered. | |
| 113 accept_transform_value = lite_page_directive(); | 146 accept_transform_value = lite_page_directive(); |
| 114 | 147 |
| 115 // Since a Lite Page was not triggered client side, ask the server to | 148 // Since a Lite Page was not triggered client side, ask the server to |
| 116 // provide a Lite Page only if the page is otherwise data-heavy. | 149 // provide a Lite Page only if the page is otherwise data-heavy. |
| 117 if (!(request_info->GetPreviewsState() & content::SERVER_LITE_PAGE_ON)) | 150 if (!(request_info->GetPreviewsState() & content::SERVER_LITE_PAGE_ON)) |
| 118 accept_transform_value += base::StringPrintf(";%s", if_heavy_qualifier()); | 151 accept_transform_value += base::StringPrintf(";%s", if_heavy_qualifier()); |
| 119 } else if (lofi_enabled_via_flags_or_field_trial && | 152 } else if (lofi_enabled_via_flags_or_field_trial && |
| 120 !lite_page_enabled_via_flags_or_field_trial && | 153 !lite_page_enabled_via_flags_or_field_trial && |
| 121 resource_type_supports_empty_image && | 154 resource_type_supports_empty_image && |
| 122 !(request_info->GetPreviewsState() & | 155 !(request_info->GetPreviewsState() & |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 } | 236 } |
| 204 | 237 |
| 205 bool ContentLoFiDecider::IsClientLoFiAutoReloadRequest( | 238 bool ContentLoFiDecider::IsClientLoFiAutoReloadRequest( |
| 206 const net::URLRequest& request) const { | 239 const net::URLRequest& request) const { |
| 207 const content::ResourceRequestInfo* request_info = | 240 const content::ResourceRequestInfo* request_info = |
| 208 content::ResourceRequestInfo::ForRequest(&request); | 241 content::ResourceRequestInfo::ForRequest(&request); |
| 209 return request_info && | 242 return request_info && |
| 210 (request_info->GetPreviewsState() & content::CLIENT_LOFI_AUTO_RELOAD); | 243 (request_info->GetPreviewsState() & content::CLIENT_LOFI_AUTO_RELOAD); |
| 211 } | 244 } |
| 212 } // namespace data_reduction_proxy | 245 } // namespace data_reduction_proxy |
| OLD | NEW |