Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/proxy/proxy_service.h" | 5 #include "net/proxy/proxy_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 910 ProxyConfig::ID config_id_; // The config id when the resolve was started. | 910 ProxyConfig::ID config_id_; // The config id when the resolve was started. |
| 911 ProxyConfigSource config_source_; // The source of proxy settings. | 911 ProxyConfigSource config_source_; // The source of proxy settings. |
| 912 BoundNetLog net_log_; | 912 BoundNetLog net_log_; |
| 913 // Time when the request was created. Stored here rather than in |results_| | 913 // Time when the request was created. Stored here rather than in |results_| |
| 914 // because the time in |results_| will be cleared. | 914 // because the time in |results_| will be cleared. |
| 915 TimeTicks creation_time_; | 915 TimeTicks creation_time_; |
| 916 }; | 916 }; |
| 917 | 917 |
| 918 // ProxyService --------------------------------------------------------------- | 918 // ProxyService --------------------------------------------------------------- |
| 919 | 919 |
| 920 ProxyService::ProxyService(ProxyConfigService* config_service, | 920 ProxyService::ProxyService(scoped_ptr<ProxyConfigService> config_service, |
| 921 scoped_ptr<ProxyResolverFactory> resolver_factory, | 921 scoped_ptr<ProxyResolverFactory> resolver_factory, |
| 922 NetLog* net_log) | 922 NetLog* net_log) |
| 923 : resolver_factory_(resolver_factory.Pass()), | 923 : resolver_factory_(resolver_factory.Pass()), |
| 924 next_config_id_(1), | 924 next_config_id_(1), |
| 925 current_state_(STATE_NONE), | 925 current_state_(STATE_NONE), |
| 926 net_log_(net_log), | 926 net_log_(net_log), |
| 927 stall_proxy_auto_config_delay_( | 927 stall_proxy_auto_config_delay_( |
| 928 TimeDelta::FromMilliseconds(kDelayAfterNetworkChangesMs)), | 928 TimeDelta::FromMilliseconds(kDelayAfterNetworkChangesMs)), |
| 929 quick_check_enabled_(true) { | 929 quick_check_enabled_(true) { |
| 930 NetworkChangeNotifier::AddIPAddressObserver(this); | 930 NetworkChangeNotifier::AddIPAddressObserver(this); |
| 931 NetworkChangeNotifier::AddDNSObserver(this); | 931 NetworkChangeNotifier::AddDNSObserver(this); |
| 932 ResetConfigService(config_service); | 932 ResetConfigService(config_service.Pass()); |
| 933 } | 933 } |
| 934 | 934 |
| 935 // static | 935 // static |
| 936 ProxyService* ProxyService::CreateUsingSystemProxyResolver( | 936 ProxyService* ProxyService::CreateUsingSystemProxyResolver( |
| 937 ProxyConfigService* proxy_config_service, | 937 scoped_ptr<ProxyConfigService> proxy_config_service, |
| 938 size_t num_pac_threads, | 938 size_t num_pac_threads, |
| 939 NetLog* net_log) { | 939 NetLog* net_log) { |
| 940 DCHECK(proxy_config_service); | 940 DCHECK(proxy_config_service); |
| 941 | 941 |
| 942 if (!ProxyResolverFactoryForSystem::IsSupported()) { | 942 if (!ProxyResolverFactoryForSystem::IsSupported()) { |
| 943 VLOG(1) << "PAC support disabled because there is no system implementation"; | 943 VLOG(1) << "PAC support disabled because there is no system implementation"; |
| 944 return CreateWithoutProxyResolver(proxy_config_service, net_log); | 944 return CreateWithoutProxyResolver(proxy_config_service.Pass(), net_log); |
| 945 } | 945 } |
| 946 | 946 |
| 947 if (num_pac_threads == 0) | 947 if (num_pac_threads == 0) |
| 948 num_pac_threads = kDefaultNumPacThreads; | 948 num_pac_threads = kDefaultNumPacThreads; |
| 949 | 949 |
| 950 return new ProxyService( | 950 return new ProxyService( |
| 951 proxy_config_service, | 951 proxy_config_service.Pass(), |
| 952 make_scoped_ptr(new ProxyResolverFactoryForSystem(num_pac_threads)), | 952 make_scoped_ptr(new ProxyResolverFactoryForSystem(num_pac_threads)), |
| 953 net_log); | 953 net_log); |
| 954 } | 954 } |
| 955 | 955 |
| 956 // static | 956 // static |
| 957 ProxyService* ProxyService::CreateWithoutProxyResolver( | 957 ProxyService* ProxyService::CreateWithoutProxyResolver( |
| 958 ProxyConfigService* proxy_config_service, | 958 scoped_ptr<ProxyConfigService> proxy_config_service, |
| 959 NetLog* net_log) { | 959 NetLog* net_log) { |
| 960 return new ProxyService( | 960 return new ProxyService( |
| 961 proxy_config_service, | 961 proxy_config_service.Pass(), |
| 962 make_scoped_ptr(new ProxyResolverFactoryForNullResolver), net_log); | 962 make_scoped_ptr(new ProxyResolverFactoryForNullResolver), net_log); |
| 963 } | 963 } |
| 964 | 964 |
| 965 // static | 965 // static |
| 966 ProxyService* ProxyService::CreateFixed(const ProxyConfig& pc) { | 966 ProxyService* ProxyService::CreateFixed(const ProxyConfig& pc) { |
| 967 // TODO(eroman): This isn't quite right, won't work if |pc| specifies | 967 // TODO(eroman): This isn't quite right, won't work if |pc| specifies |
| 968 // a PAC script. | 968 // a PAC script. |
| 969 return CreateUsingSystemProxyResolver(new ProxyConfigServiceFixed(pc), | 969 return CreateUsingSystemProxyResolver( |
| 970 0, NULL); | 970 make_scoped_ptr(new ProxyConfigServiceFixed(pc)).Pass(), 0, NULL); |
| 971 } | 971 } |
| 972 | 972 |
| 973 // static | 973 // static |
| 974 ProxyService* ProxyService::CreateFixed(const std::string& proxy) { | 974 ProxyService* ProxyService::CreateFixed(const std::string& proxy) { |
| 975 ProxyConfig proxy_config; | 975 ProxyConfig proxy_config; |
| 976 proxy_config.proxy_rules().ParseFromString(proxy); | 976 proxy_config.proxy_rules().ParseFromString(proxy); |
| 977 return ProxyService::CreateFixed(proxy_config); | 977 return ProxyService::CreateFixed(proxy_config); |
| 978 } | 978 } |
| 979 | 979 |
| 980 // static | 980 // static |
| 981 ProxyService* ProxyService::CreateDirect() { | 981 ProxyService* ProxyService::CreateDirect() { |
| 982 return CreateDirectWithNetLog(NULL); | 982 return CreateDirectWithNetLog(NULL); |
| 983 } | 983 } |
| 984 | 984 |
| 985 ProxyService* ProxyService::CreateDirectWithNetLog(NetLog* net_log) { | 985 ProxyService* ProxyService::CreateDirectWithNetLog(NetLog* net_log) { |
| 986 // Use direct connections. | 986 // Use direct connections. |
| 987 return new ProxyService( | 987 return new ProxyService( |
| 988 new ProxyConfigServiceDirect, | 988 make_scoped_ptr(new ProxyConfigServiceDirect).Pass(), |
|
Randy Smith (Not in Mondays)
2015/08/24 21:58:19
As you can see from the line underneath, you don't
| |
| 989 make_scoped_ptr(new ProxyResolverFactoryForNullResolver), net_log); | 989 make_scoped_ptr(new ProxyResolverFactoryForNullResolver), net_log); |
| 990 } | 990 } |
| 991 | 991 |
| 992 // static | 992 // static |
| 993 ProxyService* ProxyService::CreateFixedFromPacResult( | 993 ProxyService* ProxyService::CreateFixedFromPacResult( |
| 994 const std::string& pac_string) { | 994 const std::string& pac_string) { |
| 995 | 995 |
| 996 // We need the settings to contain an "automatic" setting, otherwise the | 996 // We need the settings to contain an "automatic" setting, otherwise the |
| 997 // ProxyResolver dependency we give it will never be used. | 997 // ProxyResolver dependency we give it will never be used. |
| 998 scoped_ptr<ProxyConfigService> proxy_config_service( | 998 scoped_ptr<ProxyConfigService> proxy_config_service( |
| 999 new ProxyConfigServiceFixed(ProxyConfig::CreateAutoDetect())); | 999 new ProxyConfigServiceFixed(ProxyConfig::CreateAutoDetect())); |
| 1000 | 1000 |
| 1001 return new ProxyService( | 1001 return new ProxyService( |
| 1002 proxy_config_service.release(), | 1002 proxy_config_service.Pass(), |
| 1003 make_scoped_ptr(new ProxyResolverFactoryForPacResult(pac_string)), NULL); | 1003 make_scoped_ptr(new ProxyResolverFactoryForPacResult(pac_string)), NULL); |
| 1004 } | 1004 } |
| 1005 | 1005 |
| 1006 int ProxyService::ResolveProxy(const GURL& raw_url, | 1006 int ProxyService::ResolveProxy(const GURL& raw_url, |
| 1007 int load_flags, | 1007 int load_flags, |
| 1008 ProxyInfo* result, | 1008 ProxyInfo* result, |
| 1009 const CompletionCallback& callback, | 1009 const CompletionCallback& callback, |
| 1010 PacRequest** pac_request, | 1010 PacRequest** pac_request, |
| 1011 NetworkDelegate* network_delegate, | 1011 NetworkDelegate* network_delegate, |
| 1012 const BoundNetLog& net_log) { | 1012 const BoundNetLog& net_log) { |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1466 resolver_.reset(); | 1466 resolver_.reset(); |
| 1467 config_ = ProxyConfig(); | 1467 config_ = ProxyConfig(); |
| 1468 if (reset_fetched_config) | 1468 if (reset_fetched_config) |
| 1469 fetched_config_ = ProxyConfig(); | 1469 fetched_config_ = ProxyConfig(); |
| 1470 current_state_ = STATE_NONE; | 1470 current_state_ = STATE_NONE; |
| 1471 | 1471 |
| 1472 return previous_state; | 1472 return previous_state; |
| 1473 } | 1473 } |
| 1474 | 1474 |
| 1475 void ProxyService::ResetConfigService( | 1475 void ProxyService::ResetConfigService( |
| 1476 ProxyConfigService* new_proxy_config_service) { | 1476 scoped_ptr<ProxyConfigService> new_proxy_config_service) { |
| 1477 DCHECK(CalledOnValidThread()); | 1477 DCHECK(CalledOnValidThread()); |
| 1478 State previous_state = ResetProxyConfig(true); | 1478 State previous_state = ResetProxyConfig(true); |
| 1479 | 1479 |
| 1480 // Release the old configuration service. | 1480 // Release the old configuration service. |
| 1481 if (config_service_.get()) | 1481 if (config_service_.get()) |
| 1482 config_service_->RemoveObserver(this); | 1482 config_service_->RemoveObserver(this); |
| 1483 | 1483 |
| 1484 // Set the new configuration service. | 1484 // Set the new configuration service. |
| 1485 config_service_.reset(new_proxy_config_service); | 1485 config_service_ = new_proxy_config_service.Pass(); |
| 1486 config_service_->AddObserver(this); | 1486 config_service_->AddObserver(this); |
| 1487 | 1487 |
| 1488 if (previous_state != STATE_NONE) | 1488 if (previous_state != STATE_NONE) |
| 1489 ApplyProxyConfigIfAvailable(); | 1489 ApplyProxyConfigIfAvailable(); |
| 1490 } | 1490 } |
| 1491 | 1491 |
| 1492 void ProxyService::ForceReloadProxyConfig() { | 1492 void ProxyService::ForceReloadProxyConfig() { |
| 1493 DCHECK(CalledOnValidThread()); | 1493 DCHECK(CalledOnValidThread()); |
| 1494 ResetProxyConfig(false); | 1494 ResetProxyConfig(false); |
| 1495 ApplyProxyConfigIfAvailable(); | 1495 ApplyProxyConfigIfAvailable(); |
| 1496 } | 1496 } |
| 1497 | 1497 |
| 1498 // static | 1498 // static |
| 1499 ProxyConfigService* ProxyService::CreateSystemProxyConfigService( | 1499 scoped_ptr<ProxyConfigService> ProxyService::CreateSystemProxyConfigService( |
| 1500 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | 1500 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, |
| 1501 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) { | 1501 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) { |
| 1502 #if defined(OS_WIN) | 1502 #if defined(OS_WIN) |
| 1503 return new ProxyConfigServiceWin(); | 1503 return make_scoped_ptr(new ProxyConfigServiceWin()).Pass(); |
| 1504 #elif defined(OS_IOS) | 1504 #elif defined(OS_IOS) |
| 1505 return new ProxyConfigServiceIOS(); | 1505 return make_scoped_ptr(new ProxyConfigServiceIOS()).Pass(); |
| 1506 #elif defined(OS_MACOSX) | 1506 #elif defined(OS_MACOSX) |
| 1507 return new ProxyConfigServiceMac(io_task_runner); | 1507 return make_scoped_ptr(new ProxyConfigServiceMac(io_task_runner)).Pass(); |
| 1508 #elif defined(OS_CHROMEOS) | 1508 #elif defined(OS_CHROMEOS) |
| 1509 LOG(ERROR) << "ProxyConfigService for ChromeOS should be created in " | 1509 LOG(ERROR) << "ProxyConfigService for ChromeOS should be created in " |
| 1510 << "profile_io_data.cc::CreateProxyConfigService and this should " | 1510 << "profile_io_data.cc::CreateProxyConfigService and this should " |
| 1511 << "be used only for examples."; | 1511 << "be used only for examples."; |
| 1512 return new UnsetProxyConfigService; | 1512 return make_scoped_ptr(new UnsetProxyConfigService).Pass(); |
| 1513 #elif defined(OS_LINUX) | 1513 #elif defined(OS_LINUX) |
| 1514 ProxyConfigServiceLinux* linux_config_service = | 1514 scoped_ptr<ProxyConfigServiceLinux> linux_config_service( |
| 1515 new ProxyConfigServiceLinux(); | 1515 new ProxyConfigServiceLinux()); |
| 1516 | 1516 |
| 1517 // Assume we got called on the thread that runs the default glib | 1517 // Assume we got called on the thread that runs the default glib |
| 1518 // main loop, so the current thread is where we should be running | 1518 // main loop, so the current thread is where we should be running |
| 1519 // gconf calls from. | 1519 // gconf calls from. |
| 1520 scoped_refptr<base::SingleThreadTaskRunner> glib_thread_task_runner = | 1520 scoped_refptr<base::SingleThreadTaskRunner> glib_thread_task_runner = |
| 1521 base::ThreadTaskRunnerHandle::Get(); | 1521 base::ThreadTaskRunnerHandle::Get(); |
| 1522 | 1522 |
| 1523 // Synchronously fetch the current proxy config (since we are running on | 1523 // Synchronously fetch the current proxy config (since we are running on |
| 1524 // glib_default_loop). Additionally register for notifications (delivered in | 1524 // glib_default_loop). Additionally register for notifications (delivered in |
| 1525 // either |glib_default_loop| or |file_task_runner|) to keep us updated when | 1525 // either |glib_default_loop| or |file_task_runner|) to keep us updated when |
| 1526 // the proxy config changes. | 1526 // the proxy config changes. |
| 1527 linux_config_service->SetupAndFetchInitialConfig( | 1527 linux_config_service->SetupAndFetchInitialConfig( |
| 1528 glib_thread_task_runner, io_task_runner, file_task_runner); | 1528 glib_thread_task_runner, io_task_runner, file_task_runner); |
| 1529 | 1529 |
| 1530 return linux_config_service; | 1530 return linux_config_service.Pass(); |
| 1531 #elif defined(OS_ANDROID) | 1531 #elif defined(OS_ANDROID) |
| 1532 return new ProxyConfigServiceAndroid(io_task_runner, | 1532 return make_scoped_ptr( |
| 1533 base::ThreadTaskRunnerHandle::Get()); | 1533 new ProxyConfigServiceAndroid(io_task_runner, |
| 1534 base::ThreadTaskRunnerHandle::Get())) | |
| 1535 .Pass(); | |
| 1534 #else | 1536 #else |
| 1535 LOG(WARNING) << "Failed to choose a system proxy settings fetcher " | 1537 LOG(WARNING) << "Failed to choose a system proxy settings fetcher " |
| 1536 "for this platform."; | 1538 "for this platform."; |
| 1537 return new ProxyConfigServiceDirect(); | 1539 return make_scoped_ptr(new ProxyConfigServiceDirect()).Pass(); |
| 1538 #endif | 1540 #endif |
| 1539 } | 1541 } |
| 1540 | 1542 |
| 1541 // static | 1543 // static |
| 1542 const ProxyService::PacPollPolicy* ProxyService::set_pac_script_poll_policy( | 1544 const ProxyService::PacPollPolicy* ProxyService::set_pac_script_poll_policy( |
| 1543 const PacPollPolicy* policy) { | 1545 const PacPollPolicy* policy) { |
| 1544 return ProxyScriptDeciderPoller::set_policy(policy); | 1546 return ProxyScriptDeciderPoller::set_policy(policy); |
| 1545 } | 1547 } |
| 1546 | 1548 |
| 1547 // static | 1549 // static |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1646 State previous_state = ResetProxyConfig(false); | 1648 State previous_state = ResetProxyConfig(false); |
| 1647 if (previous_state != STATE_NONE) | 1649 if (previous_state != STATE_NONE) |
| 1648 ApplyProxyConfigIfAvailable(); | 1650 ApplyProxyConfigIfAvailable(); |
| 1649 } | 1651 } |
| 1650 | 1652 |
| 1651 void ProxyService::OnDNSChanged() { | 1653 void ProxyService::OnDNSChanged() { |
| 1652 OnIPAddressChanged(); | 1654 OnIPAddressChanged(); |
| 1653 } | 1655 } |
| 1654 | 1656 |
| 1655 } // namespace net | 1657 } // namespace net |
| OLD | NEW |