OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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_MANAGEMENT_TASK_MANAGER_OBSERVER_H_ | 5 #ifndef CHROME_BROWSER_TASK_MANAGEMENT_TASK_MANAGER_OBSERVER_H_ |
6 #define CHROME_BROWSER_TASK_MANAGEMENT_TASK_MANAGER_OBSERVER_H_ | 6 #define CHROME_BROWSER_TASK_MANAGEMENT_TASK_MANAGER_OBSERVER_H_ |
7 | 7 |
| 8 #include <stdint.h> |
| 9 |
8 #include <vector> | 10 #include <vector> |
9 | 11 |
| 12 #include "base/macros.h" |
10 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "build/build_config.h" |
11 | 15 |
12 namespace task_management { | 16 namespace task_management { |
13 | 17 |
14 class TaskManagerInterface; | 18 class TaskManagerInterface; |
15 | 19 |
16 typedef int64 TaskId; | 20 typedef int64_t TaskId; |
17 typedef std::vector<TaskId> TaskIdList; | 21 typedef std::vector<TaskId> TaskIdList; |
18 | 22 |
19 // Defines a list of types of resources that an observer needs to be refreshed | 23 // Defines a list of types of resources that an observer needs to be refreshed |
20 // on every task manager refresh cycle. | 24 // on every task manager refresh cycle. |
21 enum RefreshType { | 25 enum RefreshType { |
22 REFRESH_TYPE_NONE = 0, | 26 REFRESH_TYPE_NONE = 0, |
23 REFRESH_TYPE_CPU = 1, | 27 REFRESH_TYPE_CPU = 1, |
24 REFRESH_TYPE_MEMORY = 1 << 1, | 28 REFRESH_TYPE_MEMORY = 1 << 1, |
25 REFRESH_TYPE_GPU_MEMORY = 1 << 2, | 29 REFRESH_TYPE_GPU_MEMORY = 1 << 2, |
26 REFRESH_TYPE_V8_MEMORY = 1 << 3, | 30 REFRESH_TYPE_V8_MEMORY = 1 << 3, |
(...skipping 26 matching lines...) Expand all Loading... |
53 // Notes: | 57 // Notes: |
54 // 1- The task manager will refresh at least once every |refresh_time| as | 58 // 1- The task manager will refresh at least once every |refresh_time| as |
55 // long as this observer is added to it. There might be other observers that | 59 // long as this observer is added to it. There might be other observers that |
56 // require more frequent refreshes. | 60 // require more frequent refreshes. |
57 // 2- Refresh time values less than 1 second will be considered as 1 second. | 61 // 2- Refresh time values less than 1 second will be considered as 1 second. |
58 // 3- Depending on the other observers, the task manager may refresh more | 62 // 3- Depending on the other observers, the task manager may refresh more |
59 // resources than those defined in |resources_flags|. | 63 // resources than those defined in |resources_flags|. |
60 // 4- Upon the removal of the observer from the task manager, the task manager | 64 // 4- Upon the removal of the observer from the task manager, the task manager |
61 // will update its refresh time and the calculated resources to be the minimum | 65 // will update its refresh time and the calculated resources to be the minimum |
62 // required value of all the remaining observers. | 66 // required value of all the remaining observers. |
63 TaskManagerObserver(base::TimeDelta refresh_time, int64 resources_flags); | 67 TaskManagerObserver(base::TimeDelta refresh_time, int64_t resources_flags); |
64 virtual ~TaskManagerObserver(); | 68 virtual ~TaskManagerObserver(); |
65 | 69 |
66 // Notifies the observer that a chrome task with |id| has started and the task | 70 // Notifies the observer that a chrome task with |id| has started and the task |
67 // manager is now monitoring it. The resource usage of this newly-added task | 71 // manager is now monitoring it. The resource usage of this newly-added task |
68 // will remain invalid until the next refresh cycle of the task manager. | 72 // will remain invalid until the next refresh cycle of the task manager. |
69 virtual void OnTaskAdded(TaskId id) = 0; | 73 virtual void OnTaskAdded(TaskId id) = 0; |
70 | 74 |
71 // Notifies the observer that a chrome task with |id| is about to be destroyed | 75 // Notifies the observer that a chrome task with |id| is about to be destroyed |
72 // and removed from the task manager right after this call. Observers which | 76 // and removed from the task manager right after this call. Observers which |
73 // are interested in doing some calculations related to the resource usage of | 77 // are interested in doing some calculations related to the resource usage of |
74 // this task upon its removal may do so inside this call. | 78 // this task upon its removal may do so inside this call. |
75 virtual void OnTaskToBeRemoved(TaskId id) = 0; | 79 virtual void OnTaskToBeRemoved(TaskId id) = 0; |
76 | 80 |
77 // Notifies the observer that the task manager has just finished a refresh | 81 // Notifies the observer that the task manager has just finished a refresh |
78 // cycle to calculate the resources usage of all tasks whose IDs are given in | 82 // cycle to calculate the resources usage of all tasks whose IDs are given in |
79 // |task_ids|. |task_ids| will be sorted such that the task representing the | 83 // |task_ids|. |task_ids| will be sorted such that the task representing the |
80 // browser process is at the top of the list and the rest of the IDs will be | 84 // browser process is at the top of the list and the rest of the IDs will be |
81 // sorted by the process IDs on which the tasks are running, then by the task | 85 // sorted by the process IDs on which the tasks are running, then by the task |
82 // IDs themselves. | 86 // IDs themselves. |
83 virtual void OnTasksRefreshed(const TaskIdList& task_ids) = 0; | 87 virtual void OnTasksRefreshed(const TaskIdList& task_ids) = 0; |
84 | 88 |
85 const base::TimeDelta& desired_refresh_time() const { | 89 const base::TimeDelta& desired_refresh_time() const { |
86 return desired_refresh_time_; | 90 return desired_refresh_time_; |
87 } | 91 } |
88 | 92 |
89 int64 desired_resources_flags() const { return desired_resources_flags_; } | 93 int64_t desired_resources_flags() const { return desired_resources_flags_; } |
90 | 94 |
91 protected: | 95 protected: |
92 TaskManagerInterface* observed_task_manager() const { | 96 TaskManagerInterface* observed_task_manager() const { |
93 return observed_task_manager_; | 97 return observed_task_manager_; |
94 } | 98 } |
95 | 99 |
96 // Add or Remove a refresh |type|. | 100 // Add or Remove a refresh |type|. |
97 void AddRefreshType(RefreshType type); | 101 void AddRefreshType(RefreshType type); |
98 void RemoveRefreshType(RefreshType type); | 102 void RemoveRefreshType(RefreshType type); |
99 | 103 |
100 private: | 104 private: |
101 friend class TaskManagerInterface; | 105 friend class TaskManagerInterface; |
102 | 106 |
103 // The currently observed task Manager. | 107 // The currently observed task Manager. |
104 TaskManagerInterface* observed_task_manager_; | 108 TaskManagerInterface* observed_task_manager_; |
105 | 109 |
106 // The minimum update time of the task manager that this observer needs to | 110 // The minimum update time of the task manager that this observer needs to |
107 // do its job. | 111 // do its job. |
108 base::TimeDelta desired_refresh_time_; | 112 base::TimeDelta desired_refresh_time_; |
109 | 113 |
110 // The flags that contain the resources that this observer needs to be | 114 // The flags that contain the resources that this observer needs to be |
111 // calculated on each refresh. | 115 // calculated on each refresh. |
112 int64 desired_resources_flags_; | 116 int64_t desired_resources_flags_; |
113 | 117 |
114 DISALLOW_COPY_AND_ASSIGN(TaskManagerObserver); | 118 DISALLOW_COPY_AND_ASSIGN(TaskManagerObserver); |
115 }; | 119 }; |
116 | 120 |
117 } // namespace task_management | 121 } // namespace task_management |
118 | 122 |
119 | 123 |
120 #endif // CHROME_BROWSER_TASK_MANAGEMENT_TASK_MANAGER_OBSERVER_H_ | 124 #endif // CHROME_BROWSER_TASK_MANAGEMENT_TASK_MANAGER_OBSERVER_H_ |
OLD | NEW |