| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/task_manager/task_manager_resource_providers.h" | 5 #include "chrome/browser/task_manager/task_manager_resource_providers.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 | 780 |
| 781 SkBitmap TaskManagerChildProcessResource::GetIcon() const { | 781 SkBitmap TaskManagerChildProcessResource::GetIcon() const { |
| 782 return *default_icon_; | 782 return *default_icon_; |
| 783 } | 783 } |
| 784 | 784 |
| 785 base::ProcessHandle TaskManagerChildProcessResource::GetProcess() const { | 785 base::ProcessHandle TaskManagerChildProcessResource::GetProcess() const { |
| 786 return handle_; | 786 return handle_; |
| 787 } | 787 } |
| 788 | 788 |
| 789 TaskManager::Resource::Type TaskManagerChildProcessResource::GetType() const { | 789 TaskManager::Resource::Type TaskManagerChildProcessResource::GetType() const { |
| 790 // Translate types to TaskManager::ResourceType, since ChildProcessInfo's type | 790 // Translate types to TaskManager::ResourceType, since ChildProcessData's type |
| 791 // is not available for all TaskManager resources. | 791 // is not available for all TaskManager resources. |
| 792 switch (type_) { | 792 switch (type_) { |
| 793 case content::PROCESS_TYPE_PLUGIN: | 793 case content::PROCESS_TYPE_PLUGIN: |
| 794 case content::PROCESS_TYPE_PPAPI_PLUGIN: | 794 case content::PROCESS_TYPE_PPAPI_PLUGIN: |
| 795 case content::PROCESS_TYPE_PPAPI_BROKER: | 795 case content::PROCESS_TYPE_PPAPI_BROKER: |
| 796 return TaskManager::Resource::PLUGIN; | 796 return TaskManager::Resource::PLUGIN; |
| 797 case content::PROCESS_TYPE_NACL_LOADER: | 797 case content::PROCESS_TYPE_NACL_LOADER: |
| 798 case content::PROCESS_TYPE_NACL_BROKER: | 798 case content::PROCESS_TYPE_NACL_BROKER: |
| 799 return TaskManager::Resource::NACL; | 799 return TaskManager::Resource::NACL; |
| 800 case content::PROCESS_TYPE_UTILITY: | 800 case content::PROCESS_TYPE_UTILITY: |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 // Register for notifications to get new child processes. | 917 // Register for notifications to get new child processes. |
| 918 registrar_.Add(this, content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED, | 918 registrar_.Add(this, content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED, |
| 919 content::NotificationService::AllBrowserContextsAndSources()); | 919 content::NotificationService::AllBrowserContextsAndSources()); |
| 920 registrar_.Add(this, content::NOTIFICATION_CHILD_PROCESS_HOST_DISCONNECTED, | 920 registrar_.Add(this, content::NOTIFICATION_CHILD_PROCESS_HOST_DISCONNECTED, |
| 921 content::NotificationService::AllBrowserContextsAndSources()); | 921 content::NotificationService::AllBrowserContextsAndSources()); |
| 922 | 922 |
| 923 // Get the existing child processes. | 923 // Get the existing child processes. |
| 924 BrowserThread::PostTask( | 924 BrowserThread::PostTask( |
| 925 BrowserThread::IO, FROM_HERE, | 925 BrowserThread::IO, FROM_HERE, |
| 926 base::Bind( | 926 base::Bind( |
| 927 &TaskManagerChildProcessResourceProvider::RetrieveChildProcessInfo, | 927 &TaskManagerChildProcessResourceProvider::RetrieveChildProcessData, |
| 928 this)); | 928 this)); |
| 929 } | 929 } |
| 930 | 930 |
| 931 void TaskManagerChildProcessResourceProvider::StopUpdating() { | 931 void TaskManagerChildProcessResourceProvider::StopUpdating() { |
| 932 DCHECK(updating_); | 932 DCHECK(updating_); |
| 933 updating_ = false; | 933 updating_ = false; |
| 934 | 934 |
| 935 // Unregister for notifications to get new plugin processes. | 935 // Unregister for notifications to get new plugin processes. |
| 936 registrar_.Remove( | 936 registrar_.Remove( |
| 937 this, content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED, | 937 this, content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED, |
| 938 content::NotificationService::AllBrowserContextsAndSources()); | 938 content::NotificationService::AllBrowserContextsAndSources()); |
| 939 registrar_.Remove( | 939 registrar_.Remove( |
| 940 this, | 940 this, |
| 941 content::NOTIFICATION_CHILD_PROCESS_HOST_DISCONNECTED, | 941 content::NOTIFICATION_CHILD_PROCESS_HOST_DISCONNECTED, |
| 942 content::NotificationService::AllBrowserContextsAndSources()); | 942 content::NotificationService::AllBrowserContextsAndSources()); |
| 943 | 943 |
| 944 // Delete all the resources. | 944 // Delete all the resources. |
| 945 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); | 945 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); |
| 946 | 946 |
| 947 resources_.clear(); | 947 resources_.clear(); |
| 948 pid_to_resources_.clear(); | 948 pid_to_resources_.clear(); |
| 949 } | 949 } |
| 950 | 950 |
| 951 void TaskManagerChildProcessResourceProvider::Observe( | 951 void TaskManagerChildProcessResourceProvider::Observe( |
| 952 int type, | 952 int type, |
| 953 const content::NotificationSource& source, | 953 const content::NotificationSource& source, |
| 954 const content::NotificationDetails& details) { | 954 const content::NotificationDetails& details) { |
| 955 content::Details<ChildProcessInfo> child_details(details); | 955 content::ChildProcessData data = |
| 956 ChildProcessData data; | 956 *content::Details<content::ChildProcessData>(details).ptr(); |
| 957 data.type = child_details->type(); | |
| 958 data.name = child_details->name(); | |
| 959 data.handle = child_details->handle(); | |
| 960 switch (type) { | 957 switch (type) { |
| 961 case content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED: | 958 case content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED: |
| 962 Add(data); | 959 Add(data); |
| 963 break; | 960 break; |
| 964 case content::NOTIFICATION_CHILD_PROCESS_HOST_DISCONNECTED: | 961 case content::NOTIFICATION_CHILD_PROCESS_HOST_DISCONNECTED: |
| 965 Remove(data); | 962 Remove(data); |
| 966 break; | 963 break; |
| 967 default: | 964 default: |
| 968 NOTREACHED() << "Unexpected notification."; | 965 NOTREACHED() << "Unexpected notification."; |
| 969 return; | 966 return; |
| 970 } | 967 } |
| 971 } | 968 } |
| 972 | 969 |
| 973 void TaskManagerChildProcessResourceProvider::Add( | 970 void TaskManagerChildProcessResourceProvider::Add( |
| 974 const ChildProcessData& child_process_data) { | 971 const content::ChildProcessData& child_process_data) { |
| 975 if (!updating_) | 972 if (!updating_) |
| 976 return; | 973 return; |
| 977 // Workers are handled by TaskManagerWorkerResourceProvider. | 974 // Workers are handled by TaskManagerWorkerResourceProvider. |
| 978 if (child_process_data.type == content::PROCESS_TYPE_WORKER) | 975 if (child_process_data.type == content::PROCESS_TYPE_WORKER) |
| 979 return; | 976 return; |
| 980 if (resources_.count(child_process_data.handle)) { | 977 if (resources_.count(child_process_data.handle)) { |
| 981 // The case may happen that we have added a child_process_info as part of | 978 // The case may happen that we have added a child_process_info as part of |
| 982 // the iteration performed during StartUpdating() call but the notification | 979 // the iteration performed during StartUpdating() call but the notification |
| 983 // that it has connected was not fired yet. So when the notification | 980 // that it has connected was not fired yet. So when the notification |
| 984 // happens, we already know about this plugin and just ignore it. | 981 // happens, we already know about this plugin and just ignore it. |
| 985 return; | 982 return; |
| 986 } | 983 } |
| 987 AddToTaskManager(child_process_data); | 984 AddToTaskManager(child_process_data); |
| 988 } | 985 } |
| 989 | 986 |
| 990 void TaskManagerChildProcessResourceProvider::Remove( | 987 void TaskManagerChildProcessResourceProvider::Remove( |
| 991 const ChildProcessData& child_process_data) { | 988 const content::ChildProcessData& child_process_data) { |
| 992 if (!updating_) | 989 if (!updating_) |
| 993 return; | 990 return; |
| 994 if (child_process_data.type == content::PROCESS_TYPE_WORKER) | 991 if (child_process_data.type == content::PROCESS_TYPE_WORKER) |
| 995 return; | 992 return; |
| 996 ChildProcessMap::iterator iter = resources_.find(child_process_data.handle); | 993 ChildProcessMap::iterator iter = resources_.find(child_process_data.handle); |
| 997 if (iter == resources_.end()) { | 994 if (iter == resources_.end()) { |
| 998 // ChildProcessInfo disconnection notifications are asynchronous, so we | 995 // ChildProcessData disconnection notifications are asynchronous, so we |
| 999 // might be notified for a plugin we don't know anything about (if it was | 996 // might be notified for a plugin we don't know anything about (if it was |
| 1000 // closed before the task manager was shown and destroyed after that). | 997 // closed before the task manager was shown and destroyed after that). |
| 1001 return; | 998 return; |
| 1002 } | 999 } |
| 1003 // Remove the resource from the Task Manager. | 1000 // Remove the resource from the Task Manager. |
| 1004 TaskManagerChildProcessResource* resource = iter->second; | 1001 TaskManagerChildProcessResource* resource = iter->second; |
| 1005 task_manager_->RemoveResource(resource); | 1002 task_manager_->RemoveResource(resource); |
| 1006 // Remove it from the provider. | 1003 // Remove it from the provider. |
| 1007 resources_.erase(iter); | 1004 resources_.erase(iter); |
| 1008 // Remove it from our pid map. | 1005 // Remove it from our pid map. |
| 1009 PidResourceMap::iterator pid_iter = | 1006 PidResourceMap::iterator pid_iter = |
| 1010 pid_to_resources_.find(resource->process_id()); | 1007 pid_to_resources_.find(resource->process_id()); |
| 1011 DCHECK(pid_iter != pid_to_resources_.end()); | 1008 DCHECK(pid_iter != pid_to_resources_.end()); |
| 1012 if (pid_iter != pid_to_resources_.end()) | 1009 if (pid_iter != pid_to_resources_.end()) |
| 1013 pid_to_resources_.erase(pid_iter); | 1010 pid_to_resources_.erase(pid_iter); |
| 1014 | 1011 |
| 1015 // Finally, delete the resource. | 1012 // Finally, delete the resource. |
| 1016 delete resource; | 1013 delete resource; |
| 1017 } | 1014 } |
| 1018 | 1015 |
| 1019 void TaskManagerChildProcessResourceProvider::AddToTaskManager( | 1016 void TaskManagerChildProcessResourceProvider::AddToTaskManager( |
| 1020 const ChildProcessData& child_process_data) { | 1017 const content::ChildProcessData& child_process_data) { |
| 1021 TaskManagerChildProcessResource* resource = | 1018 TaskManagerChildProcessResource* resource = |
| 1022 new TaskManagerChildProcessResource( | 1019 new TaskManagerChildProcessResource( |
| 1023 child_process_data.type, | 1020 child_process_data.type, |
| 1024 child_process_data.name, | 1021 child_process_data.name, |
| 1025 child_process_data.handle); | 1022 child_process_data.handle); |
| 1026 resources_[child_process_data.handle] = resource; | 1023 resources_[child_process_data.handle] = resource; |
| 1027 pid_to_resources_[resource->process_id()] = resource; | 1024 pid_to_resources_[resource->process_id()] = resource; |
| 1028 task_manager_->AddResource(resource); | 1025 task_manager_->AddResource(resource); |
| 1029 } | 1026 } |
| 1030 | 1027 |
| 1031 // The ChildProcessInfo::Iterator has to be used from the IO thread. | 1028 // The ChildProcessData::Iterator has to be used from the IO thread. |
| 1032 void TaskManagerChildProcessResourceProvider::RetrieveChildProcessInfo() { | 1029 void TaskManagerChildProcessResourceProvider::RetrieveChildProcessData() { |
| 1033 std::vector<ChildProcessData> child_processes; | 1030 std::vector<content::ChildProcessData> child_processes; |
| 1034 for (BrowserChildProcessHost::Iterator iter; !iter.Done(); ++iter) { | 1031 for (BrowserChildProcessHost::Iterator iter; !iter.Done(); ++iter) { |
| 1035 // Only add processes which are already started, since we need their handle. | 1032 // Only add processes which are already started, since we need their handle. |
| 1036 if ((*iter)->handle() == base::kNullProcessHandle) | 1033 if ((*iter)->handle() == base::kNullProcessHandle) |
| 1037 continue; | 1034 continue; |
| 1038 ChildProcessData data; | 1035 content::ChildProcessData data; |
| 1039 data.type = (*iter)->type(); | 1036 data.type = (*iter)->type(); |
| 1040 data.name = (*iter)->name(); | 1037 data.name = (*iter)->name(); |
| 1041 data.handle = (*iter)->handle(); | 1038 data.handle = (*iter)->handle(); |
| 1042 child_processes.push_back(data); | 1039 child_processes.push_back(data); |
| 1043 } | 1040 } |
| 1044 // Now notify the UI thread that we have retrieved information about child | 1041 // Now notify the UI thread that we have retrieved information about child |
| 1045 // processes. | 1042 // processes. |
| 1046 BrowserThread::PostTask( | 1043 BrowserThread::PostTask( |
| 1047 BrowserThread::UI, FROM_HERE, | 1044 BrowserThread::UI, FROM_HERE, |
| 1048 base::Bind( | 1045 base::Bind( |
| 1049 &TaskManagerChildProcessResourceProvider::ChildProcessInfoRetreived, | 1046 &TaskManagerChildProcessResourceProvider::ChildProcessDataRetreived, |
| 1050 this, child_processes)); | 1047 this, child_processes)); |
| 1051 } | 1048 } |
| 1052 | 1049 |
| 1053 // This is called on the UI thread. | 1050 // This is called on the UI thread. |
| 1054 void TaskManagerChildProcessResourceProvider::ChildProcessInfoRetreived( | 1051 void TaskManagerChildProcessResourceProvider::ChildProcessDataRetreived( |
| 1055 const std::vector<ChildProcessData>& child_processes) { | 1052 const std::vector<content::ChildProcessData>& child_processes) { |
| 1056 for (size_t i = 0; i < child_processes.size(); ++i) | 1053 for (size_t i = 0; i < child_processes.size(); ++i) |
| 1057 Add(child_processes[i]); | 1054 Add(child_processes[i]); |
| 1058 } | 1055 } |
| 1059 | 1056 |
| 1060 //////////////////////////////////////////////////////////////////////////////// | 1057 //////////////////////////////////////////////////////////////////////////////// |
| 1061 // TaskManagerExtensionProcessResource class | 1058 // TaskManagerExtensionProcessResource class |
| 1062 //////////////////////////////////////////////////////////////////////////////// | 1059 //////////////////////////////////////////////////////////////////////////////// |
| 1063 | 1060 |
| 1064 SkBitmap* TaskManagerExtensionProcessResource::default_icon_ = NULL; | 1061 SkBitmap* TaskManagerExtensionProcessResource::default_icon_ = NULL; |
| 1065 | 1062 |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1400 | 1397 |
| 1401 return &resource_; | 1398 return &resource_; |
| 1402 } | 1399 } |
| 1403 | 1400 |
| 1404 void TaskManagerBrowserProcessResourceProvider::StartUpdating() { | 1401 void TaskManagerBrowserProcessResourceProvider::StartUpdating() { |
| 1405 task_manager_->AddResource(&resource_); | 1402 task_manager_->AddResource(&resource_); |
| 1406 } | 1403 } |
| 1407 | 1404 |
| 1408 void TaskManagerBrowserProcessResourceProvider::StopUpdating() { | 1405 void TaskManagerBrowserProcessResourceProvider::StopUpdating() { |
| 1409 } | 1406 } |
| OLD | NEW |