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

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: add ChromeBrowserFieldTrials::AsyncDnsFieldTrial 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
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 // Configured by ChromeBrowserFieldTrials::AsyncDnsFieldTrial.
111 scoped_ptr<net::HostResolver> global_host_resolver(
112 net::HostResolver::CreateDefaultResolver(net_log));
113
110 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 114 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
111
112 size_t parallelism = net::HostResolver::kDefaultParallelism;
113
114 // Use the concurrency override from the command-line, if any.
115 if (command_line.HasSwitch(switches::kHostResolverParallelism)) {
116 std::string s =
117 command_line.GetSwitchValueASCII(switches::kHostResolverParallelism);
118
119 // Parse the switch (it should be a positive integer formatted as decimal).
120 int n;
121 if (base::StringToInt(s, &n) && n > 0) {
122 parallelism = static_cast<size_t>(n);
123 } else {
124 LOG(ERROR) << "Invalid switch for host resolver parallelism: " << s;
125 }
126 }
127
128 size_t retry_attempts = net::HostResolver::kDefaultRetryAttempts;
129
130 // Use the retry attempts override from the command-line, if any.
131 if (command_line.HasSwitch(switches::kHostResolverRetryAttempts)) {
132 std::string s =
133 command_line.GetSwitchValueASCII(switches::kHostResolverRetryAttempts);
134 // Parse the switch (it should be a non-negative integer).
135 int n;
136 if (base::StringToInt(s, &n) && n >= 0) {
137 retry_attempts = static_cast<size_t>(n);
138 } else {
139 LOG(ERROR) << "Invalid switch for host resolver retry attempts: " << s;
140 }
141 }
142
143 net::HostResolver* global_host_resolver = NULL;
144 if (command_line.HasSwitch(switches::kEnableAsyncDns)) {
145 global_host_resolver =
146 net::CreateAsyncHostResolver(parallelism, retry_attempts, net_log);
147 }
148
149 if (!global_host_resolver) {
150 global_host_resolver =
151 net::CreateSystemHostResolver(parallelism, retry_attempts, net_log);
152 }
153
154 // Determine if we should disable IPv6 support. 115 // Determine if we should disable IPv6 support.
155 if (!command_line.HasSwitch(switches::kEnableIPv6)) { 116 if (!command_line.HasSwitch(switches::kEnableIPv6)) {
156 if (command_line.HasSwitch(switches::kDisableIPv6)) { 117 if (command_line.HasSwitch(switches::kDisableIPv6)) {
157 global_host_resolver->SetDefaultAddressFamily(net::ADDRESS_FAMILY_IPV4); 118 global_host_resolver->SetDefaultAddressFamily(net::ADDRESS_FAMILY_IPV4);
158 } else { 119 } else {
159 global_host_resolver->ProbeIPv6Support(); 120 global_host_resolver->ProbeIPv6Support();
160 } 121 }
161 } 122 }
162 123
163 // If hostname remappings were specified on the command-line, layer these 124 // 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 125 // rules on top of the real host resolver. This allows forwarding all requests
165 // through a designated test server. 126 // through a designated test server.
166 if (!command_line.HasSwitch(switches::kHostResolverRules)) 127 if (!command_line.HasSwitch(switches::kHostResolverRules))
167 return global_host_resolver; 128 return global_host_resolver.PassAs<net::HostResolver>();
168 129
169 net::MappedHostResolver* remapped_resolver = 130 scoped_ptr<net::MappedHostResolver> remapped_resolver(
170 new net::MappedHostResolver(global_host_resolver); 131 new net::MappedHostResolver(global_host_resolver.Pass()));
171 remapped_resolver->SetRulesFromString( 132 remapped_resolver->SetRulesFromString(
172 command_line.GetSwitchValueASCII(switches::kHostResolverRules)); 133 command_line.GetSwitchValueASCII(switches::kHostResolverRules));
173 return remapped_resolver; 134 return remapped_resolver.PassAs<net::HostResolver>();
174 } 135 }
175 136
176 // TODO(willchan): Remove proxy script fetcher context since it's not necessary 137 // TODO(willchan): Remove proxy script fetcher context since it's not necessary
177 // now that I got rid of refcounting URLRequestContexts. 138 // now that I got rid of refcounting URLRequestContexts.
178 // See IOThread::Globals for details. 139 // See IOThread::Globals for details.
179 net::URLRequestContext* 140 net::URLRequestContext*
180 ConstructProxyScriptFetcherContext(IOThread::Globals* globals, 141 ConstructProxyScriptFetcherContext(IOThread::Globals* globals,
181 net::NetLog* net_log) { 142 net::NetLog* net_log) {
182 net::URLRequestContext* context = new URLRequestContextWithUserAgent; 143 net::URLRequestContext* context = new URLRequestContextWithUserAgent;
183 context->set_net_log(net_log); 144 context->set_net_log(net_log);
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 NULL, 367 NULL,
407 NULL, 368 NULL,
408 NULL, 369 NULL,
409 &system_enable_referrers_, 370 &system_enable_referrers_,
410 NULL); 371 NULL);
411 if (CommandLine::ForCurrentProcess()->HasSwitch( 372 if (CommandLine::ForCurrentProcess()->HasSwitch(
412 switches::kDisableExtensionsHttpThrottling)) { 373 switches::kDisableExtensionsHttpThrottling)) {
413 network_delegate->NeverThrottleRequests(); 374 network_delegate->NeverThrottleRequests();
414 } 375 }
415 globals_->system_network_delegate.reset(network_delegate); 376 globals_->system_network_delegate.reset(network_delegate);
416 globals_->host_resolver.reset( 377 globals_->host_resolver = CreateGlobalHostResolver(net_log_);
417 CreateGlobalHostResolver(net_log_));
418 globals_->cert_verifier.reset(net::CertVerifier::CreateDefault()); 378 globals_->cert_verifier.reset(net::CertVerifier::CreateDefault());
419 globals_->transport_security_state.reset(new net::TransportSecurityState()); 379 globals_->transport_security_state.reset(new net::TransportSecurityState());
420 globals_->ssl_config_service = GetSSLConfigService(); 380 globals_->ssl_config_service = GetSSLConfigService();
421 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory( 381 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory(
422 globals_->host_resolver.get())); 382 globals_->host_resolver.get()));
423 globals_->http_server_properties.reset(new net::HttpServerPropertiesImpl); 383 globals_->http_server_properties.reset(new net::HttpServerPropertiesImpl);
424 // For the ProxyScriptFetcher, we use a direct ProxyService. 384 // For the ProxyScriptFetcher, we use a direct ProxyService.
425 globals_->proxy_script_fetcher_proxy_service.reset( 385 globals_->proxy_script_fetcher_proxy_service.reset(
426 net::ProxyService::CreateDirectWithNetLog(net_log_)); 386 net::ProxyService::CreateDirectWithNetLog(net_log_));
427 // In-memory cookie store. 387 // In-memory cookie store.
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 new net::HttpNetworkLayer( 590 new net::HttpNetworkLayer(
631 new net::HttpNetworkSession(system_params))); 591 new net::HttpNetworkSession(system_params)));
632 globals_->system_ftp_transaction_factory.reset( 592 globals_->system_ftp_transaction_factory.reset(
633 new net::FtpNetworkLayer(globals_->host_resolver.get())); 593 new net::FtpNetworkLayer(globals_->host_resolver.get()));
634 globals_->system_request_context.reset( 594 globals_->system_request_context.reset(
635 ConstructSystemRequestContext(globals_, net_log_)); 595 ConstructSystemRequestContext(globals_, net_log_));
636 596
637 sdch_manager_->set_sdch_fetcher( 597 sdch_manager_->set_sdch_fetcher(
638 new SdchDictionaryFetcher(system_url_request_context_getter_.get())); 598 new SdchDictionaryFetcher(system_url_request_context_getter_.get()));
639 } 599 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698