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" |
11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h " | 13 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h " |
14 #include "net/base/host_port_pair.h" | 14 #include "net/base/host_port_pair.h" |
15 #include "net/proxy/proxy_config.h" | 15 #include "net/proxy/proxy_config.h" |
16 #include "net/proxy/proxy_info.h" | 16 #include "net/proxy/proxy_info.h" |
17 #include "net/proxy/proxy_retry_info.h" | 17 #include "net/proxy/proxy_retry_info.h" |
18 #include "net/proxy/proxy_server.h" | 18 #include "net/proxy/proxy_server.h" |
19 #include "net/proxy/proxy_service.h" | 19 #include "net/proxy/proxy_service.h" |
20 #include "net/url_request/url_request.h" | 20 #include "net/url_request/url_request.h" |
21 #include "net/url_request/url_request_context.h" | 21 #include "net/url_request/url_request_context.h" |
22 #include "url/url_constants.h" | 22 #include "url/url_constants.h" |
23 | 23 |
24 using base::FieldTrialList; | 24 using base::FieldTrialList; |
25 | 25 |
26 namespace { | 26 namespace { |
27 | |
27 const char kEnabled[] = "Enabled"; | 28 const char kEnabled[] = "Enabled"; |
28 } | 29 const char kDefaultOrigin[] = "https://proxy.googlezip.net:443/"; |
30 const char kDevHost[] = "http://proxy-dev.googlezip.net:80/"; | |
31 const char kDefaultFallbackOrigin[] = "http://compress.googlezip.net:80/"; | |
32 const char kDefaultSslOrigin[] = "http://ssl.googlezip.net:1043/"; | |
33 const char kDefaultAltOrigin[] = "https://proxy.googlezip.net:443/"; | |
34 const char kDefaultAltFallbackOrigin[] = "http://compress.googlezip.net:80/"; | |
35 const char kDefaultProbeUrl[] = "http://check.googlezip.net/connect"; | |
36 const char kDefaultWarmupUrl[] = "http://www.gstatic.com/generate_204"; | |
mmenke
2014/09/10 15:16:48
Should these URLs be in /components/google/core/br
Not at Google. Contact bengr
2014/09/10 21:38:34
Not sure why you mention putting URLs in /componen
mmenke
2014/09/10 21:46:33
google_util is nominally where the google-specific
| |
37 | |
38 } // namespace | |
29 | 39 |
30 namespace data_reduction_proxy { | 40 namespace data_reduction_proxy { |
31 | 41 |
32 // static | 42 // static |
33 bool DataReductionProxyParams::IsIncludedInFieldTrial() { | |
34 return base::FieldTrialList::FindFullName( | |
35 "DataCompressionProxyRollout") == kEnabled; | |
36 } | |
37 | |
38 // static | |
39 bool DataReductionProxyParams::IsIncludedInAlternativeFieldTrial() { | 43 bool DataReductionProxyParams::IsIncludedInAlternativeFieldTrial() { |
40 return base::FieldTrialList::FindFullName( | 44 return base::FieldTrialList::FindFullName( |
41 "DataCompressionProxyAlternativeConfiguration") == kEnabled; | 45 "DataCompressionProxyAlternativeConfiguration") == kEnabled; |
42 } | 46 } |
43 | 47 |
44 // static | 48 // static |
45 bool DataReductionProxyParams::IsIncludedInPromoFieldTrial() { | 49 bool DataReductionProxyParams::IsIncludedInPromoFieldTrial() { |
46 return FieldTrialList::FindFullName( | 50 return FieldTrialList::FindFullName( |
47 "DataCompressionProxyPromoVisibility") == kEnabled; | 51 "DataCompressionProxyPromoVisibility") == kEnabled; |
48 } | 52 } |
49 | 53 |
50 // static | 54 // static |
51 bool DataReductionProxyParams::IsIncludedInPreconnectHintingFieldTrial() { | 55 bool DataReductionProxyParams::IsIncludedInPreconnectHintingFieldTrial() { |
52 return IsIncludedInFieldTrial() && | 56 return FieldTrialList::FindFullName( |
53 FieldTrialList::FindFullName( | |
54 "DataCompressionProxyPreconnectHints") == kEnabled; | 57 "DataCompressionProxyPreconnectHints") == kEnabled; |
55 } | 58 } |
56 | 59 |
57 // static | 60 // static |
58 bool DataReductionProxyParams::IsIncludedInCriticalPathBypassFieldTrial() { | 61 bool DataReductionProxyParams::IsIncludedInCriticalPathBypassFieldTrial() { |
59 return IsIncludedInFieldTrial() && | 62 return FieldTrialList::FindFullName( |
60 FieldTrialList::FindFullName( | |
61 "DataCompressionProxyCriticalBypass") == kEnabled; | 63 "DataCompressionProxyCriticalBypass") == kEnabled; |
62 } | 64 } |
63 | 65 |
64 DataReductionProxyTypeInfo::DataReductionProxyTypeInfo() | 66 DataReductionProxyTypeInfo::DataReductionProxyTypeInfo() |
65 : proxy_servers(), | 67 : proxy_servers(), |
66 is_fallback(false), | 68 is_fallback(false), |
67 is_alternative(false), | 69 is_alternative(false), |
68 is_ssl(false) { | 70 is_ssl(false) { |
69 } | 71 } |
70 | 72 |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 data_reduction_proxy_config.proxy_rules().Apply( | 378 data_reduction_proxy_config.proxy_rules().Apply( |
377 request.url(), &result); | 379 request.url(), &result); |
378 if (!result.proxy_server().is_valid()) | 380 if (!result.proxy_server().is_valid()) |
379 return true; | 381 return true; |
380 if (result.proxy_server().is_direct()) | 382 if (result.proxy_server().is_direct()) |
381 return true; | 383 return true; |
382 return !IsDataReductionProxy(result.proxy_server().host_port_pair(), NULL); | 384 return !IsDataReductionProxy(result.proxy_server().host_port_pair(), NULL); |
383 } | 385 } |
384 | 386 |
385 std::string DataReductionProxyParams::GetDefaultDevOrigin() const { | 387 std::string DataReductionProxyParams::GetDefaultDevOrigin() const { |
386 #if defined(DATA_REDUCTION_DEV_HOST) | |
387 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 388 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
388 if (command_line.HasSwitch(switches::kDisableDataReductionProxyDev)) | 389 if (command_line.HasSwitch(switches::kDisableDataReductionProxyDev)) |
389 return std::string(); | 390 return std::string(); |
390 if (command_line.HasSwitch(switches::kEnableDataReductionProxyDev) || | 391 if (command_line.HasSwitch(switches::kEnableDataReductionProxyDev) || |
391 (FieldTrialList::FindFullName("DataCompressionProxyDevRollout") == | 392 (FieldTrialList::FindFullName("DataCompressionProxyDevRollout") == |
392 kEnabled)) { | 393 kEnabled)) { |
393 return DATA_REDUCTION_DEV_HOST; | 394 return kDevHost; |
394 } | 395 } |
395 #endif | |
396 return std::string(); | 396 return std::string(); |
397 } | 397 } |
398 | 398 |
399 bool DataReductionProxyParams::AreDataReductionProxiesBypassed( | 399 bool DataReductionProxyParams::AreDataReductionProxiesBypassed( |
400 const net::URLRequest& request, base::TimeDelta* min_retry_delay) const { | 400 const net::URLRequest& request, base::TimeDelta* min_retry_delay) const { |
401 if (request.context() != NULL && | 401 if (request.context() != NULL && |
402 request.context()->proxy_service() != NULL) { | 402 request.context()->proxy_service() != NULL) { |
403 return AreProxiesBypassed( | 403 return AreProxiesBypassed( |
404 request.context()->proxy_service()->proxy_retry_info(), | 404 request.context()->proxy_service()->proxy_retry_info(), |
405 request.url().SchemeIs(url::kHttpsScheme), | 405 request.url().SchemeIs(url::kHttpsScheme), |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
474 if (found != retry_map.end() && | 474 if (found != retry_map.end() && |
475 min_retry_delay && | 475 min_retry_delay && |
476 *min_retry_delay > found->second.current_delay) { | 476 *min_retry_delay > found->second.current_delay) { |
477 *min_retry_delay = found->second.current_delay; | 477 *min_retry_delay = found->second.current_delay; |
478 } | 478 } |
479 } | 479 } |
480 | 480 |
481 return found != retry_map.end(); | 481 return found != retry_map.end(); |
482 } | 482 } |
483 | 483 |
484 // TODO(kundaji): Remove tests for macro definitions. | |
484 std::string DataReductionProxyParams::GetDefaultOrigin() const { | 485 std::string DataReductionProxyParams::GetDefaultOrigin() const { |
485 #if defined(SPDY_PROXY_AUTH_ORIGIN) | 486 return kDefaultOrigin; |
486 return SPDY_PROXY_AUTH_ORIGIN; | |
487 #endif | |
488 return std::string(); | |
489 } | 487 } |
490 | 488 |
491 std::string DataReductionProxyParams::GetDefaultFallbackOrigin() const { | 489 std::string DataReductionProxyParams::GetDefaultFallbackOrigin() const { |
492 #if defined(DATA_REDUCTION_FALLBACK_HOST) | 490 return kDefaultFallbackOrigin; |
493 return DATA_REDUCTION_FALLBACK_HOST; | |
494 #endif | |
495 return std::string(); | |
496 } | 491 } |
497 | 492 |
498 std::string DataReductionProxyParams::GetDefaultSSLOrigin() const { | 493 std::string DataReductionProxyParams::GetDefaultSSLOrigin() const { |
499 #if defined(DATA_REDUCTION_PROXY_SSL_ORIGIN) | 494 return kDefaultSslOrigin; |
500 return DATA_REDUCTION_PROXY_SSL_ORIGIN; | |
501 #endif | |
502 return std::string(); | |
503 } | 495 } |
504 | 496 |
505 std::string DataReductionProxyParams::GetDefaultAltOrigin() const { | 497 std::string DataReductionProxyParams::GetDefaultAltOrigin() const { |
506 #if defined(DATA_REDUCTION_PROXY_ALT_ORIGIN) | 498 return kDefaultAltOrigin; |
507 return DATA_REDUCTION_PROXY_ALT_ORIGIN; | |
508 #endif | |
509 return std::string(); | |
510 } | 499 } |
511 | 500 |
512 std::string DataReductionProxyParams::GetDefaultAltFallbackOrigin() const { | 501 std::string DataReductionProxyParams::GetDefaultAltFallbackOrigin() const { |
513 #if defined(DATA_REDUCTION_PROXY_ALT_FALLBACK_ORIGIN) | 502 return kDefaultAltFallbackOrigin; |
514 return DATA_REDUCTION_PROXY_ALT_FALLBACK_ORIGIN; | |
515 #endif | |
516 return std::string(); | |
517 } | 503 } |
518 | 504 |
519 std::string DataReductionProxyParams::GetDefaultProbeURL() const { | 505 std::string DataReductionProxyParams::GetDefaultProbeURL() const { |
520 #if defined(DATA_REDUCTION_PROXY_PROBE_URL) | 506 return kDefaultProbeUrl; |
521 return DATA_REDUCTION_PROXY_PROBE_URL; | |
522 #endif | |
523 return std::string(); | |
524 } | 507 } |
525 | 508 |
526 std::string DataReductionProxyParams::GetDefaultWarmupURL() const { | 509 std::string DataReductionProxyParams::GetDefaultWarmupURL() const { |
527 #if defined(DATA_REDUCTION_PROXY_WARMUP_URL) | 510 return kDefaultWarmupUrl; |
528 return DATA_REDUCTION_PROXY_WARMUP_URL; | |
529 #endif | |
530 return std::string(); | |
531 } | 511 } |
532 | 512 |
533 } // namespace data_reduction_proxy | 513 } // namespace data_reduction_proxy |
OLD | NEW |