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] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 74 | DISALLOW_COPY_AND_ASSIGN(TaskManagerWebContentsResourceProvider); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 75 | }; |
| 76 | |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame^] | 77 | class TaskManagerChildProcessResource : public TaskManager::Resource { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 78 | public: |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame^] | 79 | explicit TaskManagerChildProcessResource(ChildProcessInfo child_proc); |
| 80 | ~TaskManagerChildProcessResource(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 81 | |
| 82 | // TaskManagerResource methods: |
| 83 | std::wstring GetTitle() const; |
| 84 | SkBitmap GetIcon() const; |
| 85 | HANDLE GetProcess() const; |
| 86 | |
| 87 | bool SupportNetworkUsage() const { |
| 88 | return network_usage_support_; |
| 89 | } |
| 90 | |
| 91 | void SetSupportNetworkUsage() { |
| 92 | network_usage_support_ = true; |
| 93 | } |
| 94 | |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame^] | 95 | // Returns the pid of the child process. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 96 | int process_id() const { return pid_; } |
| 97 | |
| 98 | private: |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame^] | 99 | ChildProcessInfo child_process_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 100 | int pid_; |
| 101 | mutable std::wstring title_; |
| 102 | bool network_usage_support_; |
| 103 | |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame^] | 104 | // The icon painted for the child processs. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 105 | // TODO (jcampan): we should have plugin specific icons for well-known |
| 106 | // plugins. |
| 107 | static SkBitmap* default_icon_; |
| 108 | |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame^] | 109 | DISALLOW_COPY_AND_ASSIGN(TaskManagerChildProcessResource); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 110 | }; |
| 111 | |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame^] | 112 | class TaskManagerChildProcessResourceProvider |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 113 | : public TaskManager::ResourceProvider, |
| 114 | public NotificationObserver { |
| 115 | public: |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame^] | 116 | explicit TaskManagerChildProcessResourceProvider(TaskManager* task_manager); |
| 117 | virtual ~TaskManagerChildProcessResourceProvider(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 118 | |
| 119 | virtual TaskManager::Resource* GetResource(int origin_pid, |
| 120 | int render_process_host_id, |
| 121 | int routing_id); |
| 122 | virtual void StartUpdating(); |
| 123 | virtual void StopUpdating(); |
| 124 | |
| 125 | // NotificationObserver method: |
| 126 | virtual void Observe(NotificationType type, |
| 127 | const NotificationSource& source, |
| 128 | const NotificationDetails& details); |
| 129 | |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame^] | 130 | // Retrieves the current ChildProcessInfo (performed in the IO thread). |
| 131 | virtual void RetrieveChildProcessInfo(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 132 | |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame^] | 133 | // Notifies the UI thread that the ChildProcessInfo have been retrieved. |
| 134 | virtual void ChildProcessInfoRetreived(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 135 | |
| 136 | // Whether we are currently reporting to the task manager. Used to ignore |
| 137 | // notifications sent after StopUpdating(). |
| 138 | bool updating_; |
| 139 | |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame^] | 140 | // The list of ChildProcessInfo retrieved when starting the update. |
| 141 | std::vector<ChildProcessInfo> existing_child_process_info_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 142 | |
| 143 | private: |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame^] | 144 | void Add(ChildProcessInfo child_process_info); |
| 145 | void Remove(ChildProcessInfo child_process_info); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 146 | |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame^] | 147 | void AddToTaskManager(ChildProcessInfo child_process_info); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 148 | |
| 149 | TaskManager* task_manager_; |
| 150 | |
| 151 | MessageLoop* ui_loop_; |
| 152 | |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame^] | 153 | // Maps the actual resources (the ChildProcessInfo) to the Task Manager |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 154 | // resources. |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame^] | 155 | std::map<ChildProcessInfo, TaskManagerChildProcessResource*> resources_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 156 | |
| 157 | // Maps the pids to the resources (used for quick access to the resource on |
| 158 | // byte read notifications). |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame^] | 159 | std::map<int, TaskManagerChildProcessResource*> pid_to_resources_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 160 | |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame^] | 161 | DISALLOW_COPY_AND_ASSIGN(TaskManagerChildProcessResourceProvider); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 162 | }; |
| 163 | |
| 164 | class TaskManagerBrowserProcessResource : public TaskManager::Resource { |
| 165 | public: |
| 166 | TaskManagerBrowserProcessResource(); |
| 167 | ~TaskManagerBrowserProcessResource(); |
| 168 | |
| 169 | // TaskManagerResource methods: |
| 170 | std::wstring GetTitle() const; |
| 171 | SkBitmap GetIcon() const; |
| 172 | HANDLE GetProcess() const; |
| 173 | |
| 174 | bool SupportNetworkUsage() const { |
| 175 | return network_usage_support_; |
| 176 | } |
| 177 | |
| 178 | void SetSupportNetworkUsage() { |
| 179 | network_usage_support_ = true; |
| 180 | } |
| 181 | |
| 182 | // Returns the pid of the browser process. |
| 183 | int process_id() const { return pid_; } |
| 184 | |
| 185 | private: |
| 186 | HANDLE process_; |
| 187 | int pid_; |
| 188 | bool network_usage_support_; |
| 189 | mutable std::wstring title_; |
| 190 | |
| 191 | static SkBitmap* default_icon_; |
| 192 | |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 193 | DISALLOW_COPY_AND_ASSIGN(TaskManagerBrowserProcessResource); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 194 | }; |
| 195 | |
| 196 | class TaskManagerBrowserProcessResourceProvider |
| 197 | : public TaskManager::ResourceProvider { |
| 198 | public: |
| 199 | explicit TaskManagerBrowserProcessResourceProvider( |
| 200 | TaskManager* task_manager); |
| 201 | virtual ~TaskManagerBrowserProcessResourceProvider(); |
| 202 | |
| 203 | virtual TaskManager::Resource* GetResource(int origin_pid, |
| 204 | int render_process_host_id, |
| 205 | int routing_id); |
| 206 | virtual void StartUpdating(); |
| 207 | virtual void StopUpdating(); |
| 208 | |
| 209 | // Whether we are currently reporting to the task manager. Used to ignore |
| 210 | // notifications sent after StopUpdating(). |
| 211 | bool updating_; |
| 212 | |
| 213 | private: |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame^] | 214 | void AddToTaskManager(ChildProcessInfo child_process_info); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 215 | |
| 216 | TaskManager* task_manager_; |
| 217 | TaskManagerBrowserProcessResource resource_; |
| 218 | |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 219 | DISALLOW_COPY_AND_ASSIGN(TaskManagerBrowserProcessResourceProvider); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 220 | }; |
| 221 | |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 222 | #endif // CHROME_BROWSER_TASK_MANAGER_RESOURCE_PROVIDERS_H_ |