1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
|
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_TASK_MANAGER_RESOURCE_PROVIDERS_H_
#define CHROME_BROWSER_TASK_MANAGER_RESOURCE_PROVIDERS_H_
#include "base/basictypes.h"
#include "chrome/browser/task_manager.h"
#include "chrome/common/child_process_info.h"
#include "chrome/common/notification_observer.h"
class WebContents;
// These file contains the resource providers used in the task manager.
class TaskManagerWebContentsResource : public TaskManager::Resource {
public:
explicit TaskManagerWebContentsResource(WebContents* web_contents);
~TaskManagerWebContentsResource();
// TaskManagerResource methods:
std::wstring GetTitle() const;
SkBitmap GetIcon() const;
HANDLE GetProcess() const;
TabContents* GetTabContents() const;
// WebContents always provide the network usage.
bool SupportNetworkUsage() const { return true; }
void SetSupportNetworkUsage() { };
private:
WebContents* web_contents_;
HANDLE process_;
int pid_;
DISALLOW_COPY_AND_ASSIGN(TaskManagerWebContentsResource);
};
class TaskManagerWebContentsResourceProvider
: public TaskManager::ResourceProvider,
public NotificationObserver {
public:
explicit TaskManagerWebContentsResourceProvider(TaskManager* task_manager);
virtual ~TaskManagerWebContentsResourceProvider();
virtual TaskManager::Resource* GetResource(int origin_pid,
int render_process_host_id,
int routing_id);
virtual void StartUpdating();
virtual void StopUpdating();
// NotificationObserver method:
virtual void Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details);
private:
void Add(WebContents* web_contents);
void Remove(WebContents* web_contents);
void AddToTaskManager(WebContents* web_contents);
// Whether we are currently reporting to the task manager. Used to ignore
// notifications sent after StopUpdating().
bool updating_;
TaskManager* task_manager_;
// Maps the actual resources (the WebContents) to the Task Manager
// resources.
std::map<WebContents*, TaskManagerWebContentsResource*> resources_;
DISALLOW_COPY_AND_ASSIGN(TaskManagerWebContentsResourceProvider);
};
class TaskManagerChildProcessResource : public TaskManager::Resource {
public:
explicit TaskManagerChildProcessResource(ChildProcessInfo child_proc);
~TaskManagerChildProcessResource();
// TaskManagerResource methods:
std::wstring GetTitle() const;
SkBitmap GetIcon() const;
HANDLE GetProcess() const;
bool SupportNetworkUsage() const {
return network_usage_support_;
}
void SetSupportNetworkUsage() {
network_usage_support_ = true;
}
// Returns the pid of the child process.
int process_id() const { return pid_; }
private:
ChildProcessInfo child_process_;
int pid_;
mutable std::wstring title_;
bool network_usage_support_;
// The icon painted for the child processs.
// TODO (jcampan): we should have plugin specific icons for well-known
// plugins.
static SkBitmap* default_icon_;
DISALLOW_COPY_AND_ASSIGN(TaskManagerChildProcessResource);
};
class TaskManagerChildProcessResourceProvider
: public TaskManager::ResourceProvider,
public NotificationObserver {
public:
explicit TaskManagerChildProcessResourceProvider(TaskManager* task_manager);
virtual ~TaskManagerChildProcessResourceProvider();
virtual TaskManager::Resource* GetResource(int origin_pid,
int render_process_host_id,
int routing_id);
virtual void StartUpdating();
virtual void StopUpdating();
// NotificationObserver method:
virtual void Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details);
// Retrieves the current ChildProcessInfo (performed in the IO thread).
virtual void RetrieveChildProcessInfo();
// Notifies the UI thread that the ChildProcessInfo have been retrieved.
virtual void ChildProcessInfoRetreived();
// Whether we are currently reporting to the task manager. Used to ignore
// notifications sent after StopUpdating().
bool updating_;
// The list of ChildProcessInfo retrieved when starting the update.
std::vector<ChildProcessInfo> existing_child_process_info_;
private:
void Add(ChildProcessInfo child_process_info);
void Remove(ChildProcessInfo child_process_info);
void AddToTaskManager(ChildProcessInfo child_process_info);
TaskManager* task_manager_;
MessageLoop* ui_loop_;
// Maps the actual resources (the ChildProcessInfo) to the Task Manager
// resources.
std::map<ChildProcessInfo, TaskManagerChildProcessResource*> resources_;
// Maps the pids to the resources (used for quick access to the resource on
// byte read notifications).
std::map<int, TaskManagerChildProcessResource*> pid_to_resources_;
DISALLOW_COPY_AND_ASSIGN(TaskManagerChildProcessResourceProvider);
};
class TaskManagerBrowserProcessResource : public TaskManager::Resource {
public:
TaskManagerBrowserProcessResource();
~TaskManagerBrowserProcessResource();
// TaskManagerResource methods:
std::wstring GetTitle() const;
SkBitmap GetIcon() const;
HANDLE GetProcess() const;
bool SupportNetworkUsage() const {
return network_usage_support_;
}
void SetSupportNetworkUsage() {
network_usage_support_ = true;
}
// Returns the pid of the browser process.
int process_id() const { return pid_; }
private:
HANDLE process_;
int pid_;
bool network_usage_support_;
mutable std::wstring title_;
static SkBitmap* default_icon_;
DISALLOW_COPY_AND_ASSIGN(TaskManagerBrowserProcessResource);
};
class TaskManagerBrowserProcessResourceProvider
: public TaskManager::ResourceProvider {
public:
explicit TaskManagerBrowserProcessResourceProvider(
TaskManager* task_manager);
virtual ~TaskManagerBrowserProcessResourceProvider();
virtual TaskManager::Resource* GetResource(int origin_pid,
int render_process_host_id,
int routing_id);
virtual void StartUpdating();
virtual void StopUpdating();
// Whether we are currently reporting to the task manager. Used to ignore
// notifications sent after StopUpdating().
bool updating_;
private:
void AddToTaskManager(ChildProcessInfo child_process_info);
TaskManager* task_manager_;
TaskManagerBrowserProcessResource resource_;
DISALLOW_COPY_AND_ASSIGN(TaskManagerBrowserProcessResourceProvider);
};
#endif // CHROME_BROWSER_TASK_MANAGER_RESOURCE_PROVIDERS_H_
|