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

Side by Side Diff: chrome/browser/io_thread.cc

Issue 10831277: [net] Change factory methods for HostResolver and HostCache to return a scoped_ptr (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 8 years, 2 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 | Annotate | Revision Log
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 "chrome/browser/io_thread.h" 5 #include "chrome/browser/io_thread.h"
6 6
7 #include <vector> 7 #include <vector>
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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 } 101 }
102 102
103 private: 103 private:
104 virtual ~SystemURLRequestContext() { 104 virtual ~SystemURLRequestContext() {
105 #if defined(USE_NSS) 105 #if defined(USE_NSS)
106 net::SetURLRequestContextForNSSHttpIO(NULL); 106 net::SetURLRequestContextForNSSHttpIO(NULL);
107 #endif // defined(USE_NSS) 107 #endif // defined(USE_NSS)
108 } 108 }
109 }; 109 };
110 110
111 net::HostResolver* CreateGlobalHostResolver(net::NetLog* net_log) { 111 scoped_ptr<net::HostResolver> CreateGlobalHostResolver(net::NetLog* net_log) {
112 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 112 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
113 113
114 bool allow_async_dns_field_trial = true; 114 bool allow_async_dns_field_trial = true;
115 115
116 size_t parallelism = net::HostResolver::kDefaultParallelism; 116 size_t parallelism = net::HostResolver::kDefaultParallelism;
117 117
118 // Use the concurrency override from the command-line, if any. 118 // Use the concurrency override from the command-line, if any.
119 if (command_line.HasSwitch(switches::kHostResolverParallelism)) { 119 if (command_line.HasSwitch(switches::kHostResolverParallelism)) {
120 allow_async_dns_field_trial = false; 120 allow_async_dns_field_trial = false;
121 std::string s = 121 std::string s =
(...skipping 17 matching lines...) Expand all
139 command_line.GetSwitchValueASCII(switches::kHostResolverRetryAttempts); 139 command_line.GetSwitchValueASCII(switches::kHostResolverRetryAttempts);
140 // Parse the switch (it should be a non-negative integer). 140 // Parse the switch (it should be a non-negative integer).
141 int n; 141 int n;
142 if (base::StringToInt(s, &n) && n >= 0) { 142 if (base::StringToInt(s, &n) && n >= 0) {
143 retry_attempts = static_cast<size_t>(n); 143 retry_attempts = static_cast<size_t>(n);
144 } else { 144 } else {
145 LOG(ERROR) << "Invalid switch for host resolver retry attempts: " << s; 145 LOG(ERROR) << "Invalid switch for host resolver retry attempts: " << s;
146 } 146 }
147 } 147 }
148 148
149 net::HostResolver* global_host_resolver = NULL;
150 bool use_async = false; 149 bool use_async = false;
151 if (command_line.HasSwitch(switches::kEnableAsyncDns)) { 150 if (command_line.HasSwitch(switches::kEnableAsyncDns)) {
152 allow_async_dns_field_trial = false; 151 allow_async_dns_field_trial = false;
153 use_async = true; 152 use_async = true;
154 } else if (command_line.HasSwitch(switches::kDisableAsyncDns)) { 153 } else if (command_line.HasSwitch(switches::kDisableAsyncDns)) {
155 allow_async_dns_field_trial = false; 154 allow_async_dns_field_trial = false;
156 use_async = false; 155 use_async = false;
157 } 156 }
158 157
159 if (allow_async_dns_field_trial) 158 if (allow_async_dns_field_trial)
160 use_async = chrome_browser_net::ConfigureAsyncDnsFieldTrial(); 159 use_async = chrome_browser_net::ConfigureAsyncDnsFieldTrial();
161 160
162 if (use_async) { 161 scoped_ptr<net::HostResolver> global_host_resolver(
163 global_host_resolver = 162 net::HostResolver::CreateSystemResolver(parallelism,
164 net::CreateAsyncHostResolver(parallelism, retry_attempts, net_log); 163 retry_attempts,
165 } else { 164 true /* use_cache */,
darin (slow to review) 2012/10/09 17:38:34 I'm not a big fan of functions that take multiples
szym 2012/10/09 21:40:43 Done.
166 global_host_resolver = 165 use_async,
167 net::CreateSystemHostResolver(parallelism, retry_attempts, net_log); 166 net_log));
168 }
169 167
170 // Determine if we should disable IPv6 support. 168 // Determine if we should disable IPv6 support.
171 if (!command_line.HasSwitch(switches::kEnableIPv6)) { 169 if (!command_line.HasSwitch(switches::kEnableIPv6)) {
172 if (command_line.HasSwitch(switches::kDisableIPv6)) { 170 if (command_line.HasSwitch(switches::kDisableIPv6)) {
173 global_host_resolver->SetDefaultAddressFamily(net::ADDRESS_FAMILY_IPV4); 171 global_host_resolver->SetDefaultAddressFamily(net::ADDRESS_FAMILY_IPV4);
174 } else { 172 } else {
175 global_host_resolver->ProbeIPv6Support(); 173 global_host_resolver->ProbeIPv6Support();
176 } 174 }
177 } 175 }
178 176
179 // If hostname remappings were specified on the command-line, layer these 177 // If hostname remappings were specified on the command-line, layer these
180 // rules on top of the real host resolver. This allows forwarding all requests 178 // rules on top of the real host resolver. This allows forwarding all requests
181 // through a designated test server. 179 // through a designated test server.
182 if (!command_line.HasSwitch(switches::kHostResolverRules)) 180 if (!command_line.HasSwitch(switches::kHostResolverRules))
183 return global_host_resolver; 181 return global_host_resolver.PassAs<net::HostResolver>();
184 182
185 net::MappedHostResolver* remapped_resolver = 183 scoped_ptr<net::MappedHostResolver> remapped_resolver(
186 new net::MappedHostResolver(global_host_resolver); 184 new net::MappedHostResolver(global_host_resolver.Pass()));
187 remapped_resolver->SetRulesFromString( 185 remapped_resolver->SetRulesFromString(
188 command_line.GetSwitchValueASCII(switches::kHostResolverRules)); 186 command_line.GetSwitchValueASCII(switches::kHostResolverRules));
189 return remapped_resolver; 187 return remapped_resolver.PassAs<net::HostResolver>();
190 } 188 }
191 189
192 // TODO(willchan): Remove proxy script fetcher context since it's not necessary 190 // TODO(willchan): Remove proxy script fetcher context since it's not necessary
193 // now that I got rid of refcounting URLRequestContexts. 191 // now that I got rid of refcounting URLRequestContexts.
194 // See IOThread::Globals for details. 192 // See IOThread::Globals for details.
195 net::URLRequestContext* 193 net::URLRequestContext*
196 ConstructProxyScriptFetcherContext(IOThread::Globals* globals, 194 ConstructProxyScriptFetcherContext(IOThread::Globals* globals,
197 net::NetLog* net_log) { 195 net::NetLog* net_log) {
198 net::URLRequestContext* context = new URLRequestContextWithUserAgent; 196 net::URLRequestContext* context = new URLRequestContextWithUserAgent;
199 context->set_net_log(net_log); 197 context->set_net_log(net_log);
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 NULL, 429 NULL,
432 NULL, 430 NULL,
433 NULL, 431 NULL,
434 NULL, 432 NULL,
435 &system_enable_referrers_, 433 &system_enable_referrers_,
436 NULL, 434 NULL,
437 NULL); 435 NULL);
438 if (command_line.HasSwitch(switches::kDisableExtensionsHttpThrottling)) 436 if (command_line.HasSwitch(switches::kDisableExtensionsHttpThrottling))
439 network_delegate->NeverThrottleRequests(); 437 network_delegate->NeverThrottleRequests();
440 globals_->system_network_delegate.reset(network_delegate); 438 globals_->system_network_delegate.reset(network_delegate);
441 globals_->host_resolver.reset( 439 globals_->host_resolver = CreateGlobalHostResolver(net_log_);
442 CreateGlobalHostResolver(net_log_));
443 globals_->cert_verifier.reset(net::CertVerifier::CreateDefault()); 440 globals_->cert_verifier.reset(net::CertVerifier::CreateDefault());
444 globals_->transport_security_state.reset(new net::TransportSecurityState()); 441 globals_->transport_security_state.reset(new net::TransportSecurityState());
445 globals_->ssl_config_service = GetSSLConfigService(); 442 globals_->ssl_config_service = GetSSLConfigService();
446 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory( 443 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory(
447 globals_->host_resolver.get())); 444 globals_->host_resolver.get()));
448 globals_->http_server_properties.reset(new net::HttpServerPropertiesImpl); 445 globals_->http_server_properties.reset(new net::HttpServerPropertiesImpl);
449 // For the ProxyScriptFetcher, we use a direct ProxyService. 446 // For the ProxyScriptFetcher, we use a direct ProxyService.
450 globals_->proxy_script_fetcher_proxy_service.reset( 447 globals_->proxy_script_fetcher_proxy_service.reset(
451 net::ProxyService::CreateDirectWithNetLog(net_log_)); 448 net::ProxyService::CreateDirectWithNetLog(net_log_));
452 // In-memory cookie store. 449 // In-memory cookie store.
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 new net::HttpNetworkLayer( 692 new net::HttpNetworkLayer(
696 new net::HttpNetworkSession(system_params))); 693 new net::HttpNetworkSession(system_params)));
697 globals_->system_ftp_transaction_factory.reset( 694 globals_->system_ftp_transaction_factory.reset(
698 new net::FtpNetworkLayer(globals_->host_resolver.get())); 695 new net::FtpNetworkLayer(globals_->host_resolver.get()));
699 globals_->system_request_context.reset( 696 globals_->system_request_context.reset(
700 ConstructSystemRequestContext(globals_, net_log_)); 697 ConstructSystemRequestContext(globals_, net_log_));
701 698
702 sdch_manager_->set_sdch_fetcher( 699 sdch_manager_->set_sdch_fetcher(
703 new SdchDictionaryFetcher(system_url_request_context_getter_.get())); 700 new SdchDictionaryFetcher(system_url_request_context_getter_.get()));
704 } 701 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/net/connection_tester.cc » ('j') | chrome/browser/net/connection_tester.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698