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