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

Side by Side Diff: components/data_reduction_proxy/content/browser/content_lofi_decider.cc

Issue 2802843003: Update CPAT protocol to send lite-page transform acceptance with ect
Patch Set: Fixed testLitePageNoFallback integration test (fixed forcing ECT) Created 3 years, 8 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"
(...skipping 25 matching lines...) Expand all
36 // Return if the user is using Lo-Fi and not part of the "Control" group. 36 // Return if the user is using Lo-Fi and not part of the "Control" group.
37 if (request_info) { 37 if (request_info) {
38 return (request_info->GetPreviewsState() & content::SERVER_LOFI_ON) && 38 return (request_info->GetPreviewsState() & content::SERVER_LOFI_ON) &&
39 lofi_enabled_via_flag_or_field_trial; 39 lofi_enabled_via_flag_or_field_trial;
40 } 40 }
41 return false; 41 return false;
42 } 42 }
43 43
44 void ContentLoFiDecider::MaybeSetAcceptTransformHeader( 44 void ContentLoFiDecider::MaybeSetAcceptTransformHeader(
45 const net::URLRequest& request, 45 const net::URLRequest& request,
46 bool are_previews_disabled,
47 net::HttpRequestHeaders* headers) const { 46 net::HttpRequestHeaders* headers) const {
48 const content::ResourceRequestInfo* request_info = 47 const content::ResourceRequestInfo* request_info =
49 content::ResourceRequestInfo::ForRequest(&request); 48 content::ResourceRequestInfo::ForRequest(&request);
50 49
51 if (!request_info) 50 if (!request_info)
52 return; 51 return;
53 52
54 // Previews only operate on HTTP. 53 // Previews only operate on HTTP.
55 if (!request.url().SchemeIs("http")) 54 if (!request.url().SchemeIs("http"))
56 return; 55 return;
57 56
58 // Chrome-Proxy-Accept-Transform takes at most one token. 57 // Chrome-Proxy-Accept-Transform takes at most one token.
59 if (headers->HasHeader(chrome_proxy_accept_transform_header())) 58 if (headers->HasHeader(chrome_proxy_accept_transform_header()))
60 return; 59 return;
61 60
62 content::ResourceType resource_type = request_info->GetResourceType(); 61 content::ResourceType resource_type = request_info->GetResourceType();
63 62
64 if (resource_type == content::RESOURCE_TYPE_MEDIA) { 63 if (resource_type == content::RESOURCE_TYPE_MEDIA) {
65 headers->SetHeader(chrome_proxy_accept_transform_header(), 64 headers->SetHeader(chrome_proxy_accept_transform_header(),
66 compressed_video_directive()); 65 compressed_video_directive());
67 return; 66 return;
68 } 67 }
69 68
70 // The Lo-Fi and Lite Page directives should not be added for users in the 69 // Do not add the Chrome-Proxy-Accept-Transform header if the page load
71 // Lo-Fi field trial "Control" group. 70 // has previews turned off.
megjablon 2017/04/25 23:10:36 s/if the page load/if the request
dougarnett 2017/04/26 19:50:48 Done.
72 bool lofi_enabled_via_flags_or_field_trial = 71 content::PreviewsState previews_state = request_info->GetPreviewsState();
73 params::IsLoFiOnViaFlags() || params::IsIncludedInLoFiEnabledFieldTrial(); 72 if (previews_state & content::PREVIEWS_OFF)
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;
83 }
84
85 // Previews has been disabled.
86 if (are_previews_disabled)
87 return; 73 return;
88 74
75 // TODO(dougarnett): Remove once blink uses Off instead of NoTransform.
89 // Do not add the Chrome-Proxy-Accept-Transform header when the page load 76 // Do not add the Chrome-Proxy-Accept-Transform header when the page load
90 // explicitly forbids previews transformations. 77 // explicitly forbids previews transformations.
91 if (request_info->GetPreviewsState() & content::PREVIEWS_NO_TRANSFORM) 78 if (previews_state & content::PREVIEWS_NO_TRANSFORM)
92 return; 79 return;
93 80
94 // Lo-Fi is not allowed on the main frame, stylesheet, script, font resource,
95 // media, service worker, or CSP report.
96 bool resource_type_supports_empty_image =
97 !(resource_type == content::RESOURCE_TYPE_MAIN_FRAME ||
98 resource_type == content::RESOURCE_TYPE_STYLESHEET ||
99 resource_type == content::RESOURCE_TYPE_SCRIPT ||
100 resource_type == content::RESOURCE_TYPE_FONT_RESOURCE ||
101 resource_type == content::RESOURCE_TYPE_MEDIA ||
102 resource_type == content::RESOURCE_TYPE_CSP_REPORT);
103
104 // If the Lite Page field trial or flag is enabled, only add the "lite-page" 81 // 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 82 // directive on main frame requests. Only add "empty-image" directives to
106 // other requests when Lite Page previews are not enabled after the main 83 // 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 84 // frame.
108 // preview when the page is data heavy on if a preview was not otherwise
109 // triggered.
110 std::string accept_transform_value; 85 std::string accept_transform_value;
111 if (lite_page_enabled_via_flags_or_field_trial && 86 if (previews_state & content::SERVER_LITE_PAGE_ON &&
112 resource_type == content::RESOURCE_TYPE_MAIN_FRAME) { 87 resource_type == content::RESOURCE_TYPE_MAIN_FRAME) {
113 accept_transform_value = lite_page_directive(); 88 accept_transform_value = lite_page_directive();
114 89 } else if (previews_state & content::SERVER_LOFI_ON) {
megjablon 2017/04/25 23:10:36 I'd keep resource_type_supports_empty_image and us
dougarnett 2017/04/26 19:50:48 Done.
115 // Since a Lite Page was not triggered client side, ask the server to 90 // Lo-Fi is not allowed on the main frame, stylesheet, script, font
116 // provide a Lite Page only if the page is otherwise data-heavy. 91 // resource, media, service worker, or CSP report.
117 if (!(request_info->GetPreviewsState() & content::SERVER_LITE_PAGE_ON)) 92 if (!(resource_type == content::RESOURCE_TYPE_MAIN_FRAME ||
118 accept_transform_value += base::StringPrintf(";%s", if_heavy_qualifier()); 93 resource_type == content::RESOURCE_TYPE_STYLESHEET ||
119 } else if (lofi_enabled_via_flags_or_field_trial && 94 resource_type == content::RESOURCE_TYPE_SCRIPT ||
120 // Only use Lo-Fi if Lite Pages aren't enabled or fallback from 95 resource_type == content::RESOURCE_TYPE_FONT_RESOURCE ||
121 // Lite Pages to Lo-Fi is enabled. 96 resource_type == content::RESOURCE_TYPE_MEDIA ||
122 (!lite_page_enabled_via_flags_or_field_trial || 97 resource_type == content::RESOURCE_TYPE_CSP_REPORT)) {
123 params::IsLitePageFallbackEnabled()) && 98 accept_transform_value = empty_image_directive();
124 resource_type_supports_empty_image && 99 }
125 !(request_info->GetPreviewsState() &
126 content::SERVER_LITE_PAGE_ON)) {
127 accept_transform_value = empty_image_directive();
128
129 // Since Lo-Fi was not triggered client side, ask the server to provide
130 // Lo-Fi only if the page is otherwise data-heavy.
131 if (!(request_info->GetPreviewsState() & content::SERVER_LOFI_ON))
132 accept_transform_value += base::StringPrintf(";%s", if_heavy_qualifier());
133 } 100 }
134 if (accept_transform_value.empty()) 101 if (accept_transform_value.empty())
135 return; 102 return;
136 103
137 headers->SetHeader(chrome_proxy_accept_transform_header(), 104 headers->SetHeader(chrome_proxy_accept_transform_header(),
138 accept_transform_value); 105 accept_transform_value);
139 } 106 }
140 107
141 bool ContentLoFiDecider::IsSlowPagePreviewRequested( 108 bool ContentLoFiDecider::IsSlowPagePreviewRequested(
142 const net::HttpRequestHeaders& headers) const { 109 const net::HttpRequestHeaders& headers) const {
(...skipping 30 matching lines...) Expand all
173 std::string transform_type; 140 std::string transform_type;
174 base::TrimWhitespaceASCII(tokens[0], base::TRIM_ALL, &transform_type); 141 base::TrimWhitespaceASCII(tokens[0], base::TRIM_ALL, &transform_type);
175 return transform_type == lite_page_directive(); 142 return transform_type == lite_page_directive();
176 } 143 }
177 144
178 void ContentLoFiDecider::RemoveAcceptTransformHeader( 145 void ContentLoFiDecider::RemoveAcceptTransformHeader(
179 net::HttpRequestHeaders* headers) const { 146 net::HttpRequestHeaders* headers) const {
180 headers->RemoveHeader(chrome_proxy_accept_transform_header()); 147 headers->RemoveHeader(chrome_proxy_accept_transform_header());
181 } 148 }
182 149
183 void ContentLoFiDecider::MaybeSetIgnorePreviewsBlacklistDirective( 150 void ContentLoFiDecider::MaybeSetForceLitePageDirective(
184 net::HttpRequestHeaders* headers) const { 151 net::HttpRequestHeaders* headers) const {
185 if (!headers || !params::AreLitePagesEnabledViaFlags() || 152 // Ensure lite page is requested in headers.
186 !IsLitePagePreviewRequested(*headers)) { 153 if (!headers || !IsLitePagePreviewRequested(*headers))
187 return; 154 return;
188 } 155
156 // Ensure either command line flag for lite pages or for LoFi on cellular.
157 if (!params::AreLitePagesEnabledViaFlags() &&
megjablon 2017/04/25 23:10:36 Why do we care about cellular only here?
dougarnett 2017/04/26 19:50:48 Yeah, not sure, reverting.
158 !params::IsLoFiCellularOnlyViaFlags())
megjablon 2017/04/25 23:10:36 Use brackets
dougarnett 2017/04/26 19:50:48 Done.
159 return;
160
189 std::string chrome_proxy_header_value; 161 std::string chrome_proxy_header_value;
190 headers->GetHeader(chrome_proxy_header(), &chrome_proxy_header_value); 162 headers->GetHeader(chrome_proxy_header(), &chrome_proxy_header_value);
191 headers->RemoveHeader(chrome_proxy_header()); 163 headers->RemoveHeader(chrome_proxy_header());
192 if (!chrome_proxy_header_value.empty()) 164 if (!chrome_proxy_header_value.empty())
193 chrome_proxy_header_value += ", "; 165 chrome_proxy_header_value += ", ";
194 chrome_proxy_header_value += 166 chrome_proxy_header_value += chrome_proxy_force_lite_page_directive();
195 chrome_proxy_lite_page_ignore_blacklist_directive();
196 headers->SetHeader(chrome_proxy_header(), chrome_proxy_header_value); 167 headers->SetHeader(chrome_proxy_header(), chrome_proxy_header_value);
197 } 168 }
198 169
199 bool ContentLoFiDecider::ShouldRecordLoFiUMA( 170 bool ContentLoFiDecider::ShouldRecordLoFiUMA(
200 const net::URLRequest& request) const { 171 const net::URLRequest& request) const {
201 const content::ResourceRequestInfo* request_info = 172 const content::ResourceRequestInfo* request_info =
202 content::ResourceRequestInfo::ForRequest(&request); 173 content::ResourceRequestInfo::ForRequest(&request);
203 174
204 // User is not using Lo-Fi. 175 // User is not using Lo-Fi.
205 if (!request_info || 176 if (!request_info ||
206 !(request_info->GetPreviewsState() & content::SERVER_LOFI_ON || 177 !(request_info->GetPreviewsState() & content::SERVER_LOFI_ON ||
207 request_info->GetPreviewsState() & content::SERVER_LITE_PAGE_ON)) { 178 request_info->GetPreviewsState() & content::SERVER_LITE_PAGE_ON)) {
208 return false; 179 return false;
209 } 180 }
210 181
211 return params::IsIncludedInLoFiEnabledFieldTrial() || 182 return params::IsIncludedInLoFiEnabledFieldTrial() ||
212 params::IsIncludedInLoFiControlFieldTrial(); 183 params::IsIncludedInLoFiControlFieldTrial();
213 } 184 }
214 185
215 } // namespace data_reduction_proxy 186 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698