diff options
author | erikkay@chromium.org <erikkay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-26 17:12:27 +0000 |
---|---|---|
committer | erikkay@chromium.org <erikkay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-26 17:12:27 +0000 |
commit | 382a070edf0c8918684e05ef57f8fae34d564ca4 (patch) | |
tree | 18d5bbef9ac29aa456435464a3560f53f0a04eae | |
parent | 056de2d024b7fe311b6ad5924e831e7c44816e68 (diff) | |
download | chromium_src-382a070edf0c8918684e05ef57f8fae34d564ca4.zip chromium_src-382a070edf0c8918684e05ef57f8fae34d564ca4.tar.gz chromium_src-382a070edf0c8918684e05ef57f8fae34d564ca4.tar.bz2 |
Change ExtensionHost to use notifications
rather than direct communication with ExtensionProcessManager.
This simplifies ownership and lifetime issues which allows me to also
revert the change that made ExtensionProcessManager owned by
ExtensionsService.
Review URL: http://codereview.chromium.org/147208
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19370 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/extensions/extension_browsertest.cc | 2 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_host.cc | 25 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_host.h | 6 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_process_manager.cc | 40 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_process_manager.h | 10 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service.cc | 1 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service.h | 7 | ||||
-rw-r--r-- | chrome/browser/profile.cc | 4 | ||||
-rw-r--r-- | chrome/browser/profile.h | 1 |
9 files changed, 36 insertions, 60 deletions
diff --git a/chrome/browser/extensions/extension_browsertest.cc b/chrome/browser/extensions/extension_browsertest.cc index 3680fdf..291dfc1 100644 --- a/chrome/browser/extensions/extension_browsertest.cc +++ b/chrome/browser/extensions/extension_browsertest.cc @@ -38,7 +38,7 @@ class MockExtensionHost : public ExtensionHost { public: MockExtensionHost(Extension* extension, const GURL& url, SiteInstance* instance) - : ExtensionHost(extension, instance, url, NULL), + : ExtensionHost(extension, instance, url), got_message_(false) { CreateRenderView(NULL); MessageLoop::current()->PostDelayedTask(FROM_HERE, diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc index 733492b..4373bd0 100644 --- a/chrome/browser/extensions/extension_host.cc +++ b/chrome/browser/extensions/extension_host.cc @@ -11,7 +11,6 @@ #include "chrome/browser/browser_list.h" #include "chrome/browser/debugger/devtools_manager.h" #include "chrome/browser/extensions/extension_message_service.h" -#include "chrome/browser/extensions/extension_process_manager.h" #include "chrome/browser/profile.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/renderer_host/render_process_host.h" @@ -22,6 +21,7 @@ #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view.h" #include "chrome/common/extensions/extension.h" +#include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" @@ -77,9 +77,9 @@ class CrashedExtensionInfobarDelegate : public ConfirmInfoBarDelegate { } // namespace ExtensionHost::ExtensionHost(Extension* extension, SiteInstance* site_instance, - const GURL& url, ExtensionProcessManager* manager) + const GURL& url) : extension_(extension), - manager_(manager), + profile_(site_instance->browsing_instance()->profile()), did_stop_loading_(false), url_(url) { render_view_host_ = new RenderViewHost( @@ -88,8 +88,10 @@ ExtensionHost::ExtensionHost(Extension* extension, SiteInstance* site_instance, } ExtensionHost::~ExtensionHost() { - if (manager_) // To allow passing NULL in tests. - manager_->OnExtensionHostDestroyed(this); + NotificationService::current()->Notify( + NotificationType::EXTENSION_HOST_DESTROYED, + Source<Profile>(profile_), + Details<ExtensionHost>(this)); render_view_host_->Shutdown(); // deletes render_view_host } @@ -128,8 +130,12 @@ void ExtensionHost::RecoverCrashedExtension() { #if defined(TOOLKIT_VIEWS) view_->RecoverCrashedExtension(); #endif - if (IsRenderViewLive()) - manager_->OnExtensionProcessRestored(this); + if (IsRenderViewLive()) { + NotificationService::current()->Notify( + NotificationType::EXTENSION_PROCESS_RESTORED, + Source<Profile>(profile_), + Details<ExtensionHost>(this)); + } } void ExtensionHost::UpdatePreferredWidth(int pref_width) { @@ -147,7 +153,10 @@ void ExtensionHost::RenderViewGone(RenderViewHost* render_view_host) { current_tab->AddInfoBar( new CrashedExtensionInfobarDelegate(current_tab, this)); } - manager_->OnExtensionProcessCrashed(this); + NotificationService::current()->Notify( + NotificationType::EXTENSION_PROCESS_CRASHED, + Source<Profile>(profile_), + Details<ExtensionHost>(this)); } WebPreferences ExtensionHost::GetWebkitPrefs() { diff --git a/chrome/browser/extensions/extension_host.h b/chrome/browser/extensions/extension_host.h index 51e0ab5..a7ca899 100644 --- a/chrome/browser/extensions/extension_host.h +++ b/chrome/browser/extensions/extension_host.h @@ -32,7 +32,7 @@ class ExtensionHost : public RenderViewHostDelegate, public ExtensionFunctionDispatcher::Delegate { public: ExtensionHost(Extension* extension, SiteInstance* site_instance, - const GURL& url, ExtensionProcessManager* manager); + const GURL& url); ~ExtensionHost(); #if defined(TOOLKIT_VIEWS) @@ -109,8 +109,8 @@ class ExtensionHost : public RenderViewHostDelegate, // The extension that we're hosting in this view. Extension* extension_; - // Manager which created us (to notify upon destruction). - ExtensionProcessManager* manager_; + // The profile that this host is tied to. + Profile* profile_; #if defined(TOOLKIT_VIEWS) // Optional view that shows the rendered content in the UI. diff --git a/chrome/browser/extensions/extension_process_manager.cc b/chrome/browser/extensions/extension_process_manager.cc index e655057..7ec8433 100644 --- a/chrome/browser/extensions/extension_process_manager.cc +++ b/chrome/browser/extensions/extension_process_manager.cc @@ -31,10 +31,8 @@ ExtensionProcessManager::ExtensionProcessManager(Profile* profile) NotificationService::AllSources()); registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, NotificationService::AllSources()); - - ExtensionsService* service = profile->GetExtensionsService(); - if (service && service->is_ready()) - CreateBackgroundHosts(this, service->extensions()); + registrar_.Add(this, NotificationType::EXTENSION_HOST_DESTROYED, + Source<Profile>(profile)); } ExtensionProcessManager::~ExtensionProcessManager() { @@ -52,7 +50,7 @@ ExtensionHost* ExtensionProcessManager::CreateView(Extension* extension, DCHECK(extension); DCHECK(browser); ExtensionHost* host = - new ExtensionHost(extension, GetSiteInstanceForURL(url), url, this); + new ExtensionHost(extension, GetSiteInstanceForURL(url), url); host->CreateView(browser); OnExtensionHostCreated(host, false); return host; @@ -74,7 +72,7 @@ ExtensionHost* ExtensionProcessManager::CreateView(const GURL& url, ExtensionHost* ExtensionProcessManager::CreateBackgroundHost( Extension* extension, const GURL& url) { ExtensionHost* host = - new ExtensionHost(extension, GetSiteInstanceForURL(url), url, this); + new ExtensionHost(extension, GetSiteInstanceForURL(url), url); host->CreateRenderView(NULL); // create a RenderViewHost with no view OnExtensionHostCreated(host, true); return host; @@ -117,34 +115,18 @@ void ExtensionProcessManager::Observe(NotificationType type, break; } + case NotificationType::EXTENSION_HOST_DESTROYED: { + ExtensionHost* host = Details<ExtensionHost>(details).ptr(); + all_hosts_.erase(host); + background_hosts_.erase(host); + break; + } + default: NOTREACHED(); } } -void ExtensionProcessManager::OnExtensionHostDestroyed(ExtensionHost* host) { - all_hosts_.erase(host); - background_hosts_.erase(host); - NotificationService::current()->Notify( - NotificationType::EXTENSION_HOST_DESTROYED, - Source<ExtensionProcessManager>(this), - Details<ExtensionHost>(host)); -} - -void ExtensionProcessManager::OnExtensionProcessCrashed(ExtensionHost* host) { - NotificationService::current()->Notify( - NotificationType::EXTENSION_PROCESS_CRASHED, - Source<ExtensionProcessManager>(this), - Details<ExtensionHost>(host)); -} - -void ExtensionProcessManager::OnExtensionProcessRestored(ExtensionHost* host) { - NotificationService::current()->Notify( - NotificationType::EXTENSION_PROCESS_RESTORED, - Source<ExtensionProcessManager>(this), - Details<ExtensionHost>(host)); -} - void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host, bool is_background) { all_hosts_.insert(host); diff --git a/chrome/browser/extensions/extension_process_manager.h b/chrome/browser/extensions/extension_process_manager.h index a5c6296..58f6639 100644 --- a/chrome/browser/extensions/extension_process_manager.h +++ b/chrome/browser/extensions/extension_process_manager.h @@ -53,16 +53,6 @@ class ExtensionProcessManager : public NotificationObserver { const_iterator begin() const { return all_hosts_.begin(); } const_iterator end() const { return all_hosts_.end(); } - // Called just before |host| is destroyed so it can be de-registered - // from our lists. - void OnExtensionHostDestroyed(ExtensionHost* host); - - // Called after an extension render process crashes. - void OnExtensionProcessCrashed(ExtensionHost* host); - - // Called after an extension process successfully restarts after crash. - void OnExtensionProcessRestored(ExtensionHost* host); - private: // Called just after |host| is created so it can be registered in our lists. void OnExtensionHostCreated(ExtensionHost* host, bool is_background); diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc index 18f5862..66b4371 100644 --- a/chrome/browser/extensions/extensions_service.cc +++ b/chrome/browser/extensions/extensions_service.cc @@ -220,7 +220,6 @@ ExtensionsService::ExtensionsService(Profile* profile, MessageLoop* frontend_loop, MessageLoop* backend_loop) : extension_prefs_(new ExtensionPrefs(prefs, install_directory)), - extension_process_manager_(new ExtensionProcessManager(profile)), backend_loop_(backend_loop), install_directory_(install_directory), extensions_enabled_(false), diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h index ea83cd2..81a44d7 100644 --- a/chrome/browser/extensions/extensions_service.h +++ b/chrome/browser/extensions/extensions_service.h @@ -169,10 +169,6 @@ class ExtensionsService ExtensionPrefs* extension_prefs() { return extension_prefs_.get(); } - ExtensionProcessManager* extension_process_manager() { - return extension_process_manager_.get(); - } - // Whether the extension service is ready. bool is_ready() { return ready_; } @@ -205,9 +201,6 @@ class ExtensionsService // Preferences for the owning profile. scoped_ptr<ExtensionPrefs> extension_prefs_; - // Controls how the various extension processes get created and destroyed. - scoped_ptr<ExtensionProcessManager> extension_process_manager_; - // The message loop to use with the backend. MessageLoop* backend_loop_; diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc index 18cd5ef..35bf8c2 100644 --- a/chrome/browser/profile.cc +++ b/chrome/browser/profile.cc @@ -434,6 +434,8 @@ ProfileImpl::ProfileImpl(const FilePath& path) TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, &ProfileImpl::EnsureSessionServiceCreated); + extension_process_manager_.reset(new ExtensionProcessManager(this)); + PrefService* prefs = GetPrefs(); prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this); prefs->AddPrefObserver(prefs::kEnableSpellCheck, this); @@ -653,7 +655,7 @@ UserScriptMaster* ProfileImpl::GetUserScriptMaster() { } ExtensionProcessManager* ProfileImpl::GetExtensionProcessManager() { - return extensions_service_->extension_process_manager(); + return extension_process_manager_.get(); } SSLHostState* ProfileImpl::GetSSLHostState() { diff --git a/chrome/browser/profile.h b/chrome/browser/profile.h index 57f3bad..1501462 100644 --- a/chrome/browser/profile.h +++ b/chrome/browser/profile.h @@ -401,6 +401,7 @@ class ProfileImpl : public Profile, scoped_ptr<VisitedLinkMaster> visited_link_master_; scoped_refptr<ExtensionsService> extensions_service_; scoped_refptr<UserScriptMaster> user_script_master_; + scoped_ptr<ExtensionProcessManager> extension_process_manager_; scoped_ptr<SSLHostState> ssl_host_state_; scoped_ptr<net::ForceTLSState> force_tls_state_; scoped_ptr<PrefService> prefs_; |