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/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 "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h" | 12 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h" |
12 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" | 13 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" |
13 #include "content/public/browser/resource_request_info.h" | 14 #include "content/public/browser/resource_request_info.h" |
14 #include "net/base/load_flags.h" | 15 #include "net/base/load_flags.h" |
15 #include "net/http/http_request_headers.h" | 16 #include "net/http/http_request_headers.h" |
16 #include "net/url_request/url_request.h" | 17 #include "net/url_request/url_request.h" |
17 | 18 |
18 namespace data_reduction_proxy { | 19 namespace data_reduction_proxy { |
19 | 20 |
20 ContentLoFiDecider::ContentLoFiDecider() {} | 21 ContentLoFiDecider::ContentLoFiDecider() {} |
(...skipping 17 matching lines...) Expand all Loading... | |
38 | 39 |
39 void ContentLoFiDecider::MaybeSetAcceptTransformHeader( | 40 void ContentLoFiDecider::MaybeSetAcceptTransformHeader( |
40 const net::URLRequest& request, | 41 const net::URLRequest& request, |
41 net::HttpRequestHeaders* headers) const { | 42 net::HttpRequestHeaders* headers) const { |
42 const content::ResourceRequestInfo* request_info = | 43 const content::ResourceRequestInfo* request_info = |
43 content::ResourceRequestInfo::ForRequest(&request); | 44 content::ResourceRequestInfo::ForRequest(&request); |
44 | 45 |
45 if (!request_info) | 46 if (!request_info) |
46 return; | 47 return; |
47 | 48 |
48 content::ResourceType resource_type = request_info->GetResourceType(); | |
49 | |
50 // The Lo-Fi and Lite Page directives should not be added for users in the | |
51 // Lo-Fi field trial "Control" group. | |
52 bool lofi_enabled_via_flag_or_field_trial = | |
53 params::IsLoFiOnViaFlags() || params::IsIncludedInLoFiEnabledFieldTrial(); | |
54 | |
55 bool lite_page_via_flag_or_field_trial = | |
56 params::AreLitePagesEnabledViaFlags() || | |
57 params::IsIncludedInLitePageFieldTrial(); | |
58 | |
59 // Previews only operate on HTTP. | 49 // Previews only operate on HTTP. |
60 if (!request.url().SchemeIs("http")) | 50 if (!request.url().SchemeIs("http")) |
61 return; | 51 return; |
62 | 52 |
63 // Chrome-Proxy-Accept-Transform takes at most one token. | 53 // Chrome-Proxy-Accept-Transform takes at most one token. |
64 if (headers->HasHeader(chrome_proxy_accept_transform_header())) | 54 if (headers->HasHeader(chrome_proxy_accept_transform_header())) |
65 return; | 55 return; |
66 | 56 |
57 content::ResourceType resource_type = request_info->GetResourceType(); | |
58 | |
67 if (resource_type == content::RESOURCE_TYPE_MEDIA) { | 59 if (resource_type == content::RESOURCE_TYPE_MEDIA) { |
68 headers->SetHeader(chrome_proxy_accept_transform_header(), | 60 headers->SetHeader(chrome_proxy_accept_transform_header(), |
69 compressed_video_directive()); | 61 compressed_video_directive()); |
70 return; | 62 return; |
71 } | 63 } |
72 | 64 |
73 // User is not using Lo-Fi or is part of the "Control" group. | 65 // The Lo-Fi and Lite Page directives should not be added for users in the |
74 if (!request_info->IsUsingLoFi() || !lofi_enabled_via_flag_or_field_trial) | 66 // Lo-Fi field trial "Control" group. |
67 bool lofi_enabled_via_flags_or_field_trial = | |
68 params::IsLoFiOnViaFlags() || params::IsIncludedInLoFiEnabledFieldTrial(); | |
69 | |
70 bool lite_page_enabled_via_flags_or_field_trial = | |
71 (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.
| |
72 params::IsIncludedInLitePageFieldTrial(); | |
73 | |
74 // User does not have previews enabled. | |
75 if (!lofi_enabled_via_flags_or_field_trial && | |
76 !lite_page_enabled_via_flags_or_field_trial) { | |
75 return; | 77 return; |
78 } | |
76 | 79 |
77 // LoFi is not allowed on the main frame, stylesheet, script, font resource, | 80 // LoFi is not allowed on the main frame, stylesheet, script, font resource, |
78 // media, service worker, or CSP report. | 81 // media, service worker, or CSP report. |
79 bool resource_type_supports_empty_image = | 82 bool resource_type_supports_empty_image = |
80 !(resource_type == content::RESOURCE_TYPE_MAIN_FRAME || | 83 !(resource_type == content::RESOURCE_TYPE_MAIN_FRAME || |
81 resource_type == content::RESOURCE_TYPE_STYLESHEET || | 84 resource_type == content::RESOURCE_TYPE_STYLESHEET || |
82 resource_type == content::RESOURCE_TYPE_SCRIPT || | 85 resource_type == content::RESOURCE_TYPE_SCRIPT || |
83 resource_type == content::RESOURCE_TYPE_FONT_RESOURCE || | 86 resource_type == content::RESOURCE_TYPE_FONT_RESOURCE || |
84 resource_type == content::RESOURCE_TYPE_MEDIA || | 87 resource_type == content::RESOURCE_TYPE_MEDIA || |
85 resource_type == content::RESOURCE_TYPE_CSP_REPORT); | 88 resource_type == content::RESOURCE_TYPE_CSP_REPORT); |
86 | 89 |
87 // If in the preview field trial or the preview flag is enabled, only add the | 90 // 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.
| |
88 // "lite-page" directive on main frame requests. Do not add "empty-image" | 91 // "lite-page" directive on main frame requests. Do not add "empty-image" |
89 // directives to other requests when Lite Page previews are enabled. | 92 // directives to other requests when Lite Page previews are enabled. |
93 // 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.
| |
94 // "if-heavy" qualifier to allow the server to provide a preview when the | |
95 // page is data heavy. | |
90 std::string accept_transform_value; | 96 std::string accept_transform_value; |
91 if (lite_page_via_flag_or_field_trial) { | 97 if (lite_page_enabled_via_flags_or_field_trial) { |
92 if (resource_type == content::RESOURCE_TYPE_MAIN_FRAME) | 98 if (resource_type == content::RESOURCE_TYPE_MAIN_FRAME) |
93 accept_transform_value = lite_page_directive(); | 99 accept_transform_value = lite_page_directive(); |
94 } else if (resource_type_supports_empty_image) { | 100 } else if (lofi_enabled_via_flags_or_field_trial) { |
95 accept_transform_value = empty_image_directive(); | 101 if (resource_type_supports_empty_image) |
102 accept_transform_value = empty_image_directive(); | |
96 } | 103 } |
97 | |
98 if (accept_transform_value.empty()) | 104 if (accept_transform_value.empty()) |
99 return; | 105 return; |
100 | 106 |
107 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.
| |
108 accept_transform_value += base::StringPrintf(";%s", if_heavy_qualifier()); | |
109 | |
101 headers->SetHeader(chrome_proxy_accept_transform_header(), | 110 headers->SetHeader(chrome_proxy_accept_transform_header(), |
102 accept_transform_value); | 111 accept_transform_value); |
103 } | 112 } |
104 | 113 |
105 bool ContentLoFiDecider::IsSlowPagePreviewRequested( | 114 bool ContentLoFiDecider::IsSlowPagePreviewRequested( |
106 const net::HttpRequestHeaders& headers) const { | 115 const net::HttpRequestHeaders& headers) const { |
107 std::string accept_transform_header_value; | 116 std::string accept_transform_header_value; |
108 if (!headers.GetHeader(chrome_proxy_accept_transform_header(), | 117 if (!headers.GetHeader(chrome_proxy_accept_transform_header(), |
109 &accept_transform_header_value)) { | 118 &accept_transform_header_value)) { |
110 return false; | 119 return false; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 | 176 |
168 // User is not using Lo-Fi. | 177 // User is not using Lo-Fi. |
169 if (!request_info || !request_info->IsUsingLoFi()) | 178 if (!request_info || !request_info->IsUsingLoFi()) |
170 return false; | 179 return false; |
171 | 180 |
172 return params::IsIncludedInLoFiEnabledFieldTrial() || | 181 return params::IsIncludedInLoFiEnabledFieldTrial() || |
173 params::IsIncludedInLoFiControlFieldTrial(); | 182 params::IsIncludedInLoFiControlFieldTrial(); |
174 } | 183 } |
175 | 184 |
176 } // namespace data_reduction_proxy | 185 } // namespace data_reduction_proxy |
OLD | NEW |