Chromium Code Reviews| 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" |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 311 // |local_state| is passed in explicitly in order to (1) reduce implicit | 311 // |local_state| is passed in explicitly in order to (1) reduce implicit |
| 312 // dependencies and (2) make IOThread more flexible for testing. | 312 // dependencies and (2) make IOThread more flexible for testing. |
| 313 IOThread::IOThread( | 313 IOThread::IOThread( |
| 314 PrefService* local_state, | 314 PrefService* local_state, |
| 315 ChromeNetLog* net_log, | 315 ChromeNetLog* net_log, |
| 316 ExtensionEventRouterForwarder* extension_event_router_forwarder) | 316 ExtensionEventRouterForwarder* extension_event_router_forwarder) |
| 317 : BrowserProcessSubThread(BrowserThread::IO), | 317 : BrowserProcessSubThread(BrowserThread::IO), |
| 318 net_log_(net_log), | 318 net_log_(net_log), |
| 319 extension_event_router_forwarder_(extension_event_router_forwarder), | 319 extension_event_router_forwarder_(extension_event_router_forwarder), |
| 320 globals_(NULL), | 320 globals_(NULL), |
| 321 speculative_interceptor_(NULL), | |
| 322 predictor_(NULL), | |
| 323 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 321 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
| 324 // We call RegisterPrefs() here (instead of inside browser_prefs.cc) to make | 322 // We call RegisterPrefs() here (instead of inside browser_prefs.cc) to make |
| 325 // sure that everything is initialized in the right order. | 323 // sure that everything is initialized in the right order. |
| 326 RegisterPrefs(local_state); | 324 RegisterPrefs(local_state); |
| 327 auth_schemes_ = local_state->GetString(prefs::kAuthSchemes); | 325 auth_schemes_ = local_state->GetString(prefs::kAuthSchemes); |
| 328 negotiate_disable_cname_lookup_ = local_state->GetBoolean( | 326 negotiate_disable_cname_lookup_ = local_state->GetBoolean( |
| 329 prefs::kDisableAuthNegotiateCnameLookup); | 327 prefs::kDisableAuthNegotiateCnameLookup); |
| 330 negotiate_enable_port_ = local_state->GetBoolean( | 328 negotiate_enable_port_ = local_state->GetBoolean( |
| 331 prefs::kEnableAuthNegotiatePort); | 329 prefs::kEnableAuthNegotiatePort); |
| 332 auth_server_whitelist_ = local_state->GetString(prefs::kAuthServerWhitelist); | 330 auth_server_whitelist_ = local_state->GetString(prefs::kAuthServerWhitelist); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 360 ChromeNetLog* IOThread::net_log() { | 358 ChromeNetLog* IOThread::net_log() { |
| 361 return net_log_; | 359 return net_log_; |
| 362 } | 360 } |
| 363 | 361 |
| 364 void IOThread::InitNetworkPredictor( | 362 void IOThread::InitNetworkPredictor( |
| 365 bool prefetching_enabled, | 363 bool prefetching_enabled, |
| 366 base::TimeDelta max_dns_queue_delay, | 364 base::TimeDelta max_dns_queue_delay, |
| 367 size_t max_speculative_parallel_resolves, | 365 size_t max_speculative_parallel_resolves, |
| 368 const chrome_common_net::UrlList& startup_urls, | 366 const chrome_common_net::UrlList& startup_urls, |
| 369 ListValue* referral_list, | 367 ListValue* referral_list, |
| 368 Profile* profile, | |
| 370 bool preconnect_enabled) { | 369 bool preconnect_enabled) { |
| 371 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 370 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 372 message_loop()->PostTask( | 371 message_loop()->PostTask( |
| 373 FROM_HERE, | 372 FROM_HERE, |
| 374 NewRunnableMethod( | 373 NewRunnableMethod( |
| 375 this, | 374 this, |
| 376 &IOThread::InitNetworkPredictorOnIOThread, | 375 &IOThread::InitNetworkPredictorOnIOThread, |
| 377 prefetching_enabled, max_dns_queue_delay, | 376 prefetching_enabled, max_dns_queue_delay, |
| 378 max_speculative_parallel_resolves, | 377 max_speculative_parallel_resolves, |
| 379 startup_urls, referral_list, preconnect_enabled)); | 378 startup_urls, referral_list, preconnect_enabled, profile)); |
| 380 } | 379 } |
| 381 | 380 |
| 382 void IOThread::RegisterURLRequestContextGetter( | 381 void IOThread::RegisterURLRequestContextGetter( |
| 383 ChromeURLRequestContextGetter* url_request_context_getter) { | 382 ChromeURLRequestContextGetter* url_request_context_getter) { |
| 384 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 383 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 385 std::list<ChromeURLRequestContextGetter*>::const_iterator it = | 384 std::list<ChromeURLRequestContextGetter*>::const_iterator it = |
| 386 std::find(url_request_context_getters_.begin(), | 385 std::find(url_request_context_getters_.begin(), |
| 387 url_request_context_getters_.end(), | 386 url_request_context_getters_.end(), |
| 388 url_request_context_getter); | 387 url_request_context_getter); |
| 389 DCHECK(it == url_request_context_getters_.end()); | 388 DCHECK(it == url_request_context_getters_.end()); |
| 390 url_request_context_getters_.push_back(url_request_context_getter); | 389 url_request_context_getters_.push_back(url_request_context_getter); |
| 391 } | 390 } |
| 392 | 391 |
| 393 void IOThread::UnregisterURLRequestContextGetter( | 392 void IOThread::UnregisterURLRequestContextGetter( |
| 394 ChromeURLRequestContextGetter* url_request_context_getter) { | 393 ChromeURLRequestContextGetter* url_request_context_getter) { |
| 395 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 394 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 396 std::list<ChromeURLRequestContextGetter*>::iterator it = | 395 std::list<ChromeURLRequestContextGetter*>::iterator it = |
| 397 std::find(url_request_context_getters_.begin(), | 396 std::find(url_request_context_getters_.begin(), |
| 398 url_request_context_getters_.end(), | 397 url_request_context_getters_.end(), |
| 399 url_request_context_getter); | 398 url_request_context_getter); |
| 400 DCHECK(it != url_request_context_getters_.end()); | 399 DCHECK(it != url_request_context_getters_.end()); |
| 401 // This does not scale, but we shouldn't have many URLRequestContextGetters in | 400 // This does not scale, but we shouldn't have many URLRequestContextGetters in |
| 402 // the first place, so this should be fine. | 401 // the first place, so this should be fine. |
| 403 url_request_context_getters_.erase(it); | 402 url_request_context_getters_.erase(it); |
| 404 } | 403 } |
| 405 | 404 |
| 406 void IOThread::ChangedToOnTheRecord() { | 405 void IOThread::ChangedToOnTheRecord(Profile* profile) { |
| 407 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 406 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 408 message_loop()->PostTask( | 407 message_loop()->PostTask( |
| 409 FROM_HERE, | 408 FROM_HERE, |
| 410 NewRunnableMethod( | 409 NewRunnableMethod( |
| 411 this, | 410 this, |
| 412 &IOThread::ChangedToOnTheRecordOnIOThread)); | 411 &IOThread::ChangedToOnTheRecordOnIOThread, |
| 412 profile)); | |
| 413 } | 413 } |
| 414 | 414 |
| 415 net::URLRequestContextGetter* IOThread::system_url_request_context_getter() { | 415 net::URLRequestContextGetter* IOThread::system_url_request_context_getter() { |
| 416 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 416 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 417 if (!system_url_request_context_getter_) { | 417 if (!system_url_request_context_getter_) { |
| 418 InitSystemRequestContext(); | 418 InitSystemRequestContext(); |
| 419 } | 419 } |
| 420 return system_url_request_context_getter_; | 420 return system_url_request_context_getter_; |
| 421 } | 421 } |
| 422 | 422 |
| 423 void IOThread::ClearNetworkingHistory() { | 423 void IOThread::ClearNetworkingHistory( |
| 424 chrome_browser_net::Predictor* predictor) { | |
| 424 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 425 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 425 ClearHostCache(); | 426 ClearHostCache(); |
| 426 // Discard acrued data used to speculate in the future. | 427 // Discard acrued data used to speculate in the future. |
| 427 chrome_browser_net::DiscardInitialNavigationHistory(); | 428 if (predictor) { |
| 428 if (predictor_) | 429 predictor->DiscardInitialNavigationHistory(); |
| 429 predictor_->DiscardAllResults(); | 430 predictor->DiscardAllResults(); |
| 431 } | |
| 430 } | 432 } |
| 431 | 433 |
| 432 void IOThread::Init() { | 434 void IOThread::Init() { |
| 433 // Though this thread is called the "IO" thread, it actually just routes | 435 // Though this thread is called the "IO" thread, it actually just routes |
| 434 // messages around; it shouldn't be allowed to perform any blocking disk I/O. | 436 // messages around; it shouldn't be allowed to perform any blocking disk I/O. |
| 435 base::ThreadRestrictions::SetIOAllowed(false); | 437 base::ThreadRestrictions::SetIOAllowed(false); |
| 436 | 438 |
| 437 BrowserProcessSubThread::Init(); | 439 BrowserProcessSubThread::Init(); |
| 438 | 440 |
| 439 DCHECK_EQ(MessageLoop::TYPE_IO, message_loop()->type()); | 441 DCHECK_EQ(MessageLoop::TYPE_IO, message_loop()->type()); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 523 } | 525 } |
| 524 | 526 |
| 525 system_url_request_context_getter_ = NULL; | 527 system_url_request_context_getter_ = NULL; |
| 526 | 528 |
| 527 // Step 2: Release objects that the net::URLRequestContext could have been | 529 // Step 2: Release objects that the net::URLRequestContext could have been |
| 528 // pointing to. | 530 // pointing to. |
| 529 | 531 |
| 530 // This must be reset before the ChromeNetLog is destroyed. | 532 // This must be reset before the ChromeNetLog is destroyed. |
| 531 network_change_observer_.reset(); | 533 network_change_observer_.reset(); |
| 532 | 534 |
| 533 // Not initialized in Init(). May not be initialized. | |
| 534 if (predictor_) { | |
| 535 predictor_->Shutdown(); | |
| 536 | |
| 537 // TODO(willchan): Stop reference counting Predictor. It's owned by | |
| 538 // IOThread now. | |
| 539 predictor_->Release(); | |
| 540 predictor_ = NULL; | |
| 541 chrome_browser_net::FreePredictorResources(); | |
| 542 } | |
| 543 | |
| 544 // Deletion will unregister this interceptor. | |
| 545 delete speculative_interceptor_; | |
| 546 speculative_interceptor_ = NULL; | |
| 547 | |
| 548 system_proxy_config_service_.reset(); | 535 system_proxy_config_service_.reset(); |
| 549 | 536 |
| 550 delete globals_; | 537 delete globals_; |
| 551 globals_ = NULL; | 538 globals_ = NULL; |
| 552 | 539 |
| 553 // net::URLRequest instances must NOT outlive the IO thread. | 540 // net::URLRequest instances must NOT outlive the IO thread. |
| 554 base::debug::LeakTracker<net::URLRequest>::CheckForLeaks(); | 541 base::debug::LeakTracker<net::URLRequest>::CheckForLeaks(); |
| 555 | 542 |
| 556 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks(); | 543 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks(); |
| 557 | 544 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 600 negotiate_disable_cname_lookup_, | 587 negotiate_disable_cname_lookup_, |
| 601 negotiate_enable_port_); | 588 negotiate_enable_port_); |
| 602 } | 589 } |
| 603 | 590 |
| 604 void IOThread::InitNetworkPredictorOnIOThread( | 591 void IOThread::InitNetworkPredictorOnIOThread( |
| 605 bool prefetching_enabled, | 592 bool prefetching_enabled, |
| 606 base::TimeDelta max_dns_queue_delay, | 593 base::TimeDelta max_dns_queue_delay, |
| 607 size_t max_speculative_parallel_resolves, | 594 size_t max_speculative_parallel_resolves, |
| 608 const chrome_common_net::UrlList& startup_urls, | 595 const chrome_common_net::UrlList& startup_urls, |
| 609 ListValue* referral_list, | 596 ListValue* referral_list, |
| 610 bool preconnect_enabled) { | 597 bool preconnect_enabled, |
| 598 Profile* profile) { | |
|
willchan no longer on Chromium
2011/07/21 12:10:53
Profile* is not allowed to be used on the IO threa
rpetterson
2011/08/10 02:24:46
Done.
| |
| 611 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 599 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 612 CHECK(!predictor_); | 600 CHECK(!profile->GetPredictor()); |
| 613 | 601 |
| 614 chrome_browser_net::EnablePredictor(prefetching_enabled); | 602 profile->SetPredictor(new chrome_browser_net::Predictor( |
| 615 | |
| 616 predictor_ = new chrome_browser_net::Predictor( | |
| 617 globals_->host_resolver.get(), | 603 globals_->host_resolver.get(), |
| 618 max_dns_queue_delay, | 604 max_dns_queue_delay, |
| 619 max_speculative_parallel_resolves, | 605 max_speculative_parallel_resolves, |
| 620 preconnect_enabled); | 606 preconnect_enabled, |
| 621 predictor_->AddRef(); | 607 prefetching_enabled)); |
| 622 | 608 |
| 623 // Speculative_interceptor_ is used to predict subresource usage. | 609 profile->GetPredictor()->FinalizeInitialization(startup_urls, referral_list); |
| 624 DCHECK(!speculative_interceptor_); | |
| 625 speculative_interceptor_ = new chrome_browser_net::ConnectInterceptor; | |
| 626 | |
| 627 FinalizePredictorInitialization(predictor_, startup_urls, referral_list); | |
| 628 } | 610 } |
| 629 | 611 |
| 630 void IOThread::ChangedToOnTheRecordOnIOThread() { | 612 void IOThread::ChangedToOnTheRecordOnIOThread(Profile* profile) { |
| 631 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 613 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 632 | 614 |
| 633 if (predictor_) { | 615 if (profile->GetPredictor()) { |
|
willchan no longer on Chromium
2011/07/21 12:10:53
This should die. Once you've made the Predictor be
rpetterson
2011/08/10 02:24:46
Done.
| |
| 634 // Destroy all evidence of our OTR session. | 616 // Destroy all evidence of our OTR session. |
| 635 // Note: OTR mode never saves InitialNavigationHistory data. | 617 // Note: OTR mode never saves InitialNavigationHistory data. |
| 636 predictor_->Predictor::DiscardAllResults(); | 618 profile->GetPredictor()->DiscardAllResults(); |
| 637 } | 619 } |
| 638 | 620 |
| 639 // Clear the host cache to avoid showing entries from the OTR session | 621 // Clear the host cache to avoid showing entries from the OTR session |
| 640 // in about:net-internals. | 622 // in about:net-internals. |
| 641 ClearHostCache(); | 623 ClearHostCache(); |
| 642 | 624 |
| 643 // Clear all of the passively logged data. | 625 // Clear all of the passively logged data. |
| 644 // TODO(eroman): this is a bit heavy handed, really all we need to do is | 626 // TODO(eroman): this is a bit heavy handed, really all we need to do is |
| 645 // clear the data pertaining to incognito context. | 627 // clear the data pertaining to incognito context. |
| 646 net_log_->ClearAllPassivelyCapturedEvents(); | 628 net_log_->ClearAllPassivelyCapturedEvents(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 701 system_params.network_delegate = globals_->system_network_delegate.get(); | 683 system_params.network_delegate = globals_->system_network_delegate.get(); |
| 702 system_params.net_log = net_log_; | 684 system_params.net_log = net_log_; |
| 703 globals_->system_http_transaction_factory.reset( | 685 globals_->system_http_transaction_factory.reset( |
| 704 new net::HttpNetworkLayer( | 686 new net::HttpNetworkLayer( |
| 705 new net::HttpNetworkSession(system_params))); | 687 new net::HttpNetworkSession(system_params))); |
| 706 globals_->system_ftp_transaction_factory.reset( | 688 globals_->system_ftp_transaction_factory.reset( |
| 707 new net::FtpNetworkLayer(globals_->host_resolver.get())); | 689 new net::FtpNetworkLayer(globals_->host_resolver.get())); |
| 708 globals_->system_request_context = | 690 globals_->system_request_context = |
| 709 ConstructSystemRequestContext(globals_, net_log_); | 691 ConstructSystemRequestContext(globals_, net_log_); |
| 710 } | 692 } |
| OLD | NEW |