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" | |
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" |
44 | 46 |
45 namespace { | 47 namespace { |
46 | 48 |
47 net::HostResolver* CreateGlobalHostResolver(net::NetLog* net_log) { | 49 net::HostResolver* CreateGlobalHostResolver(net::NetLog* net_log) { |
48 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 50 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
49 | 51 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 net::NetLog::Source(), | 169 net::NetLog::Source(), |
168 net::NetLog::PHASE_NONE, | 170 net::NetLog::PHASE_NONE, |
169 NULL); | 171 NULL); |
170 } | 172 } |
171 | 173 |
172 private: | 174 private: |
173 net::NetLog* net_log_; | 175 net::NetLog* net_log_; |
174 DISALLOW_COPY_AND_ASSIGN(LoggingNetworkChangeObserver); | 176 DISALLOW_COPY_AND_ASSIGN(LoggingNetworkChangeObserver); |
175 }; | 177 }; |
176 | 178 |
179 void InitializeProxyRequestContext(IOThread::Globals* globals, | |
eroman
2010/12/22 01:27:56
See my naming comment.
willchan no longer on Chromium
2010/12/22 02:35:07
Done.
| |
180 net::NetLog* net_log, | |
181 URLRequestContext* context) { | |
182 context->set_net_log(net_log); | |
183 context->set_host_resolver(globals->host_resolver.get()); | |
184 context->set_cert_verifier(globals->cert_verifier.get()); | |
185 context->set_dnsrr_resolver(globals->dnsrr_resolver.get()); | |
186 context->set_http_auth_handler_factory( | |
187 globals->http_auth_handler_factory.get()); | |
188 context->set_proxy_service(globals->proxy_script_fetcher_proxy_service.get()); | |
189 context->set_http_transaction_factory( | |
190 new net::HttpCache( | |
eroman
2010/12/22 01:27:56
We don't need to use an HttpCache here, since the
willchan no longer on Chromium
2010/12/22 02:35:07
Done.
| |
191 globals->host_resolver.get(), | |
192 globals->cert_verifier.get(), | |
193 globals->dnsrr_resolver.get(), | |
194 NULL /* dns_cert_checker */, | |
195 globals->proxy_script_fetcher_proxy_service.get(), | |
196 globals->ssl_config_service.get(), | |
197 globals->http_auth_handler_factory.get(), | |
198 &globals->network_delegate, | |
199 net_log, | |
200 net::HttpCache::DefaultBackend::InMemory(0))); | |
201 // In-memory cookie store. | |
202 context->set_cookie_store(new net::CookieMonster(NULL, NULL)); | |
eroman
2010/12/22 01:27:56
I wander if this might cause some subtle compat is
| |
203 } | |
204 | |
177 } // namespace | 205 } // namespace |
178 | 206 |
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 | 207 // The IOThread object must outlive any tasks posted to the IO thread before the |
208 // Quit task. | 208 // Quit task. |
209 DISABLE_RUNNABLE_METHOD_REFCOUNT(IOThread); | 209 DISABLE_RUNNABLE_METHOD_REFCOUNT(IOThread); |
210 | 210 |
211 IOThread::Globals::Globals() {} | 211 IOThread::Globals::Globals() {} |
212 | 212 |
213 IOThread::Globals::~Globals() {} | 213 IOThread::Globals::~Globals() {} |
214 | 214 |
215 // |local_state| is passed in explicitly in order to (1) reduce implicit | 215 // |local_state| is passed in explicitly in order to (1) reduce implicit |
216 // dependencies and (2) make IOThread more flexible for testing. | 216 // dependencies and (2) make IOThread more flexible for testing. |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 | 294 |
295 void IOThread::ChangedToOnTheRecord() { | 295 void IOThread::ChangedToOnTheRecord() { |
296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
297 message_loop()->PostTask( | 297 message_loop()->PostTask( |
298 FROM_HERE, | 298 FROM_HERE, |
299 NewRunnableMethod( | 299 NewRunnableMethod( |
300 this, | 300 this, |
301 &IOThread::ChangedToOnTheRecordOnIOThread)); | 301 &IOThread::ChangedToOnTheRecordOnIOThread)); |
302 } | 302 } |
303 | 303 |
304 net::ProxyScriptFetcher* IOThread::CreateAndRegisterProxyScriptFetcher( | |
305 URLRequestContext* url_request_context) { | |
306 return new ManagedProxyScriptFetcher(url_request_context, this); | |
307 } | |
308 | |
309 void IOThread::Init() { | 304 void IOThread::Init() { |
310 #if !defined(OS_CHROMEOS) | 305 #if !defined(OS_CHROMEOS) |
311 // TODO(evan): test and enable this on all platforms. | 306 // TODO(evan): test and enable this on all platforms. |
312 // Though this thread is called the "IO" thread, it actually just routes | 307 // 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. | 308 // messages around; it shouldn't be allowed to perform any blocking disk I/O. |
314 base::ThreadRestrictions::SetIOAllowed(false); | 309 base::ThreadRestrictions::SetIOAllowed(false); |
315 #endif | 310 #endif |
316 | 311 |
317 BrowserProcessSubThread::Init(); | 312 BrowserProcessSubThread::Init(); |
318 | 313 |
319 DCHECK_EQ(MessageLoop::TYPE_IO, message_loop()->type()); | 314 DCHECK_EQ(MessageLoop::TYPE_IO, message_loop()->type()); |
320 | 315 |
321 #if defined(USE_NSS) | 316 #if defined(USE_NSS) |
322 net::SetMessageLoopForOCSP(); | 317 net::SetMessageLoopForOCSP(); |
323 #endif // defined(USE_NSS) | 318 #endif // defined(USE_NSS) |
324 | 319 |
325 DCHECK(!globals_); | 320 DCHECK(!globals_); |
326 globals_ = new Globals; | 321 globals_ = new Globals; |
327 | 322 |
328 // Add an observer that will emit network change events to the ChromeNetLog. | 323 // Add an observer that will emit network change events to the ChromeNetLog. |
329 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be | 324 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be |
330 // logging the network change before other IO thread consumers respond to it. | 325 // logging the network change before other IO thread consumers respond to it. |
331 network_change_observer_.reset( | 326 network_change_observer_.reset( |
332 new LoggingNetworkChangeObserver(net_log_)); | 327 new LoggingNetworkChangeObserver(net_log_)); |
333 | 328 |
334 globals_->host_resolver.reset( | 329 globals_->host_resolver.reset( |
335 CreateGlobalHostResolver(net_log_)); | 330 CreateGlobalHostResolver(net_log_)); |
336 globals_->cert_verifier.reset(new net::CertVerifier); | 331 globals_->cert_verifier.reset(new net::CertVerifier); |
337 globals_->dnsrr_resolver.reset(new net::DnsRRResolver); | 332 globals_->dnsrr_resolver.reset(new net::DnsRRResolver); |
333 // TODO(willchan): Use the real SSLConfigService. | |
334 globals_->ssl_config_service = | |
335 net::SSLConfigService::CreateSystemSSLConfigService(); | |
338 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory( | 336 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory( |
339 globals_->host_resolver.get())); | 337 globals_->host_resolver.get())); |
338 // For the ProxyScriptFetcher, we use a direct ProxyService. | |
339 globals_->proxy_script_fetcher_proxy_service = | |
340 net::ProxyService::CreateDirectWithNetLog(net_log_); | |
341 | |
342 URLRequestContext* proxy_request_context = new URLRequestContext; | |
eroman
2010/12/22 01:27:56
See my naming suggestion.
willchan no longer on Chromium
2010/12/22 02:35:07
Done.
| |
343 InitializeProxyRequestContext(globals_, net_log_, proxy_request_context); | |
eroman
2010/12/22 01:27:56
How about making this a "Create()" method instead?
willchan no longer on Chromium
2010/12/22 02:35:07
Done.
| |
344 globals_->proxy_request_context = proxy_request_context; | |
340 | 345 |
341 if (CommandLine::ForCurrentProcess()->HasSwitch( | 346 if (CommandLine::ForCurrentProcess()->HasSwitch( |
342 switches::kEnablePagePrerender)) { | 347 switches::kEnablePagePrerender)) { |
343 prerender_interceptor_.reset(new PrerenderInterceptor()); | 348 prerender_interceptor_.reset(new PrerenderInterceptor()); |
344 } | 349 } |
345 } | 350 } |
346 | 351 |
347 void IOThread::CleanUp() { | 352 void IOThread::CleanUp() { |
348 // Step 1: Kill all things that might be holding onto | 353 // Step 1: Kill all things that might be holding onto |
349 // net::URLRequest/URLRequestContexts. | 354 // net::URLRequest/URLRequestContexts. |
350 | 355 |
351 #if defined(USE_NSS) | 356 #if defined(USE_NSS) |
352 net::ShutdownOCSP(); | 357 net::ShutdownOCSP(); |
353 #endif // defined(USE_NSS) | 358 #endif // defined(USE_NSS) |
354 | 359 |
355 // Destroy all URLRequests started by URLFetchers. | 360 // Destroy all URLRequests started by URLFetchers. |
356 URLFetcher::CancelAll(); | 361 URLFetcher::CancelAll(); |
357 | 362 |
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 | 363 // If any child processes are still running, terminate them and |
376 // and delete the BrowserChildProcessHost instances to release whatever | 364 // and delete the BrowserChildProcessHost instances to release whatever |
377 // IO thread only resources they are referencing. | 365 // IO thread only resources they are referencing. |
378 BrowserChildProcessHost::TerminateAll(); | 366 BrowserChildProcessHost::TerminateAll(); |
379 | 367 |
380 std::list<ChromeURLRequestContextGetter*> url_request_context_getters; | 368 std::list<ChromeURLRequestContextGetter*> url_request_context_getters; |
381 url_request_context_getters.swap(url_request_context_getters_); | 369 url_request_context_getters.swap(url_request_context_getters_); |
382 for (std::list<ChromeURLRequestContextGetter*>::iterator it = | 370 for (std::list<ChromeURLRequestContextGetter*>::iterator it = |
383 url_request_context_getters.begin(); | 371 url_request_context_getters.begin(); |
384 it != url_request_context_getters.end(); ++it) { | 372 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 = | 505 net::HostCache* host_cache = |
518 globals_->host_resolver.get()->GetAsHostResolverImpl()->cache(); | 506 globals_->host_resolver.get()->GetAsHostResolverImpl()->cache(); |
519 if (host_cache) | 507 if (host_cache) |
520 host_cache->clear(); | 508 host_cache->clear(); |
521 } | 509 } |
522 // Clear all of the passively logged data. | 510 // Clear all of the passively logged data. |
523 // TODO(eroman): this is a bit heavy handed, really all we need to do is | 511 // 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. | 512 // clear the data pertaining to off the record context. |
525 net_log_->ClearAllPassivelyCapturedEvents(); | 513 net_log_->ClearAllPassivelyCapturedEvents(); |
526 } | 514 } |
OLD | NEW |