1 // Copyright 2015 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.
5 #ifndef CHROME_BROWSER_TASK_MANAGEMENT_SAMPLING_TASK_MANAGER_IMPL_H_
6 #define CHROME_BROWSER_TASK_MANAGEMENT_SAMPLING_TASK_MANAGER_IMPL_H_
10 #include "base/sequenced_task_runner.h"
11 #include "chrome/browser/task_management/providers/task_provider_observer.h"
12 #include "chrome/browser/task_management/task_manager_interface.h"
13 #include "content/public/browser/gpu_data_manager_observer.h"
15 namespace task_management
{
19 // Defines a concrete implementation of the TaskManagerInterface.
20 class TaskManagerImpl
:
21 public TaskManagerInterface
,
22 public TaskProviderObserver
,
23 content::GpuDataManagerObserver
{
26 ~TaskManagerImpl() override
;
28 // task_management::TaskManagerInterface:
29 void ActivateTask(TaskId task_id
) override
;
30 double GetCpuUsage(TaskId task_id
) const override
;
31 int64
GetPhysicalMemoryUsage(TaskId task_id
) const override
;
32 int64
GetPrivateMemoryUsage(TaskId task_id
) const override
;
33 int64
GetSharedMemoryUsage(TaskId task_id
) const override
;
34 int64
GetGpuMemoryUsage(TaskId task_id
, bool* has_duplicates
) const override
;
35 int GetIdleWakeupsPerSecond(TaskId task_id
) const override
;
36 int GetNaClDebugStubPort(TaskId task_id
) const override
;
37 void GetGDIHandles(TaskId task_id
,
39 int64
* peak
) const override
;
40 void GetUSERHandles(TaskId task_id
,
42 int64
* peak
) const override
;
43 const base::string16
& GetTitle(TaskId task_id
) const override
;
44 base::string16
GetProfileName(TaskId task_id
) const override
;
45 const gfx::ImageSkia
& GetIcon(TaskId task_id
) const override
;
46 const base::ProcessHandle
& GetProcessHandle(TaskId task_id
) const override
;
47 const base::ProcessId
& GetProcessId(TaskId task_id
) const override
;
48 Task::Type
GetType(TaskId task_id
) const override
;
49 int64
GetNetworkUsage(TaskId task_id
) const override
;
50 int64
GetSqliteMemoryUsed(TaskId task_id
) const override
;
51 bool GetV8Memory(TaskId task_id
,
53 int64
* used
) const override
;
54 bool GetWebCacheStats(
56 blink::WebCache::ResourceTypeStats
* stats
) const override
;
58 // task_management::TaskProviderObserver:
59 void TaskAdded(Task
* task
) override
;
60 void TaskRemoved(Task
* task
) override
;
62 // content::GpuDataManagerObserver:
63 void OnVideoMemoryUsageStatsUpdate(
64 const content::GPUVideoMemoryUsageStats
& gpu_memory_stats
) override
;
67 // task_management::TaskManagerInterface:
68 void Refresh() override
;
70 TaskGroup
* GetTaskGroupByTaskId(TaskId task_id
) const;
71 Task
* GetTaskByTaskId(TaskId task_id
) const;
73 // Map TaskGroups by the IDs of the processes they represent.
74 // Keys and values are unique (no duplicates).
75 std::map
<base::ProcessId
, TaskGroup
*> task_groups_by_proc_id_
;
77 // Map each task by its ID to the TaskGroup on which it resides.
78 // Keys are unique but values will have duplicates (i.e. multiple tasks
79 // running on the same process represented by a single TaskGroup).
80 std::map
<TaskId
, TaskGroup
*> task_groups_by_task_id_
;
82 // The current GPU memory usage stats that was last received from the
84 content::GPUVideoMemoryUsageStats gpu_memory_stats_
;
86 // The specific blocking pool SequencedTaskRunner that will be used to make
87 // sure TaskGroupSampler posts their refreshes serially.
88 scoped_refptr
<base::SequencedTaskRunner
> blocking_pool_runner_
;
90 DISALLOW_COPY_AND_ASSIGN(TaskManagerImpl
);
93 } // namespace task_management
95 #endif // CHROME_BROWSER_TASK_MANAGEMENT_SAMPLING_TASK_MANAGER_IMPL_H_