OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_RESOURCE_PROVIDERS_H_ | 5 #ifndef CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_RESOURCE_PROVIDERS_H_ |
6 #define CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_RESOURCE_PROVIDERS_H_ | 6 #define CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_RESOURCE_PROVIDERS_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/process_util.h" | 14 #include "base/process_util.h" |
15 #include "chrome/browser/task_manager/task_manager.h" | 15 #include "chrome/browser/task_manager/task_manager.h" |
16 #include "content/common/child_process_info.h" | |
17 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
18 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
| 18 #include "content/public/common/process_type.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCache.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCache.h" |
20 | 20 |
21 class BackgroundContents; | 21 class BackgroundContents; |
22 class BalloonHost; | 22 class BalloonHost; |
23 class Extension; | 23 class Extension; |
24 class ExtensionHost; | 24 class ExtensionHost; |
25 class RenderViewHost; | 25 class RenderViewHost; |
26 class TabContentsWrapper; | 26 class TabContentsWrapper; |
27 | 27 |
28 // These file contains the resource providers used in the task manager. | 28 // These file contains the resource providers used in the task manager. |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 Resources resources_; | 226 Resources resources_; |
227 | 227 |
228 // A scoped container for notification registries. | 228 // A scoped container for notification registries. |
229 content::NotificationRegistrar registrar_; | 229 content::NotificationRegistrar registrar_; |
230 | 230 |
231 DISALLOW_COPY_AND_ASSIGN(TaskManagerBackgroundContentsResourceProvider); | 231 DISALLOW_COPY_AND_ASSIGN(TaskManagerBackgroundContentsResourceProvider); |
232 }; | 232 }; |
233 | 233 |
234 class TaskManagerChildProcessResource : public TaskManager::Resource { | 234 class TaskManagerChildProcessResource : public TaskManager::Resource { |
235 public: | 235 public: |
236 explicit TaskManagerChildProcessResource(const ChildProcessInfo& child_proc); | 236 TaskManagerChildProcessResource(content::ProcessType type, |
| 237 const string16& name, |
| 238 base::ProcessHandle handle); |
237 virtual ~TaskManagerChildProcessResource(); | 239 virtual ~TaskManagerChildProcessResource(); |
238 | 240 |
239 // TaskManager::Resource methods: | 241 // TaskManager::Resource methods: |
240 virtual string16 GetTitle() const OVERRIDE; | 242 virtual string16 GetTitle() const OVERRIDE; |
241 virtual string16 GetProfileName() const OVERRIDE; | 243 virtual string16 GetProfileName() const OVERRIDE; |
242 virtual SkBitmap GetIcon() const OVERRIDE; | 244 virtual SkBitmap GetIcon() const OVERRIDE; |
243 virtual base::ProcessHandle GetProcess() const OVERRIDE; | 245 virtual base::ProcessHandle GetProcess() const OVERRIDE; |
244 virtual Type GetType() const OVERRIDE; | 246 virtual Type GetType() const OVERRIDE; |
245 virtual bool SupportNetworkUsage() const OVERRIDE; | 247 virtual bool SupportNetworkUsage() const OVERRIDE; |
246 virtual void SetSupportNetworkUsage() OVERRIDE; | 248 virtual void SetSupportNetworkUsage() OVERRIDE; |
247 | 249 |
248 // Returns the pid of the child process. | 250 // Returns the pid of the child process. |
249 int process_id() const { return pid_; } | 251 int process_id() const { return pid_; } |
250 | 252 |
251 private: | 253 private: |
252 // Returns a localized title for the child process. For example, a plugin | 254 // Returns a localized title for the child process. For example, a plugin |
253 // process would be "Plug-in: Flash" when name is "Flash". | 255 // process would be "Plug-in: Flash" when name is "Flash". |
254 string16 GetLocalizedTitle() const; | 256 string16 GetLocalizedTitle() const; |
255 | 257 |
256 ChildProcessInfo child_process_; | 258 content::ProcessType type_; |
| 259 string16 name_; |
| 260 base::ProcessHandle handle_; |
257 int pid_; | 261 int pid_; |
258 mutable string16 title_; | 262 mutable string16 title_; |
259 bool network_usage_support_; | 263 bool network_usage_support_; |
260 | 264 |
261 // The icon painted for the child processs. | 265 // The icon painted for the child processs. |
262 // TODO(jcampan): we should have plugin specific icons for well-known | 266 // TODO(jcampan): we should have plugin specific icons for well-known |
263 // plugins. | 267 // plugins. |
264 static SkBitmap* default_icon_; | 268 static SkBitmap* default_icon_; |
265 | 269 |
266 DISALLOW_COPY_AND_ASSIGN(TaskManagerChildProcessResource); | 270 DISALLOW_COPY_AND_ASSIGN(TaskManagerChildProcessResource); |
267 }; | 271 }; |
268 | 272 |
269 class TaskManagerChildProcessResourceProvider | 273 class TaskManagerChildProcessResourceProvider |
270 : public TaskManager::ResourceProvider, | 274 : public TaskManager::ResourceProvider, |
271 public content::NotificationObserver { | 275 public content::NotificationObserver { |
272 public: | 276 public: |
273 explicit TaskManagerChildProcessResourceProvider(TaskManager* task_manager); | 277 explicit TaskManagerChildProcessResourceProvider(TaskManager* task_manager); |
274 | 278 |
275 virtual TaskManager::Resource* GetResource(int origin_pid, | 279 virtual TaskManager::Resource* GetResource(int origin_pid, |
276 int render_process_host_id, | 280 int render_process_host_id, |
277 int routing_id) OVERRIDE; | 281 int routing_id) OVERRIDE; |
278 virtual void StartUpdating() OVERRIDE; | 282 virtual void StartUpdating() OVERRIDE; |
279 virtual void StopUpdating() OVERRIDE; | 283 virtual void StopUpdating() OVERRIDE; |
280 | 284 |
281 // content::NotificationObserver method: | 285 // content::NotificationObserver method: |
282 virtual void Observe(int type, | 286 virtual void Observe(int type, |
283 const content::NotificationSource& source, | 287 const content::NotificationSource& source, |
284 const content::NotificationDetails& details) OVERRIDE; | 288 const content::NotificationDetails& details) OVERRIDE; |
285 | 289 |
286 // Retrieves the current ChildProcessInfo (performed in the IO thread). | 290 private: |
| 291 struct ChildProcessData { |
| 292 content::ProcessType type; |
| 293 string16 name; |
| 294 base::ProcessHandle handle; |
| 295 }; |
| 296 |
| 297 virtual ~TaskManagerChildProcessResourceProvider(); |
| 298 |
| 299 // Retrieves information about the running ChildProcessHosts (performed in the |
| 300 // IO thread). |
287 virtual void RetrieveChildProcessInfo(); | 301 virtual void RetrieveChildProcessInfo(); |
288 | 302 |
289 // Notifies the UI thread that the ChildProcessInfo have been retrieved. | 303 // Notifies the UI thread that the ChildProcessHosts information have been |
290 virtual void ChildProcessInfoRetreived(); | 304 // retrieved. |
| 305 virtual void ChildProcessInfoRetreived( |
| 306 const std::vector<ChildProcessData>& child_processes); |
| 307 |
| 308 void Add(const ChildProcessData& child_process_data); |
| 309 void Remove(const ChildProcessData& child_process_data); |
| 310 |
| 311 void AddToTaskManager(const ChildProcessData& child_process_data); |
| 312 |
| 313 TaskManager* task_manager_; |
291 | 314 |
292 // Whether we are currently reporting to the task manager. Used to ignore | 315 // Whether we are currently reporting to the task manager. Used to ignore |
293 // notifications sent after StopUpdating(). | 316 // notifications sent after StopUpdating(). |
294 bool updating_; | 317 bool updating_; |
295 | 318 |
296 // The list of ChildProcessInfo retrieved when starting the update. | |
297 std::vector<ChildProcessInfo> existing_child_process_info_; | |
298 | |
299 private: | |
300 virtual ~TaskManagerChildProcessResourceProvider(); | |
301 | |
302 void Add(const ChildProcessInfo& child_process_info); | |
303 void Remove(const ChildProcessInfo& child_process_info); | |
304 | |
305 void AddToTaskManager(const ChildProcessInfo& child_process_info); | |
306 | |
307 TaskManager* task_manager_; | |
308 | |
309 // Maps the actual resources (the ChildProcessInfo) to the Task Manager | 319 // Maps the actual resources (the ChildProcessInfo) to the Task Manager |
310 // resources. | 320 // resources. |
311 std::map<ChildProcessInfo, TaskManagerChildProcessResource*> resources_; | 321 typedef std::map<base::ProcessHandle, TaskManagerChildProcessResource*> |
| 322 ChildProcessMap; |
| 323 ChildProcessMap resources_; |
312 | 324 |
313 // Maps the pids to the resources (used for quick access to the resource on | 325 // Maps the pids to the resources (used for quick access to the resource on |
314 // byte read notifications). | 326 // byte read notifications). |
315 std::map<int, TaskManagerChildProcessResource*> pid_to_resources_; | 327 typedef std::map<int, TaskManagerChildProcessResource*> PidResourceMap; |
| 328 PidResourceMap pid_to_resources_; |
316 | 329 |
317 // A scoped container for notification registries. | 330 // A scoped container for notification registries. |
318 content::NotificationRegistrar registrar_; | 331 content::NotificationRegistrar registrar_; |
319 | 332 |
320 DISALLOW_COPY_AND_ASSIGN(TaskManagerChildProcessResourceProvider); | 333 DISALLOW_COPY_AND_ASSIGN(TaskManagerChildProcessResourceProvider); |
321 }; | 334 }; |
322 | 335 |
323 class TaskManagerExtensionProcessResource : public TaskManager::Resource { | 336 class TaskManagerExtensionProcessResource : public TaskManager::Resource { |
324 public: | 337 public: |
325 explicit TaskManagerExtensionProcessResource(ExtensionHost* extension_host); | 338 explicit TaskManagerExtensionProcessResource(ExtensionHost* extension_host); |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 virtual void StartUpdating() OVERRIDE; | 524 virtual void StartUpdating() OVERRIDE; |
512 virtual void StopUpdating() OVERRIDE; | 525 virtual void StopUpdating() OVERRIDE; |
513 | 526 |
514 // Whether we are currently reporting to the task manager. Used to ignore | 527 // Whether we are currently reporting to the task manager. Used to ignore |
515 // notifications sent after StopUpdating(). | 528 // notifications sent after StopUpdating(). |
516 bool updating_; | 529 bool updating_; |
517 | 530 |
518 private: | 531 private: |
519 virtual ~TaskManagerBrowserProcessResourceProvider(); | 532 virtual ~TaskManagerBrowserProcessResourceProvider(); |
520 | 533 |
521 void AddToTaskManager(ChildProcessInfo child_process_info); | |
522 | |
523 TaskManager* task_manager_; | 534 TaskManager* task_manager_; |
524 TaskManagerBrowserProcessResource resource_; | 535 TaskManagerBrowserProcessResource resource_; |
525 | 536 |
526 DISALLOW_COPY_AND_ASSIGN(TaskManagerBrowserProcessResourceProvider); | 537 DISALLOW_COPY_AND_ASSIGN(TaskManagerBrowserProcessResourceProvider); |
527 }; | 538 }; |
528 | 539 |
529 #endif // CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_RESOURCE_PROVIDERS_H_ | 540 #endif // CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_RESOURCE_PROVIDERS_H_ |
OLD | NEW |