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" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 | 42 |
43 if (!request_info) | 43 if (!request_info) |
44 return false; | 44 return false; |
45 | 45 |
46 // The Lo-Fi directive should not be added for users in the Lo-Fi field | 46 // The Lo-Fi directive should not be added for users in the Lo-Fi field |
47 // trial "Control" group. Check that the user is in a group that should | 47 // trial "Control" group. Check that the user is in a group that should |
48 // get "q=low". | 48 // get "q=low". |
49 bool lofi_enabled_via_flag_or_field_trial = | 49 bool lofi_enabled_via_flag_or_field_trial = |
50 params::IsLoFiOnViaFlags() || params::IsIncludedInLoFiEnabledFieldTrial(); | 50 params::IsLoFiOnViaFlags() || params::IsIncludedInLoFiEnabledFieldTrial(); |
51 | 51 |
52 bool lofi_preview_via_flag_or_field_trial = | 52 bool lite_page_via_flag_or_field_trial = |
53 params::AreLoFiPreviewsEnabledViaFlags() || | 53 params::AreLitePagesEnabledViaFlags() || |
54 params::IsIncludedInLoFiPreviewFieldTrial(); | 54 params::IsIncludedInLitePageFieldTrial(); |
55 | 55 |
56 // User is not using Lo-Fi or is part of the "Control" group. | 56 // User is not using Lo-Fi or is part of the "Control" group. |
57 if (!request_info->IsUsingLoFi() || !lofi_enabled_via_flag_or_field_trial) | 57 if (!request_info->IsUsingLoFi() || !lofi_enabled_via_flag_or_field_trial) |
58 return false; | 58 return false; |
59 | 59 |
60 std::string header_value; | 60 std::string header_value; |
61 | 61 |
62 if (headers->HasHeader(chrome_proxy_header())) { | 62 if (headers->HasHeader(chrome_proxy_header())) { |
63 headers->GetHeader(chrome_proxy_header(), &header_value); | 63 headers->GetHeader(chrome_proxy_header(), &header_value); |
64 headers->RemoveHeader(chrome_proxy_header()); | 64 headers->RemoveHeader(chrome_proxy_header()); |
65 header_value += ", "; | 65 header_value += ", "; |
66 } | 66 } |
67 | 67 |
68 // If in the preview field trial or the preview flag is enabled, only add the | 68 // If in the lite page field trial or flag is enabled, only add the |
69 // "q=preview" directive on main frame requests. Do not add Lo-Fi directives | 69 // "q=preview" directive on main frame requests. Do not add Lo-Fi directives |
70 // to other requests when previews are enabled. | 70 // to other requests when lite pages are enabled. |
71 if (lofi_preview_via_flag_or_field_trial) { | 71 if (lite_page_via_flag_or_field_trial) { |
72 if (request.load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) { | 72 if (request.load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) { |
73 if (params::AreLoFiPreviewsEnabledViaFlags()) { | 73 if (params::AreLitePagesEnabledViaFlags()) { |
74 header_value += chrome_proxy_lo_fi_ignore_preview_blacklist_directive(); | 74 header_value += chrome_proxy_lite_page_ignore_blacklist_directive(); |
75 header_value += ", "; | 75 header_value += ", "; |
76 } | 76 } |
77 header_value += chrome_proxy_lo_fi_preview_directive(); | 77 header_value += chrome_proxy_lite_page_directive(); |
78 } | 78 } |
79 } else if (!(request.load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED)) { | 79 } else if (!(request.load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED)) { |
80 // If previews are not enabled, add "q=low" for requests that are not main | 80 // If previews are not enabled, add "q=low" for requests that are not main |
81 // frame. | 81 // frame. |
82 header_value += chrome_proxy_lo_fi_directive(); | 82 header_value += chrome_proxy_lo_fi_directive(); |
83 } | 83 } |
84 | 84 |
85 if (!header_value.empty()) | 85 if (!header_value.empty()) |
86 headers->SetHeader(chrome_proxy_header(), header_value); | 86 headers->SetHeader(chrome_proxy_header(), header_value); |
87 | 87 |
88 return true; | 88 return true; |
89 } | 89 } |
90 | 90 |
91 bool ContentLoFiDecider::ShouldRecordLoFiUMA( | 91 bool ContentLoFiDecider::ShouldRecordLoFiUMA( |
92 const net::URLRequest& request) const { | 92 const net::URLRequest& request) const { |
93 const content::ResourceRequestInfo* request_info = | 93 const content::ResourceRequestInfo* request_info = |
94 content::ResourceRequestInfo::ForRequest(&request); | 94 content::ResourceRequestInfo::ForRequest(&request); |
95 | 95 |
96 // User is not using Lo-Fi. | 96 // User is not using Lo-Fi. |
97 if (!request_info || !request_info->IsUsingLoFi()) | 97 if (!request_info || !request_info->IsUsingLoFi()) |
98 return false; | 98 return false; |
99 | 99 |
100 return params::IsIncludedInLoFiEnabledFieldTrial() || | 100 return params::IsIncludedInLoFiEnabledFieldTrial() || |
101 params::IsIncludedInLoFiControlFieldTrial(); | 101 params::IsIncludedInLoFiControlFieldTrial(); |
102 } | 102 } |
103 | 103 |
104 } // namespace data_reduction_proxy | 104 } // namespace data_reduction_proxy |
OLD | NEW |