| 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 kDevOrigin[] = "http://proxy-dev.googlezip.net:443/"; |
| 31 const char kDevFallbackOrigin[] = "http://proxy-dev.googlezip.net:80/"; |
| 32 const char kDefaultFallbackOrigin[] = "http://compress.googlezip.net:80/"; |
| 33 const char kDefaultSslOrigin[] = "http://ssl.googlezip.net:1043/"; |
| 34 const char kDefaultAltOrigin[] = "https://proxy.googlezip.net:443/"; |
| 35 const char kDefaultAltFallbackOrigin[] = "http://compress.googlezip.net:80/"; |
| 36 const char kDefaultProbeUrl[] = "http://check.googlezip.net/connect"; |
| 37 const char kDefaultWarmupUrl[] = "http://www.gstatic.com/generate_204"; |
| 38 |
| 39 } // namespace |
| 29 | 40 |
| 30 namespace data_reduction_proxy { | 41 namespace data_reduction_proxy { |
| 31 | 42 |
| 32 // static | 43 // static |
| 33 bool DataReductionProxyParams::IsIncludedInFieldTrial() { | |
| 34 return base::FieldTrialList::FindFullName( | |
| 35 "DataCompressionProxyRollout") == kEnabled; | |
| 36 } | |
| 37 | |
| 38 // static | |
| 39 bool DataReductionProxyParams::IsIncludedInAlternativeFieldTrial() { | 44 bool DataReductionProxyParams::IsIncludedInAlternativeFieldTrial() { |
| 40 const std::string group_name = base::FieldTrialList::FindFullName( | 45 const std::string group_name = base::FieldTrialList::FindFullName( |
| 41 "DataCompressionProxyAlternativeConfiguration"); | 46 "DataCompressionProxyAlternativeConfiguration"); |
| 42 if (CommandLine::ForCurrentProcess()->HasSwitch( | 47 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 43 data_reduction_proxy::switches::kEnableDataReductionProxyAlt)) { | 48 data_reduction_proxy::switches::kEnableDataReductionProxyAlt)) { |
| 44 return true; | 49 return true; |
| 45 } | 50 } |
| 46 return group_name == kEnabled; | 51 return group_name == kEnabled; |
| 47 } | 52 } |
| 48 | 53 |
| 49 // static | 54 // static |
| 50 bool DataReductionProxyParams::IsIncludedInPromoFieldTrial() { | 55 bool DataReductionProxyParams::IsIncludedInPromoFieldTrial() { |
| 51 return FieldTrialList::FindFullName( | 56 return FieldTrialList::FindFullName( |
| 52 "DataCompressionProxyPromoVisibility") == kEnabled; | 57 "DataCompressionProxyPromoVisibility") == kEnabled; |
| 53 } | 58 } |
| 54 | 59 |
| 55 // static | 60 // static |
| 56 bool DataReductionProxyParams::IsIncludedInPreconnectHintingFieldTrial() { | 61 bool DataReductionProxyParams::IsIncludedInPreconnectHintingFieldTrial() { |
| 57 return IsIncludedInFieldTrial() && | 62 return FieldTrialList::FindFullName( |
| 58 FieldTrialList::FindFullName( | |
| 59 "DataCompressionProxyPreconnectHints") == kEnabled; | 63 "DataCompressionProxyPreconnectHints") == kEnabled; |
| 60 } | 64 } |
| 61 | 65 |
| 62 // static | 66 // static |
| 63 bool DataReductionProxyParams::IsIncludedInCriticalPathBypassFieldTrial() { | 67 bool DataReductionProxyParams::IsIncludedInCriticalPathBypassFieldTrial() { |
| 64 return IsIncludedInFieldTrial() && | 68 return FieldTrialList::FindFullName( |
| 65 FieldTrialList::FindFullName( | |
| 66 "DataCompressionProxyCriticalBypass") == kEnabled; | 69 "DataCompressionProxyCriticalBypass") == kEnabled; |
| 67 } | 70 } |
| 68 | 71 |
| 69 // static | 72 // static |
| 70 bool DataReductionProxyParams::IsIncludedInHoldbackFieldTrial() { | 73 bool DataReductionProxyParams::IsIncludedInHoldbackFieldTrial() { |
| 71 return FieldTrialList::FindFullName( | 74 return FieldTrialList::FindFullName( |
| 72 "DataCompressionProxyHoldback") == kEnabled; | 75 "DataCompressionProxyHoldback") == kEnabled; |
| 73 } | 76 } |
| 74 | 77 |
| 75 // static | 78 // static |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 data_reduction_proxy_config.proxy_rules().Apply( | 374 data_reduction_proxy_config.proxy_rules().Apply( |
| 372 request.url(), &result); | 375 request.url(), &result); |
| 373 if (!result.proxy_server().is_valid()) | 376 if (!result.proxy_server().is_valid()) |
| 374 return true; | 377 return true; |
| 375 if (result.proxy_server().is_direct()) | 378 if (result.proxy_server().is_direct()) |
| 376 return true; | 379 return true; |
| 377 return !IsDataReductionProxy(result.proxy_server().host_port_pair(), NULL); | 380 return !IsDataReductionProxy(result.proxy_server().host_port_pair(), NULL); |
| 378 } | 381 } |
| 379 | 382 |
| 380 std::string DataReductionProxyParams::GetDefaultDevOrigin() const { | 383 std::string DataReductionProxyParams::GetDefaultDevOrigin() const { |
| 381 #if defined(DATA_REDUCTION_DEV_HOST) | |
| 382 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 384 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 383 if (command_line.HasSwitch(switches::kDisableDataReductionProxyDev)) | 385 if (command_line.HasSwitch(switches::kDisableDataReductionProxyDev)) |
| 384 return std::string(); | 386 return std::string(); |
| 385 if (command_line.HasSwitch(switches::kEnableDataReductionProxyDev) || | 387 if (command_line.HasSwitch(switches::kEnableDataReductionProxyDev) || |
| 386 (FieldTrialList::FindFullName("DataCompressionProxyDevRollout") == | 388 (FieldTrialList::FindFullName("DataCompressionProxyDevRollout") == |
| 387 kEnabled)) { | 389 kEnabled)) { |
| 388 return DATA_REDUCTION_DEV_HOST; | 390 return kDevOrigin; |
| 389 } | 391 } |
| 390 #endif | |
| 391 return std::string(); | 392 return std::string(); |
| 392 } | 393 } |
| 393 | 394 |
| 394 std::string DataReductionProxyParams::GetDefaultDevFallbackOrigin() const { | 395 std::string DataReductionProxyParams::GetDefaultDevFallbackOrigin() const { |
| 395 #if defined(DATA_REDUCTION_DEV_FALLBACK_HOST) | |
| 396 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 396 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 397 if (command_line.HasSwitch(switches::kDisableDataReductionProxyDev)) | 397 if (command_line.HasSwitch(switches::kDisableDataReductionProxyDev)) |
| 398 return std::string(); | 398 return std::string(); |
| 399 if (command_line.HasSwitch(switches::kEnableDataReductionProxyDev) || | 399 if (command_line.HasSwitch(switches::kEnableDataReductionProxyDev) || |
| 400 (FieldTrialList::FindFullName("DataCompressionProxyDevRollout") == | 400 (FieldTrialList::FindFullName("DataCompressionProxyDevRollout") == |
| 401 kEnabled)) { | 401 kEnabled)) { |
| 402 return DATA_REDUCTION_DEV_FALLBACK_HOST; | 402 return kDevFallbackOrigin; |
| 403 } | 403 } |
| 404 #endif | |
| 405 return std::string(); | 404 return std::string(); |
| 406 } | 405 } |
| 407 | 406 |
| 408 bool DataReductionProxyParams::AreDataReductionProxiesBypassed( | 407 bool DataReductionProxyParams::AreDataReductionProxiesBypassed( |
| 409 const net::URLRequest& request, base::TimeDelta* min_retry_delay) const { | 408 const net::URLRequest& request, base::TimeDelta* min_retry_delay) const { |
| 410 if (request.context() != NULL && | 409 if (request.context() != NULL && |
| 411 request.context()->proxy_service() != NULL) { | 410 request.context()->proxy_service() != NULL) { |
| 412 return AreProxiesBypassed( | 411 return AreProxiesBypassed( |
| 413 request.context()->proxy_service()->proxy_retry_info(), | 412 request.context()->proxy_service()->proxy_retry_info(), |
| 414 request.url().SchemeIs(url::kHttpsScheme), | 413 request.url().SchemeIs(url::kHttpsScheme), |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 if (found != retry_map.end() && | 482 if (found != retry_map.end() && |
| 484 min_retry_delay && | 483 min_retry_delay && |
| 485 *min_retry_delay > found->second.current_delay) { | 484 *min_retry_delay > found->second.current_delay) { |
| 486 *min_retry_delay = found->second.current_delay; | 485 *min_retry_delay = found->second.current_delay; |
| 487 } | 486 } |
| 488 } | 487 } |
| 489 | 488 |
| 490 return found != retry_map.end(); | 489 return found != retry_map.end(); |
| 491 } | 490 } |
| 492 | 491 |
| 492 // TODO(kundaji): Remove tests for macro definitions. |
| 493 std::string DataReductionProxyParams::GetDefaultOrigin() const { | 493 std::string DataReductionProxyParams::GetDefaultOrigin() const { |
| 494 #if defined(SPDY_PROXY_AUTH_ORIGIN) | 494 return kDefaultOrigin; |
| 495 return SPDY_PROXY_AUTH_ORIGIN; | |
| 496 #endif | |
| 497 return std::string(); | |
| 498 } | 495 } |
| 499 | 496 |
| 500 std::string DataReductionProxyParams::GetDefaultFallbackOrigin() const { | 497 std::string DataReductionProxyParams::GetDefaultFallbackOrigin() const { |
| 501 #if defined(DATA_REDUCTION_FALLBACK_HOST) | 498 return kDefaultFallbackOrigin; |
| 502 return DATA_REDUCTION_FALLBACK_HOST; | |
| 503 #endif | |
| 504 return std::string(); | |
| 505 } | 499 } |
| 506 | 500 |
| 507 std::string DataReductionProxyParams::GetDefaultSSLOrigin() const { | 501 std::string DataReductionProxyParams::GetDefaultSSLOrigin() const { |
| 508 #if defined(DATA_REDUCTION_PROXY_SSL_ORIGIN) | 502 return kDefaultSslOrigin; |
| 509 return DATA_REDUCTION_PROXY_SSL_ORIGIN; | |
| 510 #endif | |
| 511 return std::string(); | |
| 512 } | 503 } |
| 513 | 504 |
| 514 std::string DataReductionProxyParams::GetDefaultAltOrigin() const { | 505 std::string DataReductionProxyParams::GetDefaultAltOrigin() const { |
| 515 #if defined(DATA_REDUCTION_PROXY_ALT_ORIGIN) | 506 return kDefaultAltOrigin; |
| 516 return DATA_REDUCTION_PROXY_ALT_ORIGIN; | |
| 517 #endif | |
| 518 return std::string(); | |
| 519 } | 507 } |
| 520 | 508 |
| 521 std::string DataReductionProxyParams::GetDefaultAltFallbackOrigin() const { | 509 std::string DataReductionProxyParams::GetDefaultAltFallbackOrigin() const { |
| 522 #if defined(DATA_REDUCTION_PROXY_ALT_FALLBACK_ORIGIN) | 510 return kDefaultAltFallbackOrigin; |
| 523 return DATA_REDUCTION_PROXY_ALT_FALLBACK_ORIGIN; | |
| 524 #endif | |
| 525 return std::string(); | |
| 526 } | 511 } |
| 527 | 512 |
| 528 std::string DataReductionProxyParams::GetDefaultProbeURL() const { | 513 std::string DataReductionProxyParams::GetDefaultProbeURL() const { |
| 529 #if defined(DATA_REDUCTION_PROXY_PROBE_URL) | 514 return kDefaultProbeUrl; |
| 530 return DATA_REDUCTION_PROXY_PROBE_URL; | |
| 531 #endif | |
| 532 return std::string(); | |
| 533 } | 515 } |
| 534 | 516 |
| 535 std::string DataReductionProxyParams::GetDefaultWarmupURL() const { | 517 std::string DataReductionProxyParams::GetDefaultWarmupURL() const { |
| 536 #if defined(DATA_REDUCTION_PROXY_WARMUP_URL) | 518 return kDefaultWarmupUrl; |
| 537 return DATA_REDUCTION_PROXY_WARMUP_URL; | |
| 538 #endif | |
| 539 return std::string(); | |
| 540 } | 519 } |
| 541 | 520 |
| 542 } // namespace data_reduction_proxy | 521 } // namespace data_reduction_proxy |
| OLD | NEW |