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