| 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 "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
ig.h" | |
| 10 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade
rs.h" | 9 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade
rs.h" |
| 11 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param
s.h" | 10 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param
s.h" |
| 12 #include "content/public/browser/resource_request_info.h" | 11 #include "content/public/browser/resource_request_info.h" |
| 13 #include "net/base/load_flags.h" | 12 #include "net/base/load_flags.h" |
| 14 #include "net/http/http_request_headers.h" | 13 #include "net/http/http_request_headers.h" |
| 15 #include "net/proxy/proxy_server.h" | |
| 16 #include "net/url_request/url_request.h" | 14 #include "net/url_request/url_request.h" |
| 17 | 15 |
| 18 namespace data_reduction_proxy { | 16 namespace data_reduction_proxy { |
| 19 | 17 |
| 20 ContentLoFiDecider::ContentLoFiDecider() {} | 18 ContentLoFiDecider::ContentLoFiDecider() {} |
| 21 | 19 |
| 22 ContentLoFiDecider::~ContentLoFiDecider() {} | 20 ContentLoFiDecider::~ContentLoFiDecider() {} |
| 23 | 21 |
| 24 bool ContentLoFiDecider::IsUsingLoFiMode(const net::URLRequest& request) const { | 22 bool ContentLoFiDecider::IsUsingLoFiMode(const net::URLRequest& request) const { |
| 25 const content::ResourceRequestInfo* request_info = | 23 const content::ResourceRequestInfo* request_info = |
| 26 content::ResourceRequestInfo::ForRequest(&request); | 24 content::ResourceRequestInfo::ForRequest(&request); |
| 27 // The Lo-Fi directive should not be added for users in the Lo-Fi field | 25 // The Lo-Fi directive should not be added for users in the Lo-Fi field |
| 28 // trial "Control" group. Check that the user is in a group that can get | 26 // trial "Control" group. Check that the user is in a group that can get |
| 29 // "q=low". | 27 // "q=low". |
| 30 bool lofi_enabled_via_flag_or_field_trial = | 28 bool lofi_enabled_via_flag_or_field_trial = |
| 31 params::IsLoFiOnViaFlags() || params::IsIncludedInLoFiEnabledFieldTrial(); | 29 params::IsLoFiOnViaFlags() || params::IsIncludedInLoFiEnabledFieldTrial(); |
| 32 | 30 |
| 33 // Return if the user is using Lo-Fi and not part of the "Control" group. | 31 // Return if the user is using Lo-Fi and not part of the "Control" group. |
| 34 if (request_info) | 32 if (request_info) |
| 35 return request_info->IsUsingLoFi() && lofi_enabled_via_flag_or_field_trial; | 33 return request_info->IsUsingLoFi() && lofi_enabled_via_flag_or_field_trial; |
| 36 return false; | 34 return false; |
| 37 } | 35 } |
| 38 | 36 |
| 39 bool ContentLoFiDecider::MaybeAddLoFiDirectiveToHeaders( | 37 bool ContentLoFiDecider::MaybeAddLoFiDirectiveToHeaders( |
| 40 const net::URLRequest& request, | 38 const net::URLRequest& request, |
| 41 net::HttpRequestHeaders* headers, | 39 net::HttpRequestHeaders* headers) const { |
| 42 const net::ProxyServer& proxy_server, | |
| 43 DataReductionProxyConfig* config) const { | |
| 44 if (!proxy_server.is_valid() || proxy_server.is_direct() || | |
| 45 proxy_server.host_port_pair().IsEmpty() || | |
| 46 !config->IsDataReductionProxy(proxy_server.host_port_pair(), nullptr)) { | |
| 47 return false; | |
| 48 } | |
| 49 | |
| 50 const content::ResourceRequestInfo* request_info = | 40 const content::ResourceRequestInfo* request_info = |
| 51 content::ResourceRequestInfo::ForRequest(&request); | 41 content::ResourceRequestInfo::ForRequest(&request); |
| 52 | 42 |
| 53 if (!request_info) | 43 if (!request_info) |
| 54 return false; | 44 return false; |
| 55 | 45 |
| 56 // The Lo-Fi directive should not be added for users in the Lo-Fi field | 46 // The Lo-Fi directive should not be added for users in the Lo-Fi field |
| 57 // trial "Control" group. Check that the user is in a group that should | 47 // trial "Control" group. Check that the user is in a group that should |
| 58 // get "q=low". | 48 // get "q=low". |
| 59 bool lofi_enabled_via_flag_or_field_trial = | 49 bool lofi_enabled_via_flag_or_field_trial = |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 | 83 |
| 94 // |header_value| may be empty because the Lo-Fi directive is not added | 84 // |header_value| may be empty because the Lo-Fi directive is not added |
| 95 // to subrequests when preview mode is enabled. | 85 // to subrequests when preview mode is enabled. |
| 96 if (!header_value.empty()) | 86 if (!header_value.empty()) |
| 97 headers->SetHeader(chrome_proxy_header(), header_value); | 87 headers->SetHeader(chrome_proxy_header(), header_value); |
| 98 | 88 |
| 99 return true; | 89 return true; |
| 100 } | 90 } |
| 101 | 91 |
| 102 } // namespace data_reduction_proxy | 92 } // namespace data_reduction_proxy |
| OLD | NEW |