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> |
| 8 |
| 9 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade
rs.h" |
| 10 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param
s.h" |
7 #include "content/public/browser/resource_request_info.h" | 11 #include "content/public/browser/resource_request_info.h" |
| 12 #include "net/http/http_request_headers.h" |
8 | 13 |
9 namespace data_reduction_proxy { | 14 namespace data_reduction_proxy { |
10 | 15 |
11 ContentLoFiDecider::ContentLoFiDecider() {} | 16 ContentLoFiDecider::ContentLoFiDecider() {} |
12 | 17 |
13 ContentLoFiDecider::~ContentLoFiDecider() {} | 18 ContentLoFiDecider::~ContentLoFiDecider() {} |
14 | 19 |
15 bool ContentLoFiDecider::IsUsingLoFiMode(const net::URLRequest& request) const { | 20 bool ContentLoFiDecider::IsUsingLoFiMode(const net::URLRequest& request) const { |
16 const content::ResourceRequestInfo* request_info = | 21 const content::ResourceRequestInfo* request_info = |
17 content::ResourceRequestInfo::ForRequest(&request); | 22 content::ResourceRequestInfo::ForRequest(&request); |
| 23 // The Lo-Fi directive should not be added for users in the Lo-Fi field |
| 24 // trial "Control" group. Check that the user is in a group that can get |
| 25 // "q=low". |
| 26 bool lofi_enabled_via_flag_or_field_trial = |
| 27 params::IsLoFiOnViaFlags() || params::IsIncludedInLoFiEnabledFieldTrial(); |
| 28 |
| 29 // Return if the user is using Lo-Fi and not part of the "Control" group. |
18 if (request_info) | 30 if (request_info) |
19 return request_info->IsUsingLoFi(); | 31 return request_info->IsUsingLoFi() && lofi_enabled_via_flag_or_field_trial; |
20 return false; | 32 return false; |
21 } | 33 } |
22 | 34 |
| 35 bool ContentLoFiDecider::MaybeAddLoFiDirectiveToHeaders( |
| 36 const net::URLRequest& request, |
| 37 net::HttpRequestHeaders* headers) const { |
| 38 const content::ResourceRequestInfo* request_info = |
| 39 content::ResourceRequestInfo::ForRequest(&request); |
| 40 |
| 41 if (!request_info) |
| 42 return false; |
| 43 |
| 44 // The Lo-Fi directive should not be added for users in the Lo-Fi field |
| 45 // trial "Control" group. Check that the user is in a group that should |
| 46 // get "q=low". |
| 47 bool lofi_enabled_via_flag_or_field_trial = |
| 48 params::IsLoFiOnViaFlags() || params::IsIncludedInLoFiEnabledFieldTrial(); |
| 49 |
| 50 std::string header_value; |
| 51 |
| 52 // User is using Lo-Fi and not part of the "Control" group. |
| 53 if (request_info->IsUsingLoFi() && lofi_enabled_via_flag_or_field_trial) { |
| 54 if (headers->HasHeader(chrome_proxy_header())) { |
| 55 headers->GetHeader(chrome_proxy_header(), &header_value); |
| 56 headers->RemoveHeader(chrome_proxy_header()); |
| 57 header_value += ", "; |
| 58 } |
| 59 header_value += chrome_proxy_lo_fi_directive(); |
| 60 headers->SetHeader(chrome_proxy_header(), header_value); |
| 61 return true; |
| 62 } |
| 63 |
| 64 // User is part of Lo-Fi active control experiment. |
| 65 if (request_info->IsUsingLoFi() && |
| 66 params::IsIncludedInLoFiControlFieldTrial()) { |
| 67 if (headers->HasHeader(chrome_proxy_header())) { |
| 68 headers->GetHeader(chrome_proxy_header(), &header_value); |
| 69 headers->RemoveHeader(chrome_proxy_header()); |
| 70 header_value += ", "; |
| 71 } |
| 72 header_value += chrome_proxy_lo_fi_experiment_directive(); |
| 73 headers->SetHeader(chrome_proxy_header(), header_value); |
| 74 } |
| 75 |
| 76 return false; |
| 77 } |
| 78 |
23 } // namespace data_reduction_proxy | 79 } // namespace data_reduction_proxy |
OLD | NEW |