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

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

Powered by Google App Engine
This is Rietveld 408576698