OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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.h" | 5 #include "chrome/browser/task_manager/task_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/i18n/number_formatting.h" | 8 #include "base/i18n/number_formatting.h" |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
10 #include "base/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 values.goats_teleported = goat_salt_ * (index + 1); | 741 values.goats_teleported = goat_salt_ * (index + 1); |
742 values.goats_teleported = (values.goats_teleported >> 16) & 255; | 742 values.goats_teleported = (values.goats_teleported >> 16) & 255; |
743 } | 743 } |
744 return values.goats_teleported; | 744 return values.goats_teleported; |
745 } | 745 } |
746 | 746 |
747 bool TaskManagerModel::IsResourceFirstInGroup(int index) const { | 747 bool TaskManagerModel::IsResourceFirstInGroup(int index) const { |
748 Resource* resource = GetResource(index); | 748 Resource* resource = GetResource(index); |
749 GroupMap::const_iterator iter = group_map_.find(resource->GetProcess()); | 749 GroupMap::const_iterator iter = group_map_.find(resource->GetProcess()); |
750 DCHECK(iter != group_map_.end()); | 750 DCHECK(iter != group_map_.end()); |
751 const ResourceList* group = iter->second; | 751 const ResourceList& group = iter->second; |
752 return ((*group)[0] == resource); | 752 return (group[0] == resource); |
753 } | 753 } |
754 | 754 |
755 bool TaskManagerModel::IsResourceLastInGroup(int index) const { | 755 bool TaskManagerModel::IsResourceLastInGroup(int index) const { |
756 Resource* resource = GetResource(index); | 756 Resource* resource = GetResource(index); |
757 GroupMap::const_iterator iter = group_map_.find(resource->GetProcess()); | 757 GroupMap::const_iterator iter = group_map_.find(resource->GetProcess()); |
758 DCHECK(iter != group_map_.end()); | 758 DCHECK(iter != group_map_.end()); |
759 const ResourceList* group = iter->second; | 759 const ResourceList& group = iter->second; |
760 return (group->back() == resource); | 760 return (group.back() == resource); |
761 } | 761 } |
762 | 762 |
763 gfx::ImageSkia TaskManagerModel::GetResourceIcon(int index) const { | 763 gfx::ImageSkia TaskManagerModel::GetResourceIcon(int index) const { |
764 gfx::ImageSkia icon = GetResource(index)->GetIcon(); | 764 gfx::ImageSkia icon = GetResource(index)->GetIcon(); |
765 if (!icon.isNull()) | 765 if (!icon.isNull()) |
766 return icon; | 766 return icon; |
767 | 767 |
768 static gfx::ImageSkia* default_icon = ResourceBundle::GetSharedInstance(). | 768 static gfx::ImageSkia* default_icon = ResourceBundle::GetSharedInstance(). |
769 GetImageSkiaNamed(IDR_DEFAULT_FAVICON); | 769 GetImageSkiaNamed(IDR_DEFAULT_FAVICON); |
770 return *default_icon; | 770 return *default_icon; |
771 } | 771 } |
772 | 772 |
773 TaskManagerModel::GroupRange | 773 TaskManagerModel::GroupRange |
774 TaskManagerModel::GetGroupRangeForResource(int index) const { | 774 TaskManagerModel::GetGroupRangeForResource(int index) const { |
775 Resource* resource = GetResource(index); | 775 Resource* resource = GetResource(index); |
776 GroupMap::const_iterator group_iter = | 776 GroupMap::const_iterator group_iter = |
777 group_map_.find(resource->GetProcess()); | 777 group_map_.find(resource->GetProcess()); |
778 DCHECK(group_iter != group_map_.end()); | 778 DCHECK(group_iter != group_map_.end()); |
779 ResourceList* group = group_iter->second; | 779 const ResourceList& group = group_iter->second; |
780 DCHECK(group); | 780 if (group.size() == 1) { |
781 if (group->size() == 1) { | |
782 return std::make_pair(index, 1); | 781 return std::make_pair(index, 1); |
783 } else { | 782 } else { |
784 for (int i = index; i >= 0; --i) { | 783 for (int i = index; i >= 0; --i) { |
785 if (GetResource(i) == (*group)[0]) | 784 if (GetResource(i) == group[0]) |
786 return std::make_pair(i, group->size()); | 785 return std::make_pair(i, group.size()); |
787 } | 786 } |
788 NOTREACHED(); | 787 NOTREACHED(); |
789 return std::make_pair(-1, -1); | 788 return std::make_pair(-1, -1); |
790 } | 789 } |
791 } | 790 } |
792 | 791 |
793 int TaskManagerModel::GetGroupIndexForResource(int index) const { | 792 int TaskManagerModel::GetGroupIndexForResource(int index) const { |
794 int group_index = -1; | 793 int group_index = -1; |
795 for (int i = 0; i <= index; ++i) { | 794 for (int i = 0; i <= index; ++i) { |
796 if (IsResourceFirstInGroup(i)) | 795 if (IsResourceFirstInGroup(i)) |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
968 return GetResource(index)->GetType(); | 967 return GetResource(index)->GetType(); |
969 } | 968 } |
970 | 969 |
971 WebContents* TaskManagerModel::GetResourceWebContents(int index) const { | 970 WebContents* TaskManagerModel::GetResourceWebContents(int index) const { |
972 return GetResource(index)->GetWebContents(); | 971 return GetResource(index)->GetWebContents(); |
973 } | 972 } |
974 | 973 |
975 void TaskManagerModel::AddResource(Resource* resource) { | 974 void TaskManagerModel::AddResource(Resource* resource) { |
976 base::ProcessHandle process = resource->GetProcess(); | 975 base::ProcessHandle process = resource->GetProcess(); |
977 | 976 |
978 ResourceList* group_entries = NULL; | 977 GroupMap::iterator group_iter = group_map_.find(process); |
979 GroupMap::const_iterator group_iter = group_map_.find(process); | |
980 int new_entry_index = 0; | 978 int new_entry_index = 0; |
981 if (group_iter == group_map_.end()) { | 979 if (group_iter == group_map_.end()) { |
982 group_entries = new ResourceList(); | 980 group_map_.insert(make_pair(process, ResourceList(1, resource))); |
983 group_map_[process] = group_entries; | |
984 group_entries->push_back(resource); | |
985 | 981 |
986 // Not part of a group, just put at the end of the list. | 982 // Not part of a group, just put at the end of the list. |
987 resources_.push_back(resource); | 983 resources_.push_back(resource); |
988 new_entry_index = static_cast<int>(resources_.size() - 1); | 984 new_entry_index = static_cast<int>(resources_.size() - 1); |
989 } else { | 985 } else { |
990 group_entries = group_iter->second; | 986 ResourceList* group_entries = &(group_iter->second); |
991 group_entries->push_back(resource); | 987 group_entries->push_back(resource); |
992 | 988 |
993 // Insert the new entry right after the last entry of its group. | 989 // Insert the new entry right after the last entry of its group. |
994 ResourceList::iterator iter = | 990 ResourceList::iterator iter = |
995 std::find(resources_.begin(), | 991 std::find(resources_.begin(), |
996 resources_.end(), | 992 resources_.end(), |
997 (*group_entries)[group_entries->size() - 2]); | 993 (*group_entries)[group_entries->size() - 2]); |
998 DCHECK(iter != resources_.end()); | 994 DCHECK(iter != resources_.end()); |
999 new_entry_index = static_cast<int>(iter - resources_.begin()) + 1; | 995 new_entry_index = static_cast<int>(iter - resources_.begin()) + 1; |
1000 resources_.insert(++iter, resource); | 996 resources_.insert(++iter, resource); |
(...skipping 16 matching lines...) Expand all Loading... |
1017 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, | 1013 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, |
1018 OnItemsAdded(new_entry_index, 1)); | 1014 OnItemsAdded(new_entry_index, 1)); |
1019 } | 1015 } |
1020 | 1016 |
1021 void TaskManagerModel::RemoveResource(Resource* resource) { | 1017 void TaskManagerModel::RemoveResource(Resource* resource) { |
1022 base::ProcessHandle process = resource->GetProcess(); | 1018 base::ProcessHandle process = resource->GetProcess(); |
1023 | 1019 |
1024 // Find the associated group. | 1020 // Find the associated group. |
1025 GroupMap::iterator group_iter = group_map_.find(process); | 1021 GroupMap::iterator group_iter = group_map_.find(process); |
1026 DCHECK(group_iter != group_map_.end()); | 1022 DCHECK(group_iter != group_map_.end()); |
1027 ResourceList* group_entries = group_iter->second; | 1023 ResourceList& group_entries = group_iter->second; |
1028 | 1024 |
1029 // Remove the entry from the group map. | 1025 // Remove the entry from the group map. |
1030 ResourceList::iterator iter = std::find(group_entries->begin(), | 1026 ResourceList::iterator iter = std::find(group_entries.begin(), |
1031 group_entries->end(), | 1027 group_entries.end(), |
1032 resource); | 1028 resource); |
1033 DCHECK(iter != group_entries->end()); | 1029 DCHECK(iter != group_entries.end()); |
1034 group_entries->erase(iter); | 1030 group_entries.erase(iter); |
1035 | 1031 |
1036 // If there are no more entries for that process, do the clean-up. | 1032 // If there are no more entries for that process, do the clean-up. |
1037 if (group_entries->empty()) { | 1033 if (group_entries.empty()) { |
1038 delete group_entries; | 1034 group_map_.erase(group_iter); |
1039 group_map_.erase(process); | |
1040 | 1035 |
1041 // Nobody is using this process, we don't need the process metrics anymore. | 1036 // Nobody is using this process, we don't need the process metrics anymore. |
1042 MetricsMap::iterator pm_iter = metrics_map_.find(process); | 1037 MetricsMap::iterator pm_iter = metrics_map_.find(process); |
1043 DCHECK(pm_iter != metrics_map_.end()); | 1038 DCHECK(pm_iter != metrics_map_.end()); |
1044 if (pm_iter != metrics_map_.end()) { | 1039 if (pm_iter != metrics_map_.end()) { |
1045 delete pm_iter->second; | 1040 delete pm_iter->second; |
1046 metrics_map_.erase(process); | 1041 metrics_map_.erase(process); |
1047 } | 1042 } |
1048 } | 1043 } |
1049 | 1044 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1145 // Must clear the resources before the next attempt to start listening. | 1140 // Must clear the resources before the next attempt to start listening. |
1146 Clear(); | 1141 Clear(); |
1147 } | 1142 } |
1148 | 1143 |
1149 void TaskManagerModel::Clear() { | 1144 void TaskManagerModel::Clear() { |
1150 int size = ResourceCount(); | 1145 int size = ResourceCount(); |
1151 if (size > 0) { | 1146 if (size > 0) { |
1152 resources_.clear(); | 1147 resources_.clear(); |
1153 | 1148 |
1154 // Clear the groups. | 1149 // Clear the groups. |
1155 STLDeleteValues(&group_map_); | 1150 group_map_.clear(); |
1156 | 1151 |
1157 // Clear the process related info. | 1152 // Clear the process related info. |
1158 STLDeleteValues(&metrics_map_); | 1153 STLDeleteValues(&metrics_map_); |
1159 | 1154 |
1160 // Clear the network maps. | 1155 // Clear the network maps. |
1161 current_byte_count_map_.clear(); | 1156 current_byte_count_map_.clear(); |
1162 | 1157 |
1163 per_resource_cache_.clear(); | 1158 per_resource_cache_.clear(); |
1164 per_process_cache_.clear(); | 1159 per_process_cache_.clear(); |
1165 | 1160 |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1581 params.host_desktop_type = desktop_type; | 1576 params.host_desktop_type = desktop_type; |
1582 chrome::Navigate(¶ms); | 1577 chrome::Navigate(¶ms); |
1583 } | 1578 } |
1584 | 1579 |
1585 TaskManager::TaskManager() | 1580 TaskManager::TaskManager() |
1586 : model_(new TaskManagerModel(this)) { | 1581 : model_(new TaskManagerModel(this)) { |
1587 } | 1582 } |
1588 | 1583 |
1589 TaskManager::~TaskManager() { | 1584 TaskManager::~TaskManager() { |
1590 } | 1585 } |
OLD | NEW |