OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/browser/data_reduction_proxy_params.h" | 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 78 |
79 bool DataReductionProxyParams::IsIncludedInHoldbackFieldTrial() { | 79 bool DataReductionProxyParams::IsIncludedInHoldbackFieldTrial() { |
80 return FieldTrialList::FindFullName( | 80 return FieldTrialList::FindFullName( |
81 "DataCompressionProxyHoldback") == kEnabled; | 81 "DataCompressionProxyHoldback") == kEnabled; |
82 } | 82 } |
83 | 83 |
84 DataReductionProxyParams::DataReductionProxyParams(int flags) | 84 DataReductionProxyParams::DataReductionProxyParams(int flags) |
85 : allowed_((flags & kAllowed) == kAllowed), | 85 : allowed_((flags & kAllowed) == kAllowed), |
86 fallback_allowed_((flags & kFallbackAllowed) == kFallbackAllowed), | 86 fallback_allowed_((flags & kFallbackAllowed) == kFallbackAllowed), |
87 alt_allowed_((flags & kAlternativeAllowed) == kAlternativeAllowed), | 87 alt_allowed_((flags & kAlternativeAllowed) == kAlternativeAllowed), |
| 88 alt_fallback_allowed_( |
| 89 (flags & kAlternativeFallbackAllowed) == kAlternativeFallbackAllowed), |
88 promo_allowed_((flags & kPromoAllowed) == kPromoAllowed), | 90 promo_allowed_((flags & kPromoAllowed) == kPromoAllowed), |
89 holdback_((flags & kHoldback) == kHoldback), | 91 holdback_((flags & kHoldback) == kHoldback), |
90 configured_on_command_line_(false) { | 92 configured_on_command_line_(false) { |
91 bool result = Init(allowed_, fallback_allowed_, alt_allowed_); | 93 bool result = Init( |
| 94 allowed_, fallback_allowed_, alt_allowed_, alt_fallback_allowed_); |
92 DCHECK(result); | 95 DCHECK(result); |
93 } | 96 } |
94 | 97 |
95 scoped_ptr<DataReductionProxyParams> DataReductionProxyParams::Clone() { | 98 scoped_ptr<DataReductionProxyParams> DataReductionProxyParams::Clone() { |
96 return scoped_ptr<DataReductionProxyParams>( | 99 return scoped_ptr<DataReductionProxyParams>( |
97 new DataReductionProxyParams(*this)); | 100 new DataReductionProxyParams(*this)); |
98 } | 101 } |
99 | 102 |
100 DataReductionProxyParams::DataReductionProxyParams( | 103 DataReductionProxyParams::DataReductionProxyParams( |
101 const DataReductionProxyParams& other) | 104 const DataReductionProxyParams& other) |
102 : origin_(other.origin_), | 105 : origin_(other.origin_), |
103 fallback_origin_(other.fallback_origin_), | 106 fallback_origin_(other.fallback_origin_), |
104 ssl_origin_(other.ssl_origin_), | 107 ssl_origin_(other.ssl_origin_), |
105 alt_origin_(other.alt_origin_), | 108 alt_origin_(other.alt_origin_), |
106 alt_fallback_origin_(other.alt_fallback_origin_), | 109 alt_fallback_origin_(other.alt_fallback_origin_), |
107 probe_url_(other.probe_url_), | 110 probe_url_(other.probe_url_), |
108 warmup_url_(other.warmup_url_), | 111 warmup_url_(other.warmup_url_), |
109 allowed_(other.allowed_), | 112 allowed_(other.allowed_), |
110 fallback_allowed_(other.fallback_allowed_), | 113 fallback_allowed_(other.fallback_allowed_), |
111 alt_allowed_(other.alt_allowed_), | 114 alt_allowed_(other.alt_allowed_), |
| 115 alt_fallback_allowed_(other.alt_fallback_allowed_), |
112 promo_allowed_(other.promo_allowed_), | 116 promo_allowed_(other.promo_allowed_), |
113 holdback_(other.holdback_), | 117 holdback_(other.holdback_), |
114 configured_on_command_line_(other.configured_on_command_line_) { | 118 configured_on_command_line_(other.configured_on_command_line_) { |
115 } | 119 } |
116 | 120 |
117 DataReductionProxyParams::~DataReductionProxyParams() { | 121 DataReductionProxyParams::~DataReductionProxyParams() { |
118 } | 122 } |
119 | 123 |
120 DataReductionProxyParams::DataReductionProxyList | 124 DataReductionProxyParams::DataReductionProxyList |
121 DataReductionProxyParams::GetAllowedProxies() const { | 125 DataReductionProxyParams::GetAllowedProxies() const { |
122 DataReductionProxyList list; | 126 DataReductionProxyList list; |
123 if (allowed_) { | 127 if (allowed_) { |
124 list.push_back(origin_); | 128 list.push_back(origin_); |
125 } | 129 } |
126 if (allowed_ && fallback_allowed_) | 130 if (allowed_ && fallback_allowed_) |
127 list.push_back(fallback_origin_); | 131 list.push_back(fallback_origin_); |
128 if (alt_allowed_) { | 132 if (alt_allowed_) { |
129 list.push_back(alt_origin_); | 133 list.push_back(alt_origin_); |
130 list.push_back(ssl_origin_); | 134 list.push_back(ssl_origin_); |
131 } | 135 } |
132 if (alt_allowed_ && fallback_allowed_) | 136 if (alt_allowed_ && alt_fallback_allowed_) |
133 list.push_back(alt_fallback_origin_); | 137 list.push_back(alt_fallback_origin_); |
134 return list; | 138 return list; |
135 } | 139 } |
136 | 140 |
137 DataReductionProxyParams::DataReductionProxyParams(int flags, | 141 DataReductionProxyParams::DataReductionProxyParams(int flags, |
138 bool should_call_init) | 142 bool should_call_init) |
139 : allowed_((flags & kAllowed) == kAllowed), | 143 : allowed_((flags & kAllowed) == kAllowed), |
140 fallback_allowed_((flags & kFallbackAllowed) == kFallbackAllowed), | 144 fallback_allowed_((flags & kFallbackAllowed) == kFallbackAllowed), |
141 alt_allowed_((flags & kAlternativeAllowed) == kAlternativeAllowed), | 145 alt_allowed_((flags & kAlternativeAllowed) == kAlternativeAllowed), |
| 146 alt_fallback_allowed_( |
| 147 (flags & kAlternativeFallbackAllowed) == kAlternativeFallbackAllowed), |
142 promo_allowed_((flags & kPromoAllowed) == kPromoAllowed), | 148 promo_allowed_((flags & kPromoAllowed) == kPromoAllowed), |
143 holdback_((flags & kHoldback) == kHoldback), | 149 holdback_((flags & kHoldback) == kHoldback), |
144 configured_on_command_line_(false) { | 150 configured_on_command_line_(false) { |
145 if (should_call_init) { | 151 if (should_call_init) { |
146 bool result = Init(allowed_, fallback_allowed_, alt_allowed_); | 152 bool result = Init( |
| 153 allowed_, fallback_allowed_, alt_allowed_, alt_fallback_allowed_); |
147 DCHECK(result); | 154 DCHECK(result); |
148 } | 155 } |
149 } | 156 } |
150 | 157 |
151 bool DataReductionProxyParams::Init( | 158 bool DataReductionProxyParams::Init(bool allowed, |
152 bool allowed, bool fallback_allowed, bool alt_allowed) { | 159 bool fallback_allowed, |
| 160 bool alt_allowed, |
| 161 bool alt_fallback_allowed) { |
153 InitWithoutChecks(); | 162 InitWithoutChecks(); |
154 // Verify that all necessary params are set. | 163 // Verify that all necessary params are set. |
155 if (allowed) { | 164 if (allowed) { |
156 if (!origin_.is_valid()) { | 165 if (!origin_.is_valid()) { |
157 DVLOG(1) << "Invalid data reduction proxy origin: " << origin_.spec(); | 166 DVLOG(1) << "Invalid data reduction proxy origin: " << origin_.spec(); |
158 return false; | 167 return false; |
159 } | 168 } |
160 } | 169 } |
161 | 170 |
162 if (allowed && fallback_allowed) { | 171 if (allowed && fallback_allowed) { |
(...skipping 13 matching lines...) Expand all Loading... |
176 if (!alt_origin_.is_valid()) { | 185 if (!alt_origin_.is_valid()) { |
177 DVLOG(1) << "Invalid alternative origin:" << alt_origin_.spec(); | 186 DVLOG(1) << "Invalid alternative origin:" << alt_origin_.spec(); |
178 return false; | 187 return false; |
179 } | 188 } |
180 if (!ssl_origin_.is_valid()) { | 189 if (!ssl_origin_.is_valid()) { |
181 DVLOG(1) << "Invalid ssl origin: " << ssl_origin_.spec(); | 190 DVLOG(1) << "Invalid ssl origin: " << ssl_origin_.spec(); |
182 return false; | 191 return false; |
183 } | 192 } |
184 } | 193 } |
185 | 194 |
186 if (alt_allowed && fallback_allowed) { | 195 if (alt_allowed && alt_fallback_allowed) { |
187 if (!alt_fallback_origin_.is_valid()) { | 196 if (!alt_fallback_origin_.is_valid()) { |
188 DVLOG(1) << "Invalid alternative fallback origin:" | 197 DVLOG(1) << "Invalid alternative fallback origin:" |
189 << alt_fallback_origin_.spec(); | 198 << alt_fallback_origin_.spec(); |
190 return false; | 199 return false; |
191 } | 200 } |
192 } | 201 } |
193 | 202 |
194 if (allowed && !probe_url_.is_valid()) { | 203 if (allowed && !probe_url_.is_valid()) { |
195 DVLOG(1) << "Invalid probe url: <null>"; | 204 DVLOG(1) << "Invalid probe url: <null>"; |
196 return false; | 205 return false; |
197 } | 206 } |
198 | 207 |
199 if (fallback_allowed_ && !allowed_) { | 208 if (fallback_allowed_ && !allowed_) { |
200 DVLOG(1) << "The data reduction proxy fallback cannot be allowed if " | 209 DVLOG(1) << "The data reduction proxy fallback cannot be allowed if " |
201 << "the data reduction proxy is not allowed"; | 210 << "the data reduction proxy is not allowed"; |
202 return false; | 211 return false; |
203 } | 212 } |
| 213 if (alt_fallback_allowed_ && !alt_allowed_) { |
| 214 DVLOG(1) << "The data reduction proxy alternative fallback cannot be " |
| 215 << "allowed if the alternative data reduction proxy is not allowed"; |
| 216 return false; |
| 217 } |
204 if (promo_allowed_ && !allowed_) { | 218 if (promo_allowed_ && !allowed_) { |
205 DVLOG(1) << "The data reduction proxy promo cannot be allowed if the " | 219 DVLOG(1) << "The data reduction proxy promo cannot be allowed if the " |
206 << "data reduction proxy is not allowed"; | 220 << "data reduction proxy is not allowed"; |
207 return false; | 221 return false; |
208 } | 222 } |
209 return true; | 223 return true; |
210 | 224 |
211 } | 225 } |
212 | 226 |
213 void DataReductionProxyParams::InitWithoutChecks() { | 227 void DataReductionProxyParams::InitWithoutChecks() { |
(...skipping 17 matching lines...) Expand all Loading... |
231 configured_on_command_line_ = | 245 configured_on_command_line_ = |
232 !(origin.empty() && fallback_origin.empty() && ssl_origin.empty() && | 246 !(origin.empty() && fallback_origin.empty() && ssl_origin.empty() && |
233 alt_origin.empty() && alt_fallback_origin.empty()); | 247 alt_origin.empty() && alt_fallback_origin.empty()); |
234 | 248 |
235 | 249 |
236 // Configuring the proxy on the command line overrides the values of | 250 // Configuring the proxy on the command line overrides the values of |
237 // |allowed_| and |alt_allowed_|. | 251 // |allowed_| and |alt_allowed_|. |
238 if (configured_on_command_line_) | 252 if (configured_on_command_line_) |
239 allowed_ = true; | 253 allowed_ = true; |
240 if (!(ssl_origin.empty() && | 254 if (!(ssl_origin.empty() && |
241 alt_origin.empty() && | 255 alt_origin.empty())) |
242 alt_fallback_origin.empty())) | |
243 alt_allowed_ = true; | 256 alt_allowed_ = true; |
244 | 257 |
245 std::string probe_url = command_line.GetSwitchValueASCII( | 258 std::string probe_url = command_line.GetSwitchValueASCII( |
246 switches::kDataReductionProxyProbeURL); | 259 switches::kDataReductionProxyProbeURL); |
247 std::string warmup_url = command_line.GetSwitchValueASCII( | 260 std::string warmup_url = command_line.GetSwitchValueASCII( |
248 switches::kDataReductionProxyWarmupURL); | 261 switches::kDataReductionProxyWarmupURL); |
249 | 262 |
250 // Set from preprocessor constants those params that are not specified on the | 263 // Set from preprocessor constants those params that are not specified on the |
251 // command line. | 264 // command line. |
252 if (origin.empty()) | 265 if (origin.empty()) |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 proxy_info->proxy_servers.first = fallback_origin(); | 316 proxy_info->proxy_servers.first = fallback_origin(); |
304 proxy_info->proxy_servers.second = GURL(); | 317 proxy_info->proxy_servers.second = GURL(); |
305 proxy_info->is_fallback = true; | 318 proxy_info->is_fallback = true; |
306 } | 319 } |
307 return true; | 320 return true; |
308 } | 321 } |
309 if (net::HostPortPair::FromURL(alt_origin()).Equals(host_port_pair)) { | 322 if (net::HostPortPair::FromURL(alt_origin()).Equals(host_port_pair)) { |
310 if (proxy_info) { | 323 if (proxy_info) { |
311 proxy_info->proxy_servers.first = alt_origin(); | 324 proxy_info->proxy_servers.first = alt_origin(); |
312 proxy_info->is_alternative = true; | 325 proxy_info->is_alternative = true; |
313 if (fallback_allowed()) | 326 if (alternative_fallback_allowed()) |
314 proxy_info->proxy_servers.second = alt_fallback_origin(); | 327 proxy_info->proxy_servers.second = alt_fallback_origin(); |
315 } | 328 } |
316 return true; | 329 return true; |
317 } | 330 } |
318 if (fallback_allowed() && | 331 if (alternative_fallback_allowed() && |
319 net::HostPortPair::FromURL(alt_fallback_origin()).Equals( | 332 net::HostPortPair::FromURL(alt_fallback_origin()).Equals( |
320 host_port_pair)) { | 333 host_port_pair)) { |
321 if (proxy_info) { | 334 if (proxy_info) { |
322 proxy_info->proxy_servers.first = alt_fallback_origin(); | 335 proxy_info->proxy_servers.first = alt_fallback_origin(); |
323 proxy_info->proxy_servers.second = GURL(); | 336 proxy_info->proxy_servers.second = GURL(); |
324 proxy_info->is_fallback = true; | 337 proxy_info->is_fallback = true; |
325 proxy_info->is_alternative = true; | 338 proxy_info->is_alternative = true; |
326 } | 339 } |
327 return true; | 340 return true; |
328 } | 341 } |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 } | 538 } |
526 | 539 |
527 std::string DataReductionProxyParams::GetDefaultWarmupURL() const { | 540 std::string DataReductionProxyParams::GetDefaultWarmupURL() const { |
528 #if defined(DATA_REDUCTION_PROXY_WARMUP_URL) | 541 #if defined(DATA_REDUCTION_PROXY_WARMUP_URL) |
529 return DATA_REDUCTION_PROXY_WARMUP_URL; | 542 return DATA_REDUCTION_PROXY_WARMUP_URL; |
530 #endif | 543 #endif |
531 return std::string(); | 544 return std::string(); |
532 } | 545 } |
533 | 546 |
534 } // namespace data_reduction_proxy | 547 } // namespace data_reduction_proxy |
OLD | NEW |