diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-01 19:56:32 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-01 19:56:32 +0000 |
commit | 1527c4cba4d9d72d4acde8598aa9da61cb0ff9f8 (patch) | |
tree | c1d8d49da11b14904cf115e336de5293fdf29218 /chrome/browser/task_manager | |
parent | b6cc6548fc7dde9211a16444a6709bc17cc88413 (diff) | |
download | chromium_src-1527c4cba4d9d72d4acde8598aa9da61cb0ff9f8.zip chromium_src-1527c4cba4d9d72d4acde8598aa9da61cb0ff9f8.tar.gz chromium_src-1527c4cba4d9d72d4acde8598aa9da61cb0ff9f8.tar.bz2 |
Make TaskManager not use ChildProcessInfo. After this change, I will make BrowserChildProcessHost not derive from ChildProcessInfo, and just remove that struct completely.
BUG=98716
Review URL: http://codereview.chromium.org/8764021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112500 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/task_manager')
-rw-r--r-- | chrome/browser/task_manager/task_manager_resource_providers.cc | 94 | ||||
-rw-r--r-- | chrome/browser/task_manager/task_manager_resource_providers.h | 55 |
2 files changed, 84 insertions, 65 deletions
diff --git a/chrome/browser/task_manager/task_manager_resource_providers.cc b/chrome/browser/task_manager/task_manager_resource_providers.cc index 1014a93..8e1cc11 100644 --- a/chrome/browser/task_manager/task_manager_resource_providers.cc +++ b/chrome/browser/task_manager/task_manager_resource_providers.cc @@ -746,13 +746,16 @@ void TaskManagerBackgroundContentsResourceProvider::Observe( SkBitmap* TaskManagerChildProcessResource::default_icon_ = NULL; TaskManagerChildProcessResource::TaskManagerChildProcessResource( - const ChildProcessInfo& child_proc) - : child_process_(child_proc), - title_(), + content::ProcessType type, + const string16& name, + base::ProcessHandle handle) + : type_(type), + name_(name), + handle_(handle), network_usage_support_(false) { // We cache the process id because it's not cheap to calculate, and it won't // be available when we get the plugin disconnected notification. - pid_ = child_proc.pid(); + pid_ = base::GetProcId(handle); if (!default_icon_) { ResourceBundle& rb = ResourceBundle::GetSharedInstance(); default_icon_ = rb.GetBitmapNamed(IDR_PLUGIN); @@ -780,13 +783,13 @@ SkBitmap TaskManagerChildProcessResource::GetIcon() const { } base::ProcessHandle TaskManagerChildProcessResource::GetProcess() const { - return child_process_.handle(); + return handle_; } TaskManager::Resource::Type TaskManagerChildProcessResource::GetType() const { // Translate types to TaskManager::ResourceType, since ChildProcessInfo's type // is not available for all TaskManager resources. - switch (child_process_.type()) { + switch (type_) { case content::PROCESS_TYPE_PLUGIN: case content::PROCESS_TYPE_PPAPI_PLUGIN: case content::PROCESS_TYPE_PPAPI_BROKER: @@ -818,9 +821,9 @@ void TaskManagerChildProcessResource::SetSupportNetworkUsage() { } string16 TaskManagerChildProcessResource::GetLocalizedTitle() const { - string16 title = child_process_.name(); + string16 title = name_; if (title.empty()) { - switch (child_process_.type()) { + switch (type_) { case content::PROCESS_TYPE_PLUGIN: case content::PROCESS_TYPE_PPAPI_PLUGIN: case content::PROCESS_TYPE_PPAPI_BROKER: @@ -838,7 +841,7 @@ string16 TaskManagerChildProcessResource::GetLocalizedTitle() const { // or Arabic word for "plugin". base::i18n::AdjustStringForLocaleDirection(&title); - switch (child_process_.type()) { + switch (type_) { case content::PROCESS_TYPE_UTILITY: return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_UTILITY_PREFIX); @@ -853,12 +856,11 @@ string16 TaskManagerChildProcessResource::GetLocalizedTitle() const { case content::PROCESS_TYPE_PLUGIN: case content::PROCESS_TYPE_PPAPI_PLUGIN: - return l10n_util::GetStringFUTF16( - IDS_TASK_MANAGER_PLUGIN_PREFIX, title, child_process_.version()); + return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_PLUGIN_PREFIX, title); case content::PROCESS_TYPE_PPAPI_BROKER: return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_PLUGIN_BROKER_PREFIX, - title, child_process_.version()); + title); case content::PROCESS_TYPE_NACL_LOADER: return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_NACL_PREFIX, title); @@ -889,8 +891,8 @@ string16 TaskManagerChildProcessResource::GetLocalizedTitle() const { TaskManagerChildProcessResourceProvider:: TaskManagerChildProcessResourceProvider(TaskManager* task_manager) - : updating_(false), - task_manager_(task_manager) { + : task_manager_(task_manager), + updating_(false) { } TaskManagerChildProcessResourceProvider:: @@ -901,8 +903,7 @@ TaskManager::Resource* TaskManagerChildProcessResourceProvider::GetResource( int origin_pid, int render_process_host_id, int routing_id) { - std::map<int, TaskManagerChildProcessResource*>::iterator iter = - pid_to_resources_.find(origin_pid); + PidResourceMap::iterator iter = pid_to_resources_.find(origin_pid); if (iter != pid_to_resources_.end()) return iter->second; else @@ -945,19 +946,23 @@ void TaskManagerChildProcessResourceProvider::StopUpdating() { resources_.clear(); pid_to_resources_.clear(); - existing_child_process_info_.clear(); } void TaskManagerChildProcessResourceProvider::Observe( int type, const content::NotificationSource& source, const content::NotificationDetails& details) { + content::Details<ChildProcessInfo> child_details(details); + ChildProcessData data; + data.type = child_details->type(); + data.name = child_details->name(); + data.handle = child_details->handle(); switch (type) { case content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED: - Add(*content::Details<ChildProcessInfo>(details).ptr()); + Add(data); break; case content::NOTIFICATION_CHILD_PROCESS_HOST_DISCONNECTED: - Remove(*content::Details<ChildProcessInfo>(details).ptr()); + Remove(data); break; default: NOTREACHED() << "Unexpected notification."; @@ -966,32 +971,29 @@ void TaskManagerChildProcessResourceProvider::Observe( } void TaskManagerChildProcessResourceProvider::Add( - const ChildProcessInfo& child_process_info) { + const ChildProcessData& child_process_data) { if (!updating_) return; // Workers are handled by TaskManagerWorkerResourceProvider. - if (child_process_info.type() == content::PROCESS_TYPE_WORKER) + if (child_process_data.type == content::PROCESS_TYPE_WORKER) return; - std::map<ChildProcessInfo, TaskManagerChildProcessResource*>:: - const_iterator iter = resources_.find(child_process_info); - if (iter != resources_.end()) { + if (resources_.count(child_process_data.handle)) { // The case may happen that we have added a child_process_info as part of // the iteration performed during StartUpdating() call but the notification // that it has connected was not fired yet. So when the notification // happens, we already know about this plugin and just ignore it. return; } - AddToTaskManager(child_process_info); + AddToTaskManager(child_process_data); } void TaskManagerChildProcessResourceProvider::Remove( - const ChildProcessInfo& child_process_info) { + const ChildProcessData& child_process_data) { if (!updating_) return; - if (child_process_info.type() == content::PROCESS_TYPE_WORKER) + if (child_process_data.type == content::PROCESS_TYPE_WORKER) return; - std::map<ChildProcessInfo, TaskManagerChildProcessResource*> - ::iterator iter = resources_.find(child_process_info); + ChildProcessMap::iterator iter = resources_.find(child_process_data.handle); if (iter == resources_.end()) { // ChildProcessInfo disconnection notifications are asynchronous, so we // might be notified for a plugin we don't know anything about (if it was @@ -1004,7 +1006,7 @@ void TaskManagerChildProcessResourceProvider::Remove( // Remove it from the provider. resources_.erase(iter); // Remove it from our pid map. - std::map<int, TaskManagerChildProcessResource*>::iterator pid_iter = + PidResourceMap::iterator pid_iter = pid_to_resources_.find(resource->process_id()); DCHECK(pid_iter != pid_to_resources_.end()); if (pid_iter != pid_to_resources_.end()) @@ -1015,20 +1017,29 @@ void TaskManagerChildProcessResourceProvider::Remove( } void TaskManagerChildProcessResourceProvider::AddToTaskManager( - const ChildProcessInfo& child_process_info) { + const ChildProcessData& child_process_data) { TaskManagerChildProcessResource* resource = - new TaskManagerChildProcessResource(child_process_info); - resources_[child_process_info] = resource; + new TaskManagerChildProcessResource( + child_process_data.type, + child_process_data.name, + child_process_data.handle); + resources_[child_process_data.handle] = resource; pid_to_resources_[resource->process_id()] = resource; task_manager_->AddResource(resource); } // The ChildProcessInfo::Iterator has to be used from the IO thread. void TaskManagerChildProcessResourceProvider::RetrieveChildProcessInfo() { + std::vector<ChildProcessData> child_processes; for (BrowserChildProcessHost::Iterator iter; !iter.Done(); ++iter) { // Only add processes which are already started, since we need their handle. - if ((*iter)->handle() != base::kNullProcessHandle) - existing_child_process_info_.push_back(**iter); + if ((*iter)->handle() == base::kNullProcessHandle) + continue; + ChildProcessData data; + data.type = (*iter)->type(); + data.name = (*iter)->name(); + data.handle = (*iter)->handle(); + child_processes.push_back(data); } // Now notify the UI thread that we have retrieved information about child // processes. @@ -1036,17 +1047,14 @@ void TaskManagerChildProcessResourceProvider::RetrieveChildProcessInfo() { BrowserThread::UI, FROM_HERE, base::Bind( &TaskManagerChildProcessResourceProvider::ChildProcessInfoRetreived, - this)); + this, child_processes)); } // This is called on the UI thread. -void TaskManagerChildProcessResourceProvider::ChildProcessInfoRetreived() { - std::vector<ChildProcessInfo>::const_iterator iter; - for (iter = existing_child_process_info_.begin(); - iter != existing_child_process_info_.end(); ++iter) { - Add(*iter); - } - existing_child_process_info_.clear(); +void TaskManagerChildProcessResourceProvider::ChildProcessInfoRetreived( + const std::vector<ChildProcessData>& child_processes) { + for (size_t i = 0; i < child_processes.size(); ++i) + Add(child_processes[i]); } //////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/task_manager/task_manager_resource_providers.h b/chrome/browser/task_manager/task_manager_resource_providers.h index e52cadf..fea7e64 100644 --- a/chrome/browser/task_manager/task_manager_resource_providers.h +++ b/chrome/browser/task_manager/task_manager_resource_providers.h @@ -13,9 +13,9 @@ #include "base/compiler_specific.h" #include "base/process_util.h" #include "chrome/browser/task_manager/task_manager.h" -#include "content/common/child_process_info.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" +#include "content/public/common/process_type.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebCache.h" class BackgroundContents; @@ -233,7 +233,9 @@ class TaskManagerBackgroundContentsResourceProvider class TaskManagerChildProcessResource : public TaskManager::Resource { public: - explicit TaskManagerChildProcessResource(const ChildProcessInfo& child_proc); + TaskManagerChildProcessResource(content::ProcessType type, + const string16& name, + base::ProcessHandle handle); virtual ~TaskManagerChildProcessResource(); // TaskManager::Resource methods: @@ -253,7 +255,9 @@ class TaskManagerChildProcessResource : public TaskManager::Resource { // process would be "Plug-in: Flash" when name is "Flash". string16 GetLocalizedTitle() const; - ChildProcessInfo child_process_; + content::ProcessType type_; + string16 name_; + base::ProcessHandle handle_; int pid_; mutable string16 title_; bool network_usage_support_; @@ -283,36 +287,45 @@ class TaskManagerChildProcessResourceProvider const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; - // Retrieves the current ChildProcessInfo (performed in the IO thread). - virtual void RetrieveChildProcessInfo(); + private: + struct ChildProcessData { + content::ProcessType type; + string16 name; + base::ProcessHandle handle; + }; - // Notifies the UI thread that the ChildProcessInfo have been retrieved. - virtual void ChildProcessInfoRetreived(); + virtual ~TaskManagerChildProcessResourceProvider(); - // Whether we are currently reporting to the task manager. Used to ignore - // notifications sent after StopUpdating(). - bool updating_; + // Retrieves information about the running ChildProcessHosts (performed in the + // IO thread). + virtual void RetrieveChildProcessInfo(); - // The list of ChildProcessInfo retrieved when starting the update. - std::vector<ChildProcessInfo> existing_child_process_info_; + // Notifies the UI thread that the ChildProcessHosts information have been + // retrieved. + virtual void ChildProcessInfoRetreived( + const std::vector<ChildProcessData>& child_processes); - private: - virtual ~TaskManagerChildProcessResourceProvider(); - - void Add(const ChildProcessInfo& child_process_info); - void Remove(const ChildProcessInfo& child_process_info); + void Add(const ChildProcessData& child_process_data); + void Remove(const ChildProcessData& child_process_data); - void AddToTaskManager(const ChildProcessInfo& child_process_info); + void AddToTaskManager(const ChildProcessData& child_process_data); TaskManager* task_manager_; + // Whether we are currently reporting to the task manager. Used to ignore + // notifications sent after StopUpdating(). + bool updating_; + // Maps the actual resources (the ChildProcessInfo) to the Task Manager // resources. - std::map<ChildProcessInfo, TaskManagerChildProcessResource*> resources_; + typedef std::map<base::ProcessHandle, TaskManagerChildProcessResource*> + ChildProcessMap; + ChildProcessMap resources_; // Maps the pids to the resources (used for quick access to the resource on // byte read notifications). - std::map<int, TaskManagerChildProcessResource*> pid_to_resources_; + typedef std::map<int, TaskManagerChildProcessResource*> PidResourceMap; + PidResourceMap pid_to_resources_; // A scoped container for notification registries. content::NotificationRegistrar registrar_; @@ -518,8 +531,6 @@ class TaskManagerBrowserProcessResourceProvider private: virtual ~TaskManagerBrowserProcessResourceProvider(); - void AddToTaskManager(ChildProcessInfo child_process_info); - TaskManager* task_manager_; TaskManagerBrowserProcessResource resource_; |