Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / task_management / task_manager_observer.h
blob49b80da9cd6293b5062eeed99eaa5c6b00c1ee0c
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_TASK_MANAGER_OBSERVER_H_
6 #define CHROME_BROWSER_TASK_MANAGEMENT_TASK_MANAGER_OBSERVER_H_
8 #include <vector>
10 #include "base/time/time.h"
12 namespace task_management {
14 class TaskManagerInterface;
16 typedef int64 TaskId;
17 typedef std::vector<TaskId> TaskIdList;
19 // Defines a list of types of resources that an observer needs to be refreshed
20 // on every task manager refresh cycle.
21 enum RefreshType {
22 REFRESH_TYPE_NONE = 0,
23 REFRESH_TYPE_CPU = 1,
24 REFRESH_TYPE_MEMORY = 1 << 1,
25 REFRESH_TYPE_GPU_MEMORY = 1 << 2,
26 REFRESH_TYPE_V8_MEMORY = 1 << 3,
27 REFRESH_TYPE_SQLITE_MEMORY = 1 << 4,
28 REFRESH_TYPE_WEBCACHE_STATS = 1 << 5,
29 REFRESH_TYPE_NETWORK_USAGE = 1 << 6,
30 REFRESH_TYPE_NACL = 1 << 7,
31 REFRESH_TYPE_IDLE_WAKEUPS = 1 << 8,
32 REFRESH_TYPE_HANDLES = 1 << 9,
35 // Defines the interface for observers of the task manager.
36 class TaskManagerObserver {
37 public:
38 // Constructs a TaskManagerObserver given the minimum |refresh_time| that it
39 // it requires the task manager to be refreshing the values at, along with the
40 // |resources_flags| that it needs to be calculated on each refresh cycle of
41 // the task manager (use the above flags in |ResourceType|).
43 // Notes:
44 // 1- The task manager will refresh at least once every |refresh_time| as
45 // long as this observer is added to it. There might be other observers that
46 // require more frequent refreshes.
47 // 2- Refresh time values less than 1 second will be considered as 1 second.
48 // 3- Depending on the other observers, the task manager may refresh more
49 // resources than those defined in |resources_flags|.
50 // 4- Upon the removal of the observer from the task manager, the task manager
51 // will update its refresh time and the calculated resources to be the minimum
52 // required value of all the remaining observers.
53 TaskManagerObserver(base::TimeDelta refresh_time, int64 resources_flags);
54 virtual ~TaskManagerObserver();
56 // Notifies the observer that a chrome task with |id| has started and the task
57 // manager is now monitoring it. The resource usage of this newly-added task
58 // will remain invalid until the next refresh cycle of the task manager.
59 virtual void OnTaskAdded(TaskId id) = 0;
61 // Notifies the observer that a chrome task with |id| is about to be destroyed
62 // and removed from the task manager right after this call. Observers which
63 // are interested in doing some calculations related to the resource usage of
64 // this task upon its removal may do so inside this call.
65 virtual void OnTaskToBeRemoved(TaskId id) = 0;
67 // Notifies the observer that the task manager has just finished a refresh
68 // cycle to calculate the resources usage of all tasks whose IDs are given in
69 // |task_ids|. |task_ids| will be sorted such that the task representing the
70 // browser process is at the top of the list and the rest of the IDs will be
71 // sorted by the process IDs on which the tasks are running, then by the task
72 // IDs themselves.
73 virtual void OnTasksRefreshed(const TaskIdList& task_ids) = 0;
75 const base::TimeDelta& desired_refresh_time() const {
76 return desired_refresh_time_;
79 int64 desired_resources_flags() const { return desired_resources_flags_; }
81 protected:
82 TaskManagerInterface* observed_task_manager() const {
83 return observed_task_manager_;
86 // Add or Remove a refresh |type|.
87 void AddRefreshType(RefreshType type);
88 void RemoveRefreshType(RefreshType type);
90 private:
91 friend class TaskManagerInterface;
93 // The currently observed task Manager.
94 TaskManagerInterface* observed_task_manager_;
96 // The minimum update time of the task manager that this observer needs to
97 // do its job.
98 base::TimeDelta desired_refresh_time_;
100 // The flags that contain the resources that this observer needs to be
101 // calculated on each refresh.
102 int64 desired_resources_flags_;
104 DISALLOW_COPY_AND_ASSIGN(TaskManagerObserver);
107 } // namespace task_management
110 #endif // CHROME_BROWSER_TASK_MANAGEMENT_TASK_MANAGER_OBSERVER_H_