Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: net/proxy/proxy_service.cc

Issue 1356933002: make ProxyService::CreateSystemProxyConfigService return scoped_ptrs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mmenke initial review Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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());
Randy Smith (Not in Mondays) 2015/09/18 20:14:55 nit, suggestion: You might not need the .Pass() he
Charlie Harrison 2015/09/21 16:47:04 Compiler complains about these when Pass() is omit
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);
Randy Smith (Not in Mondays) 2015/09/18 20:14:55 same comment here and below (but I'm speculating).
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 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
1463 resolver_.reset(); 1463 resolver_.reset();
1464 config_ = ProxyConfig(); 1464 config_ = ProxyConfig();
1465 if (reset_fetched_config) 1465 if (reset_fetched_config)
1466 fetched_config_ = ProxyConfig(); 1466 fetched_config_ = ProxyConfig();
1467 current_state_ = STATE_NONE; 1467 current_state_ = STATE_NONE;
1468 1468
1469 return previous_state; 1469 return previous_state;
1470 } 1470 }
1471 1471
1472 void ProxyService::ResetConfigService( 1472 void ProxyService::ResetConfigService(
1473 ProxyConfigService* new_proxy_config_service) { 1473 scoped_ptr<ProxyConfigService> new_proxy_config_service) {
1474 DCHECK(CalledOnValidThread()); 1474 DCHECK(CalledOnValidThread());
1475 State previous_state = ResetProxyConfig(true); 1475 State previous_state = ResetProxyConfig(true);
1476 1476
1477 // Release the old configuration service. 1477 // Release the old configuration service.
1478 if (config_service_.get()) 1478 if (config_service_.get())
1479 config_service_->RemoveObserver(this); 1479 config_service_->RemoveObserver(this);
1480 1480
1481 // Set the new configuration service. 1481 // Set the new configuration service.
1482 config_service_.reset(new_proxy_config_service); 1482 config_service_ = new_proxy_config_service.Pass();
1483 config_service_->AddObserver(this); 1483 config_service_->AddObserver(this);
1484 1484
1485 if (previous_state != STATE_NONE) 1485 if (previous_state != STATE_NONE)
1486 ApplyProxyConfigIfAvailable(); 1486 ApplyProxyConfigIfAvailable();
1487 } 1487 }
1488 1488
1489 void ProxyService::ForceReloadProxyConfig() { 1489 void ProxyService::ForceReloadProxyConfig() {
1490 DCHECK(CalledOnValidThread()); 1490 DCHECK(CalledOnValidThread());
1491 ResetProxyConfig(false); 1491 ResetProxyConfig(false);
1492 ApplyProxyConfigIfAvailable(); 1492 ApplyProxyConfigIfAvailable();
1493 } 1493 }
1494 1494
1495 // static 1495 // static
1496 ProxyConfigService* ProxyService::CreateSystemProxyConfigService( 1496 scoped_ptr<ProxyConfigService> ProxyService::CreateSystemProxyConfigService(
1497 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, 1497 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
1498 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) { 1498 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) {
1499 #if defined(OS_WIN) 1499 #if defined(OS_WIN)
1500 return new ProxyConfigServiceWin(); 1500 return make_scoped_ptr(new ProxyConfigServiceWin());
1501 #elif defined(OS_IOS) 1501 #elif defined(OS_IOS)
1502 return new ProxyConfigServiceIOS(); 1502 return make_scoped_ptr(new ProxyConfigServiceIOS());
1503 #elif defined(OS_MACOSX) 1503 #elif defined(OS_MACOSX)
1504 return new ProxyConfigServiceMac(io_task_runner); 1504 return make_scoped_ptr(new ProxyConfigServiceMac(io_task_runner));
1505 #elif defined(OS_CHROMEOS) 1505 #elif defined(OS_CHROMEOS)
1506 LOG(ERROR) << "ProxyConfigService for ChromeOS should be created in " 1506 LOG(ERROR) << "ProxyConfigService for ChromeOS should be created in "
1507 << "profile_io_data.cc::CreateProxyConfigService and this should " 1507 << "profile_io_data.cc::CreateProxyConfigService and this should "
1508 << "be used only for examples."; 1508 << "be used only for examples.";
1509 return new UnsetProxyConfigService; 1509 return make_scoped_ptr(new UnsetProxyConfigService);
1510 #elif defined(OS_LINUX) 1510 #elif defined(OS_LINUX)
1511 ProxyConfigServiceLinux* linux_config_service = 1511 scoped_ptr<ProxyConfigServiceLinux> linux_config_service(
1512 new ProxyConfigServiceLinux(); 1512 new ProxyConfigServiceLinux());
1513 1513
1514 // Assume we got called on the thread that runs the default glib 1514 // Assume we got called on the thread that runs the default glib
1515 // main loop, so the current thread is where we should be running 1515 // main loop, so the current thread is where we should be running
1516 // gconf calls from. 1516 // gconf calls from.
1517 scoped_refptr<base::SingleThreadTaskRunner> glib_thread_task_runner = 1517 scoped_refptr<base::SingleThreadTaskRunner> glib_thread_task_runner =
1518 base::ThreadTaskRunnerHandle::Get(); 1518 base::ThreadTaskRunnerHandle::Get();
1519 1519
1520 // Synchronously fetch the current proxy config (since we are running on 1520 // Synchronously fetch the current proxy config (since we are running on
1521 // glib_default_loop). Additionally register for notifications (delivered in 1521 // glib_default_loop). Additionally register for notifications (delivered in
1522 // either |glib_default_loop| or |file_task_runner|) to keep us updated when 1522 // either |glib_default_loop| or |file_task_runner|) to keep us updated when
1523 // the proxy config changes. 1523 // the proxy config changes.
1524 linux_config_service->SetupAndFetchInitialConfig( 1524 linux_config_service->SetupAndFetchInitialConfig(
1525 glib_thread_task_runner, io_task_runner, file_task_runner); 1525 glib_thread_task_runner, io_task_runner, file_task_runner);
1526 1526
1527 return linux_config_service; 1527 return linux_config_service.Pass();
1528 #elif defined(OS_ANDROID) 1528 #elif defined(OS_ANDROID)
1529 return new ProxyConfigServiceAndroid(io_task_runner, 1529 return make_scoped_ptr(new ProxyConfigServiceAndroid(
1530 base::ThreadTaskRunnerHandle::Get()); 1530 io_task_runner, base::ThreadTaskRunnerHandle::Get()));
1531 #else 1531 #else
1532 LOG(WARNING) << "Failed to choose a system proxy settings fetcher " 1532 LOG(WARNING) << "Failed to choose a system proxy settings fetcher "
1533 "for this platform."; 1533 "for this platform.";
1534 return new ProxyConfigServiceDirect(); 1534 return make_scoped_ptr(new ProxyConfigServiceDirect());
1535 #endif 1535 #endif
1536 } 1536 }
1537 1537
1538 // static 1538 // static
1539 const ProxyService::PacPollPolicy* ProxyService::set_pac_script_poll_policy( 1539 const ProxyService::PacPollPolicy* ProxyService::set_pac_script_poll_policy(
1540 const PacPollPolicy* policy) { 1540 const PacPollPolicy* policy) {
1541 return ProxyScriptDeciderPoller::set_policy(policy); 1541 return ProxyScriptDeciderPoller::set_policy(policy);
1542 } 1542 }
1543 1543
1544 // static 1544 // static
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1643 State previous_state = ResetProxyConfig(false); 1643 State previous_state = ResetProxyConfig(false);
1644 if (previous_state != STATE_NONE) 1644 if (previous_state != STATE_NONE)
1645 ApplyProxyConfigIfAvailable(); 1645 ApplyProxyConfigIfAvailable();
1646 } 1646 }
1647 1647
1648 void ProxyService::OnDNSChanged() { 1648 void ProxyService::OnDNSChanged() {
1649 OnIPAddressChanged(); 1649 OnIPAddressChanged();
1650 } 1650 }
1651 1651
1652 } // namespace net 1652 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698