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

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: Remove FieldTrials Created 8 years, 4 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
« no previous file with comments | « no previous file | chrome/browser/net/connection_tester.cc » ('j') | net/base/host_resolver.cc » ('J')
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 "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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 } 99 }
100 100
101 private: 101 private:
102 virtual ~SystemURLRequestContext() { 102 virtual ~SystemURLRequestContext() {
103 #if defined(USE_NSS) 103 #if defined(USE_NSS)
104 net::SetURLRequestContextForNSSHttpIO(NULL); 104 net::SetURLRequestContextForNSSHttpIO(NULL);
105 #endif // defined(USE_NSS) 105 #endif // defined(USE_NSS)
106 } 106 }
107 }; 107 };
108 108
109 net::HostResolver* CreateGlobalHostResolver(net::NetLog* net_log) { 109 scoped_ptr<net::HostResolver> CreateGlobalHostResolver(net::NetLog* net_log) {
110 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 110 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
111 111
112 size_t parallelism = net::HostResolver::kDefaultParallelism; 112 size_t parallelism = net::HostResolver::kDefaultParallelism;
113 113
114 // Use the concurrency override from the command-line, if any. 114 // Use the concurrency override from the command-line, if any.
115 if (command_line.HasSwitch(switches::kHostResolverParallelism)) { 115 if (command_line.HasSwitch(switches::kHostResolverParallelism)) {
116 std::string s = 116 std::string s =
117 command_line.GetSwitchValueASCII(switches::kHostResolverParallelism); 117 command_line.GetSwitchValueASCII(switches::kHostResolverParallelism);
118 118
119 // Parse the switch (it should be a positive integer formatted as decimal). 119 // Parse the switch (it should be a positive integer formatted as decimal).
(...skipping 13 matching lines...) Expand all
133 command_line.GetSwitchValueASCII(switches::kHostResolverRetryAttempts); 133 command_line.GetSwitchValueASCII(switches::kHostResolverRetryAttempts);
134 // Parse the switch (it should be a non-negative integer). 134 // Parse the switch (it should be a non-negative integer).
135 int n; 135 int n;
136 if (base::StringToInt(s, &n) && n >= 0) { 136 if (base::StringToInt(s, &n) && n >= 0) {
137 retry_attempts = static_cast<size_t>(n); 137 retry_attempts = static_cast<size_t>(n);
138 } else { 138 } else {
139 LOG(ERROR) << "Invalid switch for host resolver retry attempts: " << s; 139 LOG(ERROR) << "Invalid switch for host resolver retry attempts: " << s;
140 } 140 }
141 } 141 }
142 142
143 net::HostResolver* global_host_resolver = NULL; 143 bool use_async = command_line.HasSwitch(switches::kEnableAsyncDns);
144 if (command_line.HasSwitch(switches::kEnableAsyncDns)) { 144 scoped_ptr<net::HostResolver> global_host_resolver(
145 global_host_resolver = 145 net::HostResolver::CreateSystemResolver(parallelism,
146 net::CreateAsyncHostResolver(parallelism, retry_attempts, net_log); 146 retry_attempts,
147 } 147 true /* use_cache */,
148 148 use_async,
149 if (!global_host_resolver) { 149 net_log));
150 global_host_resolver =
151 net::CreateSystemHostResolver(parallelism, retry_attempts, net_log);
152 }
153 150
154 // Determine if we should disable IPv6 support. 151 // Determine if we should disable IPv6 support.
155 if (!command_line.HasSwitch(switches::kEnableIPv6)) { 152 if (!command_line.HasSwitch(switches::kEnableIPv6)) {
156 if (command_line.HasSwitch(switches::kDisableIPv6)) { 153 if (command_line.HasSwitch(switches::kDisableIPv6)) {
157 global_host_resolver->SetDefaultAddressFamily(net::ADDRESS_FAMILY_IPV4); 154 global_host_resolver->SetDefaultAddressFamily(net::ADDRESS_FAMILY_IPV4);
158 } else { 155 } else {
159 global_host_resolver->ProbeIPv6Support(); 156 global_host_resolver->ProbeIPv6Support();
160 } 157 }
161 } 158 }
162 159
163 // If hostname remappings were specified on the command-line, layer these 160 // If hostname remappings were specified on the command-line, layer these
164 // rules on top of the real host resolver. This allows forwarding all requests 161 // rules on top of the real host resolver. This allows forwarding all requests
165 // through a designated test server. 162 // through a designated test server.
166 if (!command_line.HasSwitch(switches::kHostResolverRules)) 163 if (!command_line.HasSwitch(switches::kHostResolverRules))
167 return global_host_resolver; 164 return global_host_resolver.PassAs<net::HostResolver>();
168 165
169 net::MappedHostResolver* remapped_resolver = 166 scoped_ptr<net::MappedHostResolver> remapped_resolver(
170 new net::MappedHostResolver(global_host_resolver); 167 new net::MappedHostResolver(global_host_resolver.Pass()));
171 remapped_resolver->SetRulesFromString( 168 remapped_resolver->SetRulesFromString(
172 command_line.GetSwitchValueASCII(switches::kHostResolverRules)); 169 command_line.GetSwitchValueASCII(switches::kHostResolverRules));
173 return remapped_resolver; 170 return remapped_resolver.PassAs<net::HostResolver>();
174 } 171 }
175 172
176 // TODO(willchan): Remove proxy script fetcher context since it's not necessary 173 // TODO(willchan): Remove proxy script fetcher context since it's not necessary
177 // now that I got rid of refcounting URLRequestContexts. 174 // now that I got rid of refcounting URLRequestContexts.
178 // See IOThread::Globals for details. 175 // See IOThread::Globals for details.
179 net::URLRequestContext* 176 net::URLRequestContext*
180 ConstructProxyScriptFetcherContext(IOThread::Globals* globals, 177 ConstructProxyScriptFetcherContext(IOThread::Globals* globals,
181 net::NetLog* net_log) { 178 net::NetLog* net_log) {
182 net::URLRequestContext* context = new URLRequestContextWithUserAgent; 179 net::URLRequestContext* context = new URLRequestContextWithUserAgent;
183 context->set_net_log(net_log); 180 context->set_net_log(net_log);
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 NULL, 403 NULL,
407 NULL, 404 NULL,
408 NULL, 405 NULL,
409 &system_enable_referrers_, 406 &system_enable_referrers_,
410 NULL); 407 NULL);
411 if (CommandLine::ForCurrentProcess()->HasSwitch( 408 if (CommandLine::ForCurrentProcess()->HasSwitch(
412 switches::kDisableExtensionsHttpThrottling)) { 409 switches::kDisableExtensionsHttpThrottling)) {
413 network_delegate->NeverThrottleRequests(); 410 network_delegate->NeverThrottleRequests();
414 } 411 }
415 globals_->system_network_delegate.reset(network_delegate); 412 globals_->system_network_delegate.reset(network_delegate);
416 globals_->host_resolver.reset( 413 globals_->host_resolver = CreateGlobalHostResolver(net_log_);
417 CreateGlobalHostResolver(net_log_));
418 globals_->cert_verifier.reset(net::CertVerifier::CreateDefault()); 414 globals_->cert_verifier.reset(net::CertVerifier::CreateDefault());
419 globals_->transport_security_state.reset(new net::TransportSecurityState()); 415 globals_->transport_security_state.reset(new net::TransportSecurityState());
420 globals_->ssl_config_service = GetSSLConfigService(); 416 globals_->ssl_config_service = GetSSLConfigService();
421 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory( 417 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory(
422 globals_->host_resolver.get())); 418 globals_->host_resolver.get()));
423 globals_->http_server_properties.reset(new net::HttpServerPropertiesImpl); 419 globals_->http_server_properties.reset(new net::HttpServerPropertiesImpl);
424 // For the ProxyScriptFetcher, we use a direct ProxyService. 420 // For the ProxyScriptFetcher, we use a direct ProxyService.
425 globals_->proxy_script_fetcher_proxy_service.reset( 421 globals_->proxy_script_fetcher_proxy_service.reset(
426 net::ProxyService::CreateDirectWithNetLog(net_log_)); 422 net::ProxyService::CreateDirectWithNetLog(net_log_));
427 // In-memory cookie store. 423 // In-memory cookie store.
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 new net::HttpNetworkLayer( 626 new net::HttpNetworkLayer(
631 new net::HttpNetworkSession(system_params))); 627 new net::HttpNetworkSession(system_params)));
632 globals_->system_ftp_transaction_factory.reset( 628 globals_->system_ftp_transaction_factory.reset(
633 new net::FtpNetworkLayer(globals_->host_resolver.get())); 629 new net::FtpNetworkLayer(globals_->host_resolver.get()));
634 globals_->system_request_context.reset( 630 globals_->system_request_context.reset(
635 ConstructSystemRequestContext(globals_, net_log_)); 631 ConstructSystemRequestContext(globals_, net_log_));
636 632
637 sdch_manager_->set_sdch_fetcher( 633 sdch_manager_->set_sdch_fetcher(
638 new SdchDictionaryFetcher(system_url_request_context_getter_.get())); 634 new SdchDictionaryFetcher(system_url_request_context_getter_.get()));
639 } 635 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/net/connection_tester.cc » ('j') | net/base/host_resolver.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698