summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_process_manager.cc
diff options
context:
space:
mode:
authortessamac@chromium.org <tessamac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-20 20:57:12 +0000
committertessamac@chromium.org <tessamac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-20 20:57:12 +0000
commit06024c63d9de26d6fdccd8eab2bc25440dbc6d2f (patch)
tree45c715a6d0cdde0dc133fdbcf30d0256a3a83235 /chrome/browser/extensions/extension_process_manager.cc
parent390b99620dacb34962eec63e3e93dcdb507b5814 (diff)
downloadchromium_src-06024c63d9de26d6fdccd8eab2bc25440dbc6d2f.zip
chromium_src-06024c63d9de26d6fdccd8eab2bc25440dbc6d2f.tar.gz
chromium_src-06024c63d9de26d6fdccd8eab2bc25440dbc6d2f.tar.bz2
Close Lazy Background Page after event dispatch
BUG=81752 TEST= Review URL: http://codereview.chromium.org/8230035 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106573 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_process_manager.cc')
-rw-r--r--chrome/browser/extensions/extension_process_manager.cc44
1 files changed, 35 insertions, 9 deletions
diff --git a/chrome/browser/extensions/extension_process_manager.cc b/chrome/browser/extensions/extension_process_manager.cc
index df68f78..c2a61d8 100644
--- a/chrome/browser/extensions/extension_process_manager.cc
+++ b/chrome/browser/extensions/extension_process_manager.cc
@@ -191,7 +191,7 @@ void ExtensionProcessManager::CreateBackgroundHost(
return;
// Don't create multiple background hosts for an extension.
- if (GetBackgroundHostForExtension(extension))
+ if (GetBackgroundHostForExtension(extension->id()))
return;
ExtensionHost* host =
@@ -227,14 +227,15 @@ void ExtensionProcessManager::OpenOptionsPage(const Extension* extension,
}
ExtensionHost* ExtensionProcessManager::GetBackgroundHostForExtension(
- const Extension* extension) {
+ const std::string& extension_id) {
for (ExtensionHostSet::iterator iter = background_hosts_.begin();
iter != background_hosts_.end(); ++iter) {
ExtensionHost* host = *iter;
- if (host->extension() == extension)
+ if (host->extension_id() == extension_id)
return host;
}
return NULL;
+
}
std::set<RenderViewHost*>
@@ -417,6 +418,27 @@ bool ExtensionProcessManager::HasExtensionHost(ExtensionHost* host) const {
return all_hosts_.find(host) != all_hosts_.end();
}
+void ExtensionProcessManager::OnExtensionIdle(const std::string& extension_id) {
+ ExtensionHost* host = GetBackgroundHostForExtension(extension_id);
+ if (host && !HasVisibleViews(extension_id))
+ CloseBackgroundHost(host);
+}
+
+bool ExtensionProcessManager::HasVisibleViews(const std::string& extension_id) {
+ const std::set<RenderViewHost*>& views =
+ GetRenderViewHostsForExtension(extension_id);
+ for (std::set<RenderViewHost*>::const_iterator it = views.begin();
+ it != views.end(); ++it) {
+ const RenderViewHost* host = *it;
+ if (host->site_instance()->site().host() == extension_id &&
+ host->delegate()->GetRenderViewType() !=
+ chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) {
+ return true;
+ }
+ }
+ return false;
+}
+
void ExtensionProcessManager::Observe(
int type,
const content::NotificationSource& source,
@@ -447,9 +469,7 @@ void ExtensionProcessManager::Observe(
iter != background_hosts_.end(); ++iter) {
ExtensionHost* host = *iter;
if (host->extension_id() == extension->id()) {
- delete host;
- // |host| should deregister itself from our structures.
- DCHECK(background_hosts_.find(host) == background_hosts_.end());
+ CloseBackgroundHost(host);
break;
}
}
@@ -473,9 +493,7 @@ void ExtensionProcessManager::Observe(
ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
if (host->extension_host_type() ==
chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) {
- delete host;
- // |host| should deregister itself from our structures.
- CHECK(background_hosts_.find(host) == background_hosts_.end());
+ CloseBackgroundHost(host);
}
break;
}
@@ -506,6 +524,14 @@ void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host,
content::Details<ExtensionHost>(host));
}
+void ExtensionProcessManager::CloseBackgroundHost(ExtensionHost* host) {
+ CHECK(host->extension_host_type() ==
+ chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE);
+ delete host;
+ // |host| should deregister itself from our structures.
+ CHECK(background_hosts_.find(host) == background_hosts_.end());
+}
+
void ExtensionProcessManager::CloseBackgroundHosts() {
for (ExtensionHostSet::iterator iter = background_hosts_.begin();
iter != background_hosts_.end(); ) {