Chromium Code Reviews| Index: components/data_reduction_proxy/content/browser/content_lofi_decider.cc |
| diff --git a/components/data_reduction_proxy/content/browser/content_lofi_decider.cc b/components/data_reduction_proxy/content/browser/content_lofi_decider.cc |
| index 0132adde720726bed468cc670b0865b482cb5d44..1187654f29141760a69917f61a20681e01563a6f 100644 |
| --- a/components/data_reduction_proxy/content/browser/content_lofi_decider.cc |
| +++ b/components/data_reduction_proxy/content/browser/content_lofi_decider.cc |
| @@ -4,7 +4,12 @@ |
| #include "components/data_reduction_proxy/content/browser/content_lofi_decider.h" |
| +#include <string> |
| + |
| +#include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h" |
| +#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h" |
| #include "content/public/browser/resource_request_info.h" |
| +#include "net/http/http_request_headers.h" |
| namespace data_reduction_proxy { |
| @@ -15,8 +20,57 @@ ContentLoFiDecider::~ContentLoFiDecider() {} |
| bool ContentLoFiDecider::IsUsingLoFiMode(const net::URLRequest& request) const { |
| const content::ResourceRequestInfo* request_info = |
| content::ResourceRequestInfo::ForRequest(&request); |
| + // The Lo-Fi directive should not be added for users in the Lo-Fi field |
| + // trial "Control" group. Check that the user is in a group that should |
|
tbansal1
2015/11/23 20:39:52
s/should/can?
megjablon
2015/11/23 20:53:55
Done.
|
| + // get "q=low". |
| + bool lofi_enabled_via_flag_or_field_trial = |
| + params::IsLoFiOnViaFlags() || params::IsIncludedInLoFiEnabledFieldTrial(); |
| if (request_info) |
| - return request_info->IsUsingLoFi(); |
| + return request_info->IsUsingLoFi() && lofi_enabled_via_flag_or_field_trial; |
|
tbansal1
2015/11/23 20:39:52
Is it possible that "request_info->IsUsingLoFi()"
megjablon
2015/11/23 20:53:55
Done.
|
| + return false; |
| +} |
| + |
| +bool ContentLoFiDecider::MaybeAddLoFiDirectiveToHeaders( |
| + const net::URLRequest& request, |
| + net::HttpRequestHeaders* headers) const { |
| + const content::ResourceRequestInfo* request_info = |
| + content::ResourceRequestInfo::ForRequest(&request); |
| + |
| + if (request_info) { |
|
tbansal1
2015/11/23 20:39:52
nit to reduce indentation:
if(!request_info)
ret
megjablon
2015/11/23 20:53:55
Done.
|
| + // The Lo-Fi directive should not be added for users in the Lo-Fi field |
| + // trial "Control" group. Check that the user is in a group that should |
| + // get "q=low". |
| + bool lofi_enabled_via_flag_or_field_trial = |
| + params::IsLoFiOnViaFlags() || |
| + params::IsIncludedInLoFiEnabledFieldTrial(); |
| + |
| + std::string header_value; |
| + |
| + // User is using Lo-Fi and not part of the "Control" group. |
| + if (request_info->IsUsingLoFi() && lofi_enabled_via_flag_or_field_trial) { |
| + if (headers->HasHeader(chrome_proxy_header())) { |
| + headers->GetHeader(chrome_proxy_header(), &header_value); |
| + headers->RemoveHeader(chrome_proxy_header()); |
| + header_value += ", "; |
| + } |
| + header_value += chrome_proxy_lo_fi_directive(); |
| + headers->SetHeader(chrome_proxy_header(), header_value); |
| + return true; |
| + } |
| + |
| + // User is part of Lo-Fi active control experiment. |
| + if (request_info->IsUsingLoFi() && |
| + params::IsIncludedInLoFiControlFieldTrial()) { |
| + if (headers->HasHeader(chrome_proxy_header())) { |
| + headers->GetHeader(chrome_proxy_header(), &header_value); |
| + headers->RemoveHeader(chrome_proxy_header()); |
| + header_value += ", "; |
| + } |
| + header_value += chrome_proxy_lo_fi_experiment_directive(); |
| + headers->SetHeader(chrome_proxy_header(), header_value); |
| + } |
| + } |
| + |
| return false; |
| } |