OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/file_version_info.h" | 10 #include "base/file_version_info.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 // TaskManagerRendererResource class | 73 // TaskManagerRendererResource class |
74 //////////////////////////////////////////////////////////////////////////////// | 74 //////////////////////////////////////////////////////////////////////////////// |
75 TaskManagerRendererResource::TaskManagerRendererResource( | 75 TaskManagerRendererResource::TaskManagerRendererResource( |
76 base::ProcessHandle process, RenderViewHost* render_view_host) | 76 base::ProcessHandle process, RenderViewHost* render_view_host) |
77 : process_(process), | 77 : process_(process), |
78 render_view_host_(render_view_host), | 78 render_view_host_(render_view_host), |
79 pending_stats_update_(false), | 79 pending_stats_update_(false), |
80 v8_memory_allocated_(0), | 80 v8_memory_allocated_(0), |
81 v8_memory_used_(0), | 81 v8_memory_used_(0), |
82 pending_v8_memory_allocated_update_(false) { | 82 pending_v8_memory_allocated_update_(false) { |
83 // We cache the process and pid as when a Tab/BackgroundContents is closed the | |
84 // process reference becomes NULL and the TaskManager still needs it. | |
85 pid_ = base::GetProcId(process_); | |
86 stats_.images.size = 0; | 83 stats_.images.size = 0; |
87 stats_.cssStyleSheets.size = 0; | 84 stats_.cssStyleSheets.size = 0; |
88 stats_.scripts.size = 0; | 85 stats_.scripts.size = 0; |
89 stats_.xslStyleSheets.size = 0; | 86 stats_.xslStyleSheets.size = 0; |
90 stats_.fonts.size = 0; | 87 stats_.fonts.size = 0; |
91 } | 88 } |
92 | 89 |
93 TaskManagerRendererResource::~TaskManagerRendererResource() { | 90 TaskManagerRendererResource::~TaskManagerRendererResource() { |
94 } | 91 } |
95 | 92 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 TaskManagerTabContentsResourceProvider(TaskManager* task_manager) | 221 TaskManagerTabContentsResourceProvider(TaskManager* task_manager) |
225 : updating_(false), | 222 : updating_(false), |
226 task_manager_(task_manager) { | 223 task_manager_(task_manager) { |
227 } | 224 } |
228 | 225 |
229 TaskManagerTabContentsResourceProvider:: | 226 TaskManagerTabContentsResourceProvider:: |
230 ~TaskManagerTabContentsResourceProvider() { | 227 ~TaskManagerTabContentsResourceProvider() { |
231 } | 228 } |
232 | 229 |
233 TaskManager::Resource* TaskManagerTabContentsResourceProvider::GetResource( | 230 TaskManager::Resource* TaskManagerTabContentsResourceProvider::GetResource( |
234 int origin_pid, | 231 int origin_child_id, |
235 int render_process_host_id, | 232 int render_process_host_id, |
236 int routing_id) { | 233 int routing_id) { |
| 234 if (origin_child_id != render_process_host_id) |
| 235 return NULL; |
237 | 236 |
238 TabContents* tab_contents = | 237 TabContents* tab_contents = |
239 tab_util::GetTabContentsByID(render_process_host_id, routing_id); | 238 tab_util::GetTabContentsByID(render_process_host_id, routing_id); |
240 if (!tab_contents) // Not one of our resource. | 239 if (!tab_contents) // Not one of our resource. |
241 return NULL; | 240 return NULL; |
242 | 241 |
243 base::ProcessHandle process_handle = | |
244 tab_contents->GetRenderProcessHost()->GetHandle(); | |
245 if (!process_handle) { | |
246 // We should not be holding on to a dead tab (it should have been removed | |
247 // through the NOTIFY_TAB_CONTENTS_DISCONNECTED notification. | |
248 NOTREACHED(); | |
249 return NULL; | |
250 } | |
251 | |
252 int pid = base::GetProcId(process_handle); | |
253 if (pid != origin_pid) | |
254 return NULL; | |
255 | |
256 std::map<TabContents*, TaskManagerTabContentsResource*>::iterator | 242 std::map<TabContents*, TaskManagerTabContentsResource*>::iterator |
257 res_iter = resources_.find(tab_contents); | 243 res_iter = resources_.find(tab_contents); |
258 if (res_iter == resources_.end()) { | 244 if (res_iter == resources_.end()) { |
259 // Can happen if the tab was closed while a network request was being | 245 // Can happen if the tab was closed while a network request was being |
260 // performed. | 246 // performed. |
261 return NULL; | 247 return NULL; |
262 } | 248 } |
263 return res_iter->second; | 249 return res_iter->second; |
264 } | 250 } |
265 | 251 |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 : updating_(false), | 430 : updating_(false), |
445 task_manager_(task_manager) { | 431 task_manager_(task_manager) { |
446 } | 432 } |
447 | 433 |
448 TaskManagerBackgroundContentsResourceProvider:: | 434 TaskManagerBackgroundContentsResourceProvider:: |
449 ~TaskManagerBackgroundContentsResourceProvider() { | 435 ~TaskManagerBackgroundContentsResourceProvider() { |
450 } | 436 } |
451 | 437 |
452 TaskManager::Resource* | 438 TaskManager::Resource* |
453 TaskManagerBackgroundContentsResourceProvider::GetResource( | 439 TaskManagerBackgroundContentsResourceProvider::GetResource( |
454 int origin_pid, | 440 int origin_child_id, |
455 int render_process_host_id, | 441 int render_process_host_id, |
456 int routing_id) { | 442 int routing_id) { |
| 443 if (origin_child_id != render_process_host_id) |
| 444 return NULL; |
457 | 445 |
458 BackgroundContents* contents = BackgroundContents::GetBackgroundContentsByID( | 446 BackgroundContents* contents = BackgroundContents::GetBackgroundContentsByID( |
459 render_process_host_id, routing_id); | 447 render_process_host_id, routing_id); |
460 if (!contents) // This resource no longer exists. | 448 if (!contents) // This resource no longer exists. |
461 return NULL; | 449 return NULL; |
462 | 450 |
463 base::ProcessHandle process_handle = | |
464 contents->render_view_host()->process()->GetHandle(); | |
465 if (!process_handle) // Process crashed. | |
466 return NULL; | |
467 | |
468 int pid = base::GetProcId(process_handle); | |
469 if (pid != origin_pid) | |
470 return NULL; | |
471 | |
472 std::map<BackgroundContents*, | 451 std::map<BackgroundContents*, |
473 TaskManagerBackgroundContentsResource*>::iterator res_iter = | 452 TaskManagerBackgroundContentsResource*>::iterator res_iter = |
474 resources_.find(contents); | 453 resources_.find(contents); |
475 if (res_iter == resources_.end()) | 454 if (res_iter == resources_.end()) |
476 // Can happen if the page went away while a network request was being | 455 // Can happen if the page went away while a network request was being |
477 // performed. | 456 // performed. |
478 return NULL; | 457 return NULL; |
479 | 458 |
480 return res_iter->second; | 459 return res_iter->second; |
481 } | 460 } |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 //////////////////////////////////////////////////////////////////////////////// | 613 //////////////////////////////////////////////////////////////////////////////// |
635 // TaskManagerChildProcessResource class | 614 // TaskManagerChildProcessResource class |
636 //////////////////////////////////////////////////////////////////////////////// | 615 //////////////////////////////////////////////////////////////////////////////// |
637 SkBitmap* TaskManagerChildProcessResource::default_icon_ = NULL; | 616 SkBitmap* TaskManagerChildProcessResource::default_icon_ = NULL; |
638 | 617 |
639 TaskManagerChildProcessResource::TaskManagerChildProcessResource( | 618 TaskManagerChildProcessResource::TaskManagerChildProcessResource( |
640 const ChildProcessInfo& child_proc) | 619 const ChildProcessInfo& child_proc) |
641 : child_process_(child_proc), | 620 : child_process_(child_proc), |
642 title_(), | 621 title_(), |
643 network_usage_support_(false) { | 622 network_usage_support_(false) { |
644 // We cache the process id because it's not cheap to calculate, and it won't | |
645 // be available when we get the plugin disconnected notification. | |
646 pid_ = child_proc.id(); | |
647 if (!default_icon_) { | 623 if (!default_icon_) { |
648 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 624 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
649 default_icon_ = rb.GetBitmapNamed(IDR_PLUGIN); | 625 default_icon_ = rb.GetBitmapNamed(IDR_PLUGIN); |
650 // TODO(jabdelmalek): use different icon for web workers. | 626 // TODO(jabdelmalek): use different icon for web workers. |
651 } | 627 } |
652 } | 628 } |
653 | 629 |
654 TaskManagerChildProcessResource::~TaskManagerChildProcessResource() { | 630 TaskManagerChildProcessResource::~TaskManagerChildProcessResource() { |
655 } | 631 } |
656 | 632 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 TaskManagerChildProcessResourceProvider(TaskManager* task_manager) | 692 TaskManagerChildProcessResourceProvider(TaskManager* task_manager) |
717 : updating_(false), | 693 : updating_(false), |
718 task_manager_(task_manager) { | 694 task_manager_(task_manager) { |
719 } | 695 } |
720 | 696 |
721 TaskManagerChildProcessResourceProvider:: | 697 TaskManagerChildProcessResourceProvider:: |
722 ~TaskManagerChildProcessResourceProvider() { | 698 ~TaskManagerChildProcessResourceProvider() { |
723 } | 699 } |
724 | 700 |
725 TaskManager::Resource* TaskManagerChildProcessResourceProvider::GetResource( | 701 TaskManager::Resource* TaskManagerChildProcessResourceProvider::GetResource( |
726 int origin_pid, | 702 int origin_child_id, |
727 int render_process_host_id, | 703 int render_process_host_id, |
728 int routing_id) { | 704 int routing_id) { |
729 std::map<int, TaskManagerChildProcessResource*>::iterator iter = | 705 std::map<int, TaskManagerChildProcessResource*>::iterator iter = |
730 pid_to_resources_.find(origin_pid); | 706 child_id_to_resources_.find(origin_child_id); |
731 if (iter != pid_to_resources_.end()) | 707 if (iter != child_id_to_resources_.end()) |
732 return iter->second; | 708 return iter->second; |
733 else | 709 else |
734 return NULL; | 710 return NULL; |
735 } | 711 } |
736 | 712 |
737 void TaskManagerChildProcessResourceProvider::StartUpdating() { | 713 void TaskManagerChildProcessResourceProvider::StartUpdating() { |
738 DCHECK(!updating_); | 714 DCHECK(!updating_); |
739 updating_ = true; | 715 updating_ = true; |
740 | 716 |
741 // Register for notifications to get new child processes. | 717 // Register for notifications to get new child processes. |
(...skipping 18 matching lines...) Expand all Loading... |
760 registrar_.Remove(this, NotificationType::CHILD_PROCESS_HOST_CONNECTED, | 736 registrar_.Remove(this, NotificationType::CHILD_PROCESS_HOST_CONNECTED, |
761 NotificationService::AllSources()); | 737 NotificationService::AllSources()); |
762 registrar_.Remove(this, | 738 registrar_.Remove(this, |
763 NotificationType::CHILD_PROCESS_HOST_DISCONNECTED, | 739 NotificationType::CHILD_PROCESS_HOST_DISCONNECTED, |
764 NotificationService::AllSources()); | 740 NotificationService::AllSources()); |
765 | 741 |
766 // Delete all the resources. | 742 // Delete all the resources. |
767 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); | 743 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); |
768 | 744 |
769 resources_.clear(); | 745 resources_.clear(); |
770 pid_to_resources_.clear(); | 746 child_id_to_resources_.clear(); |
771 existing_child_process_info_.clear(); | 747 existing_child_process_info_.clear(); |
772 } | 748 } |
773 | 749 |
774 void TaskManagerChildProcessResourceProvider::Observe( | 750 void TaskManagerChildProcessResourceProvider::Observe( |
775 NotificationType type, | 751 NotificationType type, |
776 const NotificationSource& source, | 752 const NotificationSource& source, |
777 const NotificationDetails& details) { | 753 const NotificationDetails& details) { |
778 switch (type.value) { | 754 switch (type.value) { |
779 case NotificationType::CHILD_PROCESS_HOST_CONNECTED: | 755 case NotificationType::CHILD_PROCESS_HOST_CONNECTED: |
780 Add(*Details<ChildProcessInfo>(details).ptr()); | 756 Add(*Details<ChildProcessInfo>(details).ptr()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 // ChildProcessInfo disconnection notifications are asynchronous, so we | 790 // ChildProcessInfo disconnection notifications are asynchronous, so we |
815 // might be notified for a plugin we don't know anything about (if it was | 791 // might be notified for a plugin we don't know anything about (if it was |
816 // closed before the task manager was shown and destroyed after that). | 792 // closed before the task manager was shown and destroyed after that). |
817 return; | 793 return; |
818 } | 794 } |
819 // Remove the resource from the Task Manager. | 795 // Remove the resource from the Task Manager. |
820 TaskManagerChildProcessResource* resource = iter->second; | 796 TaskManagerChildProcessResource* resource = iter->second; |
821 task_manager_->RemoveResource(resource); | 797 task_manager_->RemoveResource(resource); |
822 // Remove it from the provider. | 798 // Remove it from the provider. |
823 resources_.erase(iter); | 799 resources_.erase(iter); |
824 // Remove it from our pid map. | 800 // Remove it from our child ID map. |
825 std::map<int, TaskManagerChildProcessResource*>::iterator pid_iter = | 801 std::map<int, TaskManagerChildProcessResource*>::iterator id_iter = |
826 pid_to_resources_.find(resource->process_id()); | 802 child_id_to_resources_.find(resource->id()); |
827 DCHECK(pid_iter != pid_to_resources_.end()); | 803 DCHECK(id_iter != child_id_to_resources_.end()); |
828 if (pid_iter != pid_to_resources_.end()) | 804 if (id_iter != child_id_to_resources_.end()) |
829 pid_to_resources_.erase(pid_iter); | 805 child_id_to_resources_.erase(id_iter); |
830 | 806 |
831 // Finally, delete the resource. | 807 // Finally, delete the resource. |
832 delete resource; | 808 delete resource; |
833 } | 809 } |
834 | 810 |
835 void TaskManagerChildProcessResourceProvider::AddToTaskManager( | 811 void TaskManagerChildProcessResourceProvider::AddToTaskManager( |
836 const ChildProcessInfo& child_process_info) { | 812 const ChildProcessInfo& child_process_info) { |
837 TaskManagerChildProcessResource* resource = | 813 TaskManagerChildProcessResource* resource = |
838 new TaskManagerChildProcessResource(child_process_info); | 814 new TaskManagerChildProcessResource(child_process_info); |
839 resources_[child_process_info] = resource; | 815 resources_[child_process_info] = resource; |
840 pid_to_resources_[resource->process_id()] = resource; | 816 child_id_to_resources_[resource->id()] = resource; |
841 task_manager_->AddResource(resource); | 817 task_manager_->AddResource(resource); |
842 } | 818 } |
843 | 819 |
844 // The ChildProcessInfo::Iterator has to be used from the IO thread. | 820 // The ChildProcessInfo::Iterator has to be used from the IO thread. |
845 void TaskManagerChildProcessResourceProvider::RetrieveChildProcessInfo() { | 821 void TaskManagerChildProcessResourceProvider::RetrieveChildProcessInfo() { |
846 for (BrowserChildProcessHost::Iterator iter; !iter.Done(); ++iter) { | 822 for (BrowserChildProcessHost::Iterator iter; !iter.Done(); ++iter) { |
847 // Only add processes which are already started, since we need their handle. | 823 // Only add processes which are already started, since we need their handle. |
848 if ((*iter)->handle() != base::kNullProcessHandle) | 824 if ((*iter)->handle() != base::kNullProcessHandle) |
849 existing_child_process_info_.push_back(**iter); | 825 existing_child_process_info_.push_back(**iter); |
850 } | 826 } |
(...skipping 22 matching lines...) Expand all Loading... |
873 SkBitmap* TaskManagerExtensionProcessResource::default_icon_ = NULL; | 849 SkBitmap* TaskManagerExtensionProcessResource::default_icon_ = NULL; |
874 | 850 |
875 TaskManagerExtensionProcessResource::TaskManagerExtensionProcessResource( | 851 TaskManagerExtensionProcessResource::TaskManagerExtensionProcessResource( |
876 ExtensionHost* extension_host) | 852 ExtensionHost* extension_host) |
877 : extension_host_(extension_host) { | 853 : extension_host_(extension_host) { |
878 if (!default_icon_) { | 854 if (!default_icon_) { |
879 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 855 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
880 default_icon_ = rb.GetBitmapNamed(IDR_PLUGIN); | 856 default_icon_ = rb.GetBitmapNamed(IDR_PLUGIN); |
881 } | 857 } |
882 process_handle_ = extension_host_->render_process_host()->GetHandle(); | 858 process_handle_ = extension_host_->render_process_host()->GetHandle(); |
883 pid_ = base::GetProcId(process_handle_); | |
884 string16 extension_name = UTF8ToUTF16(GetExtension()->name()); | 859 string16 extension_name = UTF8ToUTF16(GetExtension()->name()); |
885 DCHECK(!extension_name.empty()); | 860 DCHECK(!extension_name.empty()); |
886 | 861 |
887 int message_id = GetMessagePrefixID(GetExtension()->is_app(), true, | 862 int message_id = GetMessagePrefixID(GetExtension()->is_app(), true, |
888 extension_host_->profile()->IsOffTheRecord()); | 863 extension_host_->profile()->IsOffTheRecord()); |
889 title_ = UTF16ToWideHack(l10n_util::GetStringFUTF16(message_id, | 864 title_ = UTF16ToWideHack(l10n_util::GetStringFUTF16(message_id, |
890 extension_name)); | 865 extension_name)); |
| 866 id_ = extension_host->render_process_host()->id(); |
891 } | 867 } |
892 | 868 |
893 TaskManagerExtensionProcessResource::~TaskManagerExtensionProcessResource() { | 869 TaskManagerExtensionProcessResource::~TaskManagerExtensionProcessResource() { |
894 } | 870 } |
895 | 871 |
896 std::wstring TaskManagerExtensionProcessResource::GetTitle() const { | 872 std::wstring TaskManagerExtensionProcessResource::GetTitle() const { |
897 return title_; | 873 return title_; |
898 } | 874 } |
899 | 875 |
900 SkBitmap TaskManagerExtensionProcessResource::GetIcon() const { | 876 SkBitmap TaskManagerExtensionProcessResource::GetIcon() const { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
935 TaskManagerExtensionProcessResourceProvider(TaskManager* task_manager) | 911 TaskManagerExtensionProcessResourceProvider(TaskManager* task_manager) |
936 : task_manager_(task_manager), | 912 : task_manager_(task_manager), |
937 updating_(false) { | 913 updating_(false) { |
938 } | 914 } |
939 | 915 |
940 TaskManagerExtensionProcessResourceProvider:: | 916 TaskManagerExtensionProcessResourceProvider:: |
941 ~TaskManagerExtensionProcessResourceProvider() { | 917 ~TaskManagerExtensionProcessResourceProvider() { |
942 } | 918 } |
943 | 919 |
944 TaskManager::Resource* TaskManagerExtensionProcessResourceProvider::GetResource( | 920 TaskManager::Resource* TaskManagerExtensionProcessResourceProvider::GetResource( |
945 int origin_pid, | 921 int origin_child_id, |
946 int render_process_host_id, | 922 int render_process_host_id, |
947 int routing_id) { | 923 int routing_id) { |
948 std::map<int, TaskManagerExtensionProcessResource*>::iterator iter = | 924 std::map<int, TaskManagerExtensionProcessResource*>::iterator iter = |
949 pid_to_resources_.find(origin_pid); | 925 child_id_to_resources_.find(origin_child_id); |
950 if (iter != pid_to_resources_.end()) | 926 if (iter != child_id_to_resources_.end()) |
951 return iter->second; | 927 return iter->second; |
952 else | 928 else |
953 return NULL; | 929 return NULL; |
954 } | 930 } |
955 | 931 |
956 void TaskManagerExtensionProcessResourceProvider::StartUpdating() { | 932 void TaskManagerExtensionProcessResourceProvider::StartUpdating() { |
957 DCHECK(!updating_); | 933 DCHECK(!updating_); |
958 updating_ = true; | 934 updating_ = true; |
959 | 935 |
960 // Add all the existing ExtensionHosts. | 936 // Add all the existing ExtensionHosts. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1000 NotificationService::AllSources()); | 976 NotificationService::AllSources()); |
1001 registrar_.Remove(this, NotificationType::EXTENSION_PROCESS_TERMINATED, | 977 registrar_.Remove(this, NotificationType::EXTENSION_PROCESS_TERMINATED, |
1002 NotificationService::AllSources()); | 978 NotificationService::AllSources()); |
1003 registrar_.Remove(this, NotificationType::EXTENSION_HOST_DESTROYED, | 979 registrar_.Remove(this, NotificationType::EXTENSION_HOST_DESTROYED, |
1004 NotificationService::AllSources()); | 980 NotificationService::AllSources()); |
1005 | 981 |
1006 // Delete all the resources. | 982 // Delete all the resources. |
1007 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); | 983 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); |
1008 | 984 |
1009 resources_.clear(); | 985 resources_.clear(); |
1010 pid_to_resources_.clear(); | 986 child_id_to_resources_.clear(); |
1011 } | 987 } |
1012 | 988 |
1013 void TaskManagerExtensionProcessResourceProvider::Observe( | 989 void TaskManagerExtensionProcessResourceProvider::Observe( |
1014 NotificationType type, | 990 NotificationType type, |
1015 const NotificationSource& source, | 991 const NotificationSource& source, |
1016 const NotificationDetails& details) { | 992 const NotificationDetails& details) { |
1017 switch (type.value) { | 993 switch (type.value) { |
1018 case NotificationType::EXTENSION_PROCESS_CREATED: | 994 case NotificationType::EXTENSION_PROCESS_CREATED: |
1019 AddToTaskManager(Details<ExtensionHost>(details).ptr()); | 995 AddToTaskManager(Details<ExtensionHost>(details).ptr()); |
1020 break; | 996 break; |
(...skipping 10 matching lines...) Expand all Loading... |
1031 void TaskManagerExtensionProcessResourceProvider::AddToTaskManager( | 1007 void TaskManagerExtensionProcessResourceProvider::AddToTaskManager( |
1032 ExtensionHost* extension_host) { | 1008 ExtensionHost* extension_host) { |
1033 // Don't add dead extension processes. | 1009 // Don't add dead extension processes. |
1034 if (!extension_host->IsRenderViewLive()) | 1010 if (!extension_host->IsRenderViewLive()) |
1035 return; | 1011 return; |
1036 | 1012 |
1037 TaskManagerExtensionProcessResource* resource = | 1013 TaskManagerExtensionProcessResource* resource = |
1038 new TaskManagerExtensionProcessResource(extension_host); | 1014 new TaskManagerExtensionProcessResource(extension_host); |
1039 DCHECK(resources_.find(extension_host) == resources_.end()); | 1015 DCHECK(resources_.find(extension_host) == resources_.end()); |
1040 resources_[extension_host] = resource; | 1016 resources_[extension_host] = resource; |
1041 pid_to_resources_[resource->process_id()] = resource; | 1017 child_id_to_resources_[resource->id()] = resource; |
1042 task_manager_->AddResource(resource); | 1018 task_manager_->AddResource(resource); |
1043 } | 1019 } |
1044 | 1020 |
1045 void TaskManagerExtensionProcessResourceProvider::RemoveFromTaskManager( | 1021 void TaskManagerExtensionProcessResourceProvider::RemoveFromTaskManager( |
1046 ExtensionHost* extension_host) { | 1022 ExtensionHost* extension_host) { |
1047 if (!updating_) | 1023 if (!updating_) |
1048 return; | 1024 return; |
1049 std::map<ExtensionHost*, TaskManagerExtensionProcessResource*> | 1025 std::map<ExtensionHost*, TaskManagerExtensionProcessResource*> |
1050 ::iterator iter = resources_.find(extension_host); | 1026 ::iterator iter = resources_.find(extension_host); |
1051 if (iter == resources_.end()) | 1027 if (iter == resources_.end()) |
1052 return; | 1028 return; |
1053 | 1029 |
1054 // Remove the resource from the Task Manager. | 1030 // Remove the resource from the Task Manager. |
1055 TaskManagerExtensionProcessResource* resource = iter->second; | 1031 TaskManagerExtensionProcessResource* resource = iter->second; |
1056 task_manager_->RemoveResource(resource); | 1032 task_manager_->RemoveResource(resource); |
1057 | 1033 |
1058 // Remove it from the provider. | 1034 // Remove it from the provider. |
1059 resources_.erase(iter); | 1035 resources_.erase(iter); |
1060 | 1036 |
1061 // Remove it from our pid map. | 1037 // Remove it from our child ID map. |
1062 std::map<int, TaskManagerExtensionProcessResource*>::iterator pid_iter = | 1038 std::map<int, TaskManagerExtensionProcessResource*>::iterator id_iter = |
1063 pid_to_resources_.find(resource->process_id()); | 1039 child_id_to_resources_.find(resource->id()); |
1064 DCHECK(pid_iter != pid_to_resources_.end()); | 1040 DCHECK(id_iter != child_id_to_resources_.end()); |
1065 if (pid_iter != pid_to_resources_.end()) | 1041 if (id_iter != child_id_to_resources_.end()) |
1066 pid_to_resources_.erase(pid_iter); | 1042 child_id_to_resources_.erase(id_iter); |
1067 | 1043 |
1068 // Finally, delete the resource. | 1044 // Finally, delete the resource. |
1069 delete resource; | 1045 delete resource; |
1070 } | 1046 } |
1071 | 1047 |
1072 //////////////////////////////////////////////////////////////////////////////// | 1048 //////////////////////////////////////////////////////////////////////////////// |
1073 // TaskManagerNotificationResource class | 1049 // TaskManagerNotificationResource class |
1074 //////////////////////////////////////////////////////////////////////////////// | 1050 //////////////////////////////////////////////////////////////////////////////// |
1075 | 1051 |
1076 SkBitmap* TaskManagerNotificationResource::default_icon_ = NULL; | 1052 SkBitmap* TaskManagerNotificationResource::default_icon_ = NULL; |
1077 | 1053 |
1078 TaskManagerNotificationResource::TaskManagerNotificationResource( | 1054 TaskManagerNotificationResource::TaskManagerNotificationResource( |
1079 BalloonHost* balloon_host) | 1055 BalloonHost* balloon_host) |
1080 : balloon_host_(balloon_host) { | 1056 : balloon_host_(balloon_host) { |
1081 if (!default_icon_) { | 1057 if (!default_icon_) { |
1082 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 1058 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
1083 default_icon_ = rb.GetBitmapNamed(IDR_PLUGIN); | 1059 default_icon_ = rb.GetBitmapNamed(IDR_PLUGIN); |
1084 } | 1060 } |
1085 process_handle_ = balloon_host_->render_view_host()->process()->GetHandle(); | 1061 process_handle_ = balloon_host_->render_view_host()->process()->GetHandle(); |
1086 pid_ = base::GetProcId(process_handle_); | |
1087 title_ = UTF16ToWide(l10n_util::GetStringFUTF16( | 1062 title_ = UTF16ToWide(l10n_util::GetStringFUTF16( |
1088 IDS_TASK_MANAGER_NOTIFICATION_PREFIX, | 1063 IDS_TASK_MANAGER_NOTIFICATION_PREFIX, |
1089 balloon_host_->GetSource())); | 1064 balloon_host_->GetSource())); |
1090 } | 1065 } |
1091 | 1066 |
1092 TaskManagerNotificationResource::~TaskManagerNotificationResource() { | 1067 TaskManagerNotificationResource::~TaskManagerNotificationResource() { |
1093 } | 1068 } |
1094 | 1069 |
1095 std::wstring TaskManagerNotificationResource::GetTitle() const { | 1070 std::wstring TaskManagerNotificationResource::GetTitle() const { |
1096 return title_; | 1071 return title_; |
(...skipping 23 matching lines...) Expand all Loading... |
1120 TaskManagerNotificationResourceProvider(TaskManager* task_manager) | 1095 TaskManagerNotificationResourceProvider(TaskManager* task_manager) |
1121 : task_manager_(task_manager), | 1096 : task_manager_(task_manager), |
1122 updating_(false) { | 1097 updating_(false) { |
1123 } | 1098 } |
1124 | 1099 |
1125 TaskManagerNotificationResourceProvider:: | 1100 TaskManagerNotificationResourceProvider:: |
1126 ~TaskManagerNotificationResourceProvider() { | 1101 ~TaskManagerNotificationResourceProvider() { |
1127 } | 1102 } |
1128 | 1103 |
1129 TaskManager::Resource* TaskManagerNotificationResourceProvider::GetResource( | 1104 TaskManager::Resource* TaskManagerNotificationResourceProvider::GetResource( |
1130 int origin_pid, | 1105 int origin_child_id, |
1131 int render_process_host_id, | 1106 int render_process_host_id, |
1132 int routing_id) { | 1107 int routing_id) { |
1133 // TODO(johnnyg): provide resources by pid if necessary. | 1108 // TODO(johnnyg): provide resources by child ID if necessary. |
1134 return NULL; | 1109 return NULL; |
1135 } | 1110 } |
1136 | 1111 |
1137 void TaskManagerNotificationResourceProvider::StartUpdating() { | 1112 void TaskManagerNotificationResourceProvider::StartUpdating() { |
1138 DCHECK(!updating_); | 1113 DCHECK(!updating_); |
1139 updating_ = true; | 1114 updating_ = true; |
1140 | 1115 |
1141 // Add all the existing BalloonHosts. | 1116 // Add all the existing BalloonHosts. |
1142 BalloonCollection* collection = | 1117 BalloonCollection* collection = |
1143 g_browser_process->notification_ui_manager()->balloon_collection(); | 1118 g_browser_process->notification_ui_manager()->balloon_collection(); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1216 } | 1191 } |
1217 | 1192 |
1218 //////////////////////////////////////////////////////////////////////////////// | 1193 //////////////////////////////////////////////////////////////////////////////// |
1219 // TaskManagerBrowserProcessResource class | 1194 // TaskManagerBrowserProcessResource class |
1220 //////////////////////////////////////////////////////////////////////////////// | 1195 //////////////////////////////////////////////////////////////////////////////// |
1221 | 1196 |
1222 SkBitmap* TaskManagerBrowserProcessResource::default_icon_ = NULL; | 1197 SkBitmap* TaskManagerBrowserProcessResource::default_icon_ = NULL; |
1223 | 1198 |
1224 TaskManagerBrowserProcessResource::TaskManagerBrowserProcessResource() | 1199 TaskManagerBrowserProcessResource::TaskManagerBrowserProcessResource() |
1225 : title_() { | 1200 : title_() { |
1226 pid_ = base::GetCurrentProcId(); | 1201 int pid = base::GetCurrentProcId(); |
1227 bool success = base::OpenPrivilegedProcessHandle(pid_, &process_); | 1202 bool success = base::OpenPrivilegedProcessHandle(pid, &process_); |
1228 DCHECK(success); | 1203 DCHECK(success); |
1229 #if defined(OS_WIN) | 1204 #if defined(OS_WIN) |
1230 if (!default_icon_) { | 1205 if (!default_icon_) { |
1231 HICON icon = GetAppIcon(); | 1206 HICON icon = GetAppIcon(); |
1232 if (icon) { | 1207 if (icon) { |
1233 ICONINFO icon_info = {0}; | 1208 ICONINFO icon_info = {0}; |
1234 BITMAP bitmap_info = {0}; | 1209 BITMAP bitmap_info = {0}; |
1235 | 1210 |
1236 GetIconInfo(icon, &icon_info); | 1211 GetIconInfo(icon, &icon_info); |
1237 GetObject(icon_info.hbmMask, sizeof(bitmap_info), &bitmap_info); | 1212 GetObject(icon_info.hbmMask, sizeof(bitmap_info), &bitmap_info); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1306 TaskManagerBrowserProcessResourceProvider(TaskManager* task_manager) | 1281 TaskManagerBrowserProcessResourceProvider(TaskManager* task_manager) |
1307 : updating_(false), | 1282 : updating_(false), |
1308 task_manager_(task_manager) { | 1283 task_manager_(task_manager) { |
1309 } | 1284 } |
1310 | 1285 |
1311 TaskManagerBrowserProcessResourceProvider:: | 1286 TaskManagerBrowserProcessResourceProvider:: |
1312 ~TaskManagerBrowserProcessResourceProvider() { | 1287 ~TaskManagerBrowserProcessResourceProvider() { |
1313 } | 1288 } |
1314 | 1289 |
1315 TaskManager::Resource* TaskManagerBrowserProcessResourceProvider::GetResource( | 1290 TaskManager::Resource* TaskManagerBrowserProcessResourceProvider::GetResource( |
1316 int origin_pid, | 1291 int origin_child_id, |
1317 int render_process_host_id, | 1292 int render_process_host_id, |
1318 int routing_id) { | 1293 int routing_id) { |
1319 if (origin_pid != resource_.process_id()) { | 1294 if (origin_child_id != (-1)) // Match "unknown" child ID for now! |
1320 return NULL; | 1295 return NULL; |
1321 } | |
1322 | 1296 |
1323 return &resource_; | 1297 return &resource_; |
1324 } | 1298 } |
1325 | 1299 |
1326 void TaskManagerBrowserProcessResourceProvider::StartUpdating() { | 1300 void TaskManagerBrowserProcessResourceProvider::StartUpdating() { |
1327 task_manager_->AddResource(&resource_); | 1301 task_manager_->AddResource(&resource_); |
1328 } | 1302 } |
1329 | 1303 |
1330 void TaskManagerBrowserProcessResourceProvider::StopUpdating() { | 1304 void TaskManagerBrowserProcessResourceProvider::StopUpdating() { |
1331 } | 1305 } |
OLD | NEW |