diff options
-rw-r--r-- | chrome/browser/extensions/extension_process_manager.cc | 21 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_process_manager.h | 3 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.cc | 4 | ||||
-rw-r--r-- | chrome/browser/task_manager_resource_providers.cc | 83 | ||||
-rw-r--r-- | chrome/browser/task_manager_resource_providers.h | 12 | ||||
-rw-r--r-- | chrome/common/notification_type.h | 8 |
6 files changed, 108 insertions, 23 deletions
diff --git a/chrome/browser/extensions/extension_process_manager.cc b/chrome/browser/extensions/extension_process_manager.cc index a511920..dc068e6 100644 --- a/chrome/browser/extensions/extension_process_manager.cc +++ b/chrome/browser/extensions/extension_process_manager.cc @@ -11,6 +11,7 @@ #include "chrome/browser/tab_contents/site_instance.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/notification_service.h" +#include "chrome/common/notification_type.h" static void CreateBackgroundHosts( ExtensionProcessManager* manager, const ExtensionList* extensions) { @@ -50,7 +51,7 @@ ExtensionHost* ExtensionProcessManager::CreateView(Extension* extension, ExtensionHost* host = new ExtensionHost(extension, GetSiteInstanceForURL(url), url, this); host->CreateView(browser); - all_hosts_.insert(host); + OnExtensionHostCreated(host, false); return host; } @@ -59,8 +60,7 @@ ExtensionHost* ExtensionProcessManager::CreateBackgroundHost( ExtensionHost* host = new ExtensionHost(extension, GetSiteInstanceForURL(url), url, this); host->CreateRenderView(NULL); // create a RenderViewHost with no view - all_hosts_.insert(host); - background_hosts_.insert(host); + OnExtensionHostCreated(host, true); return host; } @@ -101,4 +101,19 @@ void ExtensionProcessManager::Observe(NotificationType type, 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::OnExtensionHostCreated(ExtensionHost* host, + bool is_background) { + all_hosts_.insert(host); + if (is_background) + background_hosts_.insert(host); + NotificationService::current()->Notify( + NotificationType::EXTENSION_HOST_CREATED, + Source<ExtensionProcessManager>(this), + Details<ExtensionHost>(host)); } diff --git a/chrome/browser/extensions/extension_process_manager.h b/chrome/browser/extensions/extension_process_manager.h index 23fcb25..f12b49e 100644 --- a/chrome/browser/extensions/extension_process_manager.h +++ b/chrome/browser/extensions/extension_process_manager.h @@ -57,6 +57,9 @@ class ExtensionProcessManager : public NotificationObserver { void OnExtensionHostDestroyed(ExtensionHost* host); private: + // Called just after |host| is created so it can be registered in our lists. + void OnExtensionHostCreated(ExtensionHost* host, bool is_background); + NotificationRegistrar registrar_; // The set of all ExtensionHosts managed by this process manager. diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index d7d787e..4033f80 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -953,8 +953,6 @@ void RenderViewHost::OnMsgNavigate(const IPC::Message& msg) { FilterURL(policy, renderer_id, &validated_params.password_form.origin); FilterURL(policy, renderer_id, &validated_params.password_form.action); - delegate_->DidNavigate(this, validated_params); - if (PageTransition::IsMainFrame(validated_params.transition)) { ExtensionFunctionDispatcher* new_efd = NULL; if (validated_params.url.SchemeIs(chrome::kExtensionScheme)) { @@ -964,6 +962,8 @@ void RenderViewHost::OnMsgNavigate(const IPC::Message& msg) { extension_function_dispatcher_.reset(new_efd); } + delegate_->DidNavigate(this, validated_params); + UpdateBackForwardListCount(); } diff --git a/chrome/browser/task_manager_resource_providers.cc b/chrome/browser/task_manager_resource_providers.cc index 6f9b6d0..7279aab 100644 --- a/chrome/browser/task_manager_resource_providers.cc +++ b/chrome/browser/task_manager_resource_providers.cc @@ -137,17 +137,11 @@ TaskManager::Resource* TaskManagerTabContentsResourceProvider::GetResource( void TaskManagerTabContentsResourceProvider::StartUpdating() { DCHECK(!updating_); updating_ = true; + // Add all the existing TabContents. - for (TabContentsIterator iterator; !iterator.done(); iterator++) { - TabContents* tab_contents = *iterator; - // Don't add dead tabs or tabs that haven't yet connected. - // Also ignore tabs which display extension content. We collapse - // all of these into one extension row. - if (tab_contents->process()->process().handle() && - tab_contents->notify_disconnection() && - !tab_contents->HostsExtension()) - AddToTaskManager(tab_contents); - } + for (TabContentsIterator iterator; !iterator.done(); iterator++) + Add(*iterator); + // Then we register for notifications to get new tabs. registrar_.Add(this, NotificationType::TAB_CONTENTS_CONNECTED, NotificationService::AllSources()); @@ -195,9 +189,12 @@ void TaskManagerTabContentsResourceProvider::Add(TabContents* tab_contents) { if (!updating_) return; - if (!tab_contents->process()->process().handle()) { - // Don't add sad tabs, we would have no information to show for them since - // they have no associated process. + // Don't add dead tabs or tabs that haven't yet connected. + // Also ignore tabs which display extension content. We collapse + // all of these into one extension row. + if (!tab_contents->process()->process().handle() || + !tab_contents->notify_disconnection() || + tab_contents->HostsExtension()) { return; } @@ -531,6 +528,7 @@ TaskManager::Resource* TaskManagerExtensionProcessResourceProvider::GetResource( void TaskManagerExtensionProcessResourceProvider::StartUpdating() { DCHECK(!updating_); updating_ = true; + // Add all the existing ExtensionHosts. ProfileManager* profile_manager = g_browser_process->profile_manager(); for (ProfileManager::const_iterator it = profile_manager->begin(); @@ -541,16 +539,23 @@ void TaskManagerExtensionProcessResourceProvider::StartUpdating() { for (jt = process_manager->begin(); jt != process_manager->end(); ++jt) AddToTaskManager(*jt); } - // TODO(phajdan.jr): Also look for TabContents which are displaying - // extension content to aggregate network usage. - // TODO(phajdan.jr): Register for notifications. + + // Register for notifications to get new extension processes. + registrar_.Add(this, NotificationType::EXTENSION_HOST_CREATED, + NotificationService::AllSources()); + registrar_.Add(this, NotificationType::EXTENSION_HOST_DESTROYED, + NotificationService::AllSources()); } void TaskManagerExtensionProcessResourceProvider::StopUpdating() { DCHECK(updating_); updating_ = false; - // TODO(phajdan.jr): Unregister notifications. + // Unregister for notifications to get new extension processes. + registrar_.Remove(this, NotificationType::EXTENSION_HOST_CREATED, + NotificationService::AllSources()); + registrar_.Remove(this, NotificationType::EXTENSION_HOST_DESTROYED, + NotificationService::AllSources()); // Delete all the resources. STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); @@ -559,6 +564,23 @@ void TaskManagerExtensionProcessResourceProvider::StopUpdating() { pid_to_resources_.clear(); } +void TaskManagerExtensionProcessResourceProvider::Observe( + NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + switch (type.value) { + case NotificationType::EXTENSION_HOST_CREATED: + AddToTaskManager(Details<ExtensionHost>(details).ptr()); + break; + case NotificationType::EXTENSION_HOST_DESTROYED: + RemoveFromTaskManager(Details<ExtensionHost>(details).ptr()); + break; + default: + NOTREACHED() << "Unexpected notification."; + return; + } +} + void TaskManagerExtensionProcessResourceProvider::AddToTaskManager( ExtensionHost* extension_host) { TaskManagerExtensionProcessResource* resource = @@ -569,6 +591,33 @@ void TaskManagerExtensionProcessResourceProvider::AddToTaskManager( task_manager_->AddResource(resource); } +void TaskManagerExtensionProcessResourceProvider::RemoveFromTaskManager( + ExtensionHost* extension_host) { + if (!updating_) + return; + std::map<ExtensionHost*, TaskManagerExtensionProcessResource*> + ::iterator iter = resources_.find(extension_host); + if (iter == resources_.end()) + return; + + // Remove the resource from the Task Manager. + TaskManagerExtensionProcessResource* resource = iter->second; + task_manager_->RemoveResource(resource); + + // Remove it from the provider. + resources_.erase(iter); + + // Remove it from our pid map. + std::map<int, TaskManagerExtensionProcessResource*>::iterator pid_iter = + pid_to_resources_.find(resource->process_id()); + DCHECK(pid_iter != pid_to_resources_.end()); + if (pid_iter != pid_to_resources_.end()) + pid_to_resources_.erase(pid_iter); + + // Finally, delete the resource. + delete resource; +} + //////////////////////////////////////////////////////////////////////////////// // TaskManagerBrowserProcessResource class //////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/task_manager_resource_providers.h b/chrome/browser/task_manager_resource_providers.h index a5ee44d..e9640f0 100644 --- a/chrome/browser/task_manager_resource_providers.h +++ b/chrome/browser/task_manager_resource_providers.h @@ -205,7 +205,8 @@ class TaskManagerExtensionProcessResource : public TaskManager::Resource { }; class TaskManagerExtensionProcessResourceProvider - : public TaskManager::ResourceProvider { + : public TaskManager::ResourceProvider, + public NotificationObserver { public: explicit TaskManagerExtensionProcessResourceProvider( TaskManager* task_manager); @@ -217,8 +218,14 @@ class TaskManagerExtensionProcessResourceProvider virtual void StartUpdating(); virtual void StopUpdating(); + // NotificationObserver method: + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + private: void AddToTaskManager(ExtensionHost* extension_host); + void RemoveFromTaskManager(ExtensionHost* extension_host); TaskManager* task_manager_; @@ -229,6 +236,9 @@ class TaskManagerExtensionProcessResourceProvider // byte read notifications). std::map<int, TaskManagerExtensionProcessResource*> pid_to_resources_; + // A scoped container for notification registries. + NotificationRegistrar registrar_; + bool updating_; DISALLOW_COPY_AND_ASSIGN(TaskManagerExtensionProcessResourceProvider); diff --git a/chrome/common/notification_type.h b/chrome/common/notification_type.h index f922844..3c8b26a 100644 --- a/chrome/common/notification_type.h +++ b/chrome/common/notification_type.h @@ -568,6 +568,14 @@ class NotificationType { // state. EXTENSION_UNLOADED, + // Sent after a new ExtensionHost is created. The details are + // an ExtensionHost*. + EXTENSION_HOST_CREATED, + + // Sent before an ExtensionHost is destroyed. The details are + // an ExtensionHost*. + EXTENSION_HOST_DESTROYED, + // Debugging --------------------------------------------------------------- // Sent from ~RenderViewHost. The source is the RenderViewHost. |