OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/metrics/field_trial.h" | 12 #include "base/metrics/field_trial.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
15 #include "base/string_split.h" | 15 #include "base/string_split.h" |
16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
17 #include "base/threading/thread_restrictions.h" | 17 #include "base/threading/thread_restrictions.h" |
18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
20 #include "chrome/browser/extensions/extension_event_router_forwarder.h" | 20 #include "chrome/browser/extensions/extension_event_router_forwarder.h" |
21 #include "chrome/browser/media/media_internals.h" | 21 #include "chrome/browser/media/media_internals.h" |
22 #include "chrome/browser/net/chrome_network_delegate.h" | 22 #include "chrome/browser/net/chrome_network_delegate.h" |
23 #include "chrome/browser/net/chrome_net_log.h" | 23 #include "chrome/browser/net/chrome_net_log.h" |
24 #include "chrome/browser/net/chrome_url_request_context.h" | 24 #include "chrome/browser/net/chrome_url_request_context.h" |
25 #include "chrome/browser/net/connect_interceptor.h" | 25 #include "chrome/browser/net/connect_interceptor.h" |
26 #include "chrome/browser/net/passive_log_collector.h" | 26 #include "chrome/browser/net/passive_log_collector.h" |
27 #include "chrome/browser/net/predictor_api.h" | 27 #include "chrome/browser/net/predictor.h" |
28 #include "chrome/browser/net/pref_proxy_config_service.h" | 28 #include "chrome/browser/net/pref_proxy_config_service.h" |
29 #include "chrome/browser/net/proxy_service_factory.h" | 29 #include "chrome/browser/net/proxy_service_factory.h" |
30 #include "chrome/browser/prefs/pref_service.h" | 30 #include "chrome/browser/prefs/pref_service.h" |
31 #include "chrome/common/chrome_switches.h" | 31 #include "chrome/common/chrome_switches.h" |
32 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
33 #include "content/browser/browser_thread.h" | 33 #include "content/browser/browser_thread.h" |
34 #include "content/browser/gpu/gpu_process_host.h" | 34 #include "content/browser/gpu/gpu_process_host.h" |
35 #include "content/browser/in_process_webkit/indexed_db_key_utility_client.h" | 35 #include "content/browser/in_process_webkit/indexed_db_key_utility_client.h" |
36 #include "content/common/url_fetcher.h" | 36 #include "content/common/url_fetcher.h" |
37 #include "net/base/cert_verifier.h" | 37 #include "net/base/cert_verifier.h" |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 // |local_state| is passed in explicitly in order to (1) reduce implicit | 333 // |local_state| is passed in explicitly in order to (1) reduce implicit |
334 // dependencies and (2) make IOThread more flexible for testing. | 334 // dependencies and (2) make IOThread more flexible for testing. |
335 IOThread::IOThread( | 335 IOThread::IOThread( |
336 PrefService* local_state, | 336 PrefService* local_state, |
337 ChromeNetLog* net_log, | 337 ChromeNetLog* net_log, |
338 ExtensionEventRouterForwarder* extension_event_router_forwarder) | 338 ExtensionEventRouterForwarder* extension_event_router_forwarder) |
339 : BrowserProcessSubThread(BrowserThread::IO), | 339 : BrowserProcessSubThread(BrowserThread::IO), |
340 net_log_(net_log), | 340 net_log_(net_log), |
341 extension_event_router_forwarder_(extension_event_router_forwarder), | 341 extension_event_router_forwarder_(extension_event_router_forwarder), |
342 globals_(NULL), | 342 globals_(NULL), |
343 speculative_interceptor_(NULL), | |
344 predictor_(NULL), | |
345 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 343 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
346 // We call RegisterPrefs() here (instead of inside browser_prefs.cc) to make | 344 // We call RegisterPrefs() here (instead of inside browser_prefs.cc) to make |
347 // sure that everything is initialized in the right order. | 345 // sure that everything is initialized in the right order. |
348 RegisterPrefs(local_state); | 346 RegisterPrefs(local_state); |
349 auth_schemes_ = local_state->GetString(prefs::kAuthSchemes); | 347 auth_schemes_ = local_state->GetString(prefs::kAuthSchemes); |
350 negotiate_disable_cname_lookup_ = local_state->GetBoolean( | 348 negotiate_disable_cname_lookup_ = local_state->GetBoolean( |
351 prefs::kDisableAuthNegotiateCnameLookup); | 349 prefs::kDisableAuthNegotiateCnameLookup); |
352 negotiate_enable_port_ = local_state->GetBoolean( | 350 negotiate_enable_port_ = local_state->GetBoolean( |
353 prefs::kEnableAuthNegotiatePort); | 351 prefs::kEnableAuthNegotiatePort); |
354 auth_server_whitelist_ = local_state->GetString(prefs::kAuthServerWhitelist); | 352 auth_server_whitelist_ = local_state->GetString(prefs::kAuthServerWhitelist); |
(...skipping 21 matching lines...) Expand all Loading... | |
376 | 374 |
377 IOThread::Globals* IOThread::globals() { | 375 IOThread::Globals* IOThread::globals() { |
378 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 376 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
379 return globals_; | 377 return globals_; |
380 } | 378 } |
381 | 379 |
382 ChromeNetLog* IOThread::net_log() { | 380 ChromeNetLog* IOThread::net_log() { |
383 return net_log_; | 381 return net_log_; |
384 } | 382 } |
385 | 383 |
386 void IOThread::InitNetworkPredictor( | 384 void IOThread::InitNetworkPredictor( |
willchan no longer on Chromium
2011/08/10 16:10:35
Please kill off IOThread::InitNetworkPredictor().
rpetterson
2011/08/12 03:12:36
Done.
| |
387 bool prefetching_enabled, | |
388 base::TimeDelta max_dns_queue_delay, | |
389 size_t max_speculative_parallel_resolves, | |
390 const chrome_common_net::UrlList& startup_urls, | 385 const chrome_common_net::UrlList& startup_urls, |
391 ListValue* referral_list, | 386 ListValue* referral_list, |
392 bool preconnect_enabled) { | 387 chrome_browser_net::Predictor* predictor) { |
393 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
394 message_loop()->PostTask( | 389 message_loop()->PostTask( |
395 FROM_HERE, | 390 FROM_HERE, |
396 NewRunnableMethod( | 391 NewRunnableMethod( |
397 this, | 392 this, |
398 &IOThread::InitNetworkPredictorOnIOThread, | 393 &IOThread::InitNetworkPredictorOnIOThread, |
399 prefetching_enabled, max_dns_queue_delay, | 394 startup_urls, referral_list, predictor)); |
400 max_speculative_parallel_resolves, | |
401 startup_urls, referral_list, preconnect_enabled)); | |
402 } | |
403 | |
404 void IOThread::ChangedToOnTheRecord() { | |
405 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
406 message_loop()->PostTask( | |
407 FROM_HERE, | |
408 NewRunnableMethod( | |
409 this, | |
410 &IOThread::ChangedToOnTheRecordOnIOThread)); | |
411 } | 395 } |
412 | 396 |
413 net::URLRequestContextGetter* IOThread::system_url_request_context_getter() { | 397 net::URLRequestContextGetter* IOThread::system_url_request_context_getter() { |
414 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 398 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
415 if (!system_url_request_context_getter_) { | 399 if (!system_url_request_context_getter_) { |
416 InitSystemRequestContext(); | 400 InitSystemRequestContext(); |
417 } | 401 } |
418 return system_url_request_context_getter_; | 402 return system_url_request_context_getter_; |
419 } | 403 } |
420 | 404 |
421 void IOThread::ClearNetworkingHistory() { | 405 void IOThread::ClearNetworkingHistory( |
406 chrome_browser_net::Predictor* predictor) { | |
422 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 407 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
423 ClearHostCache(); | 408 ClearHostCache(); |
424 // Discard acrued data used to speculate in the future. | 409 // Discard acrued data used to speculate in the future. |
425 chrome_browser_net::DiscardInitialNavigationHistory(); | 410 if (predictor) { |
426 if (predictor_) | 411 predictor->DiscardInitialNavigationHistory(); |
427 predictor_->DiscardAllResults(); | 412 predictor->DiscardAllResults(); |
413 } | |
428 } | 414 } |
429 | 415 |
430 void IOThread::Init() { | 416 void IOThread::Init() { |
431 // Though this thread is called the "IO" thread, it actually just routes | 417 // Though this thread is called the "IO" thread, it actually just routes |
432 // messages around; it shouldn't be allowed to perform any blocking disk I/O. | 418 // messages around; it shouldn't be allowed to perform any blocking disk I/O. |
433 base::ThreadRestrictions::SetIOAllowed(false); | 419 base::ThreadRestrictions::SetIOAllowed(false); |
434 | 420 |
435 BrowserProcessSubThread::Init(); | 421 BrowserProcessSubThread::Init(); |
436 | 422 |
437 DCHECK_EQ(MessageLoop::TYPE_IO, message_loop()->type()); | 423 DCHECK_EQ(MessageLoop::TYPE_IO, message_loop()->type()); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
509 BrowserChildProcessHost::TerminateAll(); | 495 BrowserChildProcessHost::TerminateAll(); |
510 | 496 |
511 system_url_request_context_getter_ = NULL; | 497 system_url_request_context_getter_ = NULL; |
512 | 498 |
513 // Step 2: Release objects that the net::URLRequestContext could have been | 499 // Step 2: Release objects that the net::URLRequestContext could have been |
514 // pointing to. | 500 // pointing to. |
515 | 501 |
516 // This must be reset before the ChromeNetLog is destroyed. | 502 // This must be reset before the ChromeNetLog is destroyed. |
517 network_change_observer_.reset(); | 503 network_change_observer_.reset(); |
518 | 504 |
519 // Not initialized in Init(). May not be initialized. | |
520 if (predictor_) { | |
521 predictor_->Shutdown(); | |
522 | |
523 // TODO(willchan): Stop reference counting Predictor. It's owned by | |
524 // IOThread now. | |
525 predictor_->Release(); | |
526 predictor_ = NULL; | |
527 chrome_browser_net::FreePredictorResources(); | |
528 } | |
529 | |
530 // Deletion will unregister this interceptor. | |
531 delete speculative_interceptor_; | |
532 speculative_interceptor_ = NULL; | |
533 | |
534 system_proxy_config_service_.reset(); | 505 system_proxy_config_service_.reset(); |
535 | 506 |
536 delete globals_; | 507 delete globals_; |
537 globals_ = NULL; | 508 globals_ = NULL; |
538 | 509 |
539 // net::URLRequest instances must NOT outlive the IO thread. | 510 // net::URLRequest instances must NOT outlive the IO thread. |
540 base::debug::LeakTracker<net::URLRequest>::CheckForLeaks(); | 511 base::debug::LeakTracker<net::URLRequest>::CheckForLeaks(); |
541 | 512 |
542 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks(); | 513 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks(); |
543 | 514 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
581 return net::HttpAuthHandlerRegistryFactory::Create( | 552 return net::HttpAuthHandlerRegistryFactory::Create( |
582 supported_schemes, | 553 supported_schemes, |
583 globals_->url_security_manager.get(), | 554 globals_->url_security_manager.get(), |
584 resolver, | 555 resolver, |
585 gssapi_library_name_, | 556 gssapi_library_name_, |
586 negotiate_disable_cname_lookup_, | 557 negotiate_disable_cname_lookup_, |
587 negotiate_enable_port_); | 558 negotiate_enable_port_); |
588 } | 559 } |
589 | 560 |
590 void IOThread::InitNetworkPredictorOnIOThread( | 561 void IOThread::InitNetworkPredictorOnIOThread( |
591 bool prefetching_enabled, | |
592 base::TimeDelta max_dns_queue_delay, | |
593 size_t max_speculative_parallel_resolves, | |
594 const chrome_common_net::UrlList& startup_urls, | 562 const chrome_common_net::UrlList& startup_urls, |
595 ListValue* referral_list, | 563 ListValue* referral_list, |
596 bool preconnect_enabled) { | 564 chrome_browser_net::Predictor* predictor) { |
597 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
598 CHECK(!predictor_); | |
599 | |
600 chrome_browser_net::EnablePredictor(prefetching_enabled); | |
601 | |
602 predictor_ = new chrome_browser_net::Predictor( | |
jar (doing other things)
2011/08/16 01:19:09
Code like this is what caused us to have such a me
| |
603 globals_->host_resolver.get(), | |
604 max_dns_queue_delay, | |
605 max_speculative_parallel_resolves, | |
606 preconnect_enabled); | |
607 predictor_->AddRef(); | |
608 | |
609 // Speculative_interceptor_ is used to predict subresource usage. | |
610 DCHECK(!speculative_interceptor_); | |
611 speculative_interceptor_ = new chrome_browser_net::ConnectInterceptor; | |
612 | |
613 FinalizePredictorInitialization(predictor_, startup_urls, referral_list); | |
614 } | |
615 | |
616 void IOThread::ChangedToOnTheRecordOnIOThread() { | |
617 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 565 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
618 | 566 |
619 if (predictor_) { | 567 predictor->FinalizeInitializationOnIOThread(startup_urls, referral_list, |
jar (doing other things)
2011/08/16 01:19:09
This method name should be reflected in the name o
willchan no longer on Chromium
2011/08/16 01:42:57
I think I may have commented on this before (I hop
rpetterson
2011/08/16 03:52:12
Yes, this has already been pulled out.
| |
620 // Destroy all evidence of our OTR session. | 568 globals_->host_resolver.get()); |
621 // Note: OTR mode never saves InitialNavigationHistory data. | |
622 predictor_->Predictor::DiscardAllResults(); | |
623 } | |
624 | |
625 // Clear the host cache to avoid showing entries from the OTR session | |
626 // in about:net-internals. | |
627 ClearHostCache(); | |
628 | |
629 // Clear all of the passively logged data. | |
630 // TODO(eroman): this is a bit heavy handed, really all we need to do is | |
631 // clear the data pertaining to incognito context. | |
632 net_log_->ClearAllPassivelyCapturedEvents(); | |
633 } | 569 } |
634 | 570 |
635 void IOThread::ClearHostCache() { | 571 void IOThread::ClearHostCache() { |
636 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 572 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
637 | 573 |
638 if (globals_->host_resolver->GetAsHostResolverImpl()) { | 574 if (globals_->host_resolver->GetAsHostResolverImpl()) { |
639 net::HostCache* host_cache = | 575 net::HostCache* host_cache = |
640 globals_->host_resolver.get()->GetAsHostResolverImpl()->cache(); | 576 globals_->host_resolver.get()->GetAsHostResolverImpl()->cache(); |
641 if (host_cache) | 577 if (host_cache) |
642 host_cache->clear(); | 578 host_cache->clear(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
690 system_params.network_delegate = globals_->system_network_delegate.get(); | 626 system_params.network_delegate = globals_->system_network_delegate.get(); |
691 system_params.net_log = net_log_; | 627 system_params.net_log = net_log_; |
692 globals_->system_http_transaction_factory.reset( | 628 globals_->system_http_transaction_factory.reset( |
693 new net::HttpNetworkLayer( | 629 new net::HttpNetworkLayer( |
694 new net::HttpNetworkSession(system_params))); | 630 new net::HttpNetworkSession(system_params))); |
695 globals_->system_ftp_transaction_factory.reset( | 631 globals_->system_ftp_transaction_factory.reset( |
696 new net::FtpNetworkLayer(globals_->host_resolver.get())); | 632 new net::FtpNetworkLayer(globals_->host_resolver.get())); |
697 globals_->system_request_context = | 633 globals_->system_request_context = |
698 ConstructSystemRequestContext(globals_, net_log_); | 634 ConstructSystemRequestContext(globals_, net_log_); |
699 } | 635 } |
OLD | NEW |