Index: chrome/browser/task_manager/task_manager_resource_providers.cc |
diff --git a/chrome/browser/task_manager/task_manager_resource_providers.cc b/chrome/browser/task_manager/task_manager_resource_providers.cc |
index 0a822365fa22eda109d00942ab8f030659854091..d208defd730b1bd1bcdeb30e168dd9c7abc1b9cd 100644 |
--- a/chrome/browser/task_manager/task_manager_resource_providers.cc |
+++ b/chrome/browser/task_manager/task_manager_resource_providers.cc |
@@ -80,9 +80,6 @@ TaskManagerRendererResource::TaskManagerRendererResource( |
v8_memory_allocated_(0), |
v8_memory_used_(0), |
pending_v8_memory_allocated_update_(false) { |
- // We cache the process and pid as when a Tab/BackgroundContents is closed the |
- // process reference becomes NULL and the TaskManager still needs it. |
- pid_ = base::GetProcId(process_); |
stats_.images.size = 0; |
stats_.cssStyleSheets.size = 0; |
stats_.scripts.size = 0; |
@@ -231,28 +228,17 @@ TaskManagerTabContentsResourceProvider:: |
} |
TaskManager::Resource* TaskManagerTabContentsResourceProvider::GetResource( |
- int origin_pid, |
+ int origin_child_id, |
int render_process_host_id, |
int routing_id) { |
+ if (origin_child_id != render_process_host_id) |
+ return NULL; |
TabContents* tab_contents = |
tab_util::GetTabContentsByID(render_process_host_id, routing_id); |
if (!tab_contents) // Not one of our resource. |
return NULL; |
- base::ProcessHandle process_handle = |
- tab_contents->GetRenderProcessHost()->GetHandle(); |
- if (!process_handle) { |
- // We should not be holding on to a dead tab (it should have been removed |
- // through the NOTIFY_TAB_CONTENTS_DISCONNECTED notification. |
- NOTREACHED(); |
- return NULL; |
- } |
- |
- int pid = base::GetProcId(process_handle); |
- if (pid != origin_pid) |
- return NULL; |
- |
std::map<TabContents*, TaskManagerTabContentsResource*>::iterator |
res_iter = resources_.find(tab_contents); |
if (res_iter == resources_.end()) { |
@@ -451,24 +437,17 @@ TaskManagerBackgroundContentsResourceProvider:: |
TaskManager::Resource* |
TaskManagerBackgroundContentsResourceProvider::GetResource( |
- int origin_pid, |
+ int origin_child_id, |
int render_process_host_id, |
int routing_id) { |
+ if (origin_child_id != render_process_host_id) |
+ return NULL; |
BackgroundContents* contents = BackgroundContents::GetBackgroundContentsByID( |
render_process_host_id, routing_id); |
if (!contents) // This resource no longer exists. |
return NULL; |
- base::ProcessHandle process_handle = |
- contents->render_view_host()->process()->GetHandle(); |
- if (!process_handle) // Process crashed. |
- return NULL; |
- |
- int pid = base::GetProcId(process_handle); |
- if (pid != origin_pid) |
- return NULL; |
- |
std::map<BackgroundContents*, |
TaskManagerBackgroundContentsResource*>::iterator res_iter = |
resources_.find(contents); |
@@ -641,9 +620,6 @@ TaskManagerChildProcessResource::TaskManagerChildProcessResource( |
: child_process_(child_proc), |
title_(), |
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.id(); |
if (!default_icon_) { |
ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
default_icon_ = rb.GetBitmapNamed(IDR_PLUGIN); |
@@ -723,12 +699,12 @@ TaskManagerChildProcessResourceProvider:: |
} |
TaskManager::Resource* TaskManagerChildProcessResourceProvider::GetResource( |
- int origin_pid, |
+ int origin_child_id, |
int render_process_host_id, |
int routing_id) { |
std::map<int, TaskManagerChildProcessResource*>::iterator iter = |
- pid_to_resources_.find(origin_pid); |
- if (iter != pid_to_resources_.end()) |
+ child_id_to_resources_.find(origin_child_id); |
+ if (iter != child_id_to_resources_.end()) |
return iter->second; |
else |
return NULL; |
@@ -767,7 +743,7 @@ void TaskManagerChildProcessResourceProvider::StopUpdating() { |
STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); |
resources_.clear(); |
- pid_to_resources_.clear(); |
+ child_id_to_resources_.clear(); |
existing_child_process_info_.clear(); |
} |
@@ -821,12 +797,12 @@ void TaskManagerChildProcessResourceProvider::Remove( |
task_manager_->RemoveResource(resource); |
// Remove it from the provider. |
resources_.erase(iter); |
- // Remove it from our pid map. |
- std::map<int, TaskManagerChildProcessResource*>::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); |
+ // Remove it from our child ID map. |
+ std::map<int, TaskManagerChildProcessResource*>::iterator id_iter = |
+ child_id_to_resources_.find(resource->id()); |
+ DCHECK(id_iter != child_id_to_resources_.end()); |
+ if (id_iter != child_id_to_resources_.end()) |
+ child_id_to_resources_.erase(id_iter); |
// Finally, delete the resource. |
delete resource; |
@@ -837,7 +813,7 @@ void TaskManagerChildProcessResourceProvider::AddToTaskManager( |
TaskManagerChildProcessResource* resource = |
new TaskManagerChildProcessResource(child_process_info); |
resources_[child_process_info] = resource; |
- pid_to_resources_[resource->process_id()] = resource; |
+ child_id_to_resources_[resource->id()] = resource; |
task_manager_->AddResource(resource); |
} |
@@ -880,7 +856,6 @@ TaskManagerExtensionProcessResource::TaskManagerExtensionProcessResource( |
default_icon_ = rb.GetBitmapNamed(IDR_PLUGIN); |
} |
process_handle_ = extension_host_->render_process_host()->GetHandle(); |
- pid_ = base::GetProcId(process_handle_); |
string16 extension_name = UTF8ToUTF16(GetExtension()->name()); |
DCHECK(!extension_name.empty()); |
@@ -888,6 +863,7 @@ TaskManagerExtensionProcessResource::TaskManagerExtensionProcessResource( |
extension_host_->profile()->IsOffTheRecord()); |
title_ = UTF16ToWideHack(l10n_util::GetStringFUTF16(message_id, |
extension_name)); |
+ id_ = extension_host->render_process_host()->id(); |
} |
TaskManagerExtensionProcessResource::~TaskManagerExtensionProcessResource() { |
@@ -942,12 +918,12 @@ TaskManagerExtensionProcessResourceProvider:: |
} |
TaskManager::Resource* TaskManagerExtensionProcessResourceProvider::GetResource( |
- int origin_pid, |
+ int origin_child_id, |
int render_process_host_id, |
int routing_id) { |
std::map<int, TaskManagerExtensionProcessResource*>::iterator iter = |
- pid_to_resources_.find(origin_pid); |
- if (iter != pid_to_resources_.end()) |
+ child_id_to_resources_.find(origin_child_id); |
+ if (iter != child_id_to_resources_.end()) |
return iter->second; |
else |
return NULL; |
@@ -1007,7 +983,7 @@ void TaskManagerExtensionProcessResourceProvider::StopUpdating() { |
STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); |
resources_.clear(); |
- pid_to_resources_.clear(); |
+ child_id_to_resources_.clear(); |
} |
void TaskManagerExtensionProcessResourceProvider::Observe( |
@@ -1038,7 +1014,7 @@ void TaskManagerExtensionProcessResourceProvider::AddToTaskManager( |
new TaskManagerExtensionProcessResource(extension_host); |
DCHECK(resources_.find(extension_host) == resources_.end()); |
resources_[extension_host] = resource; |
- pid_to_resources_[resource->process_id()] = resource; |
+ child_id_to_resources_[resource->id()] = resource; |
task_manager_->AddResource(resource); |
} |
@@ -1058,12 +1034,12 @@ void TaskManagerExtensionProcessResourceProvider::RemoveFromTaskManager( |
// 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); |
+ // Remove it from our child ID map. |
+ std::map<int, TaskManagerExtensionProcessResource*>::iterator id_iter = |
+ child_id_to_resources_.find(resource->id()); |
+ DCHECK(id_iter != child_id_to_resources_.end()); |
+ if (id_iter != child_id_to_resources_.end()) |
+ child_id_to_resources_.erase(id_iter); |
// Finally, delete the resource. |
delete resource; |
@@ -1083,7 +1059,6 @@ TaskManagerNotificationResource::TaskManagerNotificationResource( |
default_icon_ = rb.GetBitmapNamed(IDR_PLUGIN); |
} |
process_handle_ = balloon_host_->render_view_host()->process()->GetHandle(); |
- pid_ = base::GetProcId(process_handle_); |
title_ = UTF16ToWide(l10n_util::GetStringFUTF16( |
IDS_TASK_MANAGER_NOTIFICATION_PREFIX, |
balloon_host_->GetSource())); |
@@ -1127,10 +1102,10 @@ TaskManagerNotificationResourceProvider:: |
} |
TaskManager::Resource* TaskManagerNotificationResourceProvider::GetResource( |
- int origin_pid, |
+ int origin_child_id, |
int render_process_host_id, |
int routing_id) { |
- // TODO(johnnyg): provide resources by pid if necessary. |
+ // TODO(johnnyg): provide resources by child ID if necessary. |
return NULL; |
} |
@@ -1223,8 +1198,8 @@ SkBitmap* TaskManagerBrowserProcessResource::default_icon_ = NULL; |
TaskManagerBrowserProcessResource::TaskManagerBrowserProcessResource() |
: title_() { |
- pid_ = base::GetCurrentProcId(); |
- bool success = base::OpenPrivilegedProcessHandle(pid_, &process_); |
+ int pid = base::GetCurrentProcId(); |
+ bool success = base::OpenPrivilegedProcessHandle(pid, &process_); |
DCHECK(success); |
#if defined(OS_WIN) |
if (!default_icon_) { |
@@ -1313,12 +1288,11 @@ TaskManagerBrowserProcessResourceProvider:: |
} |
TaskManager::Resource* TaskManagerBrowserProcessResourceProvider::GetResource( |
- int origin_pid, |
+ int origin_child_id, |
int render_process_host_id, |
int routing_id) { |
- if (origin_pid != resource_.process_id()) { |
+ if (origin_child_id != (-1)) // Match "unknown" child ID for now! |
return NULL; |
- } |
return &resource_; |
} |