OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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.h" | 5 #include "chrome/browser/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/process_util.h" | 11 #include "base/process_util.h" |
11 #include "base/stats_table.h" | 12 #include "base/stats_table.h" |
12 #include "base/string_util.h" | 13 #include "base/string_util.h" |
13 #include "base/thread.h" | 14 #include "base/thread.h" |
14 #include "chrome/browser/browser_list.h" | 15 #include "chrome/browser/browser_list.h" |
15 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/net/url_request_tracking.h" | 17 #include "chrome/browser/net/url_request_tracking.h" |
17 #include "chrome/browser/renderer_host/render_process_host.h" | 18 #include "chrome/browser/renderer_host/render_process_host.h" |
18 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 19 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
19 #include "chrome/browser/task_manager_resource_providers.h" | 20 #include "chrome/browser/task_manager_resource_providers.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 } | 122 } |
122 | 123 |
123 std::wstring TaskManagerModel::GetResourcePrivateMemory(int index) const { | 124 std::wstring TaskManagerModel::GetResourcePrivateMemory(int index) const { |
124 DCHECK(index < ResourceCount()); | 125 DCHECK(index < ResourceCount()); |
125 // We report committed (working set + paged) private usage. This is NOT | 126 // We report committed (working set + paged) private usage. This is NOT |
126 // going to match what Windows Task Manager shows (which is working set). | 127 // going to match what Windows Task Manager shows (which is working set). |
127 MetricsMap::const_iterator iter = | 128 MetricsMap::const_iterator iter = |
128 metrics_map_.find(resources_[index]->GetProcess()); | 129 metrics_map_.find(resources_[index]->GetProcess()); |
129 DCHECK(iter != metrics_map_.end()); | 130 DCHECK(iter != metrics_map_.end()); |
130 base::ProcessMetrics* process_metrics = iter->second; | 131 base::ProcessMetrics* process_metrics = iter->second; |
131 std::wstring number = FormatNumber(GetPrivateMemory(process_metrics)); | 132 return GetMemCellText(GetPrivateMemory(process_metrics)); |
132 return GetMemCellText(&number); | |
133 } | 133 } |
134 | 134 |
135 std::wstring TaskManagerModel::GetResourceSharedMemory(int index) const { | 135 std::wstring TaskManagerModel::GetResourceSharedMemory(int index) const { |
136 DCHECK(index < ResourceCount()); | 136 DCHECK(index < ResourceCount()); |
137 MetricsMap::const_iterator iter = | 137 MetricsMap::const_iterator iter = |
138 metrics_map_.find(resources_[index]->GetProcess()); | 138 metrics_map_.find(resources_[index]->GetProcess()); |
139 DCHECK(iter != metrics_map_.end()); | 139 DCHECK(iter != metrics_map_.end()); |
140 base::ProcessMetrics* process_metrics = iter->second; | 140 base::ProcessMetrics* process_metrics = iter->second; |
141 std::wstring number = FormatNumber(GetSharedMemory(process_metrics)); | 141 return GetMemCellText(GetSharedMemory(process_metrics)); |
142 return GetMemCellText(&number); | |
143 } | 142 } |
144 | 143 |
145 std::wstring TaskManagerModel::GetResourcePhysicalMemory(int index) const { | 144 std::wstring TaskManagerModel::GetResourcePhysicalMemory(int index) const { |
146 DCHECK(index < ResourceCount()); | 145 DCHECK(index < ResourceCount()); |
147 MetricsMap::const_iterator iter = | 146 MetricsMap::const_iterator iter = |
148 metrics_map_.find(resources_[index]->GetProcess()); | 147 metrics_map_.find(resources_[index]->GetProcess()); |
149 DCHECK(iter != metrics_map_.end()); | 148 DCHECK(iter != metrics_map_.end()); |
150 base::ProcessMetrics* process_metrics = iter->second; | 149 base::ProcessMetrics* process_metrics = iter->second; |
151 std::wstring number = FormatNumber(GetPhysicalMemory(process_metrics)); | 150 return GetMemCellText(GetPhysicalMemory(process_metrics)); |
152 return GetMemCellText(&number); | |
153 } | 151 } |
154 | 152 |
155 std::wstring TaskManagerModel::GetResourceProcessId(int index) const { | 153 std::wstring TaskManagerModel::GetResourceProcessId(int index) const { |
156 DCHECK(index < ResourceCount()); | 154 DCHECK(index < ResourceCount()); |
157 return IntToWString(base::GetProcId(resources_[index]->GetProcess())); | 155 return IntToWString(base::GetProcId(resources_[index]->GetProcess())); |
158 } | 156 } |
159 | 157 |
160 std::wstring TaskManagerModel::GetResourceStatsValue(int index, int col_id) | 158 std::wstring TaskManagerModel::GetResourceStatsValue(int index, int col_id) |
161 const { | 159 const { |
162 DCHECK(index < ResourceCount()); | 160 DCHECK(index < ResourceCount()); |
163 return IntToWString(GetStatsValue(resources_[index], col_id)); | 161 return IntToWString(GetStatsValue(resources_[index], col_id)); |
164 } | 162 } |
165 | 163 |
166 std::wstring TaskManagerModel::GetResourceGoatsTeleported(int index) const { | 164 std::wstring TaskManagerModel::GetResourceGoatsTeleported(int index) const { |
167 DCHECK(index < ResourceCount()); | 165 DCHECK(index < ResourceCount()); |
168 goats_teleported_ += rand() & 4095; | 166 goats_teleported_ += rand() & 4095; |
169 return FormatNumber(goats_teleported_); | 167 return UTF16ToWide(base::FormatNumber(goats_teleported_)); |
170 } | 168 } |
171 | 169 |
172 std::wstring TaskManagerModel::GetResourceWebCoreImageCacheSize( | 170 std::wstring TaskManagerModel::GetResourceWebCoreImageCacheSize( |
173 int index) const { | 171 int index) const { |
174 DCHECK(index < ResourceCount()); | 172 DCHECK(index < ResourceCount()); |
175 if (!resources_[index]->ReportsCacheStats()) | 173 if (!resources_[index]->ReportsCacheStats()) |
176 return l10n_util::GetString(IDS_TASK_MANAGER_NA_CELL_TEXT); | 174 return l10n_util::GetString(IDS_TASK_MANAGER_NA_CELL_TEXT); |
177 const WebKit::WebCache::ResourceTypeStats stats( | 175 const WebKit::WebCache::ResourceTypeStats stats( |
178 resources_[index]->GetWebCoreCacheStats()); | 176 resources_[index]->GetWebCoreCacheStats()); |
179 return FormatStatsSize(stats.images); | 177 return FormatStatsSize(stats.images); |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 if (counter != NULL && counter[0] != '\0') { | 376 if (counter != NULL && counter[0] != '\0') { |
379 return table->GetCounterValue(counter, | 377 return table->GetCounterValue(counter, |
380 base::GetProcId(resource->GetProcess())); | 378 base::GetProcId(resource->GetProcess())); |
381 } else { | 379 } else { |
382 NOTREACHED() << "Invalid column."; | 380 NOTREACHED() << "Invalid column."; |
383 } | 381 } |
384 } | 382 } |
385 return 0; | 383 return 0; |
386 } | 384 } |
387 | 385 |
388 std::wstring TaskManagerModel::GetMemCellText( | 386 std::wstring TaskManagerModel::GetMemCellText(int64 number) const { |
389 std::wstring* number) const { | 387 std::wstring str = UTF16ToWide(base::FormatNumber(number)); |
| 388 |
390 // Adjust number string if necessary. | 389 // Adjust number string if necessary. |
391 l10n_util::AdjustStringForLocaleDirection(*number, number); | 390 l10n_util::AdjustStringForLocaleDirection(str, &str); |
392 return l10n_util::GetStringF(IDS_TASK_MANAGER_MEM_CELL_TEXT, *number); | 391 return l10n_util::GetStringF(IDS_TASK_MANAGER_MEM_CELL_TEXT, str); |
393 } | 392 } |
394 | 393 |
395 void TaskManagerModel::StartUpdating() { | 394 void TaskManagerModel::StartUpdating() { |
396 DCHECK_NE(TASK_PENDING, update_state_); | 395 DCHECK_NE(TASK_PENDING, update_state_); |
397 | 396 |
398 // If update_state_ is STOPPING, it means a task is still pending. Setting | 397 // If update_state_ is STOPPING, it means a task is still pending. Setting |
399 // it to TASK_PENDING ensures the tasks keep being posted (by Refresh()). | 398 // it to TASK_PENDING ensures the tasks keep being posted (by Refresh()). |
400 if (update_state_ == IDLE) { | 399 if (update_state_ == IDLE) { |
401 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 400 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
402 NewRunnableMethod(this, &TaskManagerModel::Refresh), | 401 NewRunnableMethod(this, &TaskManagerModel::Refresh), |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 | 813 |
815 void TaskManager::OnWindowClosed() { | 814 void TaskManager::OnWindowClosed() { |
816 model_->StopUpdating(); | 815 model_->StopUpdating(); |
817 model_->Clear(); | 816 model_->Clear(); |
818 } | 817 } |
819 | 818 |
820 // static | 819 // static |
821 TaskManager* TaskManager::GetInstance() { | 820 TaskManager* TaskManager::GetInstance() { |
822 return Singleton<TaskManager>::get(); | 821 return Singleton<TaskManager>::get(); |
823 } | 822 } |
OLD | NEW |