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_param s.h" | |
7 #include "content/public/browser/resource_request_info.h" | 10 #include "content/public/browser/resource_request_info.h" |
11 #include "net/http/http_request_headers.h" | |
8 | 12 |
9 namespace data_reduction_proxy { | 13 namespace data_reduction_proxy { |
10 | 14 |
15 const char kLoFiHeader[] = "q=low"; | |
tbansal1
2015/11/20 21:56:58
Is it possible to move kLoFiHeader from data_reduc
megjablon
2015/11/20 23:14:50
Just using the value from data_reduction_proxy_hea
| |
16 const char kLoFiExperimentHeader[] = "exp=lofi_active_control"; | |
17 | |
11 ContentLoFiDecider::ContentLoFiDecider() {} | 18 ContentLoFiDecider::ContentLoFiDecider() {} |
12 | 19 |
13 ContentLoFiDecider::~ContentLoFiDecider() {} | 20 ContentLoFiDecider::~ContentLoFiDecider() {} |
14 | 21 |
15 bool ContentLoFiDecider::IsUsingLoFiMode(const net::URLRequest& request) const { | 22 bool ContentLoFiDecider::IsUsingLoFiMode(const net::URLRequest& request) const { |
16 const content::ResourceRequestInfo* request_info = | 23 const content::ResourceRequestInfo* request_info = |
17 content::ResourceRequestInfo::ForRequest(&request); | 24 content::ResourceRequestInfo::ForRequest(&request); |
25 // The Lo-Fi directive should not be added for users in the Lo-Fi field | |
26 // trial "Control" group. Check that the user is in a group that should | |
27 // get "q=low". | |
28 bool lofi_enabled_via_flag_or_field_trial = | |
29 params::IsLoFiOnViaFlags() || params::IsIncludedInLoFiEnabledFieldTrial(); | |
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::MaybeEnableLoFiMode( | |
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) { | |
sclittle
2015/11/20 22:59:11
So, Lo-Fi mode is not enabled for any requests tha
megjablon
2015/11/20 23:14:50
Yep this was a side effect of the implementation t
| |
42 // The Lo-Fi directive should not be added for users in the Lo-Fi field | |
43 // trial "Control" group. Check that the user is in a group that should | |
44 // get "q=low". | |
45 bool lofi_enabled_via_flag_or_field_trial = | |
46 params::IsLoFiOnViaFlags() || | |
47 params::IsIncludedInLoFiEnabledFieldTrial(); | |
tbansal1
2015/11/20 21:56:58
Is it possible to move this common code to anonymo
megjablon
2015/11/20 23:14:50
I don't see the need to move this. We don't use th
tbansal1
2015/11/23 20:39:52
Line 26 up.
| |
48 | |
49 const char kChromeProxyHeader[] = "Chrome-Proxy"; | |
tbansal1
2015/11/20 21:56:58
Same here, is it possible to move this to params?
megjablon
2015/11/20 23:14:50
Just using the value from data_reduction_proxy_hea
| |
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(kChromeProxyHeader)) { | |
55 headers->GetHeader(kChromeProxyHeader, &header_value); | |
56 headers->RemoveHeader(kChromeProxyHeader); | |
57 header_value += ", "; | |
58 } | |
59 header_value += kLoFiHeader; | |
60 headers->SetHeader(kChromeProxyHeader, 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()) { | |
tbansal1
2015/11/20 21:56:58
Should this also check that Lo-Fi is not enabled f
megjablon
2015/11/20 23:14:50
That's redundant. If it's enabled from flags then
tbansal1
2015/11/23 20:39:52
Aah, did not see the return statement.
| |
67 if (headers->HasHeader(kChromeProxyHeader)) { | |
68 headers->GetHeader(kChromeProxyHeader, &header_value); | |
69 headers->RemoveHeader(kChromeProxyHeader); | |
70 header_value += ", "; | |
71 } | |
72 header_value += kLoFiExperimentHeader; | |
tbansal1
2015/11/20 21:56:58
Can the user be in more than two experiments?
In t
megjablon
2015/11/20 23:14:50
Yes the user can. It looks like exp=a,exp=b
https
| |
73 headers->SetHeader(kChromeProxyHeader, header_value); | |
74 } | |
75 } | |
76 | |
77 return false; | |
78 } | |
79 | |
23 } // namespace data_reduction_proxy | 80 } // namespace data_reduction_proxy |
OLD | NEW |