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

Side by Side Diff: chrome/browser/io_thread.cc

Issue 7467012: Modifying prefetch to account for multi-profile. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Modifying prefetch to account for multi-profile. Created 9 years, 3 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) 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"
28 #include "chrome/browser/net/pref_proxy_config_service.h" 27 #include "chrome/browser/net/pref_proxy_config_service.h"
29 #include "chrome/browser/net/proxy_service_factory.h" 28 #include "chrome/browser/net/proxy_service_factory.h"
30 #include "chrome/browser/prefs/pref_service.h" 29 #include "chrome/browser/prefs/pref_service.h"
31 #include "chrome/common/chrome_switches.h" 30 #include "chrome/common/chrome_switches.h"
32 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
33 #include "content/browser/browser_thread.h" 32 #include "content/browser/browser_thread.h"
34 #include "content/browser/gpu/gpu_process_host.h" 33 #include "content/browser/gpu/gpu_process_host.h"
35 #include "content/browser/in_process_webkit/indexed_db_key_utility_client.h" 34 #include "content/browser/in_process_webkit/indexed_db_key_utility_client.h"
36 #include "content/common/url_fetcher.h" 35 #include "content/common/url_fetcher.h"
37 #include "net/base/cert_verifier.h" 36 #include "net/base/cert_verifier.h"
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 // |local_state| is passed in explicitly in order to (1) reduce implicit 336 // |local_state| is passed in explicitly in order to (1) reduce implicit
338 // dependencies and (2) make IOThread more flexible for testing. 337 // dependencies and (2) make IOThread more flexible for testing.
339 IOThread::IOThread( 338 IOThread::IOThread(
340 PrefService* local_state, 339 PrefService* local_state,
341 ChromeNetLog* net_log, 340 ChromeNetLog* net_log,
342 ExtensionEventRouterForwarder* extension_event_router_forwarder) 341 ExtensionEventRouterForwarder* extension_event_router_forwarder)
343 : BrowserProcessSubThread(BrowserThread::IO), 342 : BrowserProcessSubThread(BrowserThread::IO),
344 net_log_(net_log), 343 net_log_(net_log),
345 extension_event_router_forwarder_(extension_event_router_forwarder), 344 extension_event_router_forwarder_(extension_event_router_forwarder),
346 globals_(NULL), 345 globals_(NULL),
347 speculative_interceptor_(NULL),
348 predictor_(NULL),
349 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { 346 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
350 // We call RegisterPrefs() here (instead of inside browser_prefs.cc) to make 347 // We call RegisterPrefs() here (instead of inside browser_prefs.cc) to make
351 // sure that everything is initialized in the right order. 348 // sure that everything is initialized in the right order.
352 RegisterPrefs(local_state); 349 RegisterPrefs(local_state);
353 auth_schemes_ = local_state->GetString(prefs::kAuthSchemes); 350 auth_schemes_ = local_state->GetString(prefs::kAuthSchemes);
354 negotiate_disable_cname_lookup_ = local_state->GetBoolean( 351 negotiate_disable_cname_lookup_ = local_state->GetBoolean(
355 prefs::kDisableAuthNegotiateCnameLookup); 352 prefs::kDisableAuthNegotiateCnameLookup);
356 negotiate_enable_port_ = local_state->GetBoolean( 353 negotiate_enable_port_ = local_state->GetBoolean(
357 prefs::kEnableAuthNegotiatePort); 354 prefs::kEnableAuthNegotiatePort);
358 auth_server_whitelist_ = local_state->GetString(prefs::kAuthServerWhitelist); 355 auth_server_whitelist_ = local_state->GetString(prefs::kAuthServerWhitelist);
(...skipping 21 matching lines...) Expand all
380 377
381 IOThread::Globals* IOThread::globals() { 378 IOThread::Globals* IOThread::globals() {
382 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 379 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
383 return globals_; 380 return globals_;
384 } 381 }
385 382
386 ChromeNetLog* IOThread::net_log() { 383 ChromeNetLog* IOThread::net_log() {
387 return net_log_; 384 return net_log_;
388 } 385 }
389 386
390 void IOThread::InitNetworkPredictor(
391 bool prefetching_enabled,
392 base::TimeDelta max_dns_queue_delay,
393 size_t max_speculative_parallel_resolves,
394 const chrome_common_net::UrlList& startup_urls,
395 ListValue* referral_list,
396 bool preconnect_enabled) {
397 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
398 message_loop()->PostTask(
399 FROM_HERE,
400 NewRunnableMethod(
401 this,
402 &IOThread::InitNetworkPredictorOnIOThread,
403 prefetching_enabled, max_dns_queue_delay,
404 max_speculative_parallel_resolves,
405 startup_urls, referral_list, preconnect_enabled));
406 }
407
408 void IOThread::ChangedToOnTheRecord() {
409 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
410 message_loop()->PostTask(
411 FROM_HERE,
412 NewRunnableMethod(
413 this,
414 &IOThread::ChangedToOnTheRecordOnIOThread));
415 }
416
417 net::URLRequestContextGetter* IOThread::system_url_request_context_getter() { 387 net::URLRequestContextGetter* IOThread::system_url_request_context_getter() {
418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
419 if (!system_url_request_context_getter_) { 389 if (!system_url_request_context_getter_) {
420 InitSystemRequestContext(); 390 InitSystemRequestContext();
421 } 391 }
422 return system_url_request_context_getter_; 392 return system_url_request_context_getter_;
423 } 393 }
424 394
425 void IOThread::ClearNetworkingHistory() {
426 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
427 ClearHostCache();
428 // Discard acrued data used to speculate in the future.
429 chrome_browser_net::DiscardInitialNavigationHistory();
430 if (predictor_)
431 predictor_->DiscardAllResults();
432 }
433
434 void IOThread::Init() { 395 void IOThread::Init() {
435 // Though this thread is called the "IO" thread, it actually just routes 396 // Though this thread is called the "IO" thread, it actually just routes
436 // messages around; it shouldn't be allowed to perform any blocking disk I/O. 397 // messages around; it shouldn't be allowed to perform any blocking disk I/O.
437 base::ThreadRestrictions::SetIOAllowed(false); 398 base::ThreadRestrictions::SetIOAllowed(false);
438 399
439 BrowserProcessSubThread::Init(); 400 BrowserProcessSubThread::Init();
440 401
441 DCHECK_EQ(MessageLoop::TYPE_IO, message_loop()->type()); 402 DCHECK_EQ(MessageLoop::TYPE_IO, message_loop()->type());
442 403
443 #if defined(USE_NSS) 404 #if defined(USE_NSS)
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 BrowserChildProcessHost::TerminateAll(); 482 BrowserChildProcessHost::TerminateAll();
522 483
523 system_url_request_context_getter_ = NULL; 484 system_url_request_context_getter_ = NULL;
524 485
525 // Step 2: Release objects that the net::URLRequestContext could have been 486 // Step 2: Release objects that the net::URLRequestContext could have been
526 // pointing to. 487 // pointing to.
527 488
528 // This must be reset before the ChromeNetLog is destroyed. 489 // This must be reset before the ChromeNetLog is destroyed.
529 network_change_observer_.reset(); 490 network_change_observer_.reset();
530 491
531 // Not initialized in Init(). May not be initialized.
532 if (predictor_) {
533 predictor_->Shutdown();
534
535 // TODO(willchan): Stop reference counting Predictor. It's owned by
536 // IOThread now.
537 predictor_->Release();
538 predictor_ = NULL;
539 chrome_browser_net::FreePredictorResources();
540 }
541
542 // Deletion will unregister this interceptor.
543 delete speculative_interceptor_;
544 speculative_interceptor_ = NULL;
545
546 system_proxy_config_service_.reset(); 492 system_proxy_config_service_.reset();
547 493
548 delete globals_; 494 delete globals_;
549 globals_ = NULL; 495 globals_ = NULL;
550 496
551 // net::URLRequest instances must NOT outlive the IO thread. 497 // net::URLRequest instances must NOT outlive the IO thread.
552 base::debug::LeakTracker<net::URLRequest>::CheckForLeaks(); 498 base::debug::LeakTracker<net::URLRequest>::CheckForLeaks();
553 499
554 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks(); 500 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks();
555 501
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 538
593 return net::HttpAuthHandlerRegistryFactory::Create( 539 return net::HttpAuthHandlerRegistryFactory::Create(
594 supported_schemes, 540 supported_schemes,
595 globals_->url_security_manager.get(), 541 globals_->url_security_manager.get(),
596 resolver, 542 resolver,
597 gssapi_library_name_, 543 gssapi_library_name_,
598 negotiate_disable_cname_lookup_, 544 negotiate_disable_cname_lookup_,
599 negotiate_enable_port_); 545 negotiate_enable_port_);
600 } 546 }
601 547
602 void IOThread::InitNetworkPredictorOnIOThread(
603 bool prefetching_enabled,
604 base::TimeDelta max_dns_queue_delay,
605 size_t max_speculative_parallel_resolves,
606 const chrome_common_net::UrlList& startup_urls,
607 ListValue* referral_list,
608 bool preconnect_enabled) {
609 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
610 CHECK(!predictor_);
611
612 chrome_browser_net::EnablePredictor(prefetching_enabled);
613
614 predictor_ = new chrome_browser_net::Predictor(
615 globals_->host_resolver.get(),
616 max_dns_queue_delay,
617 max_speculative_parallel_resolves,
618 preconnect_enabled);
619 predictor_->AddRef();
620
621 // Speculative_interceptor_ is used to predict subresource usage.
622 DCHECK(!speculative_interceptor_);
623 speculative_interceptor_ = new chrome_browser_net::ConnectInterceptor;
624
625 FinalizePredictorInitialization(predictor_, startup_urls, referral_list);
626 }
627
628 void IOThread::ChangedToOnTheRecordOnIOThread() {
629 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
630
631 if (predictor_) {
632 // Destroy all evidence of our OTR session.
633 // Note: OTR mode never saves InitialNavigationHistory data.
634 predictor_->Predictor::DiscardAllResults();
635 }
636
637 // Clear the host cache to avoid showing entries from the OTR session
638 // in about:net-internals.
639 ClearHostCache();
640
641 // Clear all of the passively logged data.
642 // TODO(eroman): this is a bit heavy handed, really all we need to do is
643 // clear the data pertaining to incognito context.
644 net_log_->ClearAllPassivelyCapturedEvents();
645 }
646
647 void IOThread::ClearHostCache() { 548 void IOThread::ClearHostCache() {
648 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 549 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
649 550
650 if (globals_->host_resolver->GetAsHostResolverImpl()) { 551 if (globals_->host_resolver->GetAsHostResolverImpl()) {
651 net::HostCache* host_cache = 552 net::HostCache* host_cache =
652 globals_->host_resolver.get()->GetAsHostResolverImpl()->cache(); 553 globals_->host_resolver.get()->GetAsHostResolverImpl()->cache();
653 if (host_cache) 554 if (host_cache)
654 host_cache->clear(); 555 host_cache->clear();
655 } 556 }
656 } 557 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 system_params.network_delegate = globals_->system_network_delegate.get(); 605 system_params.network_delegate = globals_->system_network_delegate.get();
705 system_params.net_log = net_log_; 606 system_params.net_log = net_log_;
706 globals_->system_http_transaction_factory.reset( 607 globals_->system_http_transaction_factory.reset(
707 new net::HttpNetworkLayer( 608 new net::HttpNetworkLayer(
708 new net::HttpNetworkSession(system_params))); 609 new net::HttpNetworkSession(system_params)));
709 globals_->system_ftp_transaction_factory.reset( 610 globals_->system_ftp_transaction_factory.reset(
710 new net::FtpNetworkLayer(globals_->host_resolver.get())); 611 new net::FtpNetworkLayer(globals_->host_resolver.get()));
711 globals_->system_request_context = 612 globals_->system_request_context =
712 ConstructSystemRequestContext(globals_, net_log_); 613 ConstructSystemRequestContext(globals_, net_log_);
713 } 614 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698