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

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

Issue 1545233002: Convert Pass()→std::move() in //net (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
« no previous file with comments | « net/proxy/proxy_script_fetcher_impl_unittest.cc ('k') | net/proxy/proxy_service_mojo.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include <utility>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
11 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
12 #include "base/location.h" 13 #include "base/location.h"
13 #include "base/logging.h" 14 #include "base/logging.h"
14 #include "base/macros.h" 15 #include "base/macros.h"
15 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
16 #include "base/metrics/histogram_macros.h" 17 #include "base/metrics/histogram_macros.h"
17 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 scoped_ptr<base::Value> NetLogProxyConfigChangedCallback( 297 scoped_ptr<base::Value> NetLogProxyConfigChangedCallback(
297 const ProxyConfig* old_config, 298 const ProxyConfig* old_config,
298 const ProxyConfig* new_config, 299 const ProxyConfig* new_config,
299 NetLogCaptureMode /* capture_mode */) { 300 NetLogCaptureMode /* capture_mode */) {
300 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 301 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
301 // The "old_config" is optional -- the first notification will not have 302 // The "old_config" is optional -- the first notification will not have
302 // any "previous" configuration. 303 // any "previous" configuration.
303 if (old_config->is_valid()) 304 if (old_config->is_valid())
304 dict->Set("old_config", old_config->ToValue()); 305 dict->Set("old_config", old_config->ToValue());
305 dict->Set("new_config", new_config->ToValue()); 306 dict->Set("new_config", new_config->ToValue());
306 return dict.Pass(); 307 return std::move(dict);
307 } 308 }
308 309
309 scoped_ptr<base::Value> NetLogBadProxyListCallback( 310 scoped_ptr<base::Value> NetLogBadProxyListCallback(
310 const ProxyRetryInfoMap* retry_info, 311 const ProxyRetryInfoMap* retry_info,
311 NetLogCaptureMode /* capture_mode */) { 312 NetLogCaptureMode /* capture_mode */) {
312 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 313 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
313 base::ListValue* list = new base::ListValue(); 314 base::ListValue* list = new base::ListValue();
314 315
315 for (ProxyRetryInfoMap::const_iterator iter = retry_info->begin(); 316 for (ProxyRetryInfoMap::const_iterator iter = retry_info->begin();
316 iter != retry_info->end(); ++iter) { 317 iter != retry_info->end(); ++iter) {
317 list->Append(new base::StringValue(iter->first)); 318 list->Append(new base::StringValue(iter->first));
318 } 319 }
319 dict->Set("bad_proxy_list", list); 320 dict->Set("bad_proxy_list", list);
320 return dict.Pass(); 321 return std::move(dict);
321 } 322 }
322 323
323 // Returns NetLog parameters on a successfuly proxy resolution. 324 // Returns NetLog parameters on a successfuly proxy resolution.
324 scoped_ptr<base::Value> NetLogFinishedResolvingProxyCallback( 325 scoped_ptr<base::Value> NetLogFinishedResolvingProxyCallback(
325 const ProxyInfo* result, 326 const ProxyInfo* result,
326 NetLogCaptureMode /* capture_mode */) { 327 NetLogCaptureMode /* capture_mode */) {
327 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 328 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
328 dict->SetString("pac_string", result->ToPacString()); 329 dict->SetString("pac_string", result->ToPacString());
329 return dict.Pass(); 330 return std::move(dict);
330 } 331 }
331 332
332 #if defined(OS_CHROMEOS) 333 #if defined(OS_CHROMEOS)
333 class UnsetProxyConfigService : public ProxyConfigService { 334 class UnsetProxyConfigService : public ProxyConfigService {
334 public: 335 public:
335 UnsetProxyConfigService() {} 336 UnsetProxyConfigService() {}
336 ~UnsetProxyConfigService() override {} 337 ~UnsetProxyConfigService() override {}
337 338
338 void AddObserver(Observer* observer) override {} 339 void AddObserver(Observer* observer) override {}
339 void RemoveObserver(Observer* observer) override {} 340 void RemoveObserver(Observer* observer) override {}
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 // Time when the request was created. Stored here rather than in |results_| 917 // Time when the request was created. Stored here rather than in |results_|
917 // because the time in |results_| will be cleared. 918 // because the time in |results_| will be cleared.
918 TimeTicks creation_time_; 919 TimeTicks creation_time_;
919 }; 920 };
920 921
921 // ProxyService --------------------------------------------------------------- 922 // ProxyService ---------------------------------------------------------------
922 923
923 ProxyService::ProxyService(scoped_ptr<ProxyConfigService> config_service, 924 ProxyService::ProxyService(scoped_ptr<ProxyConfigService> config_service,
924 scoped_ptr<ProxyResolverFactory> resolver_factory, 925 scoped_ptr<ProxyResolverFactory> resolver_factory,
925 NetLog* net_log) 926 NetLog* net_log)
926 : resolver_factory_(resolver_factory.Pass()), 927 : resolver_factory_(std::move(resolver_factory)),
927 next_config_id_(1), 928 next_config_id_(1),
928 current_state_(STATE_NONE), 929 current_state_(STATE_NONE),
929 net_log_(net_log), 930 net_log_(net_log),
930 stall_proxy_auto_config_delay_( 931 stall_proxy_auto_config_delay_(
931 TimeDelta::FromMilliseconds(kDelayAfterNetworkChangesMs)), 932 TimeDelta::FromMilliseconds(kDelayAfterNetworkChangesMs)),
932 quick_check_enabled_(true) { 933 quick_check_enabled_(true) {
933 NetworkChangeNotifier::AddIPAddressObserver(this); 934 NetworkChangeNotifier::AddIPAddressObserver(this);
934 NetworkChangeNotifier::AddDNSObserver(this); 935 NetworkChangeNotifier::AddDNSObserver(this);
935 ResetConfigService(config_service.Pass()); 936 ResetConfigService(std::move(config_service));
936 } 937 }
937 938
938 // static 939 // static
939 scoped_ptr<ProxyService> ProxyService::CreateUsingSystemProxyResolver( 940 scoped_ptr<ProxyService> ProxyService::CreateUsingSystemProxyResolver(
940 scoped_ptr<ProxyConfigService> proxy_config_service, 941 scoped_ptr<ProxyConfigService> proxy_config_service,
941 size_t num_pac_threads, 942 size_t num_pac_threads,
942 NetLog* net_log) { 943 NetLog* net_log) {
943 DCHECK(proxy_config_service); 944 DCHECK(proxy_config_service);
944 945
945 if (!ProxyResolverFactoryForSystem::IsSupported()) { 946 if (!ProxyResolverFactoryForSystem::IsSupported()) {
946 VLOG(1) << "PAC support disabled because there is no system implementation"; 947 VLOG(1) << "PAC support disabled because there is no system implementation";
947 return CreateWithoutProxyResolver(proxy_config_service.Pass(), net_log); 948 return CreateWithoutProxyResolver(std::move(proxy_config_service), net_log);
948 } 949 }
949 950
950 if (num_pac_threads == 0) 951 if (num_pac_threads == 0)
951 num_pac_threads = kDefaultNumPacThreads; 952 num_pac_threads = kDefaultNumPacThreads;
952 953
953 return make_scoped_ptr(new ProxyService( 954 return make_scoped_ptr(new ProxyService(
954 proxy_config_service.Pass(), 955 std::move(proxy_config_service),
955 make_scoped_ptr(new ProxyResolverFactoryForSystem(num_pac_threads)), 956 make_scoped_ptr(new ProxyResolverFactoryForSystem(num_pac_threads)),
956 net_log)); 957 net_log));
957 } 958 }
958 959
959 // static 960 // static
960 scoped_ptr<ProxyService> ProxyService::CreateWithoutProxyResolver( 961 scoped_ptr<ProxyService> ProxyService::CreateWithoutProxyResolver(
961 scoped_ptr<ProxyConfigService> proxy_config_service, 962 scoped_ptr<ProxyConfigService> proxy_config_service,
962 NetLog* net_log) { 963 NetLog* net_log) {
963 return make_scoped_ptr(new ProxyService( 964 return make_scoped_ptr(new ProxyService(
964 proxy_config_service.Pass(), 965 std::move(proxy_config_service),
965 make_scoped_ptr(new ProxyResolverFactoryForNullResolver), net_log)); 966 make_scoped_ptr(new ProxyResolverFactoryForNullResolver), net_log));
966 } 967 }
967 968
968 // static 969 // static
969 scoped_ptr<ProxyService> ProxyService::CreateFixed(const ProxyConfig& pc) { 970 scoped_ptr<ProxyService> ProxyService::CreateFixed(const ProxyConfig& pc) {
970 // TODO(eroman): This isn't quite right, won't work if |pc| specifies 971 // TODO(eroman): This isn't quite right, won't work if |pc| specifies
971 // a PAC script. 972 // a PAC script.
972 return CreateUsingSystemProxyResolver( 973 return CreateUsingSystemProxyResolver(
973 make_scoped_ptr(new ProxyConfigServiceFixed(pc)), 0, NULL); 974 make_scoped_ptr(new ProxyConfigServiceFixed(pc)), 0, NULL);
974 } 975 }
(...skipping 19 matching lines...) Expand all
994 995
995 // static 996 // static
996 scoped_ptr<ProxyService> ProxyService::CreateFixedFromPacResult( 997 scoped_ptr<ProxyService> ProxyService::CreateFixedFromPacResult(
997 const std::string& pac_string) { 998 const std::string& pac_string) {
998 // We need the settings to contain an "automatic" setting, otherwise the 999 // We need the settings to contain an "automatic" setting, otherwise the
999 // ProxyResolver dependency we give it will never be used. 1000 // ProxyResolver dependency we give it will never be used.
1000 scoped_ptr<ProxyConfigService> proxy_config_service( 1001 scoped_ptr<ProxyConfigService> proxy_config_service(
1001 new ProxyConfigServiceFixed(ProxyConfig::CreateAutoDetect())); 1002 new ProxyConfigServiceFixed(ProxyConfig::CreateAutoDetect()));
1002 1003
1003 return make_scoped_ptr(new ProxyService( 1004 return make_scoped_ptr(new ProxyService(
1004 proxy_config_service.Pass(), 1005 std::move(proxy_config_service),
1005 make_scoped_ptr(new ProxyResolverFactoryForPacResult(pac_string)), NULL)); 1006 make_scoped_ptr(new ProxyResolverFactoryForPacResult(pac_string)), NULL));
1006 } 1007 }
1007 1008
1008 int ProxyService::ResolveProxy(const GURL& raw_url, 1009 int ProxyService::ResolveProxy(const GURL& raw_url,
1009 int load_flags, 1010 int load_flags,
1010 ProxyInfo* result, 1011 ProxyInfo* result,
1011 const CompletionCallback& callback, 1012 const CompletionCallback& callback,
1012 PacRequest** pac_request, 1013 PacRequest** pac_request,
1013 NetworkDelegate* network_delegate, 1014 NetworkDelegate* network_delegate,
1014 const BoundNetLog& net_log) { 1015 const BoundNetLog& net_log) {
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
1439 net_log.EndEvent(NetLog::TYPE_PROXY_SERVICE); 1440 net_log.EndEvent(NetLog::TYPE_PROXY_SERVICE);
1440 return result_code; 1441 return result_code;
1441 } 1442 }
1442 1443
1443 void ProxyService::SetProxyScriptFetchers( 1444 void ProxyService::SetProxyScriptFetchers(
1444 ProxyScriptFetcher* proxy_script_fetcher, 1445 ProxyScriptFetcher* proxy_script_fetcher,
1445 scoped_ptr<DhcpProxyScriptFetcher> dhcp_proxy_script_fetcher) { 1446 scoped_ptr<DhcpProxyScriptFetcher> dhcp_proxy_script_fetcher) {
1446 DCHECK(CalledOnValidThread()); 1447 DCHECK(CalledOnValidThread());
1447 State previous_state = ResetProxyConfig(false); 1448 State previous_state = ResetProxyConfig(false);
1448 proxy_script_fetcher_.reset(proxy_script_fetcher); 1449 proxy_script_fetcher_.reset(proxy_script_fetcher);
1449 dhcp_proxy_script_fetcher_ = dhcp_proxy_script_fetcher.Pass(); 1450 dhcp_proxy_script_fetcher_ = std::move(dhcp_proxy_script_fetcher);
1450 if (previous_state != STATE_NONE) 1451 if (previous_state != STATE_NONE)
1451 ApplyProxyConfigIfAvailable(); 1452 ApplyProxyConfigIfAvailable();
1452 } 1453 }
1453 1454
1454 ProxyScriptFetcher* ProxyService::GetProxyScriptFetcher() const { 1455 ProxyScriptFetcher* ProxyService::GetProxyScriptFetcher() const {
1455 DCHECK(CalledOnValidThread()); 1456 DCHECK(CalledOnValidThread());
1456 return proxy_script_fetcher_.get(); 1457 return proxy_script_fetcher_.get();
1457 } 1458 }
1458 1459
1459 ProxyService::State ProxyService::ResetProxyConfig(bool reset_fetched_config) { 1460 ProxyService::State ProxyService::ResetProxyConfig(bool reset_fetched_config) {
(...skipping 17 matching lines...) Expand all
1477 void ProxyService::ResetConfigService( 1478 void ProxyService::ResetConfigService(
1478 scoped_ptr<ProxyConfigService> new_proxy_config_service) { 1479 scoped_ptr<ProxyConfigService> new_proxy_config_service) {
1479 DCHECK(CalledOnValidThread()); 1480 DCHECK(CalledOnValidThread());
1480 State previous_state = ResetProxyConfig(true); 1481 State previous_state = ResetProxyConfig(true);
1481 1482
1482 // Release the old configuration service. 1483 // Release the old configuration service.
1483 if (config_service_.get()) 1484 if (config_service_.get())
1484 config_service_->RemoveObserver(this); 1485 config_service_->RemoveObserver(this);
1485 1486
1486 // Set the new configuration service. 1487 // Set the new configuration service.
1487 config_service_ = new_proxy_config_service.Pass(); 1488 config_service_ = std::move(new_proxy_config_service);
1488 config_service_->AddObserver(this); 1489 config_service_->AddObserver(this);
1489 1490
1490 if (previous_state != STATE_NONE) 1491 if (previous_state != STATE_NONE)
1491 ApplyProxyConfigIfAvailable(); 1492 ApplyProxyConfigIfAvailable();
1492 } 1493 }
1493 1494
1494 void ProxyService::ForceReloadProxyConfig() { 1495 void ProxyService::ForceReloadProxyConfig() {
1495 DCHECK(CalledOnValidThread()); 1496 DCHECK(CalledOnValidThread());
1496 ResetProxyConfig(false); 1497 ResetProxyConfig(false);
1497 ApplyProxyConfigIfAvailable(); 1498 ApplyProxyConfigIfAvailable();
(...skipping 24 matching lines...) Expand all
1522 scoped_refptr<base::SingleThreadTaskRunner> glib_thread_task_runner = 1523 scoped_refptr<base::SingleThreadTaskRunner> glib_thread_task_runner =
1523 base::ThreadTaskRunnerHandle::Get(); 1524 base::ThreadTaskRunnerHandle::Get();
1524 1525
1525 // Synchronously fetch the current proxy config (since we are running on 1526 // Synchronously fetch the current proxy config (since we are running on
1526 // glib_default_loop). Additionally register for notifications (delivered in 1527 // glib_default_loop). Additionally register for notifications (delivered in
1527 // either |glib_default_loop| or |file_task_runner|) to keep us updated when 1528 // either |glib_default_loop| or |file_task_runner|) to keep us updated when
1528 // the proxy config changes. 1529 // the proxy config changes.
1529 linux_config_service->SetupAndFetchInitialConfig( 1530 linux_config_service->SetupAndFetchInitialConfig(
1530 glib_thread_task_runner, io_task_runner, file_task_runner); 1531 glib_thread_task_runner, io_task_runner, file_task_runner);
1531 1532
1532 return linux_config_service.Pass(); 1533 return std::move(linux_config_service);
1533 #elif defined(OS_ANDROID) 1534 #elif defined(OS_ANDROID)
1534 return make_scoped_ptr(new ProxyConfigServiceAndroid( 1535 return make_scoped_ptr(new ProxyConfigServiceAndroid(
1535 io_task_runner, base::ThreadTaskRunnerHandle::Get())); 1536 io_task_runner, base::ThreadTaskRunnerHandle::Get()));
1536 #else 1537 #else
1537 LOG(WARNING) << "Failed to choose a system proxy settings fetcher " 1538 LOG(WARNING) << "Failed to choose a system proxy settings fetcher "
1538 "for this platform."; 1539 "for this platform.";
1539 return make_scoped_ptr(new ProxyConfigServiceDirect()); 1540 return make_scoped_ptr(new ProxyConfigServiceDirect());
1540 #endif 1541 #endif
1541 } 1542 }
1542 1543
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1648 State previous_state = ResetProxyConfig(false); 1649 State previous_state = ResetProxyConfig(false);
1649 if (previous_state != STATE_NONE) 1650 if (previous_state != STATE_NONE)
1650 ApplyProxyConfigIfAvailable(); 1651 ApplyProxyConfigIfAvailable();
1651 } 1652 }
1652 1653
1653 void ProxyService::OnDNSChanged() { 1654 void ProxyService::OnDNSChanged() {
1654 OnIPAddressChanged(); 1655 OnIPAddressChanged();
1655 } 1656 }
1656 1657
1657 } // namespace net 1658 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_script_fetcher_impl_unittest.cc ('k') | net/proxy/proxy_service_mojo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698