Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(321)

Side by Side Diff: chrome/browser/task_manager/task_manager.cc

Issue 9565041: Cleanup: Typedef std::pairs in TaskManager code. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/task_manager/task_manager.h ('k') | chrome/browser/ui/cocoa/task_manager_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/i18n/number_formatting.h" 9 #include "base/i18n/number_formatting.h"
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
11 #include "base/process_util.h" 11 #include "base/process_util.h"
12 #include "base/rand_util.h"
12 #include "base/string_number_conversions.h" 13 #include "base/string_number_conversions.h"
13 #include "base/stringprintf.h" 14 #include "base/stringprintf.h"
14 #include "base/threading/thread.h" 15 #include "base/threading/thread.h"
15 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
16 #include "chrome/browser/background/background_contents_service.h" 17 #include "chrome/browser/background/background_contents_service.h"
17 #include "chrome/browser/background/background_contents_service_factory.h" 18 #include "chrome/browser/background/background_contents_service_factory.h"
18 #include "chrome/browser/browser_process.h" 19 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/extensions/extension_host.h" 20 #include "chrome/browser/extensions/extension_host.h"
20 #include "chrome/browser/extensions/extension_process_manager.h" 21 #include "chrome/browser/extensions/extension_process_manager.h"
21 #include "chrome/browser/prefs/pref_service.h" 22 #include "chrome/browser/prefs/pref_service.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 77
77 } // namespace 78 } // namespace
78 79
79 //////////////////////////////////////////////////////////////////////////////// 80 ////////////////////////////////////////////////////////////////////////////////
80 // TaskManagerModel class 81 // TaskManagerModel class
81 //////////////////////////////////////////////////////////////////////////////// 82 ////////////////////////////////////////////////////////////////////////////////
82 83
83 TaskManagerModel::TaskManagerModel(TaskManager* task_manager) 84 TaskManagerModel::TaskManagerModel(TaskManager* task_manager)
84 : update_requests_(0), 85 : update_requests_(0),
85 update_state_(IDLE), 86 update_state_(IDLE),
86 goat_salt_(rand()), 87 goat_salt_(base::RandUint64()),
87 last_unique_id_(0) { 88 last_unique_id_(0) {
88 AddResourceProvider( 89 AddResourceProvider(
89 new TaskManagerBrowserProcessResourceProvider(task_manager)); 90 new TaskManagerBrowserProcessResourceProvider(task_manager));
90 AddResourceProvider( 91 AddResourceProvider(
91 new TaskManagerBackgroundContentsResourceProvider(task_manager)); 92 new TaskManagerBackgroundContentsResourceProvider(task_manager));
92 AddResourceProvider(new TaskManagerTabContentsResourceProvider(task_manager)); 93 AddResourceProvider(new TaskManagerTabContentsResourceProvider(task_manager));
93 AddResourceProvider( 94 AddResourceProvider(
94 new TaskManagerChildProcessResourceProvider(task_manager)); 95 new TaskManagerChildProcessResourceProvider(task_manager));
95 AddResourceProvider( 96 AddResourceProvider(
96 new TaskManagerExtensionProcessResourceProvider(task_manager)); 97 new TaskManagerExtensionProcessResourceProvider(task_manager));
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 CHECK_LT(index, ResourceCount()); 303 CHECK_LT(index, ResourceCount());
303 SkBitmap icon = resources_[index]->GetIcon(); 304 SkBitmap icon = resources_[index]->GetIcon();
304 if (!icon.isNull()) 305 if (!icon.isNull())
305 return icon; 306 return icon;
306 307
307 static SkBitmap* default_icon = ResourceBundle::GetSharedInstance(). 308 static SkBitmap* default_icon = ResourceBundle::GetSharedInstance().
308 GetBitmapNamed(IDR_DEFAULT_FAVICON); 309 GetBitmapNamed(IDR_DEFAULT_FAVICON);
309 return *default_icon; 310 return *default_icon;
310 } 311 }
311 312
312 std::pair<int, int> TaskManagerModel::GetGroupRangeForResource(int index) 313 TaskManagerModel::GroupRange
313 const { 314 TaskManagerModel::GetGroupRangeForResource(int index) const {
314 CHECK_LT(index, ResourceCount()); 315 CHECK_LT(index, ResourceCount());
315 TaskManager::Resource* resource = resources_[index]; 316 TaskManager::Resource* resource = resources_[index];
316 GroupMap::const_iterator group_iter = 317 GroupMap::const_iterator group_iter =
317 group_map_.find(resource->GetProcess()); 318 group_map_.find(resource->GetProcess());
318 DCHECK(group_iter != group_map_.end()); 319 DCHECK(group_iter != group_map_.end());
319 ResourceList* group = group_iter->second; 320 ResourceList* group = group_iter->second;
320 DCHECK(group); 321 DCHECK(group);
321 if (group->size() == 1) { 322 if (group->size() == 1) {
322 return std::make_pair(index, 1); 323 return std::make_pair(index, 1);
323 } else { 324 } else {
324 for (int i = index; i >= 0; --i) { 325 for (int i = index; i >= 0; --i) {
325 if (resources_[i] == (*group)[0]) 326 if (resources_[i] == (*group)[0])
326 return std::make_pair(i, group->size()); 327 return std::make_pair(i, group->size());
327 } 328 }
328 NOTREACHED(); 329 NOTREACHED();
329 return std::make_pair(-1, -1); 330 return std::make_pair(-1, -1);
330 } 331 }
331 } 332 }
332 333
333 int TaskManagerModel::GetGroupIndexForResource(int index) const { 334 int TaskManagerModel::GetGroupIndexForResource(int index) const {
334 int group_index = -1; 335 int group_index = -1;
335 for (int i = 0; i <= index; ++i) { 336 for (int i = 0; i <= index; ++i) {
336 if (IsResourceFirstInGroup(i)) 337 if (IsResourceFirstInGroup(i))
337 group_index++; 338 group_index++;
338 } 339 }
339 340
340 DCHECK(group_index != -1); 341 DCHECK_NE(group_index, -1);
341 return group_index; 342 return group_index;
342 } 343 }
343 344
344 int TaskManagerModel::GetResourceIndexForGroup(int group_index, 345 int TaskManagerModel::GetResourceIndexForGroup(int group_index,
345 int index_in_group) const { 346 int index_in_group) const {
346 int group_count = -1; 347 int group_count = -1;
347 int count_in_group = -1; 348 int count_in_group = -1;
348 for (int i = 0; i < ResourceCount(); ++i) { 349 for (int i = 0; i < ResourceCount(); ++i) {
349 if (IsResourceFirstInGroup(i)) 350 if (IsResourceFirstInGroup(i))
350 group_count++; 351 group_count++;
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 cpu_usage_map_.find(resource->GetProcess()); 492 cpu_usage_map_.find(resource->GetProcess());
492 if (iter == cpu_usage_map_.end()) 493 if (iter == cpu_usage_map_.end())
493 return 0; 494 return 0;
494 return iter->second; 495 return iter->second;
495 } 496 }
496 497
497 bool TaskManagerModel::GetPrivateMemory(int index, size_t* result) const { 498 bool TaskManagerModel::GetPrivateMemory(int index, size_t* result) const {
498 base::ProcessHandle handle = resources_[index]->GetProcess(); 499 base::ProcessHandle handle = resources_[index]->GetProcess();
499 MemoryUsageMap::const_iterator iter = memory_usage_map_.find(handle); 500 MemoryUsageMap::const_iterator iter = memory_usage_map_.find(handle);
500 if (iter == memory_usage_map_.end()) { 501 if (iter == memory_usage_map_.end()) {
501 std::pair<size_t, size_t> usage; 502 MemoryUsageEntry usage;
502 if (!GetAndCacheMemoryMetrics(handle, &usage)) 503 if (!GetAndCacheMemoryMetrics(handle, &usage))
503 return false; 504 return false;
504 505
505 *result = usage.first; 506 *result = usage.first;
506 } else { 507 } else {
507 *result = iter->second.first; 508 *result = iter->second.first;
508 } 509 }
509 510
510 return true; 511 return true;
511 } 512 }
512 513
513 bool TaskManagerModel::GetSharedMemory(int index, size_t* result) const { 514 bool TaskManagerModel::GetSharedMemory(int index, size_t* result) const {
514 base::ProcessHandle handle = resources_[index]->GetProcess(); 515 base::ProcessHandle handle = resources_[index]->GetProcess();
515 MemoryUsageMap::const_iterator iter = memory_usage_map_.find(handle); 516 MemoryUsageMap::const_iterator iter = memory_usage_map_.find(handle);
516 if (iter == memory_usage_map_.end()) { 517 if (iter == memory_usage_map_.end()) {
517 std::pair<size_t, size_t> usage; 518 MemoryUsageEntry usage;
518 if (!GetAndCacheMemoryMetrics(handle, &usage)) 519 if (!GetAndCacheMemoryMetrics(handle, &usage))
519 return false; 520 return false;
520 521
521 *result = usage.second; 522 *result = usage.second;
522 } else { 523 } else {
523 *result = iter->second.second; 524 *result = iter->second.second;
524 } 525 }
525 526
526 return true; 527 return true;
527 } 528 }
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 844
844 void TaskManagerModel::Refresh() { 845 void TaskManagerModel::Refresh() {
845 DCHECK_NE(IDLE, update_state_); 846 DCHECK_NE(IDLE, update_state_);
846 847
847 if (update_state_ == STOPPING) { 848 if (update_state_ == STOPPING) {
848 // We have been asked to stop. 849 // We have been asked to stop.
849 update_state_ = IDLE; 850 update_state_ = IDLE;
850 return; 851 return;
851 } 852 }
852 853
853 goat_salt_ = rand(); 854 goat_salt_ = base::RandUint64();
854 855
855 // Compute the CPU usage values. 856 // Compute the CPU usage values.
856 // Note that we compute the CPU usage for all resources (instead of doing it 857 // Note that we compute the CPU usage for all resources (instead of doing it
857 // lazily) as process_util::GetCPUUsage() returns the CPU usage since the last 858 // lazily) as process_util::GetCPUUsage() returns the CPU usage since the last
858 // time it was called, and not calling it everytime would skew the value the 859 // time it was called, and not calling it everytime would skew the value the
859 // next time it is retrieved (as it would be for more than 1 cycle). 860 // next time it is retrieved (as it would be for more than 1 cycle).
860 cpu_usage_map_.clear(); 861 cpu_usage_map_.clear();
861 for (ResourceList::iterator iter = resources_.begin(); 862 for (ResourceList::iterator iter = resources_.begin();
862 iter != resources_.end(); ++iter) { 863 iter != resources_.end(); ++iter) {
863 base::ProcessHandle process = (*iter)->GetProcess(); 864 base::ProcessHandle process = (*iter)->GetProcess();
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 // TabContents in a tabbed browser, so we need to grab it with 1098 // TabContents in a tabbed browser, so we need to grab it with
1098 // GetLastActive before the call to show(). 1099 // GetLastActive before the call to show().
1099 if (!browser->is_type_tabbed()) { 1100 if (!browser->is_type_tabbed()) {
1100 browser = BrowserList::GetLastActive(); 1101 browser = BrowserList::GetLastActive();
1101 DCHECK(browser); 1102 DCHECK(browser);
1102 } 1103 }
1103 } 1104 }
1104 browser->window()->Show(); 1105 browser->window()->Show();
1105 } 1106 }
1106 1107
1107 bool TaskManagerModel::GetAndCacheMemoryMetrics( 1108 bool TaskManagerModel::GetAndCacheMemoryMetrics(base::ProcessHandle handle,
1108 base::ProcessHandle handle, 1109 MemoryUsageEntry* usage) const {
1109 std::pair<size_t, size_t>* usage) const {
1110 MetricsMap::const_iterator iter = metrics_map_.find(handle); 1110 MetricsMap::const_iterator iter = metrics_map_.find(handle);
1111 if (iter == metrics_map_.end()) 1111 if (iter == metrics_map_.end())
1112 return false; 1112 return false;
1113 1113
1114 if (!iter->second->GetMemoryBytes(&usage->first, &usage->second)) 1114 if (!iter->second->GetMemoryBytes(&usage->first, &usage->second))
1115 return false; 1115 return false;
1116 1116
1117 memory_usage_map_.insert(std::make_pair(handle, *usage)); 1117 memory_usage_map_.insert(std::make_pair(handle, *usage));
1118 return true; 1118 return true;
1119 } 1119 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 // Count the number of extensions with background pages (including 1161 // Count the number of extensions with background pages (including
1162 // incognito). 1162 // incognito).
1163 count += CountExtensionBackgroundPagesForProfile(profile); 1163 count += CountExtensionBackgroundPagesForProfile(profile);
1164 if (profile->HasOffTheRecordProfile()) { 1164 if (profile->HasOffTheRecordProfile()) {
1165 count += CountExtensionBackgroundPagesForProfile( 1165 count += CountExtensionBackgroundPagesForProfile(
1166 profile->GetOffTheRecordProfile()); 1166 profile->GetOffTheRecordProfile());
1167 } 1167 }
1168 } 1168 }
1169 return count; 1169 return count;
1170 } 1170 }
OLDNEW
« no previous file with comments | « chrome/browser/task_manager/task_manager.h ('k') | chrome/browser/ui/cocoa/task_manager_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698