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