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

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

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 | « no previous file | chrome/browser/task_manager/task_manager.cc » ('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 #ifndef CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_H_ 5 #ifndef CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_H_
6 #define CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_H_ 6 #define CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <string>
11 #include <utility> 10 #include <utility>
12 #include <vector> 11 #include <vector>
13 12
14 #include "base/basictypes.h" 13 #include "base/basictypes.h"
15 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
16 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
17 #include "base/memory/singleton.h" 16 #include "base/memory/singleton.h"
18 #include "base/observer_list.h" 17 #include "base/observer_list.h"
19 #include "base/process_util.h" 18 #include "base/process_util.h"
20 #include "base/string16.h" 19 #include "base/string16.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 static const char* GetResourceTypeAsString(const Type type) { 128 static const char* GetResourceTypeAsString(const Type type) {
130 switch (type) { 129 switch (type) {
131 TASKMANAGER_RESOURCE_TYPE_LIST(TASKMANAGER_RESOURCE_TYPE_LIST_AS_STRING) 130 TASKMANAGER_RESOURCE_TYPE_LIST(TASKMANAGER_RESOURCE_TYPE_LIST_AS_STRING)
132 default: return "UNKNOWN"; 131 default: return "UNKNOWN";
133 } 132 }
134 } 133 }
135 134
136 // Returns resource identifier that is unique within single task manager 135 // Returns resource identifier that is unique within single task manager
137 // session (between StartUpdating and StopUpdating). 136 // session (between StartUpdating and StopUpdating).
138 int get_unique_id() { return unique_id_; } 137 int get_unique_id() { return unique_id_; }
138
139 protected: 139 protected:
140 Resource() : unique_id_(0) {} 140 Resource() : unique_id_(0) {}
141 141
142 private: 142 private:
143 friend class TaskManagerModel; 143 friend class TaskManagerModel;
144 int unique_id_; 144 int unique_id_;
145 }; 145 };
146 146
147 // ResourceProviders are responsible for adding/removing resources to the task 147 // ResourceProviders are responsible for adding/removing resources to the task
148 // manager. The task manager notifies the ResourceProvider that it is ready 148 // manager. The task manager notifies the ResourceProvider that it is ready
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 256
257 // Invoked when the initialization of the model has been finished and 257 // Invoked when the initialization of the model has been finished and
258 // periodical updates is started. The first periodical update will be done 258 // periodical updates is started. The first periodical update will be done
259 // in a few seconds. (depending on platform) 259 // in a few seconds. (depending on platform)
260 virtual void OnReadyPeriodicalUpdate() {} 260 virtual void OnReadyPeriodicalUpdate() {}
261 }; 261 };
262 262
263 // The model that the TaskManager is using. 263 // The model that the TaskManager is using.
264 class TaskManagerModel : public base::RefCountedThreadSafe<TaskManagerModel> { 264 class TaskManagerModel : public base::RefCountedThreadSafe<TaskManagerModel> {
265 public: 265 public:
266 // (start, length)
267 typedef std::pair<int, int> GroupRange;
268
266 explicit TaskManagerModel(TaskManager* task_manager); 269 explicit TaskManagerModel(TaskManager* task_manager);
267 270
268 void AddObserver(TaskManagerModelObserver* observer); 271 void AddObserver(TaskManagerModelObserver* observer);
269 void RemoveObserver(TaskManagerModelObserver* observer); 272 void RemoveObserver(TaskManagerModelObserver* observer);
270 273
271 // Returns number of registered resources. 274 // Returns number of registered resources.
272 int ResourceCount() const; 275 int ResourceCount() const;
273 // Returns number of registered groups. 276 // Returns number of registered groups.
274 int GroupCount() const; 277 int GroupCount() const;
275 278
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 bool IsResourceFirstInGroup(int index) const; 351 bool IsResourceFirstInGroup(int index) const;
349 bool IsResourceLastInGroup(int index) const; 352 bool IsResourceLastInGroup(int index) const;
350 353
351 // Returns true if the resource runs in the background (not visible to the 354 // Returns true if the resource runs in the background (not visible to the
352 // user, e.g. extension background pages and BackgroundContents). 355 // user, e.g. extension background pages and BackgroundContents).
353 bool IsBackgroundResource(int index) const; 356 bool IsBackgroundResource(int index) const;
354 357
355 // Returns icon to be used for resource (for example a favicon). 358 // Returns icon to be used for resource (for example a favicon).
356 SkBitmap GetResourceIcon(int index) const; 359 SkBitmap GetResourceIcon(int index) const;
357 360
358 // Returns a pair (start, length) of the group range of resource. 361 // Returns the group range of resource.
359 std::pair<int, int> GetGroupRangeForResource(int index) const; 362 GroupRange GetGroupRangeForResource(int index) const;
360 363
361 // Returns an index of groups to which the resource belongs. 364 // Returns an index of groups to which the resource belongs.
362 int GetGroupIndexForResource(int index) const; 365 int GetGroupIndexForResource(int index) const;
363 366
364 // Returns an index of resource which belongs to the |group_index|th group 367 // Returns an index of resource which belongs to the |group_index|th group
365 // and which is the |index_in_group|th resource in group. 368 // and which is the |index_in_group|th resource in group.
366 int GetResourceIndexForGroup(int group_index, int index_in_group) const; 369 int GetResourceIndexForGroup(int group_index, int index_in_group) const;
367 370
368 // Compares values in column |col_id| and rows |row1|, |row2|. 371 // Compares values in column |col_id| and rows |row1|, |row2|.
369 // Returns -1 if value in |row1| is less than value in |row2|, 372 // Returns -1 if value in |row1| is less than value in |row2|,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 int byte_count; 446 int byte_count;
444 }; 447 };
445 448
446 typedef std::vector<TaskManager::Resource*> ResourceList; 449 typedef std::vector<TaskManager::Resource*> ResourceList;
447 typedef std::vector<scoped_refptr<TaskManager::ResourceProvider> > 450 typedef std::vector<scoped_refptr<TaskManager::ResourceProvider> >
448 ResourceProviderList; 451 ResourceProviderList;
449 typedef std::map<base::ProcessHandle, ResourceList*> GroupMap; 452 typedef std::map<base::ProcessHandle, ResourceList*> GroupMap;
450 typedef std::map<base::ProcessHandle, base::ProcessMetrics*> MetricsMap; 453 typedef std::map<base::ProcessHandle, base::ProcessMetrics*> MetricsMap;
451 typedef std::map<base::ProcessHandle, double> CPUUsageMap; 454 typedef std::map<base::ProcessHandle, double> CPUUsageMap;
452 typedef std::map<TaskManager::Resource*, int64> ResourceValueMap; 455 typedef std::map<TaskManager::Resource*, int64> ResourceValueMap;
453 typedef std::map<base::ProcessHandle, 456 // Private memory in bytes, shared memory in bytes.
454 std::pair<size_t, size_t> > MemoryUsageMap; 457 typedef std::pair<size_t, size_t> MemoryUsageEntry;
458 typedef std::map<base::ProcessHandle, MemoryUsageEntry> MemoryUsageMap;
455 459
456 // Updates the values for all rows. 460 // Updates the values for all rows.
457 void Refresh(); 461 void Refresh();
458 462
459 void AddItem(TaskManager::Resource* resource, bool notify_table); 463 void AddItem(TaskManager::Resource* resource, bool notify_table);
460 void RemoveItem(TaskManager::Resource* resource); 464 void RemoveItem(TaskManager::Resource* resource);
461 465
462 // Returns the network usage (in bytes per seconds) for the specified 466 // Returns the network usage (in bytes per seconds) for the specified
463 // resource. That's the value retrieved at the last timer's tick. 467 // resource. That's the value retrieved at the last timer's tick.
464 int64 GetNetworkUsageForResource(TaskManager::Resource* resource) const; 468 int64 GetNetworkUsageForResource(TaskManager::Resource* resource) const;
(...skipping 15 matching lines...) Expand all
480 bool GetProcessMetricsForRow(int row, 484 bool GetProcessMetricsForRow(int row,
481 base::ProcessMetrics** proc_metrics) const; 485 base::ProcessMetrics** proc_metrics) const;
482 486
483 // Given a number, this function returns the formatted string that should be 487 // Given a number, this function returns the formatted string that should be
484 // displayed in the task manager's memory cell. 488 // displayed in the task manager's memory cell.
485 string16 GetMemCellText(int64 number) const; 489 string16 GetMemCellText(int64 number) const;
486 490
487 // Looks up the data for |handle| and puts it in the mutable cache 491 // Looks up the data for |handle| and puts it in the mutable cache
488 // |memory_usage_map_|. 492 // |memory_usage_map_|.
489 bool GetAndCacheMemoryMetrics(base::ProcessHandle handle, 493 bool GetAndCacheMemoryMetrics(base::ProcessHandle handle,
490 std::pair<size_t, size_t>* usage) const; 494 MemoryUsageEntry* usage) const;
491 495
492 // Adds a resource provider to be managed. 496 // Adds a resource provider to be managed.
493 void AddResourceProvider(TaskManager::ResourceProvider* provider); 497 void AddResourceProvider(TaskManager::ResourceProvider* provider);
494 498
495 // The list of providers to the task manager. They are ref counted. 499 // The list of providers to the task manager. They are ref counted.
496 ResourceProviderList providers_; 500 ResourceProviderList providers_;
497 501
498 // The list of all the resources displayed in the task manager. They are owned 502 // The list of all the resources displayed in the task manager. They are owned
499 // by the ResourceProviders. 503 // by the ResourceProviders.
500 ResourceList resources_; 504 ResourceList resources_;
(...skipping 28 matching lines...) Expand all
529 ObserverList<TaskManagerModelObserver> observer_list_; 533 ObserverList<TaskManagerModelObserver> observer_list_;
530 534
531 // How many calls to StartUpdating have been made without matching calls to 535 // How many calls to StartUpdating have been made without matching calls to
532 // StopUpdating. 536 // StopUpdating.
533 int update_requests_; 537 int update_requests_;
534 538
535 // Whether we are currently in the process of updating. 539 // Whether we are currently in the process of updating.
536 UpdateState update_state_; 540 UpdateState update_state_;
537 541
538 // A salt lick for the goats. 542 // A salt lick for the goats.
539 int goat_salt_; 543 uint64 goat_salt_;
540 544
541 // Resource identifier that is unique within single session. 545 // Resource identifier that is unique within single session.
542 int last_unique_id_; 546 int last_unique_id_;
543 547
544 DISALLOW_COPY_AND_ASSIGN(TaskManagerModel); 548 DISALLOW_COPY_AND_ASSIGN(TaskManagerModel);
545 }; 549 };
546 550
547 #endif // CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_H_ 551 #endif // CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/task_manager/task_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698