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 "chrome/browser/io_thread.h" | 5 #include "chrome/browser/io_thread.h" |
6 | 6 |
| 7 #include <utility> |
7 #include <vector> | 8 #include <vector> |
8 | 9 |
9 #include "base/base64.h" | 10 #include "base/base64.h" |
10 #include "base/bind.h" | 11 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
12 #include "base/command_line.h" | 13 #include "base/command_line.h" |
13 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
14 #include "base/debug/leak_tracker.h" | 15 #include "base/debug/leak_tracker.h" |
15 #include "base/environment.h" | 16 #include "base/environment.h" |
16 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 net_log); | 244 net_log); |
244 #else | 245 #else |
245 global_host_resolver = | 246 global_host_resolver = |
246 net::HostResolver::CreateSystemResolver(options, net_log); | 247 net::HostResolver::CreateSystemResolver(options, net_log); |
247 #endif | 248 #endif |
248 | 249 |
249 // If hostname remappings were specified on the command-line, layer these | 250 // If hostname remappings were specified on the command-line, layer these |
250 // rules on top of the real host resolver. This allows forwarding all requests | 251 // rules on top of the real host resolver. This allows forwarding all requests |
251 // through a designated test server. | 252 // through a designated test server. |
252 if (!command_line.HasSwitch(switches::kHostResolverRules)) | 253 if (!command_line.HasSwitch(switches::kHostResolverRules)) |
253 return global_host_resolver.Pass(); | 254 return global_host_resolver; |
254 | 255 |
255 scoped_ptr<net::MappedHostResolver> remapped_resolver( | 256 scoped_ptr<net::MappedHostResolver> remapped_resolver( |
256 new net::MappedHostResolver(global_host_resolver.Pass())); | 257 new net::MappedHostResolver(std::move(global_host_resolver))); |
257 remapped_resolver->SetRulesFromString( | 258 remapped_resolver->SetRulesFromString( |
258 command_line.GetSwitchValueASCII(switches::kHostResolverRules)); | 259 command_line.GetSwitchValueASCII(switches::kHostResolverRules)); |
259 return remapped_resolver.Pass(); | 260 return std::move(remapped_resolver); |
260 } | 261 } |
261 | 262 |
262 int GetSwitchValueAsInt(const base::CommandLine& command_line, | 263 int GetSwitchValueAsInt(const base::CommandLine& command_line, |
263 const std::string& switch_name) { | 264 const std::string& switch_name) { |
264 int value; | 265 int value; |
265 if (!base::StringToInt(command_line.GetSwitchValueASCII(switch_name), | 266 if (!base::StringToInt(command_line.GetSwitchValueASCII(switch_name), |
266 &value)) { | 267 &value)) { |
267 return 0; | 268 return 0; |
268 } | 269 } |
269 return value; | 270 return value; |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 #endif | 638 #endif |
638 | 639 |
639 scoped_ptr<data_usage::DataUseAmortizer> data_use_amortizer; | 640 scoped_ptr<data_usage::DataUseAmortizer> data_use_amortizer; |
640 #if BUILDFLAG(ANDROID_JAVA_UI) | 641 #if BUILDFLAG(ANDROID_JAVA_UI) |
641 data_use_amortizer.reset(new data_usage::android::TrafficStatsAmortizer()); | 642 data_use_amortizer.reset(new data_usage::android::TrafficStatsAmortizer()); |
642 #endif | 643 #endif |
643 | 644 |
644 globals_->data_use_aggregator.reset(new data_usage::DataUseAggregator( | 645 globals_->data_use_aggregator.reset(new data_usage::DataUseAggregator( |
645 scoped_ptr<data_usage::DataUseAnnotator>( | 646 scoped_ptr<data_usage::DataUseAnnotator>( |
646 new chrome_browser_data_usage::TabIdAnnotator()), | 647 new chrome_browser_data_usage::TabIdAnnotator()), |
647 data_use_amortizer.Pass())); | 648 std::move(data_use_amortizer))); |
648 | 649 |
649 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 | 650 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 |
650 // is fixed. | 651 // is fixed. |
651 tracked_objects::ScopedTracker tracking_profile3( | 652 tracked_objects::ScopedTracker tracking_profile3( |
652 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 653 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
653 "466432 IOThread::InitAsync::ChromeNetworkDelegate")); | 654 "466432 IOThread::InitAsync::ChromeNetworkDelegate")); |
654 scoped_ptr<ChromeNetworkDelegate> chrome_network_delegate( | 655 scoped_ptr<ChromeNetworkDelegate> chrome_network_delegate( |
655 new ChromeNetworkDelegate(extension_event_router_forwarder(), | 656 new ChromeNetworkDelegate(extension_event_router_forwarder(), |
656 &system_enable_referrers_)); | 657 &system_enable_referrers_)); |
657 // By default, data usage is considered off the record. | 658 // By default, data usage is considered off the record. |
658 chrome_network_delegate->set_data_use_aggregator( | 659 chrome_network_delegate->set_data_use_aggregator( |
659 globals_->data_use_aggregator.get(), | 660 globals_->data_use_aggregator.get(), |
660 true /* is_data_usage_off_the_record */); | 661 true /* is_data_usage_off_the_record */); |
661 | 662 |
662 #if BUILDFLAG(ANDROID_JAVA_UI) | 663 #if BUILDFLAG(ANDROID_JAVA_UI) |
663 globals_->external_data_use_observer.reset( | 664 globals_->external_data_use_observer.reset( |
664 new chrome::android::ExternalDataUseObserver( | 665 new chrome::android::ExternalDataUseObserver( |
665 globals_->data_use_aggregator.get(), | 666 globals_->data_use_aggregator.get(), |
666 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), | 667 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
667 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI))); | 668 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI))); |
668 #endif | 669 #endif |
669 | 670 |
670 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 | 671 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 |
671 // is fixed. | 672 // is fixed. |
672 tracked_objects::ScopedTracker tracking_profile4( | 673 tracked_objects::ScopedTracker tracking_profile4( |
673 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 674 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
674 "466432 IOThread::InitAsync::CreateGlobalHostResolver")); | 675 "466432 IOThread::InitAsync::CreateGlobalHostResolver")); |
675 globals_->system_network_delegate = chrome_network_delegate.Pass(); | 676 globals_->system_network_delegate = std::move(chrome_network_delegate); |
676 globals_->host_resolver = CreateGlobalHostResolver(net_log_); | 677 globals_->host_resolver = CreateGlobalHostResolver(net_log_); |
677 | 678 |
678 std::map<std::string, std::string> network_quality_estimator_params; | 679 std::map<std::string, std::string> network_quality_estimator_params; |
679 variations::GetVariationParams(kNetworkQualityEstimatorFieldTrialName, | 680 variations::GetVariationParams(kNetworkQualityEstimatorFieldTrialName, |
680 &network_quality_estimator_params); | 681 &network_quality_estimator_params); |
681 | 682 |
682 scoped_ptr<net::ExternalEstimateProvider> external_estimate_provider; | 683 scoped_ptr<net::ExternalEstimateProvider> external_estimate_provider; |
683 #if BUILDFLAG(ANDROID_JAVA_UI) | 684 #if BUILDFLAG(ANDROID_JAVA_UI) |
684 external_estimate_provider.reset( | 685 external_estimate_provider.reset( |
685 new chrome::android::ExternalEstimateProviderAndroid()); | 686 new chrome::android::ExternalEstimateProviderAndroid()); |
686 #endif | 687 #endif |
687 // Pass ownership. | 688 // Pass ownership. |
688 globals_->network_quality_estimator.reset(new net::NetworkQualityEstimator( | 689 globals_->network_quality_estimator.reset(new net::NetworkQualityEstimator( |
689 external_estimate_provider.Pass(), network_quality_estimator_params)); | 690 std::move(external_estimate_provider), network_quality_estimator_params)); |
690 | 691 |
691 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 | 692 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 |
692 // is fixed. | 693 // is fixed. |
693 tracked_objects::ScopedTracker tracking_profile5( | 694 tracked_objects::ScopedTracker tracking_profile5( |
694 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 695 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
695 "466432 IOThread::InitAsync::UpdateDnsClientEnabled::Start")); | 696 "466432 IOThread::InitAsync::UpdateDnsClientEnabled::Start")); |
696 UpdateDnsClientEnabled(); | 697 UpdateDnsClientEnabled(); |
697 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 | 698 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 |
698 // is fixed. | 699 // is fixed. |
699 tracked_objects::ScopedTracker tracking_profile6( | 700 tracked_objects::ScopedTracker tracking_profile6( |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1082 )); | 1083 )); |
1083 UpdateServerWhitelist(); | 1084 UpdateServerWhitelist(); |
1084 UpdateDelegateWhitelist(); | 1085 UpdateDelegateWhitelist(); |
1085 UpdateNegotiateDisableCnameLookup(); | 1086 UpdateNegotiateDisableCnameLookup(); |
1086 UpdateNegotiateEnablePort(); | 1087 UpdateNegotiateEnablePort(); |
1087 #if defined(OS_ANDROID) | 1088 #if defined(OS_ANDROID) |
1088 UpdateAndroidAuthNegotiateAccountType(); | 1089 UpdateAndroidAuthNegotiateAccountType(); |
1089 #endif | 1090 #endif |
1090 globals_->http_auth_handler_factory = | 1091 globals_->http_auth_handler_factory = |
1091 net::HttpAuthHandlerRegistryFactory::Create( | 1092 net::HttpAuthHandlerRegistryFactory::Create( |
1092 globals_->http_auth_preferences.get(), globals_->host_resolver.get()) | 1093 globals_->http_auth_preferences.get(), globals_->host_resolver.get()); |
1093 .Pass(); | |
1094 } | 1094 } |
1095 | 1095 |
1096 void IOThread::ClearHostCache() { | 1096 void IOThread::ClearHostCache() { |
1097 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1097 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1098 | 1098 |
1099 net::HostCache* host_cache = globals_->host_resolver->GetHostCache(); | 1099 net::HostCache* host_cache = globals_->host_resolver->GetHostCache(); |
1100 if (host_cache) | 1100 if (host_cache) |
1101 host_cache->clear(); | 1101 host_cache->clear(); |
1102 } | 1102 } |
1103 | 1103 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1218 void IOThread::InitSystemRequestContextOnIOThread() { | 1218 void IOThread::InitSystemRequestContextOnIOThread() { |
1219 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1219 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1220 DCHECK(!globals_->system_proxy_service.get()); | 1220 DCHECK(!globals_->system_proxy_service.get()); |
1221 DCHECK(system_proxy_config_service_.get()); | 1221 DCHECK(system_proxy_config_service_.get()); |
1222 | 1222 |
1223 const base::CommandLine& command_line = | 1223 const base::CommandLine& command_line = |
1224 *base::CommandLine::ForCurrentProcess(); | 1224 *base::CommandLine::ForCurrentProcess(); |
1225 globals_->system_proxy_service = ProxyServiceFactory::CreateProxyService( | 1225 globals_->system_proxy_service = ProxyServiceFactory::CreateProxyService( |
1226 net_log_, globals_->proxy_script_fetcher_context.get(), | 1226 net_log_, globals_->proxy_script_fetcher_context.get(), |
1227 globals_->system_network_delegate.get(), | 1227 globals_->system_network_delegate.get(), |
1228 system_proxy_config_service_.Pass(), command_line, | 1228 std::move(system_proxy_config_service_), command_line, |
1229 quick_check_enabled_.GetValue()); | 1229 quick_check_enabled_.GetValue()); |
1230 | 1230 |
1231 globals_->system_request_context.reset( | 1231 globals_->system_request_context.reset( |
1232 ConstructSystemRequestContext(globals_, net_log_)); | 1232 ConstructSystemRequestContext(globals_, net_log_)); |
1233 } | 1233 } |
1234 | 1234 |
1235 void IOThread::UpdateDnsClientEnabled() { | 1235 void IOThread::UpdateDnsClientEnabled() { |
1236 globals()->host_resolver->SetDnsClientEnabled(*dns_client_enabled_); | 1236 globals()->host_resolver->SetDnsClientEnabled(*dns_client_enabled_); |
1237 } | 1237 } |
1238 | 1238 |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1732 ->GetTaskRunnerWithShutdownBehavior( | 1732 ->GetTaskRunnerWithShutdownBehavior( |
1733 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)))); | 1733 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)))); |
1734 #if !defined(DISABLE_FTP_SUPPORT) | 1734 #if !defined(DISABLE_FTP_SUPPORT) |
1735 globals->proxy_script_fetcher_ftp_transaction_factory.reset( | 1735 globals->proxy_script_fetcher_ftp_transaction_factory.reset( |
1736 new net::FtpNetworkLayer(globals->host_resolver.get())); | 1736 new net::FtpNetworkLayer(globals->host_resolver.get())); |
1737 job_factory->SetProtocolHandler( | 1737 job_factory->SetProtocolHandler( |
1738 url::kFtpScheme, | 1738 url::kFtpScheme, |
1739 make_scoped_ptr(new net::FtpProtocolHandler( | 1739 make_scoped_ptr(new net::FtpProtocolHandler( |
1740 globals->proxy_script_fetcher_ftp_transaction_factory.get()))); | 1740 globals->proxy_script_fetcher_ftp_transaction_factory.get()))); |
1741 #endif | 1741 #endif |
1742 globals->proxy_script_fetcher_url_request_job_factory = job_factory.Pass(); | 1742 globals->proxy_script_fetcher_url_request_job_factory = |
| 1743 std::move(job_factory); |
1743 | 1744 |
1744 context->set_job_factory( | 1745 context->set_job_factory( |
1745 globals->proxy_script_fetcher_url_request_job_factory.get()); | 1746 globals->proxy_script_fetcher_url_request_job_factory.get()); |
1746 | 1747 |
1747 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the | 1748 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the |
1748 // system URLRequestContext too. There's no reason this should be tied to a | 1749 // system URLRequestContext too. There's no reason this should be tied to a |
1749 // profile. | 1750 // profile. |
1750 return context; | 1751 return context; |
1751 } | 1752 } |
OLD | NEW |