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.h" | 5 #include "chrome/browser/task_manager/task_manager.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.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/process_util.h" | 10 #include "base/process_util.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 | 71 |
72 } // namespace | 72 } // namespace |
73 | 73 |
74 //////////////////////////////////////////////////////////////////////////////// | 74 //////////////////////////////////////////////////////////////////////////////// |
75 // TaskManagerModel class | 75 // TaskManagerModel class |
76 //////////////////////////////////////////////////////////////////////////////// | 76 //////////////////////////////////////////////////////////////////////////////// |
77 | 77 |
78 TaskManagerModel::TaskManagerModel(TaskManager* task_manager) | 78 TaskManagerModel::TaskManagerModel(TaskManager* task_manager) |
79 : update_requests_(0), | 79 : update_requests_(0), |
80 update_state_(IDLE), | 80 update_state_(IDLE), |
81 goat_salt_(rand()) { | 81 goat_salt_(rand()), |
| 82 last_unique_id_(0) { |
82 AddResourceProvider( | 83 AddResourceProvider( |
83 new TaskManagerBrowserProcessResourceProvider(task_manager)); | 84 new TaskManagerBrowserProcessResourceProvider(task_manager)); |
84 AddResourceProvider( | 85 AddResourceProvider( |
85 new TaskManagerBackgroundContentsResourceProvider(task_manager)); | 86 new TaskManagerBackgroundContentsResourceProvider(task_manager)); |
86 AddResourceProvider(new TaskManagerTabContentsResourceProvider(task_manager)); | 87 AddResourceProvider(new TaskManagerTabContentsResourceProvider(task_manager)); |
87 AddResourceProvider( | 88 AddResourceProvider( |
88 new TaskManagerChildProcessResourceProvider(task_manager)); | 89 new TaskManagerChildProcessResourceProvider(task_manager)); |
89 AddResourceProvider( | 90 AddResourceProvider( |
90 new TaskManagerExtensionProcessResourceProvider(task_manager)); | 91 new TaskManagerExtensionProcessResourceProvider(task_manager)); |
91 | 92 |
(...skipping 19 matching lines...) Expand all Loading... |
111 } | 112 } |
112 | 113 |
113 void TaskManagerModel::AddObserver(TaskManagerModelObserver* observer) { | 114 void TaskManagerModel::AddObserver(TaskManagerModelObserver* observer) { |
114 observer_list_.AddObserver(observer); | 115 observer_list_.AddObserver(observer); |
115 } | 116 } |
116 | 117 |
117 void TaskManagerModel::RemoveObserver(TaskManagerModelObserver* observer) { | 118 void TaskManagerModel::RemoveObserver(TaskManagerModelObserver* observer) { |
118 observer_list_.RemoveObserver(observer); | 119 observer_list_.RemoveObserver(observer); |
119 } | 120 } |
120 | 121 |
| 122 int TaskManagerModel::GetResourceUniqueId(int index) const { |
| 123 CHECK_LT(index, ResourceCount()); |
| 124 return resources_[index]->get_unique_id(); |
| 125 } |
| 126 |
121 string16 TaskManagerModel::GetResourceTitle(int index) const { | 127 string16 TaskManagerModel::GetResourceTitle(int index) const { |
122 CHECK_LT(index, ResourceCount()); | 128 CHECK_LT(index, ResourceCount()); |
123 return resources_[index]->GetTitle(); | 129 return resources_[index]->GetTitle(); |
124 } | 130 } |
125 | 131 |
126 string16 TaskManagerModel::GetResourceProfileName(int index) const { | 132 string16 TaskManagerModel::GetResourceProfileName(int index) const { |
127 CHECK_LT(index, ResourceCount()); | 133 CHECK_LT(index, ResourceCount()); |
128 return resources_[index]->GetProfileName(); | 134 return resources_[index]->GetProfileName(); |
129 } | 135 } |
130 | 136 |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 bool TaskManagerModel::GetV8Memory(int index, size_t* result) const { | 560 bool TaskManagerModel::GetV8Memory(int index, size_t* result) const { |
555 *result = 0; | 561 *result = 0; |
556 if (!resources_[index]->ReportsV8MemoryStats()) | 562 if (!resources_[index]->ReportsV8MemoryStats()) |
557 return false; | 563 return false; |
558 | 564 |
559 *result = resources_[index]->GetV8MemoryAllocated(); | 565 *result = resources_[index]->GetV8MemoryAllocated(); |
560 return true; | 566 return true; |
561 } | 567 } |
562 | 568 |
563 bool TaskManagerModel::CanInspect(int index) const { | 569 bool TaskManagerModel::CanInspect(int index) const { |
| 570 CHECK_LT(index, ResourceCount()); |
564 return resources_[index]->CanInspect(); | 571 return resources_[index]->CanInspect(); |
565 } | 572 } |
566 | 573 |
567 void TaskManagerModel::Inspect(int index) const { | 574 void TaskManagerModel::Inspect(int index) const { |
| 575 CHECK_LT(index, ResourceCount()); |
568 resources_[index]->Inspect(); | 576 resources_[index]->Inspect(); |
569 } | 577 } |
570 | 578 |
571 int TaskManagerModel::GetGoatsTeleported(int index) const { | 579 int TaskManagerModel::GetGoatsTeleported(int index) const { |
572 int seed = goat_salt_ * (index + 1); | 580 int seed = goat_salt_ * (index + 1); |
573 return (seed >> 16) & 255; | 581 return (seed >> 16) & 255; |
574 } | 582 } |
575 | 583 |
576 string16 TaskManagerModel::GetMemCellText(int64 number) const { | 584 string16 TaskManagerModel::GetMemCellText(int64 number) const { |
577 #if !defined(OS_MACOSX) | 585 #if !defined(OS_MACOSX) |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 | 643 |
636 void TaskManagerModel::AddResourceProvider( | 644 void TaskManagerModel::AddResourceProvider( |
637 TaskManager::ResourceProvider* provider) { | 645 TaskManager::ResourceProvider* provider) { |
638 DCHECK(provider); | 646 DCHECK(provider); |
639 // AddRef matched with Release in destructor. | 647 // AddRef matched with Release in destructor. |
640 provider->AddRef(); | 648 provider->AddRef(); |
641 providers_.push_back(provider); | 649 providers_.push_back(provider); |
642 } | 650 } |
643 | 651 |
644 void TaskManagerModel::AddResource(TaskManager::Resource* resource) { | 652 void TaskManagerModel::AddResource(TaskManager::Resource* resource) { |
| 653 resource->unique_id_ = ++last_unique_id_; |
| 654 |
645 base::ProcessHandle process = resource->GetProcess(); | 655 base::ProcessHandle process = resource->GetProcess(); |
646 | 656 |
647 ResourceList* group_entries = NULL; | 657 ResourceList* group_entries = NULL; |
648 GroupMap::const_iterator group_iter = group_map_.find(process); | 658 GroupMap::const_iterator group_iter = group_map_.find(process); |
649 int new_entry_index = 0; | 659 int new_entry_index = 0; |
650 if (group_iter == group_map_.end()) { | 660 if (group_iter == group_map_.end()) { |
651 group_entries = new ResourceList(); | 661 group_entries = new ResourceList(); |
652 group_map_[process] = group_entries; | 662 group_map_[process] = group_entries; |
653 group_entries->push_back(resource); | 663 group_entries->push_back(resource); |
654 | 664 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 metrics_map_.clear(); | 770 metrics_map_.clear(); |
761 cpu_usage_map_.clear(); | 771 cpu_usage_map_.clear(); |
762 | 772 |
763 // Clear the network maps. | 773 // Clear the network maps. |
764 current_byte_count_map_.clear(); | 774 current_byte_count_map_.clear(); |
765 displayed_network_usage_map_.clear(); | 775 displayed_network_usage_map_.clear(); |
766 | 776 |
767 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, | 777 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, |
768 OnItemsRemoved(0, size)); | 778 OnItemsRemoved(0, size)); |
769 } | 779 } |
| 780 last_unique_id_ = 0; |
770 } | 781 } |
771 | 782 |
772 void TaskManagerModel::ModelChanged() { | 783 void TaskManagerModel::ModelChanged() { |
773 // Notify the table that the contents have changed for it to redraw. | 784 // Notify the table that the contents have changed for it to redraw. |
774 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, OnModelChanged()); | 785 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, OnModelChanged()); |
775 } | 786 } |
776 | 787 |
777 void TaskManagerModel::NotifyResourceTypeStats( | 788 void TaskManagerModel::NotifyResourceTypeStats( |
778 base::ProcessId renderer_id, | 789 base::ProcessId renderer_id, |
779 const WebKit::WebCache::ResourceTypeStats& stats) { | 790 const WebKit::WebCache::ResourceTypeStats& stats) { |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1127 // Count the number of extensions with background pages (including | 1138 // Count the number of extensions with background pages (including |
1128 // incognito). | 1139 // incognito). |
1129 count += CountExtensionBackgroundPagesForProfile(profile); | 1140 count += CountExtensionBackgroundPagesForProfile(profile); |
1130 if (profile->HasOffTheRecordProfile()) { | 1141 if (profile->HasOffTheRecordProfile()) { |
1131 count += CountExtensionBackgroundPagesForProfile( | 1142 count += CountExtensionBackgroundPagesForProfile( |
1132 profile->GetOffTheRecordProfile()); | 1143 profile->GetOffTheRecordProfile()); |
1133 } | 1144 } |
1134 } | 1145 } |
1135 return count; | 1146 return count; |
1136 } | 1147 } |
OLD | NEW |