| 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/common/data_reduction_proxy_heade
rs.h" | 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" | 10 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param
s.h" |
| 11 #include "content/public/browser/resource_request_info.h" | 11 #include "content/public/browser/resource_request_info.h" |
| 12 #include "net/base/load_flags.h" |
| 12 #include "net/http/http_request_headers.h" | 13 #include "net/http/http_request_headers.h" |
| 13 | 14 |
| 14 namespace data_reduction_proxy { | 15 namespace data_reduction_proxy { |
| 15 | 16 |
| 16 ContentLoFiDecider::ContentLoFiDecider() {} | 17 ContentLoFiDecider::ContentLoFiDecider() {} |
| 17 | 18 |
| 18 ContentLoFiDecider::~ContentLoFiDecider() {} | 19 ContentLoFiDecider::~ContentLoFiDecider() {} |
| 19 | 20 |
| 20 bool ContentLoFiDecider::IsUsingLoFiMode(const net::URLRequest& request) const { | 21 bool ContentLoFiDecider::IsUsingLoFiMode(const net::URLRequest& request) const { |
| 21 const content::ResourceRequestInfo* request_info = | 22 const content::ResourceRequestInfo* request_info = |
| (...skipping 18 matching lines...) Expand all Loading... |
| 40 | 41 |
| 41 if (!request_info) | 42 if (!request_info) |
| 42 return false; | 43 return false; |
| 43 | 44 |
| 44 // The Lo-Fi directive should not be added for users in the Lo-Fi field | 45 // 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 // trial "Control" group. Check that the user is in a group that should |
| 46 // get "q=low". | 47 // get "q=low". |
| 47 bool lofi_enabled_via_flag_or_field_trial = | 48 bool lofi_enabled_via_flag_or_field_trial = |
| 48 params::IsLoFiOnViaFlags() || params::IsIncludedInLoFiEnabledFieldTrial(); | 49 params::IsLoFiOnViaFlags() || params::IsIncludedInLoFiEnabledFieldTrial(); |
| 49 | 50 |
| 51 bool lofi_preview_via_flag_or_field_trial = |
| 52 params::AreLoFiPreviewsEnabledViaFlags() || |
| 53 params::IsIncludedInLoFiPreviewFieldTrial(); |
| 54 |
| 50 std::string header_value; | 55 std::string header_value; |
| 51 | 56 |
| 52 // User is using Lo-Fi and not part of the "Control" group. | 57 // User is using Lo-Fi and not part of the "Control" group. |
| 53 if (request_info->IsUsingLoFi() && lofi_enabled_via_flag_or_field_trial) { | 58 if (request_info->IsUsingLoFi() && lofi_enabled_via_flag_or_field_trial) { |
| 54 if (headers->HasHeader(chrome_proxy_header())) { | 59 if (headers->HasHeader(chrome_proxy_header())) { |
| 55 headers->GetHeader(chrome_proxy_header(), &header_value); | 60 headers->GetHeader(chrome_proxy_header(), &header_value); |
| 56 headers->RemoveHeader(chrome_proxy_header()); | 61 headers->RemoveHeader(chrome_proxy_header()); |
| 57 header_value += ", "; | 62 header_value += ", "; |
| 58 } | 63 } |
| 59 header_value += chrome_proxy_lo_fi_directive(); | 64 |
| 65 // Only add the "q=preview" directive on mainframe requests. Otherwise, |
| 66 // add "q=low" |
| 67 if (lofi_preview_via_flag_or_field_trial && |
| 68 (request.load_flags() & net::LOAD_MAIN_FRAME)) { |
| 69 header_value += chrome_proxy_lo_fi_preview_directive(); |
| 70 } else { |
| 71 header_value += chrome_proxy_lo_fi_directive(); |
| 72 } |
| 73 |
| 60 headers->SetHeader(chrome_proxy_header(), header_value); | 74 headers->SetHeader(chrome_proxy_header(), header_value); |
| 61 return true; | 75 return true; |
| 62 } | 76 } |
| 63 | 77 |
| 64 // User is part of Lo-Fi active control experiment. | 78 // User is part of Lo-Fi active control experiment. |
| 65 if (request_info->IsUsingLoFi() && | 79 if (request_info->IsUsingLoFi() && |
| 66 params::IsIncludedInLoFiControlFieldTrial()) { | 80 params::IsIncludedInLoFiControlFieldTrial()) { |
| 67 if (headers->HasHeader(chrome_proxy_header())) { | 81 if (headers->HasHeader(chrome_proxy_header())) { |
| 68 headers->GetHeader(chrome_proxy_header(), &header_value); | 82 headers->GetHeader(chrome_proxy_header(), &header_value); |
| 69 headers->RemoveHeader(chrome_proxy_header()); | 83 headers->RemoveHeader(chrome_proxy_header()); |
| 70 header_value += ", "; | 84 header_value += ", "; |
| 71 } | 85 } |
| 72 header_value += chrome_proxy_lo_fi_experiment_directive(); | 86 header_value += chrome_proxy_lo_fi_experiment_directive(); |
| 73 headers->SetHeader(chrome_proxy_header(), header_value); | 87 headers->SetHeader(chrome_proxy_header(), header_value); |
| 74 } | 88 } |
| 75 | 89 |
| 76 return false; | 90 return false; |
| 77 } | 91 } |
| 78 | 92 |
| 79 } // namespace data_reduction_proxy | 93 } // namespace data_reduction_proxy |
| OLD | NEW |