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