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 "base/strings/stringprintf.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_heade
rs.h" |
13 #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" |
14 #include "content/public/browser/resource_request_info.h" | 14 #include "content/public/browser/resource_request_info.h" |
| 15 #include "content/public/common/previews_state.h" |
15 #include "content/public/common/resource_type.h" | 16 #include "content/public/common/resource_type.h" |
16 #include "net/base/load_flags.h" | 17 #include "net/base/load_flags.h" |
17 #include "net/http/http_request_headers.h" | 18 #include "net/http/http_request_headers.h" |
18 #include "net/url_request/url_request.h" | 19 #include "net/url_request/url_request.h" |
19 | 20 |
20 namespace data_reduction_proxy { | 21 namespace data_reduction_proxy { |
21 | 22 |
22 ContentLoFiDecider::ContentLoFiDecider() {} | 23 ContentLoFiDecider::ContentLoFiDecider() {} |
23 | 24 |
24 ContentLoFiDecider::~ContentLoFiDecider() {} | 25 ContentLoFiDecider::~ContentLoFiDecider() {} |
25 | 26 |
26 bool ContentLoFiDecider::IsUsingLoFiMode(const net::URLRequest& request) const { | 27 bool ContentLoFiDecider::IsUsingLoFiMode(const net::URLRequest& request) const { |
27 const content::ResourceRequestInfo* request_info = | 28 const content::ResourceRequestInfo* request_info = |
28 content::ResourceRequestInfo::ForRequest(&request); | 29 content::ResourceRequestInfo::ForRequest(&request); |
29 // The Lo-Fi directive should not be added for users in the Lo-Fi field | 30 // The Lo-Fi directive should not be added for users in the Lo-Fi field |
30 // trial "Control" group. Check that the user is in a group that can get | 31 // trial "Control" group. Check that the user is in a group that can get |
31 // "q=low". | 32 // "q=low". |
32 bool lofi_enabled_via_flag_or_field_trial = | 33 bool lofi_enabled_via_flag_or_field_trial = |
33 params::IsLoFiOnViaFlags() || params::IsIncludedInLoFiEnabledFieldTrial(); | 34 params::IsLoFiOnViaFlags() || params::IsIncludedInLoFiEnabledFieldTrial(); |
34 | 35 |
35 // 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. |
36 if (request_info) | 37 if (request_info) { |
37 return request_info->IsUsingLoFi() && lofi_enabled_via_flag_or_field_trial; | 38 return (request_info->GetPreviewsState() & content::SERVER_LOFI_ON) && |
| 39 lofi_enabled_via_flag_or_field_trial; |
| 40 } |
38 return false; | 41 return false; |
39 } | 42 } |
40 | 43 |
41 void ContentLoFiDecider::MaybeSetAcceptTransformHeader( | 44 void ContentLoFiDecider::MaybeSetAcceptTransformHeader( |
42 const net::URLRequest& request, | 45 const net::URLRequest& request, |
43 bool is_previews_disabled, | 46 bool is_previews_disabled, |
44 net::HttpRequestHeaders* headers) const { | 47 net::HttpRequestHeaders* headers) const { |
45 const content::ResourceRequestInfo* request_info = | 48 const content::ResourceRequestInfo* request_info = |
46 content::ResourceRequestInfo::ForRequest(&request); | 49 content::ResourceRequestInfo::ForRequest(&request); |
47 | 50 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 if (lite_page_enabled_via_flags_or_field_trial) { | 105 if (lite_page_enabled_via_flags_or_field_trial) { |
103 if (resource_type == content::RESOURCE_TYPE_MAIN_FRAME) | 106 if (resource_type == content::RESOURCE_TYPE_MAIN_FRAME) |
104 accept_transform_value = lite_page_directive(); | 107 accept_transform_value = lite_page_directive(); |
105 } else if (lofi_enabled_via_flags_or_field_trial) { | 108 } else if (lofi_enabled_via_flags_or_field_trial) { |
106 if (resource_type_supports_empty_image) | 109 if (resource_type_supports_empty_image) |
107 accept_transform_value = empty_image_directive(); | 110 accept_transform_value = empty_image_directive(); |
108 } | 111 } |
109 if (accept_transform_value.empty()) | 112 if (accept_transform_value.empty()) |
110 return; | 113 return; |
111 | 114 |
112 if (!request_info->IsUsingLoFi()) | 115 if (!(request_info->GetPreviewsState() & content::SERVER_LOFI_ON)) |
113 accept_transform_value += base::StringPrintf(";%s", if_heavy_qualifier()); | 116 accept_transform_value += base::StringPrintf(";%s", if_heavy_qualifier()); |
114 | 117 |
115 headers->SetHeader(chrome_proxy_accept_transform_header(), | 118 headers->SetHeader(chrome_proxy_accept_transform_header(), |
116 accept_transform_value); | 119 accept_transform_value); |
117 } | 120 } |
118 | 121 |
119 bool ContentLoFiDecider::IsSlowPagePreviewRequested( | 122 bool ContentLoFiDecider::IsSlowPagePreviewRequested( |
120 const net::HttpRequestHeaders& headers) const { | 123 const net::HttpRequestHeaders& headers) const { |
121 std::string accept_transform_header_value; | 124 std::string accept_transform_header_value; |
122 if (!headers.GetHeader(chrome_proxy_accept_transform_header(), | 125 if (!headers.GetHeader(chrome_proxy_accept_transform_header(), |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 chrome_proxy_lite_page_ignore_blacklist_directive(); | 176 chrome_proxy_lite_page_ignore_blacklist_directive(); |
174 headers->SetHeader(chrome_proxy_header(), chrome_proxy_header_value); | 177 headers->SetHeader(chrome_proxy_header(), chrome_proxy_header_value); |
175 } | 178 } |
176 | 179 |
177 bool ContentLoFiDecider::ShouldRecordLoFiUMA( | 180 bool ContentLoFiDecider::ShouldRecordLoFiUMA( |
178 const net::URLRequest& request) const { | 181 const net::URLRequest& request) const { |
179 const content::ResourceRequestInfo* request_info = | 182 const content::ResourceRequestInfo* request_info = |
180 content::ResourceRequestInfo::ForRequest(&request); | 183 content::ResourceRequestInfo::ForRequest(&request); |
181 | 184 |
182 // User is not using Lo-Fi. | 185 // User is not using Lo-Fi. |
183 if (!request_info || !request_info->IsUsingLoFi()) | 186 if (!request_info || |
| 187 !(request_info->GetPreviewsState() & content::SERVER_LOFI_ON)) { |
184 return false; | 188 return false; |
| 189 } |
185 | 190 |
186 return params::IsIncludedInLoFiEnabledFieldTrial() || | 191 return params::IsIncludedInLoFiEnabledFieldTrial() || |
187 params::IsIncludedInLoFiControlFieldTrial(); | 192 params::IsIncludedInLoFiControlFieldTrial(); |
188 } | 193 } |
189 | 194 |
190 } // namespace data_reduction_proxy | 195 } // namespace data_reduction_proxy |
OLD | NEW |