summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-06 08:19:49 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-06 08:19:49 +0000
commit8a17bd55d6f0336a3d8e3c66af61a0a3b074dfe9 (patch)
treec46ba5bfb499017b07cacdb6f8665070e77bbb3a /chrome/browser/extensions
parent31e8a0105e34d04ec14a5387b907b90a776d82f5 (diff)
downloadchromium_src-8a17bd55d6f0336a3d8e3c66af61a0a3b074dfe9.zip
chromium_src-8a17bd55d6f0336a3d8e3c66af61a0a3b074dfe9.tar.gz
chromium_src-8a17bd55d6f0336a3d8e3c66af61a0a3b074dfe9.tar.bz2
Display extension processes in task manager.
This is the first part of the change. I will submit code to listen for new extension processes while task manager is open in following patch(es). TEST=Install an extension which renders to the extension shelf, like Buildbot Monitor from http://dev.chromium.org/developers/design-documents/extensions/samples. Open the task manager. You should see the extension process. http://crbug.com/12127 Review URL: http://codereview.chromium.org/115858 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17826 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r--chrome/browser/extensions/extension_host.cc11
-rw-r--r--chrome/browser/extensions/extension_host.h11
-rw-r--r--chrome/browser/extensions/extension_process_manager.cc28
-rw-r--r--chrome/browser/extensions/extension_process_manager.h22
-rw-r--r--chrome/browser/extensions/extension_view_unittest.cc2
5 files changed, 57 insertions, 17 deletions
diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc
index 9509577..c9eeda8 100644
--- a/chrome/browser/extensions/extension_host.cc
+++ b/chrome/browser/extensions/extension_host.cc
@@ -10,6 +10,7 @@
#include "chrome/browser/browser_process.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/extensions/extension_view.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/renderer_host/render_view_host.h"
@@ -28,8 +29,10 @@
#include "webkit/glue/context_menu.h"
-ExtensionHost::ExtensionHost(Extension* extension, SiteInstance* site_instance)
+ExtensionHost::ExtensionHost(Extension* extension, SiteInstance* site_instance,
+ ExtensionProcessManager* manager)
: extension_(extension),
+ manager_(manager),
#if defined(OS_WIN)
view_(NULL),
#endif
@@ -40,9 +43,15 @@ ExtensionHost::ExtensionHost(Extension* extension, SiteInstance* site_instance)
}
ExtensionHost::~ExtensionHost() {
+ if (manager_) // To allow passing NULL in tests.
+ manager_->OnExtensionHostDestroyed(this);
render_view_host_->Shutdown(); // deletes render_view_host
}
+RenderProcessHost* ExtensionHost::render_process_host() const {
+ return render_view_host_->process();
+}
+
SiteInstance* ExtensionHost::site_instance() const {
return render_view_host_->site_instance();
}
diff --git a/chrome/browser/extensions/extension_host.h b/chrome/browser/extensions/extension_host.h
index ba7c283..751e07f 100644
--- a/chrome/browser/extensions/extension_host.h
+++ b/chrome/browser/extensions/extension_host.h
@@ -5,12 +5,16 @@
#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_HOST_H_
#define CHROME_BROWSER_EXTENSIONS_EXTENSION_HOST_H_
+#include <string>
+
#include "chrome/browser/renderer_host/render_view_host_delegate.h"
#include "chrome/browser/tab_contents/render_view_host_delegate_helper.h"
class Browser;
class Extension;
+class ExtensionProcessManager;
class ExtensionView;
+class RenderProcessHost;
class RenderWidgetHost;
class RenderWidgetHostView;
class TabContents;
@@ -24,7 +28,8 @@ class ExtensionHost : public RenderViewHostDelegate,
public RenderViewHostDelegate::View,
public ExtensionFunctionDispatcher::Delegate {
public:
- ExtensionHost(Extension* extension, SiteInstance* site_instance);
+ ExtensionHost(Extension* extension, SiteInstance* site_instance,
+ ExtensionProcessManager* manager);
~ExtensionHost();
#if defined(TOOLKIT_VIEWS)
@@ -33,6 +38,7 @@ class ExtensionHost : public RenderViewHostDelegate,
#endif
Extension* extension() { return extension_; }
RenderViewHost* render_view_host() const { return render_view_host_; }
+ RenderProcessHost* render_process_host() const;
SiteInstance* site_instance() const;
bool did_stop_loading() const { return did_stop_loading_; }
@@ -86,6 +92,9 @@ 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_;
+
#if defined(TOOLKIT_VIEWS)
// Optional view that shows the rendered content in the UI.
ExtensionView* view_;
diff --git a/chrome/browser/extensions/extension_process_manager.cc b/chrome/browser/extensions/extension_process_manager.cc
index f2bcad4..3aab7fb 100644
--- a/chrome/browser/extensions/extension_process_manager.cc
+++ b/chrome/browser/extensions/extension_process_manager.cc
@@ -37,8 +37,11 @@ ExtensionProcessManager::ExtensionProcessManager(Profile* profile)
}
ExtensionProcessManager::~ExtensionProcessManager() {
- for (ExtensionHostList::iterator iter = background_hosts_.begin();
- iter != background_hosts_.end(); ++iter)
+ // Copy background_hosts_ to avoid iterator invalidation issues.
+ ExtensionHostSet to_delete(background_hosts_.begin(),
+ background_hosts_.end());
+ ExtensionHostSet::iterator iter;
+ for (iter = to_delete.begin(); iter != to_delete.end(); ++iter)
delete *iter;
}
@@ -46,17 +49,20 @@ ExtensionProcessManager::~ExtensionProcessManager() {
ExtensionView* ExtensionProcessManager::CreateView(Extension* extension,
const GURL& url,
Browser* browser) {
- return new ExtensionView(
- new ExtensionHost(extension, GetSiteInstanceForURL(url)), browser, url);
+ ExtensionHost* host = new ExtensionHost(extension,
+ GetSiteInstanceForURL(url), this);
+ all_hosts_.insert(host);
+ return new ExtensionView(host, browser, url);
}
#endif
void ExtensionProcessManager::CreateBackgroundHost(Extension* extension,
const GURL& url) {
ExtensionHost* host =
- new ExtensionHost(extension, GetSiteInstanceForURL(url));
+ new ExtensionHost(extension, GetSiteInstanceForURL(url), this);
host->CreateRenderView(url, NULL); // create a RenderViewHost with no view
- background_hosts_.push_back(host);
+ all_hosts_.insert(host);
+ background_hosts_.insert(host);
}
SiteInstance* ExtensionProcessManager::GetSiteInstanceForURL(const GURL& url) {
@@ -75,12 +81,13 @@ void ExtensionProcessManager::Observe(NotificationType type,
case NotificationType::EXTENSION_UNLOADED: {
Extension* extension = Details<Extension>(details).ptr();
- for (ExtensionHostList::iterator iter = background_hosts_.begin();
+ for (ExtensionHostSet::iterator iter = background_hosts_.begin();
iter != background_hosts_.end(); ++iter) {
ExtensionHost* host = *iter;
if (host->extension()->id() == extension->id()) {
- background_hosts_.erase(iter);
delete host;
+ // |host| should deregister itself from our structures.
+ DCHECK(background_hosts_.find(host) == background_hosts_.end());
break;
}
}
@@ -91,3 +98,8 @@ void ExtensionProcessManager::Observe(NotificationType type,
NOTREACHED();
}
}
+
+void ExtensionProcessManager::OnExtensionHostDestroyed(ExtensionHost* host) {
+ all_hosts_.erase(host);
+ background_hosts_.erase(host);
+}
diff --git a/chrome/browser/extensions/extension_process_manager.h b/chrome/browser/extensions/extension_process_manager.h
index 1b99933..48ce382 100644
--- a/chrome/browser/extensions/extension_process_manager.h
+++ b/chrome/browser/extensions/extension_process_manager.h
@@ -5,7 +5,7 @@
#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_
#define CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_
-#include <list>
+#include <set>
#include "base/ref_counted.h"
#include "chrome/common/notification_registrar.h"
@@ -25,7 +25,7 @@ class SiteInstance;
// of this class per Profile (including OTR).
class ExtensionProcessManager : public NotificationObserver {
public:
- ExtensionProcessManager(Profile* profile);
+ explicit ExtensionProcessManager(Profile* profile);
~ExtensionProcessManager();
#if defined(TOOLKIT_VIEWS)
@@ -48,13 +48,23 @@ class ExtensionProcessManager : public NotificationObserver {
const NotificationSource& source,
const NotificationDetails& details);
- private:
- typedef std::list<ExtensionHost*> ExtensionHostList;
+ typedef std::set<ExtensionHost*> ExtensionHostSet;
+ typedef ExtensionHostSet::const_iterator const_iterator;
+ 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);
+ private:
NotificationRegistrar registrar_;
- // The list of running viewless background extensions.
- ExtensionHostList background_hosts_;
+ // The set of all ExtensionHosts managed by this process manager.
+ ExtensionHostSet all_hosts_;
+
+ // The set of running viewless background extensions.
+ ExtensionHostSet background_hosts_;
// The BrowsingInstance shared by all extensions in this profile. This
// controls process grouping.
diff --git a/chrome/browser/extensions/extension_view_unittest.cc b/chrome/browser/extensions/extension_view_unittest.cc
index da4374e..6b35eac 100644
--- a/chrome/browser/extensions/extension_view_unittest.cc
+++ b/chrome/browser/extensions/extension_view_unittest.cc
@@ -35,7 +35,7 @@ class MockExtensionHost : public ExtensionHost {
public:
MockExtensionHost(Extension* extension, const GURL& url,
SiteInstance* instance)
- : ExtensionHost(extension, instance),
+ : ExtensionHost(extension, instance, NULL),
got_message_(false) {
CreateRenderView(url, NULL);
MessageLoop::current()->PostDelayedTask(FROM_HERE,