Chromium Code Reviews| 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.h" | 5 #include "chrome/browser/task_manager/task_manager.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/i18n/number_formatting.h" | 10 #include "base/i18n/number_formatting.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 | 71 |
| 72 TaskManagerModel::TaskManagerModel(TaskManager* task_manager) | 72 TaskManagerModel::TaskManagerModel(TaskManager* task_manager) |
| 73 : update_requests_(0), | 73 : update_requests_(0), |
| 74 update_state_(IDLE), | 74 update_state_(IDLE), |
| 75 goat_salt_(rand()) { | 75 goat_salt_(rand()) { |
| 76 | 76 |
| 77 TaskManagerBrowserProcessResourceProvider* browser_provider = | 77 TaskManagerBrowserProcessResourceProvider* browser_provider = |
| 78 new TaskManagerBrowserProcessResourceProvider(task_manager); | 78 new TaskManagerBrowserProcessResourceProvider(task_manager); |
| 79 browser_provider->AddRef(); | 79 browser_provider->AddRef(); |
| 80 providers_.push_back(browser_provider); | 80 providers_.push_back(browser_provider); |
| 81 TaskManagerTabContentsResourceProvider* wc_provider = | |
| 82 new TaskManagerTabContentsResourceProvider(task_manager); | |
| 83 wc_provider->AddRef(); | |
| 84 providers_.push_back(wc_provider); | |
| 85 TaskManagerBackgroundContentsResourceProvider* bc_provider = | 81 TaskManagerBackgroundContentsResourceProvider* bc_provider = |
| 86 new TaskManagerBackgroundContentsResourceProvider(task_manager); | 82 new TaskManagerBackgroundContentsResourceProvider(task_manager); |
| 87 bc_provider->AddRef(); | 83 bc_provider->AddRef(); |
| 88 providers_.push_back(bc_provider); | 84 providers_.push_back(bc_provider); |
| 85 TaskManagerTabContentsResourceProvider* wc_provider = | |
|
Evan Stade
2010/11/15 03:54:00
indent weird.
why did you move this?
Andrew T Wilson (Slow)
2010/11/15 08:20:57
The order the providers are defined also defines t
| |
| 86 new TaskManagerTabContentsResourceProvider(task_manager); | |
| 87 wc_provider->AddRef(); | |
| 88 providers_.push_back(wc_provider); | |
| 89 TaskManagerChildProcessResourceProvider* child_process_provider = | 89 TaskManagerChildProcessResourceProvider* child_process_provider = |
| 90 new TaskManagerChildProcessResourceProvider(task_manager); | 90 new TaskManagerChildProcessResourceProvider(task_manager); |
| 91 child_process_provider->AddRef(); | 91 child_process_provider->AddRef(); |
| 92 providers_.push_back(child_process_provider); | 92 providers_.push_back(child_process_provider); |
| 93 TaskManagerExtensionProcessResourceProvider* extension_process_provider = | 93 TaskManagerExtensionProcessResourceProvider* extension_process_provider = |
| 94 new TaskManagerExtensionProcessResourceProvider(task_manager); | 94 new TaskManagerExtensionProcessResourceProvider(task_manager); |
| 95 extension_process_provider->AddRef(); | 95 extension_process_provider->AddRef(); |
| 96 providers_.push_back(extension_process_provider); | 96 providers_.push_back(extension_process_provider); |
| 97 TaskManagerNotificationResourceProvider* notification_provider = | 97 TaskManagerNotificationResourceProvider* notification_provider = |
| 98 new TaskManagerNotificationResourceProvider(task_manager); | 98 new TaskManagerNotificationResourceProvider(task_manager); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 | 245 |
| 246 bool TaskManagerModel::IsResourceFirstInGroup(int index) const { | 246 bool TaskManagerModel::IsResourceFirstInGroup(int index) const { |
| 247 CHECK(index < ResourceCount()); | 247 CHECK(index < ResourceCount()); |
| 248 TaskManager::Resource* resource = resources_[index]; | 248 TaskManager::Resource* resource = resources_[index]; |
| 249 GroupMap::const_iterator iter = group_map_.find(resource->GetProcess()); | 249 GroupMap::const_iterator iter = group_map_.find(resource->GetProcess()); |
| 250 DCHECK(iter != group_map_.end()); | 250 DCHECK(iter != group_map_.end()); |
| 251 const ResourceList* group = iter->second; | 251 const ResourceList* group = iter->second; |
| 252 return ((*group)[0] == resource); | 252 return ((*group)[0] == resource); |
| 253 } | 253 } |
| 254 | 254 |
| 255 bool TaskManagerModel::IsBackgroundResource(int index) const { | |
| 256 CHECK(index < ResourceCount()); | |
|
Evan Stade
2010/11/15 03:54:00
is there no CHECK_LT?
Andrew T Wilson (Slow)
2010/11/15 08:20:57
There is - I was just following the pattern used i
| |
| 257 return resources_[index]->IsBackground(); | |
| 258 } | |
| 259 | |
| 255 SkBitmap TaskManagerModel::GetResourceIcon(int index) const { | 260 SkBitmap TaskManagerModel::GetResourceIcon(int index) const { |
| 256 CHECK(index < ResourceCount()); | 261 CHECK(index < ResourceCount()); |
| 257 SkBitmap icon = resources_[index]->GetIcon(); | 262 SkBitmap icon = resources_[index]->GetIcon(); |
| 258 if (!icon.isNull()) | 263 if (!icon.isNull()) |
| 259 return icon; | 264 return icon; |
| 260 | 265 |
| 261 static SkBitmap* default_icon = ResourceBundle::GetSharedInstance(). | 266 static SkBitmap* default_icon = ResourceBundle::GetSharedInstance(). |
| 262 GetBitmapNamed(IDR_DEFAULT_FAVICON); | 267 GetBitmapNamed(IDR_DEFAULT_FAVICON); |
| 263 return *default_icon; | 268 return *default_icon; |
| 264 } | 269 } |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 604 } else { | 609 } else { |
| 605 group_entries = group_iter->second; | 610 group_entries = group_iter->second; |
| 606 group_entries->push_back(resource); | 611 group_entries->push_back(resource); |
| 607 | 612 |
| 608 // Insert the new entry right after the last entry of its group. | 613 // Insert the new entry right after the last entry of its group. |
| 609 ResourceList::iterator iter = | 614 ResourceList::iterator iter = |
| 610 std::find(resources_.begin(), | 615 std::find(resources_.begin(), |
| 611 resources_.end(), | 616 resources_.end(), |
| 612 (*group_entries)[group_entries->size() - 2]); | 617 (*group_entries)[group_entries->size() - 2]); |
| 613 DCHECK(iter != resources_.end()); | 618 DCHECK(iter != resources_.end()); |
| 614 new_entry_index = static_cast<int>(iter - resources_.begin()); | 619 new_entry_index = static_cast<int>(iter - resources_.begin()) + 1; |
| 615 resources_.insert(++iter, resource); | 620 resources_.insert(++iter, resource); |
| 616 } | 621 } |
| 617 | 622 |
| 618 // Create the ProcessMetrics for this process if needed (not in map). | 623 // Create the ProcessMetrics for this process if needed (not in map). |
| 619 if (metrics_map_.find(process) == metrics_map_.end()) { | 624 if (metrics_map_.find(process) == metrics_map_.end()) { |
| 620 base::ProcessMetrics* pm = | 625 base::ProcessMetrics* pm = |
| 621 #if !defined(OS_MACOSX) | 626 #if !defined(OS_MACOSX) |
| 622 base::ProcessMetrics::CreateProcessMetrics(process); | 627 base::ProcessMetrics::CreateProcessMetrics(process); |
| 623 #else | 628 #else |
| 624 base::ProcessMetrics::CreateProcessMetrics(process, | 629 base::ProcessMetrics::CreateProcessMetrics(process, |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 708 | 713 |
| 709 // Clear the network maps. | 714 // Clear the network maps. |
| 710 current_byte_count_map_.clear(); | 715 current_byte_count_map_.clear(); |
| 711 displayed_network_usage_map_.clear(); | 716 displayed_network_usage_map_.clear(); |
| 712 | 717 |
| 713 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, | 718 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, |
| 714 OnItemsRemoved(0, size)); | 719 OnItemsRemoved(0, size)); |
| 715 } | 720 } |
| 716 } | 721 } |
| 717 | 722 |
| 723 void TaskManagerModel::ModelChanged() { | |
| 724 // Notify the table that the contents have changed for it to redraw. | |
| 725 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, | |
|
Evan Stade
2010/11/15 03:54:00
can this all fit on one row?
Andrew T Wilson (Slow)
2010/11/15 08:20:57
Wow, it just fit. Good eye.
| |
| 726 OnModelChanged()); | |
| 727 } | |
| 728 | |
| 718 void TaskManagerModel::NotifyResourceTypeStats( | 729 void TaskManagerModel::NotifyResourceTypeStats( |
| 719 base::ProcessId renderer_id, | 730 base::ProcessId renderer_id, |
| 720 const WebKit::WebCache::ResourceTypeStats& stats) { | 731 const WebKit::WebCache::ResourceTypeStats& stats) { |
| 721 for (ResourceList::iterator it = resources_.begin(); | 732 for (ResourceList::iterator it = resources_.begin(); |
| 722 it != resources_.end(); ++it) { | 733 it != resources_.end(); ++it) { |
| 723 if (base::GetProcId((*it)->GetProcess()) == renderer_id) { | 734 if (base::GetProcId((*it)->GetProcess()) == renderer_id) { |
| 724 (*it)->NotifyResourceTypeStats(stats); | 735 (*it)->NotifyResourceTypeStats(stats); |
| 725 } | 736 } |
| 726 } | 737 } |
| 727 } | 738 } |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 959 } | 970 } |
| 960 | 971 |
| 961 void TaskManager::RemoveResource(Resource* resource) { | 972 void TaskManager::RemoveResource(Resource* resource) { |
| 962 model_->RemoveResource(resource); | 973 model_->RemoveResource(resource); |
| 963 } | 974 } |
| 964 | 975 |
| 965 void TaskManager::OnWindowClosed() { | 976 void TaskManager::OnWindowClosed() { |
| 966 model_->StopUpdating(); | 977 model_->StopUpdating(); |
| 967 } | 978 } |
| 968 | 979 |
| 980 void TaskManager::ModelChanged() { | |
| 981 model_->ModelChanged(); | |
| 982 } | |
| 983 | |
| 969 // static | 984 // static |
| 970 TaskManager* TaskManager::GetInstance() { | 985 TaskManager* TaskManager::GetInstance() { |
| 971 return Singleton<TaskManager>::get(); | 986 return Singleton<TaskManager>::get(); |
| 972 } | 987 } |
| 973 | 988 |
| 974 void TaskManager::OpenAboutMemory() { | 989 void TaskManager::OpenAboutMemory() { |
| 975 Browser* browser = BrowserList::GetLastActive(); | 990 Browser* browser = BrowserList::GetLastActive(); |
| 976 | 991 |
| 977 if (!browser) { | 992 if (!browser) { |
| 978 // On OS X, the task manager can be open without any open browser windows. | 993 // On OS X, the task manager can be open without any open browser windows. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1010 MetricsMap::const_iterator iter = metrics_map_.find(handle); | 1025 MetricsMap::const_iterator iter = metrics_map_.find(handle); |
| 1011 if (iter == metrics_map_.end()) | 1026 if (iter == metrics_map_.end()) |
| 1012 return false; | 1027 return false; |
| 1013 | 1028 |
| 1014 if (!iter->second->GetMemoryBytes(&usage->first, &usage->second)) | 1029 if (!iter->second->GetMemoryBytes(&usage->first, &usage->second)) |
| 1015 return false; | 1030 return false; |
| 1016 | 1031 |
| 1017 memory_usage_map_.insert(std::make_pair(handle, *usage)); | 1032 memory_usage_map_.insert(std::make_pair(handle, *usage)); |
| 1018 return true; | 1033 return true; |
| 1019 } | 1034 } |
| OLD | NEW |