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 18 matching lines...) Expand all Loading... |
29 #include "content/browser/renderer_host/render_process_host.h" | 29 #include "content/browser/renderer_host/render_process_host.h" |
30 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 30 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
31 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" | 31 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" |
32 #include "content/browser/tab_contents/tab_contents.h" | 32 #include "content/browser/tab_contents/tab_contents.h" |
33 #include "content/common/result_codes.h" | 33 #include "content/common/result_codes.h" |
34 #include "grit/app_resources.h" | 34 #include "grit/app_resources.h" |
35 #include "grit/chromium_strings.h" | 35 #include "grit/chromium_strings.h" |
36 #include "grit/generated_resources.h" | 36 #include "grit/generated_resources.h" |
37 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
38 #include "ui/base/resource/resource_bundle.h" | 38 #include "ui/base/resource/resource_bundle.h" |
| 39 #include "ui/base/text/bytes_formatting.h" |
39 #include "unicode/coll.h" | 40 #include "unicode/coll.h" |
40 | 41 |
41 #if defined(OS_MACOSX) | 42 #if defined(OS_MACOSX) |
42 #include "chrome/browser/mach_broker_mac.h" | 43 #include "chrome/browser/mach_broker_mac.h" |
43 #endif | 44 #endif |
44 | 45 |
45 namespace { | 46 namespace { |
46 | 47 |
47 // The delay between updates of the information (in ms). | 48 // The delay between updates of the information (in ms). |
48 #if defined(OS_MACOSX) | 49 #if defined(OS_MACOSX) |
49 // Match Activity Monitor's default refresh rate. | 50 // Match Activity Monitor's default refresh rate. |
50 const int kUpdateTimeMs = 2000; | 51 const int kUpdateTimeMs = 2000; |
51 #else | 52 #else |
52 const int kUpdateTimeMs = 1000; | 53 const int kUpdateTimeMs = 1000; |
53 #endif | 54 #endif |
54 | 55 |
55 template <class T> | 56 template <class T> |
56 int ValueCompare(T value1, T value2) { | 57 int ValueCompare(T value1, T value2) { |
57 if (value1 < value2) | 58 if (value1 < value2) |
58 return -1; | 59 return -1; |
59 if (value1 == value2) | 60 if (value1 == value2) |
60 return 0; | 61 return 0; |
61 return 1; | 62 return 1; |
62 } | 63 } |
63 | 64 |
64 string16 FormatStatsSize(const WebKit::WebCache::ResourceTypeStat& stat) { | 65 string16 FormatStatsSize(const WebKit::WebCache::ResourceTypeStat& stat) { |
65 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_CACHE_SIZE_CELL_TEXT, | 66 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_CACHE_SIZE_CELL_TEXT, |
66 FormatBytes(stat.size, DATA_UNITS_KIBIBYTE, false), | 67 ui::FormatBytesWithUnits(stat.size, ui::DATA_UNITS_KIBIBYTE, false), |
67 FormatBytes(stat.liveSize, DATA_UNITS_KIBIBYTE, false)); | 68 ui::FormatBytesWithUnits(stat.liveSize, ui::DATA_UNITS_KIBIBYTE, false)); |
68 } | 69 } |
69 | 70 |
70 } // namespace | 71 } // namespace |
71 | 72 |
72 //////////////////////////////////////////////////////////////////////////////// | 73 //////////////////////////////////////////////////////////////////////////////// |
73 // TaskManagerModel class | 74 // TaskManagerModel class |
74 //////////////////////////////////////////////////////////////////////////////// | 75 //////////////////////////////////////////////////////////////////////////////// |
75 | 76 |
76 TaskManagerModel::TaskManagerModel(TaskManager* task_manager) | 77 TaskManagerModel::TaskManagerModel(TaskManager* task_manager) |
77 : update_requests_(0), | 78 : update_requests_(0), |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 CHECK_LT(index, ResourceCount()); | 122 CHECK_LT(index, ResourceCount()); |
122 return GetNetworkUsage(resources_[index]); | 123 return GetNetworkUsage(resources_[index]); |
123 } | 124 } |
124 | 125 |
125 string16 TaskManagerModel::GetResourceNetworkUsage(int index) const { | 126 string16 TaskManagerModel::GetResourceNetworkUsage(int index) const { |
126 int64 net_usage = GetNetworkUsage(index); | 127 int64 net_usage = GetNetworkUsage(index); |
127 if (net_usage == -1) | 128 if (net_usage == -1) |
128 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT); | 129 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT); |
129 if (net_usage == 0) | 130 if (net_usage == 0) |
130 return ASCIIToUTF16("0"); | 131 return ASCIIToUTF16("0"); |
131 string16 net_byte = FormatSpeed(net_usage, GetByteDisplayUnits(net_usage), | 132 string16 net_byte = ui::FormatSpeed(net_usage); |
132 true); | |
133 // Force number string to have LTR directionality. | 133 // Force number string to have LTR directionality. |
134 return base::i18n::GetDisplayStringInLTRDirectionality(net_byte); | 134 return base::i18n::GetDisplayStringInLTRDirectionality(net_byte); |
135 } | 135 } |
136 | 136 |
137 double TaskManagerModel::GetCPUUsage(int index) const { | 137 double TaskManagerModel::GetCPUUsage(int index) const { |
138 CHECK_LT(index, ResourceCount()); | 138 CHECK_LT(index, ResourceCount()); |
139 return GetCPUUsage(resources_[index]); | 139 return GetCPUUsage(resources_[index]); |
140 } | 140 } |
141 | 141 |
142 string16 TaskManagerModel::GetResourceCPUUsage(int index) const { | 142 string16 TaskManagerModel::GetResourceCPUUsage(int index) const { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 if (!resources_[index]->ReportsSqliteMemoryUsed()) | 230 if (!resources_[index]->ReportsSqliteMemoryUsed()) |
231 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT); | 231 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT); |
232 return GetMemCellText(resources_[index]->SqliteMemoryUsedBytes()); | 232 return GetMemCellText(resources_[index]->SqliteMemoryUsedBytes()); |
233 } | 233 } |
234 | 234 |
235 string16 TaskManagerModel::GetResourceV8MemoryAllocatedSize( | 235 string16 TaskManagerModel::GetResourceV8MemoryAllocatedSize( |
236 int index) const { | 236 int index) const { |
237 if (!resources_[index]->ReportsV8MemoryStats()) | 237 if (!resources_[index]->ReportsV8MemoryStats()) |
238 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT); | 238 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT); |
239 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_CACHE_SIZE_CELL_TEXT, | 239 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_CACHE_SIZE_CELL_TEXT, |
240 FormatBytes(resources_[index]->GetV8MemoryAllocated(), | 240 ui::FormatBytesWithUnits(resources_[index]->GetV8MemoryAllocated(), |
241 DATA_UNITS_KIBIBYTE, | 241 ui::DATA_UNITS_KIBIBYTE, |
242 false), | 242 false), |
243 FormatBytes(resources_[index]->GetV8MemoryUsed(), | 243 ui::FormatBytesWithUnits(resources_[index]->GetV8MemoryUsed(), |
244 DATA_UNITS_KIBIBYTE, | 244 ui::DATA_UNITS_KIBIBYTE, |
245 false)); | 245 false)); |
246 } | 246 } |
247 | 247 |
248 bool TaskManagerModel::IsResourceFirstInGroup(int index) const { | 248 bool TaskManagerModel::IsResourceFirstInGroup(int index) const { |
249 CHECK_LT(index, ResourceCount()); | 249 CHECK_LT(index, ResourceCount()); |
250 TaskManager::Resource* resource = resources_[index]; | 250 TaskManager::Resource* resource = resources_[index]; |
251 GroupMap::const_iterator iter = group_map_.find(resource->GetProcess()); | 251 GroupMap::const_iterator iter = group_map_.find(resource->GetProcess()); |
252 DCHECK(iter != group_map_.end()); | 252 DCHECK(iter != group_map_.end()); |
253 const ResourceList* group = iter->second; | 253 const ResourceList* group = iter->second; |
254 return ((*group)[0] == resource); | 254 return ((*group)[0] == resource); |
255 } | 255 } |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 } | 482 } |
483 | 483 |
484 string16 TaskManagerModel::GetMemCellText(int64 number) const { | 484 string16 TaskManagerModel::GetMemCellText(int64 number) const { |
485 #if !defined(OS_MACOSX) | 485 #if !defined(OS_MACOSX) |
486 string16 str = base::FormatNumber(number / 1024); | 486 string16 str = base::FormatNumber(number / 1024); |
487 | 487 |
488 // Adjust number string if necessary. | 488 // Adjust number string if necessary. |
489 base::i18n::AdjustStringForLocaleDirection(&str); | 489 base::i18n::AdjustStringForLocaleDirection(&str); |
490 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_MEM_CELL_TEXT, str); | 490 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_MEM_CELL_TEXT, str); |
491 #else | 491 #else |
492 // System expectation is to show "100 KB", "200 MB", etc. | 492 // System expectation is to show "100 kB", "200 MB", etc. |
493 // TODO(thakis): Switch to metric units (as opposed to powers of two). | 493 // TODO(thakis): Switch to metric units (as opposed to powers of two). |
494 return FormatBytes(number, GetByteDisplayUnits(number), /*show_units=*/true); | 494 return ui::FormatBytes(number); |
495 #endif | 495 #endif |
496 } | 496 } |
497 | 497 |
498 void TaskManagerModel::StartUpdating() { | 498 void TaskManagerModel::StartUpdating() { |
499 // Multiple StartUpdating requests may come in, and we only need to take | 499 // Multiple StartUpdating requests may come in, and we only need to take |
500 // action the first time. | 500 // action the first time. |
501 update_requests_++; | 501 update_requests_++; |
502 if (update_requests_ > 1) | 502 if (update_requests_ > 1) |
503 return; | 503 return; |
504 DCHECK_EQ(1, update_requests_); | 504 DCHECK_EQ(1, update_requests_); |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1033 // Count the number of extensions with background pages (including | 1033 // Count the number of extensions with background pages (including |
1034 // incognito). | 1034 // incognito). |
1035 count += CountExtensionBackgroundPagesForProfile(profile); | 1035 count += CountExtensionBackgroundPagesForProfile(profile); |
1036 if (profile->HasOffTheRecordProfile()) { | 1036 if (profile->HasOffTheRecordProfile()) { |
1037 count += CountExtensionBackgroundPagesForProfile( | 1037 count += CountExtensionBackgroundPagesForProfile( |
1038 profile->GetOffTheRecordProfile()); | 1038 profile->GetOffTheRecordProfile()); |
1039 } | 1039 } |
1040 } | 1040 } |
1041 return count; | 1041 return count; |
1042 } | 1042 } |
OLD | NEW |