| 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 #include <cmath> | 8 #include <cmath> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 | 229 |
| 230 // Creates ProxyResolvers using a platform-specific implementation. | 230 // Creates ProxyResolvers using a platform-specific implementation. |
| 231 class ProxyResolverFactoryForSystem : public MultiThreadedProxyResolverFactory { | 231 class ProxyResolverFactoryForSystem : public MultiThreadedProxyResolverFactory { |
| 232 public: | 232 public: |
| 233 explicit ProxyResolverFactoryForSystem(size_t max_num_threads) | 233 explicit ProxyResolverFactoryForSystem(size_t max_num_threads) |
| 234 : MultiThreadedProxyResolverFactory(max_num_threads, | 234 : MultiThreadedProxyResolverFactory(max_num_threads, |
| 235 false /*expects_pac_bytes*/) {} | 235 false /*expects_pac_bytes*/) {} |
| 236 | 236 |
| 237 std::unique_ptr<ProxyResolverFactory> CreateProxyResolverFactory() override { | 237 std::unique_ptr<ProxyResolverFactory> CreateProxyResolverFactory() override { |
| 238 #if defined(OS_WIN) | 238 #if defined(OS_WIN) |
| 239 return base::WrapUnique(new ProxyResolverFactoryWinHttp()); | 239 return base::MakeUnique<ProxyResolverFactoryWinHttp>(); |
| 240 #elif defined(OS_MACOSX) | 240 #elif defined(OS_MACOSX) |
| 241 return base::WrapUnique(new ProxyResolverFactoryMac()); | 241 return base::MakeUnique<ProxyResolverFactoryMac>(); |
| 242 #else | 242 #else |
| 243 NOTREACHED(); | 243 NOTREACHED(); |
| 244 return NULL; | 244 return NULL; |
| 245 #endif | 245 #endif |
| 246 } | 246 } |
| 247 | 247 |
| 248 static bool IsSupported() { | 248 static bool IsSupported() { |
| 249 #if defined(OS_WIN) || defined(OS_MACOSX) | 249 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 250 return true; | 250 return true; |
| 251 #else | 251 #else |
| (...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 if (!ProxyResolverFactoryForSystem::IsSupported()) { | 971 if (!ProxyResolverFactoryForSystem::IsSupported()) { |
| 972 VLOG(1) << "PAC support disabled because there is no system implementation"; | 972 VLOG(1) << "PAC support disabled because there is no system implementation"; |
| 973 return CreateWithoutProxyResolver(std::move(proxy_config_service), net_log); | 973 return CreateWithoutProxyResolver(std::move(proxy_config_service), net_log); |
| 974 } | 974 } |
| 975 | 975 |
| 976 if (num_pac_threads == 0) | 976 if (num_pac_threads == 0) |
| 977 num_pac_threads = kDefaultNumPacThreads; | 977 num_pac_threads = kDefaultNumPacThreads; |
| 978 | 978 |
| 979 return base::WrapUnique(new ProxyService( | 979 return base::WrapUnique(new ProxyService( |
| 980 std::move(proxy_config_service), | 980 std::move(proxy_config_service), |
| 981 base::WrapUnique(new ProxyResolverFactoryForSystem(num_pac_threads)), | 981 base::MakeUnique<ProxyResolverFactoryForSystem>(num_pac_threads), |
| 982 net_log)); | 982 net_log)); |
| 983 } | 983 } |
| 984 | 984 |
| 985 // static | 985 // static |
| 986 std::unique_ptr<ProxyService> ProxyService::CreateWithoutProxyResolver( | 986 std::unique_ptr<ProxyService> ProxyService::CreateWithoutProxyResolver( |
| 987 std::unique_ptr<ProxyConfigService> proxy_config_service, | 987 std::unique_ptr<ProxyConfigService> proxy_config_service, |
| 988 NetLog* net_log) { | 988 NetLog* net_log) { |
| 989 return base::WrapUnique(new ProxyService( | 989 return base::WrapUnique(new ProxyService( |
| 990 std::move(proxy_config_service), | 990 std::move(proxy_config_service), |
| 991 base::WrapUnique(new ProxyResolverFactoryForNullResolver), net_log)); | 991 base::WrapUnique(new ProxyResolverFactoryForNullResolver), net_log)); |
| 992 } | 992 } |
| 993 | 993 |
| 994 // static | 994 // static |
| 995 std::unique_ptr<ProxyService> ProxyService::CreateFixed(const ProxyConfig& pc) { | 995 std::unique_ptr<ProxyService> ProxyService::CreateFixed(const ProxyConfig& pc) { |
| 996 // TODO(eroman): This isn't quite right, won't work if |pc| specifies | 996 // TODO(eroman): This isn't quite right, won't work if |pc| specifies |
| 997 // a PAC script. | 997 // a PAC script. |
| 998 return CreateUsingSystemProxyResolver( | 998 return CreateUsingSystemProxyResolver( |
| 999 base::WrapUnique(new ProxyConfigServiceFixed(pc)), 0, NULL); | 999 base::MakeUnique<ProxyConfigServiceFixed>(pc), 0, NULL); |
| 1000 } | 1000 } |
| 1001 | 1001 |
| 1002 // static | 1002 // static |
| 1003 std::unique_ptr<ProxyService> ProxyService::CreateFixed( | 1003 std::unique_ptr<ProxyService> ProxyService::CreateFixed( |
| 1004 const std::string& proxy) { | 1004 const std::string& proxy) { |
| 1005 ProxyConfig proxy_config; | 1005 ProxyConfig proxy_config; |
| 1006 proxy_config.proxy_rules().ParseFromString(proxy); | 1006 proxy_config.proxy_rules().ParseFromString(proxy); |
| 1007 return ProxyService::CreateFixed(proxy_config); | 1007 return ProxyService::CreateFixed(proxy_config); |
| 1008 } | 1008 } |
| 1009 | 1009 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1023 // static | 1023 // static |
| 1024 std::unique_ptr<ProxyService> ProxyService::CreateFixedFromPacResult( | 1024 std::unique_ptr<ProxyService> ProxyService::CreateFixedFromPacResult( |
| 1025 const std::string& pac_string) { | 1025 const std::string& pac_string) { |
| 1026 // We need the settings to contain an "automatic" setting, otherwise the | 1026 // We need the settings to contain an "automatic" setting, otherwise the |
| 1027 // ProxyResolver dependency we give it will never be used. | 1027 // ProxyResolver dependency we give it will never be used. |
| 1028 std::unique_ptr<ProxyConfigService> proxy_config_service( | 1028 std::unique_ptr<ProxyConfigService> proxy_config_service( |
| 1029 new ProxyConfigServiceFixed(ProxyConfig::CreateAutoDetect())); | 1029 new ProxyConfigServiceFixed(ProxyConfig::CreateAutoDetect())); |
| 1030 | 1030 |
| 1031 return base::WrapUnique(new ProxyService( | 1031 return base::WrapUnique(new ProxyService( |
| 1032 std::move(proxy_config_service), | 1032 std::move(proxy_config_service), |
| 1033 base::WrapUnique(new ProxyResolverFactoryForPacResult(pac_string)), | 1033 base::MakeUnique<ProxyResolverFactoryForPacResult>(pac_string), NULL)); |
| 1034 NULL)); | |
| 1035 } | 1034 } |
| 1036 | 1035 |
| 1037 int ProxyService::ResolveProxy(const GURL& raw_url, | 1036 int ProxyService::ResolveProxy(const GURL& raw_url, |
| 1038 const std::string& method, | 1037 const std::string& method, |
| 1039 ProxyInfo* result, | 1038 ProxyInfo* result, |
| 1040 const CompletionCallback& callback, | 1039 const CompletionCallback& callback, |
| 1041 PacRequest** pac_request, | 1040 PacRequest** pac_request, |
| 1042 ProxyDelegate* proxy_delegate, | 1041 ProxyDelegate* proxy_delegate, |
| 1043 const BoundNetLog& net_log) { | 1042 const BoundNetLog& net_log) { |
| 1044 DCHECK(!callback.is_null()); | 1043 DCHECK(!callback.is_null()); |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1517 ResetProxyConfig(false); | 1516 ResetProxyConfig(false); |
| 1518 ApplyProxyConfigIfAvailable(); | 1517 ApplyProxyConfigIfAvailable(); |
| 1519 } | 1518 } |
| 1520 | 1519 |
| 1521 // static | 1520 // static |
| 1522 std::unique_ptr<ProxyConfigService> | 1521 std::unique_ptr<ProxyConfigService> |
| 1523 ProxyService::CreateSystemProxyConfigService( | 1522 ProxyService::CreateSystemProxyConfigService( |
| 1524 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | 1523 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, |
| 1525 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) { | 1524 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) { |
| 1526 #if defined(OS_WIN) | 1525 #if defined(OS_WIN) |
| 1527 return base::WrapUnique(new ProxyConfigServiceWin()); | 1526 return base::MakeUnique<ProxyConfigServiceWin>(); |
| 1528 #elif defined(OS_IOS) | 1527 #elif defined(OS_IOS) |
| 1529 return base::WrapUnique(new ProxyConfigServiceIOS()); | 1528 return base::MakeUnique<ProxyConfigServiceIOS>(); |
| 1530 #elif defined(OS_MACOSX) | 1529 #elif defined(OS_MACOSX) |
| 1531 return base::WrapUnique(new ProxyConfigServiceMac(io_task_runner)); | 1530 return base::MakeUnique<ProxyConfigServiceMac>(io_task_runner); |
| 1532 #elif defined(OS_CHROMEOS) | 1531 #elif defined(OS_CHROMEOS) |
| 1533 LOG(ERROR) << "ProxyConfigService for ChromeOS should be created in " | 1532 LOG(ERROR) << "ProxyConfigService for ChromeOS should be created in " |
| 1534 << "profile_io_data.cc::CreateProxyConfigService and this should " | 1533 << "profile_io_data.cc::CreateProxyConfigService and this should " |
| 1535 << "be used only for examples."; | 1534 << "be used only for examples."; |
| 1536 return base::WrapUnique(new UnsetProxyConfigService); | 1535 return base::WrapUnique(new UnsetProxyConfigService); |
| 1537 #elif defined(OS_LINUX) | 1536 #elif defined(OS_LINUX) |
| 1538 std::unique_ptr<ProxyConfigServiceLinux> linux_config_service( | 1537 std::unique_ptr<ProxyConfigServiceLinux> linux_config_service( |
| 1539 new ProxyConfigServiceLinux()); | 1538 new ProxyConfigServiceLinux()); |
| 1540 | 1539 |
| 1541 // Assume we got called on the thread that runs the default glib | 1540 // Assume we got called on the thread that runs the default glib |
| 1542 // main loop, so the current thread is where we should be running | 1541 // main loop, so the current thread is where we should be running |
| 1543 // gconf calls from. | 1542 // gconf calls from. |
| 1544 scoped_refptr<base::SingleThreadTaskRunner> glib_thread_task_runner = | 1543 scoped_refptr<base::SingleThreadTaskRunner> glib_thread_task_runner = |
| 1545 base::ThreadTaskRunnerHandle::Get(); | 1544 base::ThreadTaskRunnerHandle::Get(); |
| 1546 | 1545 |
| 1547 // Synchronously fetch the current proxy config (since we are running on | 1546 // Synchronously fetch the current proxy config (since we are running on |
| 1548 // glib_default_loop). Additionally register for notifications (delivered in | 1547 // glib_default_loop). Additionally register for notifications (delivered in |
| 1549 // either |glib_default_loop| or |file_task_runner|) to keep us updated when | 1548 // either |glib_default_loop| or |file_task_runner|) to keep us updated when |
| 1550 // the proxy config changes. | 1549 // the proxy config changes. |
| 1551 linux_config_service->SetupAndFetchInitialConfig( | 1550 linux_config_service->SetupAndFetchInitialConfig( |
| 1552 glib_thread_task_runner, io_task_runner, file_task_runner); | 1551 glib_thread_task_runner, io_task_runner, file_task_runner); |
| 1553 | 1552 |
| 1554 return std::move(linux_config_service); | 1553 return std::move(linux_config_service); |
| 1555 #elif defined(OS_ANDROID) | 1554 #elif defined(OS_ANDROID) |
| 1556 return base::WrapUnique(new ProxyConfigServiceAndroid( | 1555 return base::MakeUnique<ProxyConfigServiceAndroid>( |
| 1557 io_task_runner, base::ThreadTaskRunnerHandle::Get())); | 1556 io_task_runner, base::ThreadTaskRunnerHandle::Get()); |
| 1558 #else | 1557 #else |
| 1559 LOG(WARNING) << "Failed to choose a system proxy settings fetcher " | 1558 LOG(WARNING) << "Failed to choose a system proxy settings fetcher " |
| 1560 "for this platform."; | 1559 "for this platform."; |
| 1561 return base::WrapUnique(new ProxyConfigServiceDirect()); | 1560 return base::MakeUnique<ProxyConfigServiceDirect>(); |
| 1562 #endif | 1561 #endif |
| 1563 } | 1562 } |
| 1564 | 1563 |
| 1565 // static | 1564 // static |
| 1566 const ProxyService::PacPollPolicy* ProxyService::set_pac_script_poll_policy( | 1565 const ProxyService::PacPollPolicy* ProxyService::set_pac_script_poll_policy( |
| 1567 const PacPollPolicy* policy) { | 1566 const PacPollPolicy* policy) { |
| 1568 return ProxyScriptDeciderPoller::set_policy(policy); | 1567 return ProxyScriptDeciderPoller::set_policy(policy); |
| 1569 } | 1568 } |
| 1570 | 1569 |
| 1571 // static | 1570 // static |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1670 State previous_state = ResetProxyConfig(false); | 1669 State previous_state = ResetProxyConfig(false); |
| 1671 if (previous_state != STATE_NONE) | 1670 if (previous_state != STATE_NONE) |
| 1672 ApplyProxyConfigIfAvailable(); | 1671 ApplyProxyConfigIfAvailable(); |
| 1673 } | 1672 } |
| 1674 | 1673 |
| 1675 void ProxyService::OnDNSChanged() { | 1674 void ProxyService::OnDNSChanged() { |
| 1676 OnIPAddressChanged(); | 1675 OnIPAddressChanged(); |
| 1677 } | 1676 } |
| 1678 | 1677 |
| 1679 } // namespace net | 1678 } // namespace net |
| OLD | NEW |