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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/time/time.h" | |
9 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h " | 10 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h " |
11 #include "net/base/host_port_pair.h" | |
10 #include "net/proxy/proxy_info.h" | 12 #include "net/proxy/proxy_info.h" |
13 #include "net/proxy/proxy_retry_info.h" | |
14 #include "net/proxy/proxy_server.h" | |
11 #include "net/proxy/proxy_service.h" | 15 #include "net/proxy/proxy_service.h" |
12 #include "net/url_request/url_request.h" | 16 #include "net/url_request/url_request.h" |
13 #include "net/url_request/url_request_context.h" | 17 #include "net/url_request/url_request_context.h" |
18 #include "url/url_constants.h" | |
14 | 19 |
15 using base::FieldTrialList; | 20 using base::FieldTrialList; |
16 | 21 |
17 namespace { | 22 namespace { |
18 const char kEnabled[] = "Enabled"; | 23 const char kEnabled[] = "Enabled"; |
19 } | 24 } |
20 | 25 |
21 namespace data_reduction_proxy { | 26 namespace data_reduction_proxy { |
22 | 27 |
23 // static | 28 // static |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 } | 159 } |
155 if (promo_allowed_ && !allowed_) { | 160 if (promo_allowed_ && !allowed_) { |
156 DVLOG(1) << "The data reduction proxy promo cannot be allowed if the " | 161 DVLOG(1) << "The data reduction proxy promo cannot be allowed if the " |
157 << "data reduction proxy is not allowed"; | 162 << "data reduction proxy is not allowed"; |
158 return false; | 163 return false; |
159 } | 164 } |
160 return true; | 165 return true; |
161 | 166 |
162 } | 167 } |
163 | 168 |
164 | |
165 void DataReductionProxyParams::InitWithoutChecks() { | 169 void DataReductionProxyParams::InitWithoutChecks() { |
166 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 170 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
167 std::string origin; | 171 std::string origin; |
168 if (!command_line.HasSwitch(switches::kDisableDataReductionProxyDev)) { | 172 if (!command_line.HasSwitch(switches::kDisableDataReductionProxyDev)) { |
169 origin = command_line.GetSwitchValueASCII( | 173 origin = command_line.GetSwitchValueASCII( |
170 switches::kDataReductionProxyDev); | 174 switches::kDataReductionProxyDev); |
171 } | 175 } |
172 if (origin.empty()) | 176 if (origin.empty()) |
173 origin = command_line.GetSwitchValueASCII(switches::kDataReductionProxy); | 177 origin = command_line.GetSwitchValueASCII(switches::kDataReductionProxy); |
174 std::string fallback_origin = | 178 std::string fallback_origin = |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
322 return std::string(); | 326 return std::string(); |
323 if (command_line.HasSwitch(switches::kEnableDataReductionProxyDev) || | 327 if (command_line.HasSwitch(switches::kEnableDataReductionProxyDev) || |
324 (FieldTrialList::FindFullName("DataCompressionProxyDevRollout") == | 328 (FieldTrialList::FindFullName("DataCompressionProxyDevRollout") == |
325 kEnabled)) { | 329 kEnabled)) { |
326 return DATA_REDUCTION_DEV_HOST; | 330 return DATA_REDUCTION_DEV_HOST; |
327 } | 331 } |
328 #endif | 332 #endif |
329 return std::string(); | 333 return std::string(); |
330 } | 334 } |
331 | 335 |
336 bool DataReductionProxyParams::AreDataReductionProxiesBypassed( | |
337 const net::URLRequest& request, base::TimeDelta* min_retry_delay) const { | |
338 if (request.context() != NULL && | |
339 request.context()->proxy_service() != NULL) { | |
340 return AreProxiesBypassed( | |
341 request.context()->proxy_service()->proxy_retry_info(), | |
342 request.url().SchemeIs(url::kHttpsScheme), | |
343 min_retry_delay); | |
344 } | |
345 | |
346 return false; | |
347 } | |
348 | |
349 bool DataReductionProxyParams::AreProxiesBypassed( | |
350 const net::ProxyRetryInfoMap& retry_map, | |
351 bool is_https, | |
352 base::TimeDelta* min_retry_delay) const { | |
353 if (retry_map.size() == 0) | |
354 return false; | |
355 | |
356 if (is_https && alt_allowed_) { | |
357 return ArePrimaryAndFallbackBypassed( | |
358 retry_map, ssl_origin_, GURL(), min_retry_delay); | |
359 } else { | |
Alexei Svitkine (slow)
2014/07/22 18:50:18
No else after early return.
megjablon
2014/07/22 21:41:45
Done.
| |
360 if (allowed_) { | |
361 if (ArePrimaryAndFallbackBypassed( | |
Alexei Svitkine (slow)
2014/07/22 18:50:18
I think you misunderstood my previous comment. My
megjablon
2014/07/22 21:41:45
Ahh that makes much more sense. Fixed.
| |
362 retry_map, origin_, fallback_origin_, min_retry_delay)) { | |
363 return true; | |
364 } | |
365 } | |
366 | |
367 if (alt_allowed_) { | |
368 if (ArePrimaryAndFallbackBypassed( | |
369 retry_map, alt_origin_, alt_fallback_origin_, min_retry_delay)) { | |
370 return true; | |
371 } | |
372 } | |
373 } | |
374 | |
375 return false; | |
376 } | |
377 | |
378 bool DataReductionProxyParams::ArePrimaryAndFallbackBypassed( | |
379 const net::ProxyRetryInfoMap& retry_map, | |
380 const GURL& primary, | |
381 const GURL& fallback, | |
382 base::TimeDelta* min_retry_delay) const { | |
383 base::TimeDelta min_delay; | |
384 net::ProxyRetryInfoMap::const_iterator found; | |
385 found = retry_map.find( | |
Alexei Svitkine (slow)
2014/07/22 18:50:18
nit: just put = on the previous line and wrap afte
megjablon
2014/07/22 21:41:45
Done.
| |
386 net::ProxyServer(primary.SchemeIs(url::kHttpsScheme) ? | |
387 net::ProxyServer::SCHEME_HTTPS : net::ProxyServer::SCHEME_HTTP, | |
388 net::HostPortPair::FromURL(primary)).ToURI()); | |
389 | |
390 if (found == retry_map.end()) { | |
391 return false; | |
Alexei Svitkine (slow)
2014/07/22 18:50:18
Nit: No need for {}'s since body is one line.
megjablon
2014/07/22 21:41:45
Done.
| |
392 } | |
393 | |
394 min_delay = found->second.current_delay; | |
Alexei Svitkine (slow)
2014/07/22 18:50:18
Just declare min_delay and assign to it here, inst
megjablon
2014/07/22 21:41:45
Done.
| |
395 if (!fallback_allowed_ || !fallback.is_valid()) { | |
396 if (min_retry_delay != NULL) | |
397 *min_retry_delay = min_delay; | |
398 return true; | |
399 } | |
400 | |
401 found = retry_map.find( | |
402 net::ProxyServer(fallback.SchemeIs(url::kHttpsScheme) ? | |
403 net::ProxyServer::SCHEME_HTTPS : net::ProxyServer::SCHEME_HTTP, | |
404 net::HostPortPair::FromURL(fallback)).ToURI()); | |
405 | |
406 if (found == retry_map.end()) { | |
407 return false; | |
Alexei Svitkine (slow)
2014/07/22 18:50:18
Nit: No need for {}'s
megjablon
2014/07/22 21:41:45
Done.
| |
408 } | |
409 | |
410 if (min_delay > found->second.current_delay) | |
411 min_delay = found->second.current_delay; | |
412 if (min_retry_delay != NULL) | |
413 *min_retry_delay = min_delay; | |
414 return true; | |
415 } | |
416 | |
332 std::string DataReductionProxyParams::GetDefaultOrigin() const { | 417 std::string DataReductionProxyParams::GetDefaultOrigin() const { |
333 #if defined(SPDY_PROXY_AUTH_ORIGIN) | 418 #if defined(SPDY_PROXY_AUTH_ORIGIN) |
334 return SPDY_PROXY_AUTH_ORIGIN; | 419 return SPDY_PROXY_AUTH_ORIGIN; |
335 #endif | 420 #endif |
336 return std::string(); | 421 return std::string(); |
337 } | 422 } |
338 | 423 |
339 std::string DataReductionProxyParams::GetDefaultFallbackOrigin() const { | 424 std::string DataReductionProxyParams::GetDefaultFallbackOrigin() const { |
340 #if defined(DATA_REDUCTION_FALLBACK_HOST) | 425 #if defined(DATA_REDUCTION_FALLBACK_HOST) |
341 return DATA_REDUCTION_FALLBACK_HOST; | 426 return DATA_REDUCTION_FALLBACK_HOST; |
(...skipping 30 matching lines...) Expand all Loading... | |
372 } | 457 } |
373 | 458 |
374 std::string DataReductionProxyParams::GetDefaultWarmupURL() const { | 459 std::string DataReductionProxyParams::GetDefaultWarmupURL() const { |
375 #if defined(DATA_REDUCTION_PROXY_WARMUP_URL) | 460 #if defined(DATA_REDUCTION_PROXY_WARMUP_URL) |
376 return DATA_REDUCTION_PROXY_WARMUP_URL; | 461 return DATA_REDUCTION_PROXY_WARMUP_URL; |
377 #endif | 462 #endif |
378 return std::string(); | 463 return std::string(); |
379 } | 464 } |
380 | 465 |
381 } // namespace data_reduction_proxy | 466 } // namespace data_reduction_proxy |
OLD | NEW |