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 917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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); |
935 } | 935 } |
936 | 936 |
937 // static | 937 // static |
938 ProxyService* ProxyService::CreateUsingSystemProxyResolver( | 938 scoped_ptr<ProxyService> ProxyService::CreateUsingSystemProxyResolver( |
939 ProxyConfigService* proxy_config_service, | 939 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, 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 new ProxyService( | 952 return make_scoped_ptr(new ProxyService( |
953 proxy_config_service, | 953 proxy_config_service, |
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 ProxyService* ProxyService::CreateWithoutProxyResolver( | 959 scoped_ptr<ProxyService> ProxyService::CreateWithoutProxyResolver( |
960 ProxyConfigService* proxy_config_service, | 960 ProxyConfigService* proxy_config_service, |
961 NetLog* net_log) { | 961 NetLog* net_log) { |
962 return new ProxyService( | 962 return make_scoped_ptr(new ProxyService( |
963 proxy_config_service, | 963 proxy_config_service, |
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 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(new ProxyConfigServiceFixed(pc), |
972 0, NULL); | 972 0, NULL); |
973 } | 973 } |
974 | 974 |
975 // static | 975 // static |
976 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 ProxyService* ProxyService::CreateDirect() { | 983 scoped_ptr<ProxyService> ProxyService::CreateDirect() { |
984 return CreateDirectWithNetLog(NULL); | 984 return CreateDirectWithNetLog(NULL); |
985 } | 985 } |
986 | 986 |
987 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 new ProxyService( | 989 return make_scoped_ptr(new ProxyService( |
990 new ProxyConfigServiceDirect, | 990 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 ProxyService* ProxyService::CreateFixedFromPacResult( | 995 scoped_ptr<ProxyService> ProxyService::CreateFixedFromPacResult( |
996 const std::string& pac_string) { | 996 const std::string& pac_string) { |
997 | |
998 // We need the settings to contain an "automatic" setting, otherwise the | 997 // We need the settings to contain an "automatic" setting, otherwise the |
999 // ProxyResolver dependency we give it will never be used. | 998 // ProxyResolver dependency we give it will never be used. |
1000 scoped_ptr<ProxyConfigService> proxy_config_service( | 999 scoped_ptr<ProxyConfigService> proxy_config_service( |
1001 new ProxyConfigServiceFixed(ProxyConfig::CreateAutoDetect())); | 1000 new ProxyConfigServiceFixed(ProxyConfig::CreateAutoDetect())); |
1002 | 1001 |
1003 return new ProxyService( | 1002 return make_scoped_ptr(new ProxyService( |
1004 proxy_config_service.release(), | 1003 proxy_config_service.release(), |
1005 make_scoped_ptr(new ProxyResolverFactoryForPacResult(pac_string)), NULL); | 1004 make_scoped_ptr(new ProxyResolverFactoryForPacResult(pac_string)), NULL)); |
1006 } | 1005 } |
1007 | 1006 |
1008 int ProxyService::ResolveProxy(const GURL& raw_url, | 1007 int ProxyService::ResolveProxy(const GURL& raw_url, |
1009 int load_flags, | 1008 int load_flags, |
1010 ProxyInfo* result, | 1009 ProxyInfo* result, |
1011 const CompletionCallback& callback, | 1010 const CompletionCallback& callback, |
1012 PacRequest** pac_request, | 1011 PacRequest** pac_request, |
1013 NetworkDelegate* network_delegate, | 1012 NetworkDelegate* network_delegate, |
1014 const BoundNetLog& net_log) { | 1013 const BoundNetLog& net_log) { |
1015 DCHECK(!callback.is_null()); | 1014 DCHECK(!callback.is_null()); |
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1644 State previous_state = ResetProxyConfig(false); | 1643 State previous_state = ResetProxyConfig(false); |
1645 if (previous_state != STATE_NONE) | 1644 if (previous_state != STATE_NONE) |
1646 ApplyProxyConfigIfAvailable(); | 1645 ApplyProxyConfigIfAvailable(); |
1647 } | 1646 } |
1648 | 1647 |
1649 void ProxyService::OnDNSChanged() { | 1648 void ProxyService::OnDNSChanged() { |
1650 OnIPAddressChanged(); | 1649 OnIPAddressChanged(); |
1651 } | 1650 } |
1652 | 1651 |
1653 } // namespace net | 1652 } // namespace net |
OLD | NEW |