diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-10 19:31:57 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-10 19:31:57 +0000 |
commit | b4e74ee7fa50d5880f6cfdb6e2d10c8e8bb98cc1 (patch) | |
tree | 40c6afa656bd48496d696790e9d47a4a7df4b315 /chrome/browser/browser_process_impl.cc | |
parent | 0a424afc9c94380ecd80967be73cfb684b6ae3f4 (diff) | |
download | chromium_src-b4e74ee7fa50d5880f6cfdb6e2d10c8e8bb98cc1.zip chromium_src-b4e74ee7fa50d5880f6cfdb6e2d10c8e8bb98cc1.tar.gz chromium_src-b4e74ee7fa50d5880f6cfdb6e2d10c8e8bb98cc1.tar.bz2 |
Move creation and ownership of ResourceDispatcherHost and PluginService to content. This gives a few benefits:
-avoid having each embedder know when to create/destruct these objects, as well as contained objects (i.e. those related to downloads)
-avoid having to tell embedders about specifics of BrowserThread startup/shutdown
-move ResourceDispatcherHost's getter to content where it belongs
Some code (extensions+promos) used the fact that RDH is NULL in unittests as a signal to not use the utility process. I've switches those unittests to set a flag on the objects instead.
I've taken out the DnsParallelism field trial (not used anymore, confirmed with jar) as it was the only thing that caused MetricsService to depend on IOThread initialization, which also depended on MetricsService (through FieldTrials). This two-sided dependency always annoyed me and made the code hard to restructure.
BUG=98716
Review URL: http://codereview.chromium.org/9150016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@117078 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/browser_process_impl.cc')
-rw-r--r-- | chrome/browser/browser_process_impl.cc | 167 |
1 files changed, 45 insertions, 122 deletions
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc index 27a458a..f68f0f2 100644 --- a/chrome/browser/browser_process_impl.cc +++ b/chrome/browser/browser_process_impl.cc @@ -68,10 +68,8 @@ #include "chrome/installer/util/google_update_constants.h" #include "content/browser/browser_child_process_host.h" #include "content/browser/child_process_security_policy.h" -#include "content/browser/download/download_file_manager.h" #include "content/browser/download/download_status_updater.h" #include "content/browser/download/mhtml_generation_manager.h" -#include "content/browser/download/save_file_manager.h" #include "content/browser/gpu/gpu_process_host_ui_shim.h" #include "content/browser/net/browser_online_state_observer.h" #include "content/browser/renderer_host/resource_dispatcher_host.h" @@ -121,8 +119,7 @@ using content::BrowserThread; using content::PluginService; BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line) - : created_resource_dispatcher_host_(false), - created_metrics_service_(false), + : created_metrics_service_(false), created_watchdog_thread_(false), created_profile_manager_(false), created_local_state_(false), @@ -155,10 +152,6 @@ BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line) } BrowserProcessImpl::~BrowserProcessImpl() { - // See StartTearDown and PreStopThread functions below, this is where - // most destruction happens so that it can be interleaved with threads - // going away. - // Wait for the pending print jobs to finish. print_job_manager_->OnQuit(); print_job_manager_.reset(); @@ -219,11 +212,6 @@ void BrowserProcessImpl::StartTearDown() { // Debugger must be cleaned up before IO thread and NotificationService. remote_debugging_server_.reset(); - if (resource_dispatcher_host_.get()) { - // Cancel pending requests and prevent new requests. - resource_dispatcher_host()->Shutdown(); - } - ExtensionTabIdMap::GetInstance()->Shutdown(); // The policy providers managed by |browser_policy_connector_| need to shut @@ -240,60 +228,18 @@ void BrowserProcessImpl::StartTearDown() { watchdog_thread_.reset(); } -void BrowserProcessImpl::PreStartThread(BrowserThread::ID thread_id) { - switch (thread_id) { - case BrowserThread::IO: - CreateIOThreadState(); - break; +void BrowserProcessImpl::PostDestroyThreads() { + // With the file_thread_ flushed, we can release any icon resources. + icon_manager_.reset(); - default: - break; - } -} - -void BrowserProcessImpl::PostStartThread(BrowserThread::ID thread_id) { -} - -void BrowserProcessImpl::PreStopThread(BrowserThread::ID thread_id) { - switch (thread_id) { - case BrowserThread::FILE: - // Clean up state that lives on or uses the file_thread_ before - // it goes away. - if (resource_dispatcher_host_.get()) { - resource_dispatcher_host()->download_file_manager()->Shutdown(); - resource_dispatcher_host()->save_file_manager()->Shutdown(); - } - break; - case BrowserThread::WEBKIT_DEPRECATED: - // Need to destroy ResourceDispatcherHost before PluginService - // and SafeBrowsingService, since it caches a pointer to - // it. - resource_dispatcher_host_.reset(); - break; - default: - break; - } -} - -void BrowserProcessImpl::PostStopThread(BrowserThread::ID thread_id) { - switch (thread_id) { - case BrowserThread::FILE: - // With the file_thread_ flushed, we can release any icon resources. - icon_manager_.reset(); - break; - case BrowserThread::IO: - // Reset associated state right after actual thread is stopped, - // as io_thread_.global_ cleanup happens in CleanUp on the IO - // thread, i.e. as the thread exits its message loop. - // - // This is important also because in various places, the - // IOThread object being NULL is considered synonymous with the - // IO thread having stopped. - io_thread_.reset(); - break; - default: - break; - } + // Reset associated state right after actual thread is stopped, + // as io_thread_.global_ cleanup happens in CleanUp on the IO + // thread, i.e. as the thread exits its message loop. + // + // This is important also because in various places, the + // IOThread object being NULL is considered synonymous with the + // IO thread having stopped. + io_thread_.reset(); } #if defined(OS_WIN) @@ -392,13 +338,6 @@ void BrowserProcessImpl::EndSession() { #endif } -ResourceDispatcherHost* BrowserProcessImpl::resource_dispatcher_host() { - DCHECK(CalledOnValidThread()); - if (!created_resource_dispatcher_host_) - CreateResourceDispatcherHost(); - return resource_dispatcher_host_.get(); -} - MetricsService* BrowserProcessImpl::metrics_service() { DCHECK(CalledOnValidThread()); if (!created_metrics_service_) @@ -697,25 +636,15 @@ AudioManager* BrowserProcessImpl::audio_manager() { return audio_manager_; } -void BrowserProcessImpl::CreateResourceDispatcherHost() { - DCHECK(!created_resource_dispatcher_host_ && - resource_dispatcher_host_.get() == NULL); - created_resource_dispatcher_host_ = true; - +void BrowserProcessImpl::ResourceDispatcherHostCreated() { // UserScriptListener and NetworkDelayListener will delete themselves. - ResourceQueue::DelegateSet resource_queue_delegates; - resource_queue_delegates.insert(new UserScriptListener()); - resource_queue_delegates.insert(new NetworkDelayListener()); - - resource_dispatcher_host_.reset( - new ResourceDispatcherHost(resource_queue_delegates)); - resource_dispatcher_host_->Initialize(); + ResourceDispatcherHost* rdh = ResourceDispatcherHost::Get(); + rdh->AddResourceQueueDelegate(new UserScriptListener()); + rdh->AddResourceQueueDelegate(new NetworkDelayListener()); resource_dispatcher_host_delegate_.reset( - new ChromeResourceDispatcherHostDelegate(resource_dispatcher_host_.get(), - prerender_tracker())); - resource_dispatcher_host_->set_delegate( - resource_dispatcher_host_delegate_.get()); + new ChromeResourceDispatcherHostDelegate(rdh, prerender_tracker())); + rdh->set_delegate(resource_dispatcher_host_delegate_.get()); pref_change_registrar_.Add(prefs::kAllowCrossOriginAuthPrompt, this); ApplyAllowCrossOriginAuthPromptPolicy(); @@ -728,38 +657,6 @@ void BrowserProcessImpl::CreateMetricsService() { metrics_service_.reset(new MetricsService); } -void BrowserProcessImpl::CreateIOThreadState() { - // Prior to any processing happening on the io thread, we create the - // plugin service as it is predominantly used from the io thread, - // but must be created on the main thread. The service ctor is - // inexpensive and does not invoke the io_thread() accessor. - PluginService* plugin_service = PluginService::GetInstance(); - plugin_service->Init(); - plugin_service->SetFilter(ChromePluginServiceFilter::GetInstance()); - plugin_service->StartWatchingPlugins(); - - // Register the internal Flash if available. - FilePath path; - if (!CommandLine::ForCurrentProcess()->HasSwitch( - switches::kDisableInternalFlash) && - PathService::Get(chrome::FILE_FLASH_PLUGIN, &path)) { - plugin_service->AddExtraPluginPath(path); - } - -#if defined(OS_POSIX) - // Also find plugins in a user-specific plugins dir, - // e.g. ~/.config/chromium/Plugins. - FilePath user_data_dir; - if (PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) { - plugin_service->AddExtraPluginPath(user_data_dir.Append("Plugins")); - } -#endif - - scoped_ptr<IOThread> thread(new IOThread( - local_state(), net_log_.get(), extension_event_router_forwarder_.get())); - io_thread_.swap(thread); -} - void BrowserProcessImpl::CreateWatchdogThread() { DCHECK(!created_watchdog_thread_ && watchdog_thread_.get() == NULL); created_watchdog_thread_ = true; @@ -826,7 +723,33 @@ void BrowserProcessImpl::CreateLocalState() { local_state_->RegisterBooleanPref(prefs::kAllowCrossOriginAuthPrompt, false); } +void BrowserProcessImpl::PreCreateThreads() { + io_thread_.reset(new IOThread( + local_state(), net_log_.get(), extension_event_router_forwarder_.get())); +} + void BrowserProcessImpl::PreMainMessageLoopRun() { + PluginService* plugin_service = PluginService::GetInstance(); + plugin_service->SetFilter(ChromePluginServiceFilter::GetInstance()); + plugin_service->StartWatchingPlugins(); + + // Register the internal Flash if available. + FilePath path; + if (!CommandLine::ForCurrentProcess()->HasSwitch( + switches::kDisableInternalFlash) && + PathService::Get(chrome::FILE_FLASH_PLUGIN, &path)) { + plugin_service->AddExtraPluginPath(path); + } + +#if defined(OS_POSIX) + // Also find plugins in a user-specific plugins dir, + // e.g. ~/.config/chromium/Plugins. + FilePath user_data_dir; + if (PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) { + plugin_service->AddExtraPluginPath(user_data_dir.Append("Plugins")); + } +#endif + if (local_state_->IsManagedPreference(prefs::kDefaultBrowserSettingEnabled)) ApplyDefaultBrowserPolicy(); } @@ -916,7 +839,7 @@ void BrowserProcessImpl::ApplyDefaultBrowserPolicy() { void BrowserProcessImpl::ApplyAllowCrossOriginAuthPromptPolicy() { bool value = local_state()->GetBoolean(prefs::kAllowCrossOriginAuthPrompt); - resource_dispatcher_host()->set_allow_cross_origin_auth_prompt(value); + ResourceDispatcherHost::Get()->set_allow_cross_origin_auth_prompt(value); } // Mac is currently not supported. |