blob: eb5dce9859940c60034d064b44368c97d9c70fb7 [file] [log] [blame]
[email protected]82916812012-02-21 04:14:171// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]a5d1e1e2010-09-23 19:34:125#ifndef CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_H_
6#define CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_H_
initial.commit09911bf2008-07-26 23:55:297
[email protected]b7937d5b2008-09-10 22:12:198#include <map>
[email protected]b7937d5b2008-09-10 22:12:199#include <vector>
10
[email protected]5d438dbad2009-04-30 08:59:3911#include "base/basictypes.h"
[email protected]20f5f8a32013-08-20 01:50:5812#include "base/callback_forward.h"
[email protected]a918f872010-06-01 14:30:5113#include "base/gtest_prod_util.h"
[email protected]3b63f8f42011-03-28 01:54:1514#include "base/memory/ref_counted.h"
15#include "base/memory/singleton.h"
[email protected]a754453c2009-07-15 20:32:5116#include "base/observer_list.h"
[email protected]9f0abdb2013-06-10 21:49:3417#include "base/strings/string16.h"
[email protected]cc86ccfe2013-06-28 00:10:5018#include "base/timer/timer.h"
[email protected]b18943a2013-05-23 15:59:1519#include "chrome/browser/task_manager/resource_provider.h"
[email protected]ddeb0e8432012-12-21 07:27:5420#include "chrome/browser/ui/host_desktop.h"
[email protected]fb246af2012-08-18 03:11:4121#include "content/public/common/gpu_memory_stats.h"
[email protected]2255a9332013-06-17 05:12:3122#include "third_party/WebKit/public/web/WebCache.h"
initial.commit09911bf2008-07-26 23:55:2923
[email protected]b1de2c72013-02-06 02:45:4724class PrefRegistrySimple;
[email protected]0860b9b92009-05-11 18:49:1825class TaskManagerModel;
[email protected]2344ca52012-08-22 22:46:0526class TaskManagerModelGpuDataManagerObserver;
initial.commit09911bf2008-07-26 23:55:2927
[email protected]176aa482008-11-14 03:25:1528namespace base {
initial.commit09911bf2008-07-26 23:55:2929class ProcessMetrics;
30}
[email protected]1c321ee2012-05-21 03:02:3431
[email protected]7ed0e8c2012-07-19 23:17:0632namespace content {
33class WebContents;
34}
35
[email protected]1c321ee2012-05-21 03:02:3436namespace extensions {
37class Extension;
38}
39
[email protected]6280b5882012-06-05 21:56:4140namespace gfx {
41class ImageSkia;
42}
43
[email protected]8523ba52011-05-22 19:00:5844namespace net {
45class URLRequest;
46}
initial.commit09911bf2008-07-26 23:55:2947
initial.commit09911bf2008-07-26 23:55:2948// This class is a singleton.
[email protected]f9fdb072009-05-06 07:27:4049class TaskManager {
initial.commit09911bf2008-07-26 23:55:2950 public:
[email protected]b1de2c72013-02-06 02:45:4751 static void RegisterPrefs(PrefRegistrySimple* registry);
initial.commit09911bf2008-07-26 23:55:2952
[email protected]8f90afd72009-06-22 22:44:3853 // Returns true if the process at the specified index is the browser process.
54 bool IsBrowserProcess(int index) const;
initial.commit09911bf2008-07-26 23:55:2955
[email protected]8f90afd72009-06-22 22:44:3856 // Terminates the process at the specified index.
57 void KillProcess(int index);
initial.commit09911bf2008-07-26 23:55:2958
[email protected]8f90afd72009-06-22 22:44:3859 // Activates the browser tab associated with the process in the specified
60 // index.
61 void ActivateProcess(int index);
[email protected]b7937d5b2008-09-10 22:12:1962
initial.commit09911bf2008-07-26 23:55:2963 // These methods are invoked by the resource providers to add/remove resources
64 // to the Task Manager. Note that the resources are owned by the
65 // ResourceProviders and are not valid after StopUpdating() has been called
66 // on the ResourceProviders.
[email protected]b18943a2013-05-23 15:59:1567 void AddResource(task_manager::Resource* resource);
68 void RemoveResource(task_manager::Resource* resource);
initial.commit09911bf2008-07-26 23:55:2969
[email protected]9c5e4172009-05-27 08:46:2870 void OnWindowClosed();
71
[email protected]c43207e2010-11-15 18:09:5272 // Invoked when a change to a resource has occurred that should cause any
73 // observers to completely refresh themselves (for example, the creation of
74 // a background resource in a process). Results in all observers receiving
75 // OnModelChanged() events.
76 void ModelChanged();
77
[email protected]8f90afd72009-06-22 22:44:3878 // Returns the singleton instance (and initializes it if necessary).
79 static TaskManager* GetInstance();
80
81 TaskManagerModel* model() const { return model_.get(); }
82
[email protected]ddeb0e8432012-12-21 07:27:5483 void OpenAboutMemory(chrome::HostDesktopType desktop_type);
[email protected]8f0d1a22009-10-08 19:55:1484
initial.commit09911bf2008-07-26 23:55:2985 private:
[email protected]a918f872010-06-01 14:30:5186 FRIEND_TEST_ALL_PREFIXES(TaskManagerTest, Basic);
87 FRIEND_TEST_ALL_PREFIXES(TaskManagerTest, Resources);
88 FRIEND_TEST_ALL_PREFIXES(TaskManagerTest, RefreshCalled);
[email protected]5ec892c2010-07-29 20:19:4989 FRIEND_TEST_ALL_PREFIXES(TaskManagerWindowControllerTest, Init);
90 FRIEND_TEST_ALL_PREFIXES(TaskManagerWindowControllerTest, Sort);
[email protected]c1b7d8cca2010-08-07 23:07:5891 FRIEND_TEST_ALL_PREFIXES(TaskManagerWindowControllerTest,
92 SelectionAdaptsToSorting);
[email protected]1222cce2009-04-27 06:58:2793
initial.commit09911bf2008-07-26 23:55:2994 // Obtain an instance via GetInstance().
95 TaskManager();
[email protected]5d438dbad2009-04-30 08:59:3996 friend struct DefaultSingletonTraits<TaskManager>;
initial.commit09911bf2008-07-26 23:55:2997
98 ~TaskManager();
99
[email protected]0860b9b92009-05-11 18:49:18100 // The model used for gathering and processing task data. It is ref counted
101 // because it is passed as a parameter to MessageLoop::InvokeLater().
102 scoped_refptr<TaskManagerModel> model_;
initial.commit09911bf2008-07-26 23:55:29103
[email protected]bfac5ac2008-10-09 17:55:38104 DISALLOW_COPY_AND_ASSIGN(TaskManager);
initial.commit09911bf2008-07-26 23:55:29105};
106
[email protected]0860b9b92009-05-11 18:49:18107class TaskManagerModelObserver {
initial.commit09911bf2008-07-26 23:55:29108 public:
[email protected]0860b9b92009-05-11 18:49:18109 virtual ~TaskManagerModelObserver() {}
initial.commit09911bf2008-07-26 23:55:29110
[email protected]0860b9b92009-05-11 18:49:18111 // Invoked when the model has been completely changed.
112 virtual void OnModelChanged() = 0;
initial.commit09911bf2008-07-26 23:55:29113
[email protected]0860b9b92009-05-11 18:49:18114 // Invoked when a range of items has changed.
115 virtual void OnItemsChanged(int start, int length) = 0;
116
117 // Invoked when new items are added.
118 virtual void OnItemsAdded(int start, int length) = 0;
119
120 // Invoked when a range of items has been removed.
121 virtual void OnItemsRemoved(int start, int length) = 0;
[email protected]82916812012-02-21 04:14:17122
[email protected]350584cd2012-05-17 18:18:26123 // Invoked when a range of items is to be immediately removed. It differs
124 // from OnItemsRemoved by the fact that the item is still in the task manager,
125 // so it can be queried for and found.
126 virtual void OnItemsToBeRemoved(int start, int length) {}
127
[email protected]82916812012-02-21 04:14:17128 // Invoked when the initialization of the model has been finished and
129 // periodical updates is started. The first periodical update will be done
130 // in a few seconds. (depending on platform)
131 virtual void OnReadyPeriodicalUpdate() {}
[email protected]0860b9b92009-05-11 18:49:18132};
133
[email protected]b6eaebd72013-01-15 23:04:09134// The model used by TaskManager.
135//
[email protected]b18943a2013-05-23 15:59:15136// TaskManagerModel caches the values from all task_manager::Resources. This is
[email protected]b6eaebd72013-01-15 23:04:09137// done so the UI sees a consistant view of the resources until it is told a
138// value has been updated.
[email protected]8523ba52011-05-22 19:00:58139class TaskManagerModel : public base::RefCountedThreadSafe<TaskManagerModel> {
[email protected]0860b9b92009-05-11 18:49:18140 public:
[email protected]abd81a522012-03-02 16:12:45141 // (start, length)
142 typedef std::pair<int, int> GroupRange;
143
[email protected]0860b9b92009-05-11 18:49:18144 explicit TaskManagerModel(TaskManager* task_manager);
[email protected]0860b9b92009-05-11 18:49:18145
[email protected]a754453c2009-07-15 20:32:51146 void AddObserver(TaskManagerModelObserver* observer);
147 void RemoveObserver(TaskManagerModelObserver* observer);
[email protected]0860b9b92009-05-11 18:49:18148
149 // Returns number of registered resources.
150 int ResourceCount() const;
[email protected]9f5d3e182011-07-11 06:22:29151 // Returns number of registered groups.
152 int GroupCount() const;
[email protected]0860b9b92009-05-11 18:49:18153
[email protected]8a661f82010-10-19 21:47:11154 // Methods to return raw resource information.
[email protected]bb4ee2d2014-01-10 02:12:59155 int GetNaClDebugStubPort(int index) const;
[email protected]8a661f82010-10-19 21:47:11156 int64 GetNetworkUsage(int index) const;
157 double GetCPUUsage(int index) const;
[email protected]ac6d0652014-01-14 00:06:37158 int GetIdleWakeupsPerSecond(int index) const;
[email protected]b6eaebd72013-01-15 23:04:09159 base::ProcessId GetProcessId(int index) const;
[email protected]350584cd2012-05-17 18:18:26160 base::ProcessHandle GetProcess(int index) const;
[email protected]8a661f82010-10-19 21:47:11161
[email protected]36cdba02013-01-12 20:16:40162 // Catchall method that calls off to the appropriate GetResourceXXX method
163 // based on |col_id|. |col_id| is an IDS_ value used to identify the column.
[email protected]0085863a2013-12-06 21:19:03164 base::string16 GetResourceById(int index, int col_id) const;
[email protected]36cdba02013-01-12 20:16:40165
[email protected]0860b9b92009-05-11 18:49:18166 // Methods to return formatted resource information.
[email protected]0085863a2013-12-06 21:19:03167 const base::string16& GetResourceTitle(int index) const;
168 const base::string16& GetResourceProfileName(int index) const;
[email protected]bb4ee2d2014-01-10 02:12:59169 base::string16 GetResourceNaClDebugStubPort(int index) const;
[email protected]0085863a2013-12-06 21:19:03170 base::string16 GetResourceNetworkUsage(int index) const;
171 base::string16 GetResourceCPUUsage(int index) const;
172 base::string16 GetResourcePrivateMemory(int index) const;
173 base::string16 GetResourceSharedMemory(int index) const;
174 base::string16 GetResourcePhysicalMemory(int index) const;
175 base::string16 GetResourceProcessId(int index) const;
176 base::string16 GetResourceGDIHandles(int index) const;
177 base::string16 GetResourceUSERHandles(int index) const;
178 base::string16 GetResourceWebCoreImageCacheSize(int index) const;
179 base::string16 GetResourceWebCoreScriptsCacheSize(int index) const;
180 base::string16 GetResourceWebCoreCSSCacheSize(int index) const;
181 base::string16 GetResourceVideoMemory(int index) const;
[email protected]0085863a2013-12-06 21:19:03182 base::string16 GetResourceSqliteMemoryUsed(int index) const;
[email protected]ac6d0652014-01-14 00:06:37183 base::string16 GetResourceIdleWakeupsPerSecond(int index) const;
[email protected]0085863a2013-12-06 21:19:03184 base::string16 GetResourceV8MemoryAllocatedSize(int index) const;
[email protected]0860b9b92009-05-11 18:49:18185
[email protected]8a661f82010-10-19 21:47:11186 // Gets the private memory (in bytes) that should be displayed for the passed
187 // resource index. Caches the result since this calculation can take time on
188 // some platforms.
189 bool GetPrivateMemory(int index, size_t* result) const;
190
191 // Gets the shared memory (in bytes) that should be displayed for the passed
192 // resource index. Caches the result since this calculation can take time on
193 // some platforms.
194 bool GetSharedMemory(int index, size_t* result) const;
195
196 // Gets the physical memory (in bytes) that should be displayed for the passed
197 // resource index.
198 bool GetPhysicalMemory(int index, size_t* result) const;
199
[email protected]f2937472013-03-18 21:48:34200 // On Windows, get the current and peak number of GDI handles in use.
201 void GetGDIHandles(int index, size_t* current, size_t* peak) const;
202
203 // On Windows, get the current and peak number of USER handles in use.
204 void GetUSERHandles(int index, size_t* current, size_t* peak) const;
205
[email protected]5d8c0b92011-07-21 07:53:32206 // Gets the statuses of webkit. Return false if the resource for the given row
207 // isn't a renderer.
208 bool GetWebCoreCacheStats(int index,
[email protected]a1221aea2013-11-07 01:31:30209 blink::WebCache::ResourceTypeStats* result) const;
[email protected]5d8c0b92011-07-21 07:53:32210
[email protected]fb246af2012-08-18 03:11:41211 // Gets the GPU memory allocated of the given page.
212 bool GetVideoMemory(int index,
213 size_t* video_memory,
214 bool* has_duplicates) const;
215
[email protected]5d8c0b92011-07-21 07:53:32216 // Gets the sqlite memory (in byte). Return false if the resource for the
217 // given row doesn't report information.
218 bool GetSqliteMemoryUsedBytes(int index, size_t* result) const;
219
[email protected]8a661f82010-10-19 21:47:11220 // Gets the amount of memory allocated for javascript. Returns false if the
221 // resource for the given row isn't a renderer.
222 bool GetV8Memory(int index, size_t* result) const;
223
[email protected]350584cd2012-05-17 18:18:26224 // Gets the amount of memory used for javascript. Returns false if the
225 // resource for the given row isn't a renderer.
226 bool GetV8MemoryUsed(int index, size_t* result) const;
227
[email protected]374bf592011-11-10 15:42:18228 // Returns true if resource for the given row can be activated.
229 bool CanActivate(int index) const;
230
[email protected]9f5d3e182011-07-11 06:22:29231 // Returns true if the resource is first/last in its group (resources
[email protected]0860b9b92009-05-11 18:49:18232 // rendered by the same process are groupped together).
233 bool IsResourceFirstInGroup(int index) const;
[email protected]9f5d3e182011-07-11 06:22:29234 bool IsResourceLastInGroup(int index) const;
[email protected]0860b9b92009-05-11 18:49:18235
[email protected]0860b9b92009-05-11 18:49:18236 // Returns icon to be used for resource (for example a favicon).
[email protected]6280b5882012-06-05 21:56:41237 gfx::ImageSkia GetResourceIcon(int index) const;
[email protected]0860b9b92009-05-11 18:49:18238
[email protected]abd81a522012-03-02 16:12:45239 // Returns the group range of resource.
240 GroupRange GetGroupRangeForResource(int index) const;
[email protected]0860b9b92009-05-11 18:49:18241
[email protected]9f5d3e182011-07-11 06:22:29242 // Returns an index of groups to which the resource belongs.
243 int GetGroupIndexForResource(int index) const;
244
245 // Returns an index of resource which belongs to the |group_index|th group
246 // and which is the |index_in_group|th resource in group.
247 int GetResourceIndexForGroup(int group_index, int index_in_group) const;
248
[email protected]0860b9b92009-05-11 18:49:18249 // Compares values in column |col_id| and rows |row1|, |row2|.
250 // Returns -1 if value in |row1| is less than value in |row2|,
251 // 0 if they are equal, and 1 otherwise.
252 int CompareValues(int row1, int row2, int col_id) const;
253
[email protected]6bfb6e702012-04-05 17:18:22254 // Returns the unique child process ID generated by Chromium, not the OS
255 // process id. This is used to identify processes internally and for
256 // extensions. It is not meant to be displayed to the user.
257 int GetUniqueChildProcessId(int index) const;
258
[email protected]8a661f82010-10-19 21:47:11259 // Returns the type of the given resource.
[email protected]b18943a2013-05-23 15:59:15260 task_manager::Resource::Type GetResourceType(int index) const;
[email protected]8a661f82010-10-19 21:47:11261
[email protected]7ed0e8c2012-07-19 23:17:06262 // Returns WebContents of given resource or NULL if not applicable.
263 content::WebContents* GetResourceWebContents(int index) const;
initial.commit09911bf2008-07-26 23:55:29264
[email protected]b18943a2013-05-23 15:59:15265 void AddResource(task_manager::Resource* resource);
266 void RemoveResource(task_manager::Resource* resource);
initial.commit09911bf2008-07-26 23:55:29267
[email protected]0860b9b92009-05-11 18:49:18268 void StartUpdating();
269 void StopUpdating();
initial.commit09911bf2008-07-26 23:55:29270
[email protected]350584cd2012-05-17 18:18:26271 // Listening involves calling StartUpdating on all resource providers. This
272 // causes all of them to subscribe to notifications and enumerate current
273 // resources. It differs from StartUpdating that it doesn't start the
274 // Refresh timer. The end result is that we have a full view of resources, but
275 // don't spend unneeded time updating, unless we have a real need to.
276 void StartListening();
277 void StopListening();
278
[email protected]0860b9b92009-05-11 18:49:18279 void Clear(); // Removes all items.
280
[email protected]c43207e2010-11-15 18:09:52281 // Sends OnModelChanged() to all observers to inform them of significant
282 // changes to the model.
283 void ModelChanged();
284
[email protected]156402ab2013-09-04 21:12:31285 // Updates the values for all rows.
286 void Refresh();
287
[email protected]ec9773682009-09-25 17:59:03288 void NotifyResourceTypeStats(
[email protected]38b48a82009-11-11 01:51:32289 base::ProcessId renderer_id,
[email protected]a1221aea2013-11-07 01:31:30290 const blink::WebCache::ResourceTypeStats& stats);
[email protected]ec9773682009-09-25 17:59:03291
[email protected]fb246af2012-08-18 03:11:41292 void NotifyVideoMemoryUsageStats(
293 const content::GPUVideoMemoryUsageStats& video_memory_usage_stats);
294
[email protected]38b48a82009-11-11 01:51:32295 void NotifyV8HeapStats(base::ProcessId renderer_id,
296 size_t v8_memory_allocated,
297 size_t v8_memory_used);
298
[email protected]8523ba52011-05-22 19:00:58299 void NotifyBytesRead(const net::URLRequest& request, int bytes_read);
300
[email protected]20f5f8a32013-08-20 01:50:58301 void RegisterOnDataReadyCallback(const base::Closure& callback);
302
303 void NotifyDataReady();
304
[email protected]0860b9b92009-05-11 18:49:18305 private:
[email protected]e6e6ba42009-11-07 01:56:19306 friend class base::RefCountedThreadSafe<TaskManagerModel>;
[email protected]5b931c82014-03-05 19:44:38307 friend class TaskManagerBrowserTest;
[email protected]8a661f82010-10-19 21:47:11308 FRIEND_TEST_ALL_PREFIXES(ExtensionApiTest, ProcessesVsTaskManager);
[email protected]b6eaebd72013-01-15 23:04:09309 FRIEND_TEST_ALL_PREFIXES(TaskManagerTest, RefreshCalled);
310 FRIEND_TEST_ALL_PREFIXES(TaskManagerWindowControllerTest,
311 SelectionAdaptsToSorting);
[email protected]e6e6ba42009-11-07 01:56:19312
[email protected]bfac5ac2008-10-09 17:55:38313 enum UpdateState {
314 IDLE = 0, // Currently not updating.
315 TASK_PENDING, // An update task is pending.
316 STOPPING // A update task is pending and it should stop the update.
317 };
318
[email protected]a9bd323d2013-06-17 20:27:56319 // The delay between updates of the information (in ms).
320#if defined(OS_MACOSX)
321 // Match Activity Monitor's default refresh rate.
322 static const int kUpdateTimeMs = 2000;
323#else
324 static const int kUpdateTimeMs = 1000;
325#endif
326
[email protected]b6eaebd72013-01-15 23:04:09327 // Values cached per resource. Values are validated on demand. The is_XXX
328 // members indicate if a value is valid.
329 struct PerResourceValues {
330 PerResourceValues();
331 ~PerResourceValues();
332
[email protected]b6eaebd72013-01-15 23:04:09333 bool is_title_valid;
[email protected]0085863a2013-12-06 21:19:03334 base::string16 title;
[email protected]b6eaebd72013-01-15 23:04:09335
336 bool is_profile_name_valid;
[email protected]0085863a2013-12-06 21:19:03337 base::string16 profile_name;
[email protected]b6eaebd72013-01-15 23:04:09338
339 // No is_network_usage since default (0) is fine.
340 int64 network_usage;
341
342 bool is_process_id_valid;
343 base::ProcessId process_id;
344
[email protected]b6eaebd72013-01-15 23:04:09345 bool is_webcore_stats_valid;
[email protected]a1221aea2013-11-07 01:31:30346 blink::WebCache::ResourceTypeStats webcore_stats;
[email protected]b6eaebd72013-01-15 23:04:09347
[email protected]b6eaebd72013-01-15 23:04:09348 bool is_sqlite_memory_bytes_valid;
349 size_t sqlite_memory_bytes;
350
351 bool is_v8_memory_valid;
352 size_t v8_memory_allocated;
353 size_t v8_memory_used;
354 };
355
356 // Values cached per process. Values are validated on demand. The is_XXX
357 // members indicate if a value is valid.
358 struct PerProcessValues {
359 PerProcessValues();
360 ~PerProcessValues();
361
362 bool is_cpu_usage_valid;
363 double cpu_usage;
364
[email protected]ac6d0652014-01-14 00:06:37365 bool is_idle_wakeups_valid;
366 int idle_wakeups;
367
[email protected]b6eaebd72013-01-15 23:04:09368 bool is_private_and_shared_valid;
369 size_t private_bytes;
370 size_t shared_bytes;
371
372 bool is_physical_memory_valid;
373 size_t physical_memory;
374
375 bool is_video_memory_valid;
376 size_t video_memory;
377 bool video_memory_has_duplicates;
[email protected]f2937472013-03-18 21:48:34378
379 bool is_gdi_handles_valid;
380 size_t gdi_handles;
381 size_t gdi_handles_peak;
382
383 bool is_user_handles_valid;
384 size_t user_handles;
385 size_t user_handles_peak;
[email protected]0c94bdf2014-05-17 01:03:21386
387 bool is_nacl_debug_stub_port_valid;
388 int nacl_debug_stub_port;
[email protected]b6eaebd72013-01-15 23:04:09389 };
390
[email protected]b18943a2013-05-23 15:59:15391 typedef std::vector<task_manager::Resource*> ResourceList;
392 typedef std::vector<scoped_refptr<task_manager::ResourceProvider> >
[email protected]b6eaebd72013-01-15 23:04:09393 ResourceProviderList;
[email protected]7ceb3dc2014-05-19 14:12:22394 typedef std::map<base::ProcessHandle, ResourceList> GroupMap;
[email protected]b6eaebd72013-01-15 23:04:09395 typedef std::map<base::ProcessHandle, base::ProcessMetrics*> MetricsMap;
[email protected]b18943a2013-05-23 15:59:15396 typedef std::map<task_manager::Resource*, int64> ResourceValueMap;
397 typedef std::map<task_manager::Resource*,
[email protected]b6eaebd72013-01-15 23:04:09398 PerResourceValues> PerResourceCache;
399 typedef std::map<base::ProcessHandle, PerProcessValues> PerProcessCache;
400
initial.commit09911bf2008-07-26 23:55:29401 // This struct is used to exchange information between the io and ui threads.
402 struct BytesReadParam {
[email protected]cdf682e2011-02-05 05:11:28403 BytesReadParam(int origin_pid,
[email protected]3b490c82014-01-03 00:17:47404 int child_id,
405 int route_id,
[email protected]76543b92009-08-31 17:27:45406 int byte_count)
[email protected]cdf682e2011-02-05 05:11:28407 : origin_pid(origin_pid),
[email protected]3b490c82014-01-03 00:17:47408 child_id(child_id),
409 route_id(route_id),
[email protected]76543b92009-08-31 17:27:45410 byte_count(byte_count) {}
initial.commit09911bf2008-07-26 23:55:29411
[email protected]cdf682e2011-02-05 05:11:28412 // The process ID that triggered the request. For plugin requests this
413 // will differ from the renderer process ID.
414 int origin_pid;
[email protected]76543b92009-08-31 17:27:45415
[email protected]3b490c82014-01-03 00:17:47416 // The child ID of the process this request was routed through.
417 int child_id;
[email protected]76543b92009-08-31 17:27:45418
[email protected]3b490c82014-01-03 00:17:47419 int route_id;
initial.commit09911bf2008-07-26 23:55:29420 int byte_count;
421 };
422
[email protected]b6eaebd72013-01-15 23:04:09423 ~TaskManagerModel();
initial.commit09911bf2008-07-26 23:55:29424
[email protected]b6eaebd72013-01-15 23:04:09425 // Callback from the timer to refresh. Invokes Refresh() as appropriate.
426 void RefreshCallback();
427
[email protected]fb246af2012-08-18 03:11:41428 void RefreshVideoMemoryUsageStats();
429
initial.commit09911bf2008-07-26 23:55:29430 // Returns the network usage (in bytes per seconds) for the specified
431 // resource. That's the value retrieved at the last timer's tick.
[email protected]b18943a2013-05-23 15:59:15432 int64 GetNetworkUsageForResource(task_manager::Resource* resource) const;
initial.commit09911bf2008-07-26 23:55:29433
initial.commit09911bf2008-07-26 23:55:29434 // Called on the UI thread when some bytes are read.
435 void BytesRead(BytesReadParam param);
436
[email protected]f173d152012-10-17 21:02:41437 void MultipleBytesRead(const std::vector<BytesReadParam>* params);
438
439 // Notifies the UI thread about all the bytes read. Allows for coalescing
440 // multiple bytes read into a single task for the UI thread. This is important
441 // for when downloading a lot of data on the IO thread, since posting a Task
442 // for each one is expensive.
443 void NotifyMultipleBytesRead();
444
tonygd2ba7bc2014-09-08 23:37:10445 // Called on the IO thread to start/stop updating byte counts.
446 void SetUpdatingByteCount(bool is_updating);
447
[email protected]bfac5ac2008-10-09 17:55:38448 // Returns the network usage (in byte per second) that should be displayed for
449 // the passed |resource|. -1 means the information is not available for that
450 // resource.
[email protected]b18943a2013-05-23 15:59:15451 int64 GetNetworkUsage(task_manager::Resource* resource) const;
[email protected]bfac5ac2008-10-09 17:55:38452
453 // Returns the CPU usage (in %) that should be displayed for the passed
454 // |resource|.
[email protected]b18943a2013-05-23 15:59:15455 double GetCPUUsage(task_manager::Resource* resource) const;
[email protected]bfac5ac2008-10-09 17:55:38456
[email protected]ac6d0652014-01-14 00:06:37457 // Returns the idle wakeups that should be displayed for the passed
458 // |resource|.
459 int GetIdleWakeupsPerSecond(task_manager::Resource* resource) const;
460
[email protected]d0767cb542009-10-08 17:38:30461 // Given a number, this function returns the formatted string that should be
462 // displayed in the task manager's memory cell.
[email protected]0085863a2013-12-06 21:19:03463 base::string16 GetMemCellText(int64 number) const;
[email protected]2a5af8a2009-01-23 23:13:05464
[email protected]b6eaebd72013-01-15 23:04:09465 // Verifies the private and shared memory for |handle| is valid in
466 // |per_process_cache_|. Returns true if the data in |per_process_cache_| is
467 // valid.
468 bool CachePrivateAndSharedMemory(base::ProcessHandle handle) const;
469
470 // Verifies |webcore_stats| in |per_resource_cache_|, returning true on
471 // success.
472 bool CacheWebCoreStats(int index) const;
473
474 // Verifies |v8_memory_allocated| and |v8_memory_used| in
475 // |per_resource_cache_|. Returns true if valid, false if not valid.
476 bool CacheV8Memory(int index) const;
[email protected]98947a02010-05-11 17:46:08477
[email protected]0f4ffe842011-03-30 18:59:46478 // Adds a resource provider to be managed.
[email protected]b18943a2013-05-23 15:59:15479 void AddResourceProvider(task_manager::ResourceProvider* provider);
[email protected]0f4ffe842011-03-30 18:59:46480
[email protected]b6eaebd72013-01-15 23:04:09481 // Returns the PerResourceValues for the specified index.
482 PerResourceValues& GetPerResourceValues(int index) const;
483
484 // Returns the Resource for the specified index.
[email protected]b18943a2013-05-23 15:59:15485 task_manager::Resource* GetResource(int index) const;
[email protected]b6eaebd72013-01-15 23:04:09486
initial.commit09911bf2008-07-26 23:55:29487 // The list of providers to the task manager. They are ref counted.
488 ResourceProviderList providers_;
489
490 // The list of all the resources displayed in the task manager. They are owned
491 // by the ResourceProviders.
492 ResourceList resources_;
493
494 // A map to keep tracks of the grouped resources (they are grouped if they
495 // share the same process). The groups (the Resources vectors) are owned by
496 // the model (but the actual Resources are owned by the ResourceProviders).
497 GroupMap group_map_;
498
499 // A map to retrieve the process metrics for a process. The ProcessMetrics are
500 // owned by the model.
501 MetricsMap metrics_map_;
502
503 // A map that keeps track of the number of bytes read per process since last
504 // tick. The Resources are owned by the ResourceProviders.
505 ResourceValueMap current_byte_count_map_;
506
[email protected]fb246af2012-08-18 03:11:41507 // A map that contains the video memory usage for a process
508 content::GPUVideoMemoryUsageStats video_memory_usage_stats_;
[email protected]b6eaebd72013-01-15 23:04:09509
510 // Set to true when we've requested video stats and false once we get them.
[email protected]fb246af2012-08-18 03:11:41511 bool pending_video_memory_usage_stats_update_;
512
[email protected]2344ca52012-08-22 22:46:05513 // An observer waiting for video memory usage stats updates from the GPU
514 // process
515 scoped_ptr<TaskManagerModelGpuDataManagerObserver>
516 video_memory_usage_stats_observer_;
517
[email protected]a754453c2009-07-15 20:32:51518 ObserverList<TaskManagerModelObserver> observer_list_;
initial.commit09911bf2008-07-26 23:55:29519
[email protected]8a661f82010-10-19 21:47:11520 // How many calls to StartUpdating have been made without matching calls to
521 // StopUpdating.
522 int update_requests_;
523
[email protected]350584cd2012-05-17 18:18:26524 // How many calls to StartListening have been made without matching calls to
525 // StopListening.
526 int listen_requests_;
527
[email protected]bfac5ac2008-10-09 17:55:38528 // Whether we are currently in the process of updating.
529 UpdateState update_state_;
530
tonygd2ba7bc2014-09-08 23:37:10531 // Whether the IO thread is currently in the process of updating; accessed
532 // only on the IO thread.
533 bool is_updating_byte_count_;
534
[email protected]f173d152012-10-17 21:02:41535 // Buffer for coalescing BytesReadParam so we don't have to post a task on
536 // each NotifyBytesRead() call.
537 std::vector<BytesReadParam> bytes_read_buffer_;
538
[email protected]20f5f8a32013-08-20 01:50:58539 std::vector<base::Closure> on_data_ready_callbacks_;
540
[email protected]b6eaebd72013-01-15 23:04:09541 // All per-Resource values are stored here.
542 mutable PerResourceCache per_resource_cache_;
543
544 // All per-Process values are stored here.
545 mutable PerProcessCache per_process_cache_;
546
[email protected]0860b9b92009-05-11 18:49:18547 DISALLOW_COPY_AND_ASSIGN(TaskManagerModel);
initial.commit09911bf2008-07-26 23:55:29548};
549
[email protected]a5d1e1e2010-09-23 19:34:12550#endif // CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_H_