license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | bfac5ac | 2008-10-09 17:55:38 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_TASK_MANAGER_H_ |
| 6 | #define CHROME_BROWSER_TASK_MANAGER_H_ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 7 | |
[email protected] | b7937d5b | 2008-09-10 22:12:19 | [diff] [blame] | 8 | #include <map> |
[email protected] | bfac5ac | 2008-10-09 17:55:38 | [diff] [blame] | 9 | #include <string> |
[email protected] | 0860b9b9 | 2009-05-11 18:49:18 | [diff] [blame] | 10 | #include <utility> |
[email protected] | b7937d5b | 2008-09-10 22:12:19 | [diff] [blame] | 11 | #include <vector> |
| 12 | |
[email protected] | 5d438dbad | 2009-04-30 08:59:39 | [diff] [blame] | 13 | #include "base/basictypes.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 14 | #include "base/lock.h" |
[email protected] | a754453c | 2009-07-15 20:32:51 | [diff] [blame] | 15 | #include "base/observer_list.h" |
[email protected] | 5d438dbad | 2009-04-30 08:59:39 | [diff] [blame] | 16 | #include "base/process_util.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 17 | #include "base/ref_counted.h" |
[email protected] | 5d438dbad | 2009-04-30 08:59:39 | [diff] [blame] | 18 | #include "base/singleton.h" |
[email protected] | 2d31666 | 2008-09-03 18:18:14 | [diff] [blame] | 19 | #include "base/timer.h" |
[email protected] | 2c434b3 | 2009-03-19 06:27:47 | [diff] [blame] | 20 | #include "chrome/browser/renderer_host/web_cache_manager.h" |
[email protected] | f3ec774 | 2009-01-15 00:59:16 | [diff] [blame] | 21 | #include "chrome/browser/tab_contents/tab_contents.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 22 | #include "net/url_request/url_request_job_tracker.h" |
[email protected] | 1222cce | 2009-04-27 06:58:27 | [diff] [blame] | 23 | #include "testing/gtest/include/gtest/gtest_prod.h" |
[email protected] | ec977368 | 2009-09-25 17:59:03 | [diff] [blame] | 24 | #include "webkit/api/public/WebCache.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 25 | |
[email protected] | e172584 | 2009-10-20 06:40:15 | [diff] [blame] | 26 | class Extension; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 27 | class SkBitmap; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 28 | class TaskManager; |
[email protected] | 0860b9b9 | 2009-05-11 18:49:18 | [diff] [blame] | 29 | class TaskManagerModel; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 30 | |
| 31 | struct BytesReadParam; |
| 32 | |
[email protected] | 176aa48 | 2008-11-14 03:25:15 | [diff] [blame] | 33 | namespace base { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 34 | class ProcessMetrics; |
| 35 | } |
| 36 | |
| 37 | // This class is a singleton. |
[email protected] | f9fdb07 | 2009-05-06 07:27:40 | [diff] [blame] | 38 | class TaskManager { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 39 | public: |
| 40 | // A resource represents one row in the task manager. |
| 41 | // Resources from similar processes are grouped together by the task manager. |
| 42 | class Resource { |
| 43 | public: |
[email protected] | b7937d5b | 2008-09-10 22:12:19 | [diff] [blame] | 44 | virtual ~Resource() {} |
| 45 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 46 | virtual std::wstring GetTitle() const = 0; |
| 47 | virtual SkBitmap GetIcon() const = 0; |
[email protected] | 5d438dbad | 2009-04-30 08:59:39 | [diff] [blame] | 48 | virtual base::ProcessHandle GetProcess() const = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 49 | |
[email protected] | 149fd6df | 2009-09-30 18:28:44 | [diff] [blame] | 50 | virtual bool ReportsCacheStats() const { return false; } |
| 51 | virtual WebKit::WebCache::ResourceTypeStats GetWebCoreCacheStats() const { |
| 52 | return WebKit::WebCache::ResourceTypeStats(); |
| 53 | } |
[email protected] | ec977368 | 2009-09-25 17:59:03 | [diff] [blame] | 54 | |
[email protected] | f545106 | 2009-10-15 20:37:24 | [diff] [blame] | 55 | virtual bool ReportsSqliteMemoryUsed() const { return false; } |
| 56 | virtual size_t SqliteMemoryUsedBytes() const { return 0; } |
| 57 | |
[email protected] | e172584 | 2009-10-20 06:40:15 | [diff] [blame] | 58 | // Return extension associated with the resource, or NULL |
| 59 | // if not applicable. |
| 60 | virtual const Extension* GetExtension() const { return NULL; } |
| 61 | |
[email protected] | 38b48a8 | 2009-11-11 01:51:32 | [diff] [blame^] | 62 | virtual bool ReportsV8MemoryStats() const { return false; } |
| 63 | virtual size_t GetV8MemoryAllocated() const { return 0; } |
| 64 | virtual size_t GetV8MemoryUsed() const { return 0; } |
| 65 | |
[email protected] | b7937d5b | 2008-09-10 22:12:19 | [diff] [blame] | 66 | // A helper function for ActivateFocusedTab. Returns NULL by default |
[email protected] | e172584 | 2009-10-20 06:40:15 | [diff] [blame] | 67 | // because not all resources have an associated tab. |
[email protected] | 149fd6df | 2009-09-30 18:28:44 | [diff] [blame] | 68 | virtual TabContents* GetTabContents() const { return NULL; } |
[email protected] | b7937d5b | 2008-09-10 22:12:19 | [diff] [blame] | 69 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 70 | // Whether this resource does report the network usage accurately. |
| 71 | // This controls whether 0 or N/A is displayed when no bytes have been |
| 72 | // reported as being read. This is because some plugins do not report the |
| 73 | // bytes read and we don't want to display a misleading 0 value in that |
| 74 | // case. |
| 75 | virtual bool SupportNetworkUsage() const = 0; |
| 76 | |
| 77 | // Called when some bytes have been read and support_network_usage returns |
[email protected] | bfac5ac | 2008-10-09 17:55:38 | [diff] [blame] | 78 | // false (meaning we do have network usage support). |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 79 | virtual void SetSupportNetworkUsage() = 0; |
[email protected] | ec977368 | 2009-09-25 17:59:03 | [diff] [blame] | 80 | |
[email protected] | d277d43 | 2009-10-13 17:27:01 | [diff] [blame] | 81 | // The TaskManagerModel periodically refreshes its data and call this |
| 82 | // on all live resources. |
| 83 | virtual void Refresh() {} |
| 84 | |
[email protected] | ec977368 | 2009-09-25 17:59:03 | [diff] [blame] | 85 | virtual void NotifyResourceTypeStats( |
| 86 | const WebKit::WebCache::ResourceTypeStats& stats) {} |
[email protected] | 38b48a8 | 2009-11-11 01:51:32 | [diff] [blame^] | 87 | virtual void NotifyV8HeapStats(size_t v8_memory_allocated, |
| 88 | size_t v8_memory_used) {} |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | // ResourceProviders are responsible for adding/removing resources to the task |
| 92 | // manager. The task manager notifies the ResourceProvider that it is ready |
| 93 | // to receive resource creation/termination notifications with a call to |
| 94 | // StartUpdating(). At that point, the resource provider should call |
| 95 | // AddResource with all the existing resources, and after that it should call |
| 96 | // AddResource/RemoveResource as resources are created/terminated. |
| 97 | // The provider remains the owner of the resource objects and is responsible |
| 98 | // for deleting them (when StopUpdating() is called). |
| 99 | // After StopUpdating() is called the provider should also stop reporting |
| 100 | // notifications to the task manager. |
| 101 | // Note: ResourceProviders have to be ref counted as they are used in |
| 102 | // MessageLoop::InvokeLater(). |
[email protected] | 4090a28 | 2009-09-29 22:20:49 | [diff] [blame] | 103 | class ResourceProvider : public base::RefCountedThreadSafe<ResourceProvider> { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 104 | public: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 105 | // Should return the resource associated to the specified ids, or NULL if |
| 106 | // the resource does not belong to this provider. |
| 107 | virtual TaskManager::Resource* GetResource(int process_id, |
| 108 | int render_process_host_id, |
| 109 | int routing_id) = 0; |
| 110 | virtual void StartUpdating() = 0; |
| 111 | virtual void StopUpdating() = 0; |
[email protected] | e6e6ba4 | 2009-11-07 01:56:19 | [diff] [blame] | 112 | |
| 113 | protected: |
| 114 | friend class base::RefCountedThreadSafe<ResourceProvider>; |
| 115 | |
| 116 | virtual ~ResourceProvider() {} |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | static void RegisterPrefs(PrefService* prefs); |
| 120 | |
[email protected] | 8f90afd7 | 2009-06-22 22:44:38 | [diff] [blame] | 121 | // Returns true if the process at the specified index is the browser process. |
| 122 | bool IsBrowserProcess(int index) const; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 123 | |
[email protected] | 8f90afd7 | 2009-06-22 22:44:38 | [diff] [blame] | 124 | // Terminates the process at the specified index. |
| 125 | void KillProcess(int index); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 126 | |
[email protected] | 8f90afd7 | 2009-06-22 22:44:38 | [diff] [blame] | 127 | // Activates the browser tab associated with the process in the specified |
| 128 | // index. |
| 129 | void ActivateProcess(int index); |
[email protected] | b7937d5b | 2008-09-10 22:12:19 | [diff] [blame] | 130 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 131 | void AddResourceProvider(ResourceProvider* provider); |
| 132 | void RemoveResourceProvider(ResourceProvider* provider); |
| 133 | |
| 134 | // These methods are invoked by the resource providers to add/remove resources |
| 135 | // to the Task Manager. Note that the resources are owned by the |
| 136 | // ResourceProviders and are not valid after StopUpdating() has been called |
| 137 | // on the ResourceProviders. |
| 138 | void AddResource(Resource* resource); |
| 139 | void RemoveResource(Resource* resource); |
| 140 | |
[email protected] | 9c5e417 | 2009-05-27 08:46:28 | [diff] [blame] | 141 | void OnWindowClosed(); |
| 142 | |
[email protected] | 8f90afd7 | 2009-06-22 22:44:38 | [diff] [blame] | 143 | // Returns the singleton instance (and initializes it if necessary). |
| 144 | static TaskManager* GetInstance(); |
| 145 | |
| 146 | TaskManagerModel* model() const { return model_.get(); } |
| 147 | |
[email protected] | 8f0d1a2 | 2009-10-08 19:55:14 | [diff] [blame] | 148 | void OpenAboutMemory(); |
| 149 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 150 | private: |
[email protected] | 4327e9a | 2009-06-04 22:05:44 | [diff] [blame] | 151 | FRIEND_TEST(TaskManagerTest, Basic); |
| 152 | FRIEND_TEST(TaskManagerTest, Resources); |
[email protected] | d277d43 | 2009-10-13 17:27:01 | [diff] [blame] | 153 | FRIEND_TEST(TaskManagerTest, RefreshCalled); |
[email protected] | 1222cce | 2009-04-27 06:58:27 | [diff] [blame] | 154 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 155 | // Obtain an instance via GetInstance(). |
| 156 | TaskManager(); |
[email protected] | 5d438dbad | 2009-04-30 08:59:39 | [diff] [blame] | 157 | friend struct DefaultSingletonTraits<TaskManager>; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 158 | |
| 159 | ~TaskManager(); |
| 160 | |
[email protected] | 0860b9b9 | 2009-05-11 18:49:18 | [diff] [blame] | 161 | // The model used for gathering and processing task data. It is ref counted |
| 162 | // because it is passed as a parameter to MessageLoop::InvokeLater(). |
| 163 | scoped_refptr<TaskManagerModel> model_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 164 | |
[email protected] | bfac5ac | 2008-10-09 17:55:38 | [diff] [blame] | 165 | DISALLOW_COPY_AND_ASSIGN(TaskManager); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 166 | }; |
| 167 | |
[email protected] | 0860b9b9 | 2009-05-11 18:49:18 | [diff] [blame] | 168 | class TaskManagerModelObserver { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 169 | public: |
[email protected] | 0860b9b9 | 2009-05-11 18:49:18 | [diff] [blame] | 170 | virtual ~TaskManagerModelObserver() {} |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 171 | |
[email protected] | 0860b9b9 | 2009-05-11 18:49:18 | [diff] [blame] | 172 | // Invoked when the model has been completely changed. |
| 173 | virtual void OnModelChanged() = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 174 | |
[email protected] | 0860b9b9 | 2009-05-11 18:49:18 | [diff] [blame] | 175 | // Invoked when a range of items has changed. |
| 176 | virtual void OnItemsChanged(int start, int length) = 0; |
| 177 | |
| 178 | // Invoked when new items are added. |
| 179 | virtual void OnItemsAdded(int start, int length) = 0; |
| 180 | |
| 181 | // Invoked when a range of items has been removed. |
| 182 | virtual void OnItemsRemoved(int start, int length) = 0; |
| 183 | }; |
| 184 | |
| 185 | // The model that the TaskManager is using. |
| 186 | class TaskManagerModel : public URLRequestJobTracker::JobObserver, |
[email protected] | 4090a28 | 2009-09-29 22:20:49 | [diff] [blame] | 187 | public base::RefCountedThreadSafe<TaskManagerModel> { |
[email protected] | 0860b9b9 | 2009-05-11 18:49:18 | [diff] [blame] | 188 | public: |
| 189 | explicit TaskManagerModel(TaskManager* task_manager); |
[email protected] | 0860b9b9 | 2009-05-11 18:49:18 | [diff] [blame] | 190 | |
[email protected] | a754453c | 2009-07-15 20:32:51 | [diff] [blame] | 191 | void AddObserver(TaskManagerModelObserver* observer); |
| 192 | void RemoveObserver(TaskManagerModelObserver* observer); |
[email protected] | 0860b9b9 | 2009-05-11 18:49:18 | [diff] [blame] | 193 | |
| 194 | // Returns number of registered resources. |
| 195 | int ResourceCount() const; |
| 196 | |
| 197 | // Methods to return formatted resource information. |
| 198 | std::wstring GetResourceTitle(int index) const; |
| 199 | std::wstring GetResourceNetworkUsage(int index) const; |
| 200 | std::wstring GetResourceCPUUsage(int index) const; |
| 201 | std::wstring GetResourcePrivateMemory(int index) const; |
| 202 | std::wstring GetResourceSharedMemory(int index) const; |
| 203 | std::wstring GetResourcePhysicalMemory(int index) const; |
| 204 | std::wstring GetResourceProcessId(int index) const; |
| 205 | std::wstring GetResourceStatsValue(int index, int col_id) const; |
[email protected] | ec977368 | 2009-09-25 17:59:03 | [diff] [blame] | 206 | std::wstring GetResourceWebCoreImageCacheSize(int index) const; |
| 207 | std::wstring GetResourceWebCoreScriptsCacheSize(int index) const; |
| 208 | std::wstring GetResourceWebCoreCSSCacheSize(int index) const; |
[email protected] | f545106 | 2009-10-15 20:37:24 | [diff] [blame] | 209 | std::wstring GetResourceSqliteMemoryUsed(int index) const; |
[email protected] | 0860b9b9 | 2009-05-11 18:49:18 | [diff] [blame] | 210 | std::wstring GetResourceGoatsTeleported(int index) const; |
[email protected] | 38b48a8 | 2009-11-11 01:51:32 | [diff] [blame^] | 211 | std::wstring GetResourceV8MemoryAllocatedSize(int index) const; |
[email protected] | 0860b9b9 | 2009-05-11 18:49:18 | [diff] [blame] | 212 | |
| 213 | // Returns true if the resource is first in its group (resources |
| 214 | // rendered by the same process are groupped together). |
| 215 | bool IsResourceFirstInGroup(int index) const; |
| 216 | |
| 217 | // Returns icon to be used for resource (for example a favicon). |
| 218 | SkBitmap GetResourceIcon(int index) const; |
| 219 | |
| 220 | // Returns a pair (start, length) of the group range of resource. |
| 221 | std::pair<int, int> GetGroupRangeForResource(int index) const; |
| 222 | |
| 223 | // Compares values in column |col_id| and rows |row1|, |row2|. |
| 224 | // Returns -1 if value in |row1| is less than value in |row2|, |
| 225 | // 0 if they are equal, and 1 otherwise. |
| 226 | int CompareValues(int row1, int row2, int col_id) const; |
| 227 | |
| 228 | // Returns process handle for given resource. |
| 229 | base::ProcessHandle GetResourceProcessHandle(int index) const; |
| 230 | |
| 231 | // Returns TabContents of given resource or NULL if not applicable. |
| 232 | TabContents* GetResourceTabContents(int index) const; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 233 | |
[email protected] | e172584 | 2009-10-20 06:40:15 | [diff] [blame] | 234 | // Returns Extension of given resource or NULL if not applicable. |
| 235 | const Extension* GetResourceExtension(int index) const; |
| 236 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 237 | // JobObserver methods: |
| 238 | void OnJobAdded(URLRequestJob* job); |
| 239 | void OnJobRemoved(URLRequestJob* job); |
| 240 | void OnJobDone(URLRequestJob* job, const URLRequestStatus& status); |
| 241 | void OnJobRedirect(URLRequestJob* job, const GURL& location, int status_code); |
| 242 | void OnBytesRead(URLRequestJob* job, int byte_count); |
| 243 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 244 | void AddResourceProvider(TaskManager::ResourceProvider* provider); |
| 245 | void RemoveResourceProvider(TaskManager::ResourceProvider* provider); |
| 246 | |
| 247 | void AddResource(TaskManager::Resource* resource); |
| 248 | void RemoveResource(TaskManager::Resource* resource); |
| 249 | |
[email protected] | 0860b9b9 | 2009-05-11 18:49:18 | [diff] [blame] | 250 | void StartUpdating(); |
| 251 | void StopUpdating(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 252 | |
[email protected] | 0860b9b9 | 2009-05-11 18:49:18 | [diff] [blame] | 253 | void Clear(); // Removes all items. |
| 254 | |
[email protected] | ec977368 | 2009-09-25 17:59:03 | [diff] [blame] | 255 | void NotifyResourceTypeStats( |
[email protected] | 38b48a8 | 2009-11-11 01:51:32 | [diff] [blame^] | 256 | base::ProcessId renderer_id, |
[email protected] | ec977368 | 2009-09-25 17:59:03 | [diff] [blame] | 257 | const WebKit::WebCache::ResourceTypeStats& stats); |
| 258 | |
[email protected] | 38b48a8 | 2009-11-11 01:51:32 | [diff] [blame^] | 259 | void NotifyV8HeapStats(base::ProcessId renderer_id, |
| 260 | size_t v8_memory_allocated, |
| 261 | size_t v8_memory_used); |
| 262 | |
[email protected] | 0860b9b9 | 2009-05-11 18:49:18 | [diff] [blame] | 263 | private: |
[email protected] | e6e6ba4 | 2009-11-07 01:56:19 | [diff] [blame] | 264 | friend class base::RefCountedThreadSafe<TaskManagerModel>; |
[email protected] | d277d43 | 2009-10-13 17:27:01 | [diff] [blame] | 265 | FRIEND_TEST(TaskManagerTest, RefreshCalled); |
| 266 | |
[email protected] | e6e6ba4 | 2009-11-07 01:56:19 | [diff] [blame] | 267 | ~TaskManagerModel(); |
| 268 | |
[email protected] | bfac5ac | 2008-10-09 17:55:38 | [diff] [blame] | 269 | enum UpdateState { |
| 270 | IDLE = 0, // Currently not updating. |
| 271 | TASK_PENDING, // An update task is pending. |
| 272 | STOPPING // A update task is pending and it should stop the update. |
| 273 | }; |
| 274 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 275 | // This struct is used to exchange information between the io and ui threads. |
| 276 | struct BytesReadParam { |
[email protected] | 76543b9 | 2009-08-31 17:27:45 | [diff] [blame] | 277 | BytesReadParam(int origin_child_id, |
| 278 | int render_process_host_child_id, |
| 279 | int routing_id, |
| 280 | int byte_count) |
| 281 | : origin_child_id(origin_child_id), |
| 282 | render_process_host_child_id(render_process_host_child_id), |
[email protected] | bfac5ac | 2008-10-09 17:55:38 | [diff] [blame] | 283 | routing_id(routing_id), |
[email protected] | 76543b9 | 2009-08-31 17:27:45 | [diff] [blame] | 284 | byte_count(byte_count) {} |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 285 | |
[email protected] | 76543b9 | 2009-08-31 17:27:45 | [diff] [blame] | 286 | // This is the child ID of the originator of the request. It will often be |
| 287 | // the same as the render_process_host_child_id, but will be different when |
| 288 | // another sub-process like a plugin is routing requests through a renderer. |
| 289 | int origin_child_id; |
| 290 | |
| 291 | // The child ID of the RenderProcessHist this request was routed through. |
| 292 | int render_process_host_child_id; |
| 293 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 294 | int routing_id; |
| 295 | int byte_count; |
| 296 | }; |
| 297 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 298 | typedef std::vector<TaskManager::Resource*> ResourceList; |
| 299 | typedef std::vector<TaskManager::ResourceProvider*> ResourceProviderList; |
[email protected] | 0860b9b9 | 2009-05-11 18:49:18 | [diff] [blame] | 300 | typedef std::map<base::ProcessHandle, ResourceList*> GroupMap; |
| 301 | typedef std::map<base::ProcessHandle, base::ProcessMetrics*> MetricsMap; |
| 302 | typedef std::map<base::ProcessHandle, int> CPUUsageMap; |
| 303 | typedef std::map<TaskManager::Resource*, int64> ResourceValueMap; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 304 | |
[email protected] | bfac5ac | 2008-10-09 17:55:38 | [diff] [blame] | 305 | // Updates the values for all rows. |
| 306 | void Refresh(); |
| 307 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 308 | void AddItem(TaskManager::Resource* resource, bool notify_table); |
| 309 | void RemoveItem(TaskManager::Resource* resource); |
| 310 | |
| 311 | // Register for network usage updates |
| 312 | void RegisterForJobDoneNotifications(); |
| 313 | void UnregisterForJobDoneNotifications(); |
| 314 | |
| 315 | // Returns the network usage (in bytes per seconds) for the specified |
| 316 | // resource. That's the value retrieved at the last timer's tick. |
[email protected] | d043c2cc | 2009-03-25 18:30:45 | [diff] [blame] | 317 | int64 GetNetworkUsageForResource(TaskManager::Resource* resource) const; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 318 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 319 | // Called on the UI thread when some bytes are read. |
| 320 | void BytesRead(BytesReadParam param); |
| 321 | |
[email protected] | bfac5ac | 2008-10-09 17:55:38 | [diff] [blame] | 322 | // Returns the network usage (in byte per second) that should be displayed for |
| 323 | // the passed |resource|. -1 means the information is not available for that |
| 324 | // resource. |
[email protected] | d043c2cc | 2009-03-25 18:30:45 | [diff] [blame] | 325 | int64 GetNetworkUsage(TaskManager::Resource* resource) const; |
[email protected] | bfac5ac | 2008-10-09 17:55:38 | [diff] [blame] | 326 | |
| 327 | // Returns the CPU usage (in %) that should be displayed for the passed |
| 328 | // |resource|. |
[email protected] | d043c2cc | 2009-03-25 18:30:45 | [diff] [blame] | 329 | int GetCPUUsage(TaskManager::Resource* resource) const; |
[email protected] | bfac5ac | 2008-10-09 17:55:38 | [diff] [blame] | 330 | |
[email protected] | 99e9d79 | 2009-10-27 01:30:57 | [diff] [blame] | 331 | // Gets the private memory (in KB) that should be displayed for the passed |
| 332 | // resource index. |
| 333 | bool GetPrivateMemory(int index, size_t* result) const; |
[email protected] | bfac5ac | 2008-10-09 17:55:38 | [diff] [blame] | 334 | |
[email protected] | 99e9d79 | 2009-10-27 01:30:57 | [diff] [blame] | 335 | // Gets the shared memory (in KB) that should be displayed for the passed |
| 336 | // resource index. |
| 337 | bool GetSharedMemory(int index, size_t* result) const; |
[email protected] | bfac5ac | 2008-10-09 17:55:38 | [diff] [blame] | 338 | |
[email protected] | 99e9d79 | 2009-10-27 01:30:57 | [diff] [blame] | 339 | // Gets the physical memory (in KB) that should be displayed for the passed |
| 340 | // resource index. |
| 341 | bool GetPhysicalMemory(int index, size_t* result) const; |
[email protected] | bfac5ac | 2008-10-09 17:55:38 | [diff] [blame] | 342 | |
| 343 | // Returns the stat value at the column |col_id| that should be displayed from |
| 344 | // the passed |process_metrics|. |
[email protected] | d043c2cc | 2009-03-25 18:30:45 | [diff] [blame] | 345 | int GetStatsValue(const TaskManager::Resource* resource, int col_id) const; |
[email protected] | 2a5af8a | 2009-01-23 23:13:05 | [diff] [blame] | 346 | |
[email protected] | 99e9d79 | 2009-10-27 01:30:57 | [diff] [blame] | 347 | // Retrieves the ProcessMetrics for the resources at the specified row. |
| 348 | // Returns true if there was a ProcessMetrics available. |
| 349 | bool GetProcessMetricsForRow(int row, |
| 350 | base::ProcessMetrics** proc_metrics) const; |
[email protected] | bfac5ac | 2008-10-09 17:55:38 | [diff] [blame] | 351 | |
[email protected] | d0767cb54 | 2009-10-08 17:38:30 | [diff] [blame] | 352 | // Given a number, this function returns the formatted string that should be |
| 353 | // displayed in the task manager's memory cell. |
| 354 | std::wstring GetMemCellText(int64 number) const; |
[email protected] | 2a5af8a | 2009-01-23 23:13:05 | [diff] [blame] | 355 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 356 | // The list of providers to the task manager. They are ref counted. |
| 357 | ResourceProviderList providers_; |
| 358 | |
| 359 | // The list of all the resources displayed in the task manager. They are owned |
| 360 | // by the ResourceProviders. |
| 361 | ResourceList resources_; |
| 362 | |
| 363 | // A map to keep tracks of the grouped resources (they are grouped if they |
| 364 | // share the same process). The groups (the Resources vectors) are owned by |
| 365 | // the model (but the actual Resources are owned by the ResourceProviders). |
| 366 | GroupMap group_map_; |
| 367 | |
| 368 | // A map to retrieve the process metrics for a process. The ProcessMetrics are |
| 369 | // owned by the model. |
| 370 | MetricsMap metrics_map_; |
| 371 | |
| 372 | // A map that keeps track of the number of bytes read per process since last |
| 373 | // tick. The Resources are owned by the ResourceProviders. |
| 374 | ResourceValueMap current_byte_count_map_; |
| 375 | |
| 376 | // A map that contains the network usage is displayed in the table, in bytes |
| 377 | // per second. It is computed every time the timer ticks. The Resources are |
| 378 | // owned by the ResourceProviders. |
| 379 | ResourceValueMap displayed_network_usage_map_; |
| 380 | |
[email protected] | bfac5ac | 2008-10-09 17:55:38 | [diff] [blame] | 381 | // A map that contains the CPU usage (in %) for a process since last refresh. |
| 382 | CPUUsageMap cpu_usage_map_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 383 | |
[email protected] | a754453c | 2009-07-15 20:32:51 | [diff] [blame] | 384 | ObserverList<TaskManagerModelObserver> observer_list_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 385 | |
[email protected] | bfac5ac | 2008-10-09 17:55:38 | [diff] [blame] | 386 | // Whether we are currently in the process of updating. |
| 387 | UpdateState update_state_; |
| 388 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 389 | // See design doc at http://go/at-teleporter for more information. |
| 390 | static int goats_teleported_; |
| 391 | |
[email protected] | 0860b9b9 | 2009-05-11 18:49:18 | [diff] [blame] | 392 | DISALLOW_COPY_AND_ASSIGN(TaskManagerModel); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 393 | }; |
| 394 | |
[email protected] | bfac5ac | 2008-10-09 17:55:38 | [diff] [blame] | 395 | #endif // CHROME_BROWSER_TASK_MANAGER_H_ |