Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / task_management / providers / task.h
blob5fa551f56326e2d28435cc89b9b88cc93b48dff1
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_PROVIDERS_TASK_H_
6 #define CHROME_BROWSER_TASK_MANAGEMENT_PROVIDERS_TASK_H_
8 #include "base/basictypes.h"
9 #include "base/process/process_handle.h"
10 #include "base/strings/string16.h"
11 #include "base/time/time.h"
12 #include "third_party/WebKit/public/web/WebCache.h"
13 #include "ui/gfx/image/image_skia.h"
15 namespace task_management {
17 // Defines a task that corresponds to a tab, an app, an extension, ... etc. It
18 // represents one row in the task manager table. Multiple tasks can share the
19 // same process, in which case they're grouped together in the task manager
20 // table. See |task_management::TaskGroup| which represents a process possibly
21 // shared by multiple tasks.
22 class Task {
23 public:
24 enum Type {
25 UNKNOWN = 0,
26 BROWSER, /* The main browser process. */
27 RENDERER, /* A normal WebContents renderer process. */
28 EXTENSION, /* An extension or app process. */
29 GUEST, /* A browser plugin guest process. */
30 PLUGIN, /* A plugin process. */
31 WORKER, /* A web worker process. */
32 NACL, /* A NativeClient loader or broker process. */
33 UTILITY, /* A browser utility process. */
34 ZYGOTE, /* A Linux zygote process. */
35 SANDBOX_HELPER, /* A sandbox helper process. */
36 GPU, /* A graphics process. */
39 // Create a task with the given |title| and the given favicon |icon|. This
40 // task runs on a process whose handle is |handle|.
41 Task(const base::string16& title,
42 const gfx::ImageSkia* icon,
43 base::ProcessHandle handle);
44 virtual ~Task();
46 // Activates this TaskManager's task by bringing its container to the front
47 // (if possible).
48 virtual void Activate();
50 // Will be called to let the task refresh itself between refresh cycles.
51 // |update_interval| is the time since the last task manager refresh.
52 // the |refresh_flags| indicate which resources should be calculated on each
53 // refresh.
54 virtual void Refresh(const base::TimeDelta& update_interval,
55 int64 refresh_flags);
57 // Will receive this notification through the task manager from
58 // |ChromeNetworkDelegate::OnNetworkBytesReceived()|. The task will add to the
59 // |current_byte_count_| in this refresh cycle.
60 void OnNetworkBytesRead(int64 bytes_read);
62 // Returns the task type.
63 virtual Type GetType() const = 0;
65 // This is the unique ID of the BrowserChildProcessHost/RenderProcessHost. It
66 // is not the PID nor the handle of the process.
67 // For a task that represents the browser process, the return value is 0. For
68 // other tasks that represent renderers and other child processes, the return
69 // value is whatever unique IDs of their hosts in the browser process.
70 virtual int GetChildProcessUniqueID() const = 0;
72 // The name of the profile associated with the browser context of the render
73 // view host that this task represents (if this task represents a renderer).
74 virtual base::string16 GetProfileName() const;
76 // Getting the Sqlite used memory (in bytes). Not all tasks reports Sqlite
77 // memory, in this case a default invalid value of -1 will be returned.
78 // Check for whether the task reports it or not first.
79 bool ReportsSqliteMemory() const;
80 virtual int64 GetSqliteMemoryUsed() const;
82 // Getting the allocated and used V8 memory (in bytes). Not all tasks reports
83 // V8 memory, in this case a default invalid value of -1 will be returned.
84 // Check for whether the task reports it or not first.
85 bool ReportsV8Memory() const;
86 virtual int64 GetV8MemoryAllocated() const;
87 virtual int64 GetV8MemoryUsed() const;
89 // Checking if the task reports Webkit resource cache statistics and getting
90 // them if it does.
91 virtual bool ReportsWebCacheStats() const;
92 virtual blink::WebCache::ResourceTypeStats GetWebCacheStats() const;
94 // Checking whether the task reports network usage.
95 bool ReportsNetworkUsage() const;
97 int64 task_id() const { return task_id_; }
98 int64 network_usage() const { return network_usage_; }
99 const base::string16& title() const { return title_; }
100 const gfx::ImageSkia& icon() const { return icon_; }
101 const base::ProcessHandle& process_handle() const { return process_handle_; }
102 const base::ProcessId& process_id() const { return process_id_; }
104 protected:
105 void set_title(const base::string16& new_title) { title_ = new_title; }
106 void set_icon(const gfx::ImageSkia& new_icon) { icon_ = new_icon; }
108 private:
109 // The unique ID of this task.
110 const int64 task_id_;
112 // The task's network usage in the current refresh cycle measured in bytes per
113 // second. A value of -1 means this task doesn't report network usage data.
114 int64 network_usage_;
116 // The current network bytes received by this task during the current refresh
117 // cycle. A value of -1 means this task has never been notified of any network
118 // usage.
119 int64 current_byte_count_;
121 // The title of the task.
122 base::string16 title_;
124 // The favicon.
125 gfx::ImageSkia icon_;
127 // The handle of the process on which this task is running.
128 const base::ProcessHandle process_handle_;
130 // The PID of the process on which this task is running.
131 const base::ProcessId process_id_;
133 DISALLOW_COPY_AND_ASSIGN(Task);
136 } // namespace task_management
138 #endif // CHROME_BROWSER_TASK_MANAGEMENT_PROVIDERS_TASK_H_