| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_CHILD_PROCESS_RESOURCE_PROVIDER
_H_ | |
| 6 #define CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_CHILD_PROCESS_RESOURCE_PROVIDER
_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/string16.h" | |
| 13 #include "chrome/browser/task_manager/task_manager.h" | |
| 14 #include "content/public/browser/browser_child_process_observer.h" | |
| 15 #include "content/public/browser/child_process_data.h" | |
| 16 #include "content/public/browser/notification_registrar.h" | |
| 17 #include "content/public/common/process_type.h" | |
| 18 #include "ui/gfx/image/image_skia.h" | |
| 19 | |
| 20 class TaskManagerChildProcessResource : public TaskManager::Resource { | |
| 21 public: | |
| 22 TaskManagerChildProcessResource(int process_type, | |
| 23 const string16& name, | |
| 24 base::ProcessHandle handle, | |
| 25 int unique_process_id); | |
| 26 virtual ~TaskManagerChildProcessResource(); | |
| 27 | |
| 28 // TaskManager::Resource methods: | |
| 29 virtual string16 GetTitle() const OVERRIDE; | |
| 30 virtual string16 GetProfileName() const OVERRIDE; | |
| 31 virtual gfx::ImageSkia GetIcon() const OVERRIDE; | |
| 32 virtual base::ProcessHandle GetProcess() const OVERRIDE; | |
| 33 virtual int GetUniqueChildProcessId() const OVERRIDE; | |
| 34 virtual Type GetType() const OVERRIDE; | |
| 35 virtual bool SupportNetworkUsage() const OVERRIDE; | |
| 36 virtual void SetSupportNetworkUsage() OVERRIDE; | |
| 37 | |
| 38 // Returns the pid of the child process. | |
| 39 int process_id() const { return pid_; } | |
| 40 | |
| 41 private: | |
| 42 // Returns a localized title for the child process. For example, a plugin | |
| 43 // process would be "Plug-in: Flash" when name is "Flash". | |
| 44 string16 GetLocalizedTitle() const; | |
| 45 | |
| 46 int process_type_; | |
| 47 string16 name_; | |
| 48 base::ProcessHandle handle_; | |
| 49 int pid_; | |
| 50 int unique_process_id_; | |
| 51 mutable string16 title_; | |
| 52 bool network_usage_support_; | |
| 53 | |
| 54 // The icon painted for the child processs. | |
| 55 // TODO(jcampan): we should have plugin specific icons for well-known | |
| 56 // plugins. | |
| 57 static gfx::ImageSkia* default_icon_; | |
| 58 | |
| 59 DISALLOW_COPY_AND_ASSIGN(TaskManagerChildProcessResource); | |
| 60 }; | |
| 61 | |
| 62 class TaskManagerChildProcessResourceProvider | |
| 63 : public TaskManager::ResourceProvider, | |
| 64 public content::BrowserChildProcessObserver { | |
| 65 public: | |
| 66 explicit TaskManagerChildProcessResourceProvider(TaskManager* task_manager); | |
| 67 | |
| 68 virtual TaskManager::Resource* GetResource(int origin_pid, | |
| 69 int render_process_host_id, | |
| 70 int routing_id) OVERRIDE; | |
| 71 virtual void StartUpdating() OVERRIDE; | |
| 72 virtual void StopUpdating() OVERRIDE; | |
| 73 | |
| 74 // content::BrowserChildProcessObserver methods: | |
| 75 virtual void BrowserChildProcessHostConnected( | |
| 76 const content::ChildProcessData& data) OVERRIDE; | |
| 77 virtual void BrowserChildProcessHostDisconnected( | |
| 78 const content::ChildProcessData& data) OVERRIDE; | |
| 79 | |
| 80 private: | |
| 81 virtual ~TaskManagerChildProcessResourceProvider(); | |
| 82 | |
| 83 // Retrieves information about the running ChildProcessHosts (performed in the | |
| 84 // IO thread). | |
| 85 virtual void RetrieveChildProcessData(); | |
| 86 | |
| 87 // Notifies the UI thread that the ChildProcessHosts information have been | |
| 88 // retrieved. | |
| 89 virtual void ChildProcessDataRetreived( | |
| 90 const std::vector<content::ChildProcessData>& child_processes); | |
| 91 | |
| 92 void AddToTaskManager(const content::ChildProcessData& child_process_data); | |
| 93 | |
| 94 TaskManager* task_manager_; | |
| 95 | |
| 96 // Whether we are currently reporting to the task manager. Used to ignore | |
| 97 // notifications sent after StopUpdating(). | |
| 98 bool updating_; | |
| 99 | |
| 100 // Maps the actual resources (the ChildProcessData) to the Task Manager | |
| 101 // resources. | |
| 102 typedef std::map<base::ProcessHandle, TaskManagerChildProcessResource*> | |
| 103 ChildProcessMap; | |
| 104 ChildProcessMap resources_; | |
| 105 | |
| 106 // Maps the pids to the resources (used for quick access to the resource on | |
| 107 // byte read notifications). | |
| 108 typedef std::map<int, TaskManagerChildProcessResource*> PidResourceMap; | |
| 109 PidResourceMap pid_to_resources_; | |
| 110 | |
| 111 // A scoped container for notification registries. | |
| 112 content::NotificationRegistrar registrar_; | |
| 113 | |
| 114 DISALLOW_COPY_AND_ASSIGN(TaskManagerChildProcessResourceProvider); | |
| 115 }; | |
| 116 | |
| 117 #endif // CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_CHILD_PROCESS_RESOURCE_PROVI
DER_H_ | |
| OLD | NEW |