blob: 0448a8caa1babbb4f5fa71b852de56a81c5adf82 [file] [log] [blame]
initial.commit09911bf2008-07-26 23:55:291// Copyright 2008, Google Inc.
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// * Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above
11// copyright notice, this list of conditions and the following disclaimer
12// in the documentation and/or other materials provided with the
13// distribution.
14// * Neither the name of Google Inc. nor the names of its
15// contributors may be used to endorse or promote products derived from
16// this software without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30#ifndef CHROME_BROWSER_TASK_MANAGER_RESOURCE_PROVIDERS_H__
31#define CHROME_BROWSER_TASK_MANAGER_RESOURCE_PROVIDERS_H__
32
33#include "chrome/browser/plugin_process_info.h"
34#include "chrome/browser/task_manager.h"
35#include "base/basictypes.h"
36
37class PluginProcessHost;
38class WebContents;
39
40// These file contains the resource providers used in the task manager.
41
42class TaskManagerWebContentsResource : public TaskManager::Resource {
43 public:
44 explicit TaskManagerWebContentsResource(WebContents* web_contents);
45 ~TaskManagerWebContentsResource();
46
47 // TaskManagerResource methods:
48 std::wstring GetTitle() const;
49 SkBitmap GetIcon() const;
50 HANDLE GetProcess() const;
51 // WebContents always provide the network usage.
52 bool SupportNetworkUsage() const { return true; }
53 void SetSupportNetworkUsage() { };
54
55 private:
56 WebContents* web_contents_;
57 HANDLE process_;
58 int pid_;
59
60 DISALLOW_EVIL_CONSTRUCTORS(TaskManagerWebContentsResource);
61};
62
63class TaskManagerWebContentsResourceProvider
64 : public TaskManager::ResourceProvider,
65 public NotificationObserver {
66 public:
67 explicit TaskManagerWebContentsResourceProvider(TaskManager* task_manager);
68 virtual ~TaskManagerWebContentsResourceProvider();
69
70 virtual TaskManager::Resource* GetResource(int origin_pid,
71 int render_process_host_id,
72 int routing_id);
73 virtual void StartUpdating();
74 virtual void StopUpdating();
75
76 // NotificationObserver method:
77 virtual void Observe(NotificationType type,
78 const NotificationSource& source,
79 const NotificationDetails& details);
80
81 private:
82 void Add(WebContents* web_contents);
83 void Remove(WebContents* web_contents);
84
85 void AddToTaskManager(WebContents* web_contents);
86
87 // Whether we are currently reporting to the task manager. Used to ignore
88 // notifications sent after StopUpdating().
89 bool updating_;
90
91 TaskManager* task_manager_;
92
93 // Maps the actual resources (the WebContents) to the Task Manager
94 // resources.
95 std::map<WebContents*, TaskManagerWebContentsResource*> resources_;
96
97 DISALLOW_EVIL_CONSTRUCTORS(TaskManagerWebContentsResourceProvider);
98};
99
100class TaskManagerPluginProcessResource : public TaskManager::Resource {
101 public:
102 explicit TaskManagerPluginProcessResource(PluginProcessInfo plugin_proc);
103 ~TaskManagerPluginProcessResource();
104
105 // TaskManagerResource methods:
106 std::wstring GetTitle() const;
107 SkBitmap GetIcon() const;
108 HANDLE GetProcess() const;
109
110 bool SupportNetworkUsage() const {
111 return network_usage_support_;
112 }
113
114 void SetSupportNetworkUsage() {
115 network_usage_support_ = true;
116 }
117
118 // Returns the pid of the plugin process.
119 int process_id() const { return pid_; }
120
121 private:
122 PluginProcessInfo plugin_process_;
123 int pid_;
124 mutable std::wstring title_;
125 bool network_usage_support_;
126
127 // The icon painted for plugins.
128 // TODO (jcampan): we should have plugin specific icons for well-known
129 // plugins.
130 static SkBitmap* default_icon_;
131
132 DISALLOW_EVIL_CONSTRUCTORS(TaskManagerPluginProcessResource);
133};
134
135class TaskManagerPluginProcessResourceProvider
136 : public TaskManager::ResourceProvider,
137 public NotificationObserver {
138 public:
139 explicit TaskManagerPluginProcessResourceProvider(TaskManager* task_manager);
140 virtual ~TaskManagerPluginProcessResourceProvider();
141
142 virtual TaskManager::Resource* GetResource(int origin_pid,
143 int render_process_host_id,
144 int routing_id);
145 virtual void StartUpdating();
146 virtual void StopUpdating();
147
148 // NotificationObserver method:
149 virtual void Observe(NotificationType type,
150 const NotificationSource& source,
151 const NotificationDetails& details);
152
153 // Retrieves the current PluginProcessInfo (performed in the IO thread).
154 virtual void RetrievePluginProcessInfo();
155
156 // Notifies the UI thread that the PluginProcessInfo have been retrieved.
157 virtual void PluginProcessInfoRetreived();
158
159 // Whether we are currently reporting to the task manager. Used to ignore
160 // notifications sent after StopUpdating().
161 bool updating_;
162
163 // The list of PluginProcessInfo retrieved when starting the update.
164 std::vector<PluginProcessInfo> existing_plugin_process_info;
165
166 private:
167 void Add(PluginProcessInfo plugin_process_info);
168 void Remove(PluginProcessInfo plugin_process_info);
169
170 void AddToTaskManager(PluginProcessInfo plugin_process_info);
171
172 TaskManager* task_manager_;
173
174 MessageLoop* ui_loop_;
175
176 // Maps the actual resources (the PluginProcessInfo) to the Task Manager
177 // resources.
178 std::map<PluginProcessInfo, TaskManagerPluginProcessResource*> resources_;
179
180 // Maps the pids to the resources (used for quick access to the resource on
181 // byte read notifications).
182 std::map<int, TaskManagerPluginProcessResource*> pid_to_resources_;
183
184 DISALLOW_EVIL_CONSTRUCTORS(TaskManagerPluginProcessResourceProvider);
185};
186
187class TaskManagerBrowserProcessResource : public TaskManager::Resource {
188 public:
189 TaskManagerBrowserProcessResource();
190 ~TaskManagerBrowserProcessResource();
191
192 // TaskManagerResource methods:
193 std::wstring GetTitle() const;
194 SkBitmap GetIcon() const;
195 HANDLE GetProcess() const;
196
197 bool SupportNetworkUsage() const {
198 return network_usage_support_;
199 }
200
201 void SetSupportNetworkUsage() {
202 network_usage_support_ = true;
203 }
204
205 // Returns the pid of the browser process.
206 int process_id() const { return pid_; }
207
208 private:
209 HANDLE process_;
210 int pid_;
211 bool network_usage_support_;
212 mutable std::wstring title_;
213
214 static SkBitmap* default_icon_;
215
216 DISALLOW_EVIL_CONSTRUCTORS(TaskManagerBrowserProcessResource);
217};
218
219class TaskManagerBrowserProcessResourceProvider
220 : public TaskManager::ResourceProvider {
221 public:
222 explicit TaskManagerBrowserProcessResourceProvider(
223 TaskManager* task_manager);
224 virtual ~TaskManagerBrowserProcessResourceProvider();
225
226 virtual TaskManager::Resource* GetResource(int origin_pid,
227 int render_process_host_id,
228 int routing_id);
229 virtual void StartUpdating();
230 virtual void StopUpdating();
231
232 // Whether we are currently reporting to the task manager. Used to ignore
233 // notifications sent after StopUpdating().
234 bool updating_;
235
236 private:
237 void AddToTaskManager(PluginProcessInfo plugin_process_info);
238
239 TaskManager* task_manager_;
240 TaskManagerBrowserProcessResource resource_;
241
242 DISALLOW_EVIL_CONSTRUCTORS(TaskManagerBrowserProcessResourceProvider);
243};
244
245#endif // CHROME_BROWSER_TASK_MANAGER_RESOURCE_PROVIDERS_H__