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