blob: a56aed519fb220265858baa2e735605a04cb52ca [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// Copyright (c) 2006-2008 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.
initial.commit09911bf2008-07-26 23:55:294
[email protected]bfd04a62009-02-01 18:16:565#ifndef CHROME_BROWSER_TASK_MANAGER_RESOURCE_PROVIDERS_H_
6#define CHROME_BROWSER_TASK_MANAGER_RESOURCE_PROVIDERS_H_
initial.commit09911bf2008-07-26 23:55:297
[email protected]b5d20662008-08-01 12:33:218#include "base/basictypes.h"
initial.commit09911bf2008-07-26 23:55:299#include "chrome/browser/task_manager.h"
[email protected]a27a9382009-02-11 23:55:1010#include "chrome/common/child_process_info.h"
[email protected]bfd04a62009-02-01 18:16:5611#include "chrome/common/notification_observer.h"
initial.commit09911bf2008-07-26 23:55:2912
initial.commit09911bf2008-07-26 23:55:2913class WebContents;
14
15// These file contains the resource providers used in the task manager.
16
17class TaskManagerWebContentsResource : public TaskManager::Resource {
18 public:
19 explicit TaskManagerWebContentsResource(WebContents* web_contents);
20 ~TaskManagerWebContentsResource();
21
22 // TaskManagerResource methods:
23 std::wstring GetTitle() const;
24 SkBitmap GetIcon() const;
25 HANDLE GetProcess() const;
[email protected]b7937d5b2008-09-10 22:12:1926 TabContents* GetTabContents() const;
27
initial.commit09911bf2008-07-26 23:55:2928 // WebContents always provide the network usage.
29 bool SupportNetworkUsage() const { return true; }
30 void SetSupportNetworkUsage() { };
31
32 private:
33 WebContents* web_contents_;
34 HANDLE process_;
35 int pid_;
36
[email protected]bfd04a62009-02-01 18:16:5637 DISALLOW_COPY_AND_ASSIGN(TaskManagerWebContentsResource);
initial.commit09911bf2008-07-26 23:55:2938};
39
40class TaskManagerWebContentsResourceProvider
41 : public TaskManager::ResourceProvider,
42 public NotificationObserver {
43 public:
44 explicit TaskManagerWebContentsResourceProvider(TaskManager* task_manager);
45 virtual ~TaskManagerWebContentsResourceProvider();
46
47 virtual TaskManager::Resource* GetResource(int origin_pid,
48 int render_process_host_id,
49 int routing_id);
50 virtual void StartUpdating();
51 virtual void StopUpdating();
52
53 // NotificationObserver method:
54 virtual void Observe(NotificationType type,
55 const NotificationSource& source,
56 const NotificationDetails& details);
57
58 private:
59 void Add(WebContents* web_contents);
60 void Remove(WebContents* web_contents);
61
62 void AddToTaskManager(WebContents* web_contents);
63
64 // Whether we are currently reporting to the task manager. Used to ignore
65 // notifications sent after StopUpdating().
66 bool updating_;
67
68 TaskManager* task_manager_;
69
70 // Maps the actual resources (the WebContents) to the Task Manager
71 // resources.
72 std::map<WebContents*, TaskManagerWebContentsResource*> resources_;
73
[email protected]bfd04a62009-02-01 18:16:5674 DISALLOW_COPY_AND_ASSIGN(TaskManagerWebContentsResourceProvider);
initial.commit09911bf2008-07-26 23:55:2975};
76
[email protected]a27a9382009-02-11 23:55:1077class TaskManagerChildProcessResource : public TaskManager::Resource {
initial.commit09911bf2008-07-26 23:55:2978 public:
[email protected]a27a9382009-02-11 23:55:1079 explicit TaskManagerChildProcessResource(ChildProcessInfo child_proc);
80 ~TaskManagerChildProcessResource();
initial.commit09911bf2008-07-26 23:55:2981
82 // TaskManagerResource methods:
83 std::wstring GetTitle() const;
84 SkBitmap GetIcon() const;
85 HANDLE GetProcess() const;
86
87 bool SupportNetworkUsage() const {
88 return network_usage_support_;
89 }
90
91 void SetSupportNetworkUsage() {
92 network_usage_support_ = true;
93 }
94
[email protected]a27a9382009-02-11 23:55:1095 // Returns the pid of the child process.
initial.commit09911bf2008-07-26 23:55:2996 int process_id() const { return pid_; }
97
98 private:
[email protected]a27a9382009-02-11 23:55:1099 ChildProcessInfo child_process_;
initial.commit09911bf2008-07-26 23:55:29100 int pid_;
101 mutable std::wstring title_;
102 bool network_usage_support_;
103
[email protected]a27a9382009-02-11 23:55:10104 // The icon painted for the child processs.
initial.commit09911bf2008-07-26 23:55:29105 // TODO (jcampan): we should have plugin specific icons for well-known
106 // plugins.
107 static SkBitmap* default_icon_;
108
[email protected]a27a9382009-02-11 23:55:10109 DISALLOW_COPY_AND_ASSIGN(TaskManagerChildProcessResource);
initial.commit09911bf2008-07-26 23:55:29110};
111
[email protected]a27a9382009-02-11 23:55:10112class TaskManagerChildProcessResourceProvider
initial.commit09911bf2008-07-26 23:55:29113 : public TaskManager::ResourceProvider,
114 public NotificationObserver {
115 public:
[email protected]a27a9382009-02-11 23:55:10116 explicit TaskManagerChildProcessResourceProvider(TaskManager* task_manager);
117 virtual ~TaskManagerChildProcessResourceProvider();
initial.commit09911bf2008-07-26 23:55:29118
119 virtual TaskManager::Resource* GetResource(int origin_pid,
120 int render_process_host_id,
121 int routing_id);
122 virtual void StartUpdating();
123 virtual void StopUpdating();
124
125 // NotificationObserver method:
126 virtual void Observe(NotificationType type,
127 const NotificationSource& source,
128 const NotificationDetails& details);
129
[email protected]a27a9382009-02-11 23:55:10130 // Retrieves the current ChildProcessInfo (performed in the IO thread).
131 virtual void RetrieveChildProcessInfo();
initial.commit09911bf2008-07-26 23:55:29132
[email protected]a27a9382009-02-11 23:55:10133 // Notifies the UI thread that the ChildProcessInfo have been retrieved.
134 virtual void ChildProcessInfoRetreived();
initial.commit09911bf2008-07-26 23:55:29135
136 // Whether we are currently reporting to the task manager. Used to ignore
137 // notifications sent after StopUpdating().
138 bool updating_;
139
[email protected]a27a9382009-02-11 23:55:10140 // The list of ChildProcessInfo retrieved when starting the update.
141 std::vector<ChildProcessInfo> existing_child_process_info_;
initial.commit09911bf2008-07-26 23:55:29142
143 private:
[email protected]a27a9382009-02-11 23:55:10144 void Add(ChildProcessInfo child_process_info);
145 void Remove(ChildProcessInfo child_process_info);
initial.commit09911bf2008-07-26 23:55:29146
[email protected]a27a9382009-02-11 23:55:10147 void AddToTaskManager(ChildProcessInfo child_process_info);
initial.commit09911bf2008-07-26 23:55:29148
149 TaskManager* task_manager_;
150
151 MessageLoop* ui_loop_;
152
[email protected]a27a9382009-02-11 23:55:10153 // Maps the actual resources (the ChildProcessInfo) to the Task Manager
initial.commit09911bf2008-07-26 23:55:29154 // resources.
[email protected]a27a9382009-02-11 23:55:10155 std::map<ChildProcessInfo, TaskManagerChildProcessResource*> resources_;
initial.commit09911bf2008-07-26 23:55:29156
157 // Maps the pids to the resources (used for quick access to the resource on
158 // byte read notifications).
[email protected]a27a9382009-02-11 23:55:10159 std::map<int, TaskManagerChildProcessResource*> pid_to_resources_;
initial.commit09911bf2008-07-26 23:55:29160
[email protected]a27a9382009-02-11 23:55:10161 DISALLOW_COPY_AND_ASSIGN(TaskManagerChildProcessResourceProvider);
initial.commit09911bf2008-07-26 23:55:29162};
163
164class TaskManagerBrowserProcessResource : public TaskManager::Resource {
165 public:
166 TaskManagerBrowserProcessResource();
167 ~TaskManagerBrowserProcessResource();
168
169 // TaskManagerResource methods:
170 std::wstring GetTitle() const;
171 SkBitmap GetIcon() const;
172 HANDLE GetProcess() const;
173
174 bool SupportNetworkUsage() const {
175 return network_usage_support_;
176 }
177
178 void SetSupportNetworkUsage() {
179 network_usage_support_ = true;
180 }
181
182 // Returns the pid of the browser process.
183 int process_id() const { return pid_; }
184
185 private:
186 HANDLE process_;
187 int pid_;
188 bool network_usage_support_;
189 mutable std::wstring title_;
190
191 static SkBitmap* default_icon_;
192
[email protected]bfd04a62009-02-01 18:16:56193 DISALLOW_COPY_AND_ASSIGN(TaskManagerBrowserProcessResource);
initial.commit09911bf2008-07-26 23:55:29194};
195
196class TaskManagerBrowserProcessResourceProvider
197 : public TaskManager::ResourceProvider {
198 public:
199 explicit TaskManagerBrowserProcessResourceProvider(
200 TaskManager* task_manager);
201 virtual ~TaskManagerBrowserProcessResourceProvider();
202
203 virtual TaskManager::Resource* GetResource(int origin_pid,
204 int render_process_host_id,
205 int routing_id);
206 virtual void StartUpdating();
207 virtual void StopUpdating();
208
209 // Whether we are currently reporting to the task manager. Used to ignore
210 // notifications sent after StopUpdating().
211 bool updating_;
212
213 private:
[email protected]a27a9382009-02-11 23:55:10214 void AddToTaskManager(ChildProcessInfo child_process_info);
initial.commit09911bf2008-07-26 23:55:29215
216 TaskManager* task_manager_;
217 TaskManagerBrowserProcessResource resource_;
218
[email protected]bfd04a62009-02-01 18:16:56219 DISALLOW_COPY_AND_ASSIGN(TaskManagerBrowserProcessResourceProvider);
initial.commit09911bf2008-07-26 23:55:29220};
221
[email protected]bfd04a62009-02-01 18:16:56222#endif // CHROME_BROWSER_TASK_MANAGER_RESOURCE_PROVIDERS_H_