Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/debug/leak_tracker.h" | 10 #include "base/debug/leak_tracker.h" |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
| 31 #include "net/base/cert_verifier.h" | 31 #include "net/base/cert_verifier.h" |
| 32 #include "net/base/dnsrr_resolver.h" | 32 #include "net/base/dnsrr_resolver.h" |
| 33 #include "net/base/host_cache.h" | 33 #include "net/base/host_cache.h" |
| 34 #include "net/base/host_resolver.h" | 34 #include "net/base/host_resolver.h" |
| 35 #include "net/base/host_resolver_impl.h" | 35 #include "net/base/host_resolver_impl.h" |
| 36 #include "net/base/mapped_host_resolver.h" | 36 #include "net/base/mapped_host_resolver.h" |
| 37 #include "net/base/net_util.h" | 37 #include "net/base/net_util.h" |
| 38 #include "net/http/http_auth_filter.h" | 38 #include "net/http/http_auth_filter.h" |
| 39 #include "net/http/http_auth_handler_factory.h" | 39 #include "net/http/http_auth_handler_factory.h" |
| 40 #include "net/http/http_cache.h" | |
|
eroman
2010/12/23 01:40:59
Is this header still needed?
willchan no longer on Chromium
2010/12/23 23:51:58
Done.
| |
| 41 #include "net/http/http_network_layer.h" | |
| 40 #if defined(USE_NSS) | 42 #if defined(USE_NSS) |
| 41 #include "net/ocsp/nss_ocsp.h" | 43 #include "net/ocsp/nss_ocsp.h" |
| 42 #endif // defined(USE_NSS) | 44 #endif // defined(USE_NSS) |
| 43 #include "net/proxy/proxy_script_fetcher_impl.h" | 45 #include "net/proxy/proxy_script_fetcher_impl.h" |
| 46 #include "net/socket/client_socket_factory.h" | |
| 47 #include "net/spdy/spdy_session_pool.h" | |
| 44 | 48 |
| 45 namespace { | 49 namespace { |
| 46 | 50 |
| 47 net::HostResolver* CreateGlobalHostResolver(net::NetLog* net_log) { | 51 net::HostResolver* CreateGlobalHostResolver(net::NetLog* net_log) { |
| 48 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 52 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 49 | 53 |
| 50 size_t parallelism = net::HostResolver::kDefaultParallelism; | 54 size_t parallelism = net::HostResolver::kDefaultParallelism; |
| 51 | 55 |
| 52 // Use the concurrency override from the command-line, if any. | 56 // Use the concurrency override from the command-line, if any. |
| 53 if (command_line.HasSwitch(switches::kHostResolverParallelism)) { | 57 if (command_line.HasSwitch(switches::kHostResolverParallelism)) { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 net::NetLog::Source(), | 171 net::NetLog::Source(), |
| 168 net::NetLog::PHASE_NONE, | 172 net::NetLog::PHASE_NONE, |
| 169 NULL); | 173 NULL); |
| 170 } | 174 } |
| 171 | 175 |
| 172 private: | 176 private: |
| 173 net::NetLog* net_log_; | 177 net::NetLog* net_log_; |
| 174 DISALLOW_COPY_AND_ASSIGN(LoggingNetworkChangeObserver); | 178 DISALLOW_COPY_AND_ASSIGN(LoggingNetworkChangeObserver); |
| 175 }; | 179 }; |
| 176 | 180 |
| 181 scoped_refptr<URLRequestContext> | |
| 182 ConstructProxyScriptFetcherContext(IOThread::Globals* globals, | |
| 183 net::NetLog* net_log) { | |
| 184 scoped_refptr<URLRequestContext> context(new URLRequestContext); | |
| 185 context->set_net_log(net_log); | |
| 186 context->set_host_resolver(globals->host_resolver.get()); | |
| 187 context->set_cert_verifier(globals->cert_verifier.get()); | |
| 188 context->set_dnsrr_resolver(globals->dnsrr_resolver.get()); | |
| 189 context->set_http_auth_handler_factory( | |
| 190 globals->http_auth_handler_factory.get()); | |
| 191 context->set_proxy_service(globals->proxy_script_fetcher_proxy_service.get()); | |
| 192 context->set_http_transaction_factory( | |
| 193 new net::HttpNetworkLayer( | |
| 194 globals->client_socket_factory, | |
| 195 globals->host_resolver.get(), | |
| 196 globals->cert_verifier.get(), | |
| 197 globals->dnsrr_resolver.get(), | |
| 198 NULL /* dns_cert_checker */, | |
| 199 NULL /* ssl_host_info_factory */, | |
| 200 globals->proxy_script_fetcher_proxy_service.get(), | |
| 201 globals->ssl_config_service.get(), | |
| 202 new net::SpdySessionPool(globals->ssl_config_service.get()), | |
|
eroman
2010/12/23 01:40:59
Does HttpNetworkLayer take ownership of the sessio
willchan no longer on Chromium
2010/12/23 23:51:58
Takes ownership. It's sort of weird. I'm hoping
| |
| 203 globals->http_auth_handler_factory.get(), | |
| 204 &globals->network_delegate, | |
| 205 net_log)); | |
| 206 // In-memory cookie store. | |
| 207 context->set_cookie_store(new net::CookieMonster(NULL, NULL)); | |
| 208 return context; | |
| 209 } | |
| 210 | |
| 177 } // namespace | 211 } // namespace |
| 178 | 212 |
| 179 // This is a wrapper class around ProxyScriptFetcherImpl that will | |
| 180 // keep track of live instances. | |
| 181 class IOThread::ManagedProxyScriptFetcher | |
| 182 : public net::ProxyScriptFetcherImpl { | |
| 183 public: | |
| 184 ManagedProxyScriptFetcher(URLRequestContext* context, | |
| 185 IOThread* io_thread) | |
| 186 : net::ProxyScriptFetcherImpl(context), | |
| 187 io_thread_(io_thread) { | |
| 188 DCHECK(!ContainsKey(*fetchers(), this)); | |
| 189 fetchers()->insert(this); | |
| 190 } | |
| 191 | |
| 192 virtual ~ManagedProxyScriptFetcher() { | |
| 193 DCHECK(ContainsKey(*fetchers(), this)); | |
| 194 fetchers()->erase(this); | |
| 195 } | |
| 196 | |
| 197 private: | |
| 198 ProxyScriptFetchers* fetchers() { | |
| 199 return &io_thread_->fetchers_; | |
| 200 } | |
| 201 | |
| 202 IOThread* io_thread_; | |
| 203 | |
| 204 DISALLOW_COPY_AND_ASSIGN(ManagedProxyScriptFetcher); | |
| 205 }; | |
| 206 | |
| 207 // The IOThread object must outlive any tasks posted to the IO thread before the | 213 // The IOThread object must outlive any tasks posted to the IO thread before the |
| 208 // Quit task. | 214 // Quit task. |
| 209 DISABLE_RUNNABLE_METHOD_REFCOUNT(IOThread); | 215 DISABLE_RUNNABLE_METHOD_REFCOUNT(IOThread); |
| 210 | 216 |
| 211 IOThread::Globals::Globals() {} | 217 IOThread::Globals::Globals() {} |
| 212 | 218 |
| 213 IOThread::Globals::~Globals() {} | 219 IOThread::Globals::~Globals() {} |
| 214 | 220 |
| 215 // |local_state| is passed in explicitly in order to (1) reduce implicit | 221 // |local_state| is passed in explicitly in order to (1) reduce implicit |
| 216 // dependencies and (2) make IOThread more flexible for testing. | 222 // dependencies and (2) make IOThread more flexible for testing. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 | 300 |
| 295 void IOThread::ChangedToOnTheRecord() { | 301 void IOThread::ChangedToOnTheRecord() { |
| 296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 302 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 297 message_loop()->PostTask( | 303 message_loop()->PostTask( |
| 298 FROM_HERE, | 304 FROM_HERE, |
| 299 NewRunnableMethod( | 305 NewRunnableMethod( |
| 300 this, | 306 this, |
| 301 &IOThread::ChangedToOnTheRecordOnIOThread)); | 307 &IOThread::ChangedToOnTheRecordOnIOThread)); |
| 302 } | 308 } |
| 303 | 309 |
| 304 net::ProxyScriptFetcher* IOThread::CreateAndRegisterProxyScriptFetcher( | |
| 305 URLRequestContext* url_request_context) { | |
| 306 return new ManagedProxyScriptFetcher(url_request_context, this); | |
| 307 } | |
| 308 | |
| 309 void IOThread::Init() { | 310 void IOThread::Init() { |
| 310 #if !defined(OS_CHROMEOS) | 311 #if !defined(OS_CHROMEOS) |
| 311 // TODO(evan): test and enable this on all platforms. | 312 // TODO(evan): test and enable this on all platforms. |
| 312 // Though this thread is called the "IO" thread, it actually just routes | 313 // Though this thread is called the "IO" thread, it actually just routes |
| 313 // messages around; it shouldn't be allowed to perform any blocking disk I/O. | 314 // messages around; it shouldn't be allowed to perform any blocking disk I/O. |
| 314 base::ThreadRestrictions::SetIOAllowed(false); | 315 base::ThreadRestrictions::SetIOAllowed(false); |
| 315 #endif | 316 #endif |
| 316 | 317 |
| 317 BrowserProcessSubThread::Init(); | 318 BrowserProcessSubThread::Init(); |
| 318 | 319 |
| 319 DCHECK_EQ(MessageLoop::TYPE_IO, message_loop()->type()); | 320 DCHECK_EQ(MessageLoop::TYPE_IO, message_loop()->type()); |
| 320 | 321 |
| 321 #if defined(USE_NSS) | 322 #if defined(USE_NSS) |
| 322 net::SetMessageLoopForOCSP(); | 323 net::SetMessageLoopForOCSP(); |
| 323 #endif // defined(USE_NSS) | 324 #endif // defined(USE_NSS) |
| 324 | 325 |
| 325 DCHECK(!globals_); | 326 DCHECK(!globals_); |
| 326 globals_ = new Globals; | 327 globals_ = new Globals; |
| 327 | 328 |
| 328 // Add an observer that will emit network change events to the ChromeNetLog. | 329 // Add an observer that will emit network change events to the ChromeNetLog. |
| 329 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be | 330 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be |
| 330 // logging the network change before other IO thread consumers respond to it. | 331 // logging the network change before other IO thread consumers respond to it. |
| 331 network_change_observer_.reset( | 332 network_change_observer_.reset( |
| 332 new LoggingNetworkChangeObserver(net_log_)); | 333 new LoggingNetworkChangeObserver(net_log_)); |
| 333 | 334 |
| 335 globals_->client_socket_factory = | |
| 336 net::ClientSocketFactory::GetDefaultFactory(); | |
| 334 globals_->host_resolver.reset( | 337 globals_->host_resolver.reset( |
| 335 CreateGlobalHostResolver(net_log_)); | 338 CreateGlobalHostResolver(net_log_)); |
| 336 globals_->cert_verifier.reset(new net::CertVerifier); | 339 globals_->cert_verifier.reset(new net::CertVerifier); |
| 337 globals_->dnsrr_resolver.reset(new net::DnsRRResolver); | 340 globals_->dnsrr_resolver.reset(new net::DnsRRResolver); |
| 341 // TODO(willchan): Use the real SSLConfigService. | |
| 342 globals_->ssl_config_service = | |
| 343 net::SSLConfigService::CreateSystemSSLConfigService(); | |
| 338 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory( | 344 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory( |
| 339 globals_->host_resolver.get())); | 345 globals_->host_resolver.get())); |
| 346 // For the ProxyScriptFetcher, we use a direct ProxyService. | |
| 347 globals_->proxy_script_fetcher_proxy_service = | |
| 348 net::ProxyService::CreateDirectWithNetLog(net_log_); | |
| 349 | |
| 350 scoped_refptr<URLRequestContext> proxy_script_fetcher_context = | |
| 351 ConstructProxyScriptFetcherContext(globals_, net_log_); | |
| 352 globals_->proxy_script_fetcher_context = proxy_script_fetcher_context; | |
| 340 | 353 |
| 341 if (CommandLine::ForCurrentProcess()->HasSwitch( | 354 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 342 switches::kEnablePagePrerender)) { | 355 switches::kEnablePagePrerender)) { |
| 343 prerender_interceptor_.reset(new PrerenderInterceptor()); | 356 prerender_interceptor_.reset(new PrerenderInterceptor()); |
| 344 } | 357 } |
| 345 } | 358 } |
| 346 | 359 |
| 347 void IOThread::CleanUp() { | 360 void IOThread::CleanUp() { |
| 348 // Step 1: Kill all things that might be holding onto | 361 // Step 1: Kill all things that might be holding onto |
| 349 // net::URLRequest/URLRequestContexts. | 362 // net::URLRequest/URLRequestContexts. |
| 350 | 363 |
| 351 #if defined(USE_NSS) | 364 #if defined(USE_NSS) |
| 352 net::ShutdownOCSP(); | 365 net::ShutdownOCSP(); |
| 353 #endif // defined(USE_NSS) | 366 #endif // defined(USE_NSS) |
| 354 | 367 |
| 355 // Destroy all URLRequests started by URLFetchers. | 368 // Destroy all URLRequests started by URLFetchers. |
| 356 URLFetcher::CancelAll(); | 369 URLFetcher::CancelAll(); |
| 357 | 370 |
| 358 // Break any cycles between the ProxyScriptFetcher and URLRequestContext. | |
| 359 for (ProxyScriptFetchers::const_iterator it = fetchers_.begin(); | |
| 360 it != fetchers_.end();) { | |
| 361 ManagedProxyScriptFetcher* fetcher = *it; | |
| 362 { | |
| 363 // Hang on to the context while cancelling to avoid problems | |
| 364 // with the cancellation causing the context to be destroyed | |
| 365 // (see http://crbug.com/63796 ). Ideally, the IOThread would | |
| 366 // own the URLRequestContexts. | |
| 367 scoped_refptr<URLRequestContext> context(fetcher->GetRequestContext()); | |
| 368 fetcher->Cancel(); | |
| 369 } | |
| 370 // Any number of fetchers may have been deleted at this point, so | |
| 371 // use upper_bound instead of a simple increment. | |
| 372 it = fetchers_.upper_bound(fetcher); | |
| 373 } | |
| 374 | |
| 375 // If any child processes are still running, terminate them and | 371 // If any child processes are still running, terminate them and |
| 376 // and delete the BrowserChildProcessHost instances to release whatever | 372 // and delete the BrowserChildProcessHost instances to release whatever |
| 377 // IO thread only resources they are referencing. | 373 // IO thread only resources they are referencing. |
| 378 BrowserChildProcessHost::TerminateAll(); | 374 BrowserChildProcessHost::TerminateAll(); |
| 379 | 375 |
| 380 std::list<ChromeURLRequestContextGetter*> url_request_context_getters; | 376 std::list<ChromeURLRequestContextGetter*> url_request_context_getters; |
| 381 url_request_context_getters.swap(url_request_context_getters_); | 377 url_request_context_getters.swap(url_request_context_getters_); |
| 382 for (std::list<ChromeURLRequestContextGetter*>::iterator it = | 378 for (std::list<ChromeURLRequestContextGetter*>::iterator it = |
| 383 url_request_context_getters.begin(); | 379 url_request_context_getters.begin(); |
| 384 it != url_request_context_getters.end(); ++it) { | 380 it != url_request_context_getters.end(); ++it) { |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 517 net::HostCache* host_cache = | 513 net::HostCache* host_cache = |
| 518 globals_->host_resolver.get()->GetAsHostResolverImpl()->cache(); | 514 globals_->host_resolver.get()->GetAsHostResolverImpl()->cache(); |
| 519 if (host_cache) | 515 if (host_cache) |
| 520 host_cache->clear(); | 516 host_cache->clear(); |
| 521 } | 517 } |
| 522 // Clear all of the passively logged data. | 518 // Clear all of the passively logged data. |
| 523 // TODO(eroman): this is a bit heavy handed, really all we need to do is | 519 // TODO(eroman): this is a bit heavy handed, really all we need to do is |
| 524 // clear the data pertaining to off the record context. | 520 // clear the data pertaining to off the record context. |
| 525 net_log_->ClearAllPassivelyCapturedEvents(); | 521 net_log_->ClearAllPassivelyCapturedEvents(); |
| 526 } | 522 } |
| OLD | NEW |