blob: fe1c233c475455610bf851ecd85ba8a74699c198 [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]9d9bbee22009-04-17 21:53:5874 // A scoped container for notification registries.
75 NotificationRegistrar registrar_;
76
[email protected]bfd04a62009-02-01 18:16:5677 DISALLOW_COPY_AND_ASSIGN(TaskManagerWebContentsResourceProvider);
initial.commit09911bf2008-07-26 23:55:2978};
79
[email protected]a27a9382009-02-11 23:55:1080class TaskManagerChildProcessResource : public TaskManager::Resource {
initial.commit09911bf2008-07-26 23:55:2981 public:
[email protected]a27a9382009-02-11 23:55:1082 explicit TaskManagerChildProcessResource(ChildProcessInfo child_proc);
83 ~TaskManagerChildProcessResource();
initial.commit09911bf2008-07-26 23:55:2984
85 // TaskManagerResource methods:
86 std::wstring GetTitle() const;
87 SkBitmap GetIcon() const;
88 HANDLE GetProcess() const;
89
90 bool SupportNetworkUsage() const {
91 return network_usage_support_;
92 }
93
94 void SetSupportNetworkUsage() {
95 network_usage_support_ = true;
96 }
97
[email protected]a27a9382009-02-11 23:55:1098 // Returns the pid of the child process.
initial.commit09911bf2008-07-26 23:55:2999 int process_id() const { return pid_; }
100
101 private:
[email protected]a27a9382009-02-11 23:55:10102 ChildProcessInfo child_process_;
initial.commit09911bf2008-07-26 23:55:29103 int pid_;
104 mutable std::wstring title_;
105 bool network_usage_support_;
106
[email protected]a27a9382009-02-11 23:55:10107 // The icon painted for the child processs.
initial.commit09911bf2008-07-26 23:55:29108 // TODO (jcampan): we should have plugin specific icons for well-known
109 // plugins.
110 static SkBitmap* default_icon_;
111
[email protected]a27a9382009-02-11 23:55:10112 DISALLOW_COPY_AND_ASSIGN(TaskManagerChildProcessResource);
initial.commit09911bf2008-07-26 23:55:29113};
114
[email protected]a27a9382009-02-11 23:55:10115class TaskManagerChildProcessResourceProvider
initial.commit09911bf2008-07-26 23:55:29116 : public TaskManager::ResourceProvider,
117 public NotificationObserver {
118 public:
[email protected]a27a9382009-02-11 23:55:10119 explicit TaskManagerChildProcessResourceProvider(TaskManager* task_manager);
120 virtual ~TaskManagerChildProcessResourceProvider();
initial.commit09911bf2008-07-26 23:55:29121
122 virtual TaskManager::Resource* GetResource(int origin_pid,
123 int render_process_host_id,
124 int routing_id);
125 virtual void StartUpdating();
126 virtual void StopUpdating();
127
128 // NotificationObserver method:
129 virtual void Observe(NotificationType type,
130 const NotificationSource& source,
131 const NotificationDetails& details);
132
[email protected]a27a9382009-02-11 23:55:10133 // Retrieves the current ChildProcessInfo (performed in the IO thread).
134 virtual void RetrieveChildProcessInfo();
initial.commit09911bf2008-07-26 23:55:29135
[email protected]a27a9382009-02-11 23:55:10136 // Notifies the UI thread that the ChildProcessInfo have been retrieved.
137 virtual void ChildProcessInfoRetreived();
initial.commit09911bf2008-07-26 23:55:29138
139 // Whether we are currently reporting to the task manager. Used to ignore
140 // notifications sent after StopUpdating().
141 bool updating_;
142
[email protected]a27a9382009-02-11 23:55:10143 // The list of ChildProcessInfo retrieved when starting the update.
144 std::vector<ChildProcessInfo> existing_child_process_info_;
initial.commit09911bf2008-07-26 23:55:29145
146 private:
[email protected]a27a9382009-02-11 23:55:10147 void Add(ChildProcessInfo child_process_info);
148 void Remove(ChildProcessInfo child_process_info);
initial.commit09911bf2008-07-26 23:55:29149
[email protected]a27a9382009-02-11 23:55:10150 void AddToTaskManager(ChildProcessInfo child_process_info);
initial.commit09911bf2008-07-26 23:55:29151
152 TaskManager* task_manager_;
153
154 MessageLoop* ui_loop_;
155
[email protected]a27a9382009-02-11 23:55:10156 // Maps the actual resources (the ChildProcessInfo) to the Task Manager
initial.commit09911bf2008-07-26 23:55:29157 // resources.
[email protected]a27a9382009-02-11 23:55:10158 std::map<ChildProcessInfo, TaskManagerChildProcessResource*> resources_;
initial.commit09911bf2008-07-26 23:55:29159
160 // Maps the pids to the resources (used for quick access to the resource on
161 // byte read notifications).
[email protected]a27a9382009-02-11 23:55:10162 std::map<int, TaskManagerChildProcessResource*> pid_to_resources_;
initial.commit09911bf2008-07-26 23:55:29163
[email protected]9d9bbee22009-04-17 21:53:58164 // A scoped container for notification registries.
165 NotificationRegistrar registrar_;
166
[email protected]a27a9382009-02-11 23:55:10167 DISALLOW_COPY_AND_ASSIGN(TaskManagerChildProcessResourceProvider);
initial.commit09911bf2008-07-26 23:55:29168};
169
170class TaskManagerBrowserProcessResource : public TaskManager::Resource {
171 public:
172 TaskManagerBrowserProcessResource();
173 ~TaskManagerBrowserProcessResource();
174
175 // TaskManagerResource methods:
176 std::wstring GetTitle() const;
177 SkBitmap GetIcon() const;
178 HANDLE GetProcess() const;
179
180 bool SupportNetworkUsage() const {
181 return network_usage_support_;
182 }
183
184 void SetSupportNetworkUsage() {
185 network_usage_support_ = true;
186 }
187
188 // Returns the pid of the browser process.
189 int process_id() const { return pid_; }
190
191 private:
192 HANDLE process_;
193 int pid_;
194 bool network_usage_support_;
195 mutable std::wstring title_;
196
197 static SkBitmap* default_icon_;
198
[email protected]bfd04a62009-02-01 18:16:56199 DISALLOW_COPY_AND_ASSIGN(TaskManagerBrowserProcessResource);
initial.commit09911bf2008-07-26 23:55:29200};
201
202class TaskManagerBrowserProcessResourceProvider
203 : public TaskManager::ResourceProvider {
204 public:
205 explicit TaskManagerBrowserProcessResourceProvider(
206 TaskManager* task_manager);
207 virtual ~TaskManagerBrowserProcessResourceProvider();
208
209 virtual TaskManager::Resource* GetResource(int origin_pid,
210 int render_process_host_id,
211 int routing_id);
212 virtual void StartUpdating();
213 virtual void StopUpdating();
214
215 // Whether we are currently reporting to the task manager. Used to ignore
216 // notifications sent after StopUpdating().
217 bool updating_;
218
219 private:
[email protected]a27a9382009-02-11 23:55:10220 void AddToTaskManager(ChildProcessInfo child_process_info);
initial.commit09911bf2008-07-26 23:55:29221
222 TaskManager* task_manager_;
223 TaskManagerBrowserProcessResource resource_;
224
[email protected]bfd04a62009-02-01 18:16:56225 DISALLOW_COPY_AND_ASSIGN(TaskManagerBrowserProcessResourceProvider);
initial.commit09911bf2008-07-26 23:55:29226};
227
[email protected]bfd04a62009-02-01 18:16:56228#endif // CHROME_BROWSER_TASK_MANAGER_RESOURCE_PROVIDERS_H_