OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/task_manager/child_process_resource_provider.h" | 5 #include "chrome/browser/task_manager/child_process_resource_provider.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
11 #include "chrome/browser/task_manager/resource_provider.h" | 11 #include "chrome/browser/task_manager/resource_provider.h" |
12 #include "chrome/browser/task_manager/task_manager.h" | 12 #include "chrome/browser/task_manager/task_manager.h" |
13 #include "chrome/grit/generated_resources.h" | 13 #include "chrome/grit/generated_resources.h" |
14 #include "components/nacl/common/nacl_process_type.h" | 14 #include "components/nacl/common/nacl_process_type.h" |
15 #include "content/public/browser/browser_child_process_host_iterator.h" | 15 #include "content/public/browser/browser_child_process_host_iterator.h" |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/browser/child_process_data.h" | 17 #include "content/public/browser/child_process_data.h" |
| 18 #include "content/public/browser/process_resource.h" |
18 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
19 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
20 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
21 #include "ui/gfx/image/image_skia.h" | 22 #include "ui/gfx/image/image_skia.h" |
22 | 23 |
23 using content::BrowserChildProcessHostIterator; | 24 using content::BrowserChildProcessHostIterator; |
24 using content::BrowserThread; | 25 using content::BrowserThread; |
| 26 using content::ProcessResource; |
25 using content::WebContents; | 27 using content::WebContents; |
26 | 28 |
27 namespace task_manager { | 29 namespace task_manager { |
28 | 30 |
29 class ChildProcessResource : public Resource { | 31 class ChildProcessResource : public Resource { |
30 public: | 32 public: |
31 ChildProcessResource(int process_type, | 33 ChildProcessResource(int process_type, |
32 const base::string16& name, | 34 const base::string16& name, |
33 base::ProcessHandle handle, | 35 base::ProcessHandle handle, |
34 int unique_process_id); | 36 int unique_process_id, |
| 37 const scoped_refptr<ProcessResource>& process_resource); |
35 ~ChildProcessResource() override; | 38 ~ChildProcessResource() override; |
36 | 39 |
37 // Resource methods: | 40 // Resource methods: |
38 base::string16 GetTitle() const override; | 41 base::string16 GetTitle() const override; |
39 base::string16 GetProfileName() const override; | 42 base::string16 GetProfileName() const override; |
40 gfx::ImageSkia GetIcon() const override; | 43 gfx::ImageSkia GetIcon() const override; |
41 base::ProcessHandle GetProcess() const override; | 44 base::ProcessHandle GetProcess() const override; |
42 int GetUniqueChildProcessId() const override; | 45 int GetUniqueChildProcessId() const override; |
43 Type GetType() const override; | 46 Type GetType() const override; |
44 bool SupportNetworkUsage() const override; | 47 bool SupportNetworkUsage() const override; |
45 void SetSupportNetworkUsage() override; | 48 void SetSupportNetworkUsage() override; |
| 49 void Refresh() override; |
| 50 bool ReportsV8MemoryStats() const override; |
| 51 size_t GetV8MemoryAllocated() const override; |
| 52 size_t GetV8MemoryUsed() const override; |
46 | 53 |
47 // Returns the pid of the child process. | 54 // Returns the pid of the child process. |
48 int process_id() const { return pid_; } | 55 int process_id() const { return pid_; } |
49 | 56 |
50 private: | 57 private: |
51 // Returns a localized title for the child process. For example, a plugin | 58 // Returns a localized title for the child process. For example, a plugin |
52 // process would be "Plug-in: Flash" when name is "Flash". | 59 // process would be "Plug-in: Flash" when name is "Flash". |
53 base::string16 GetLocalizedTitle() const; | 60 base::string16 GetLocalizedTitle() const; |
54 | 61 |
55 int process_type_; | 62 int process_type_; |
56 base::string16 name_; | 63 base::string16 name_; |
57 base::ProcessHandle handle_; | 64 base::ProcessHandle handle_; |
58 int pid_; | 65 int pid_; |
59 int unique_process_id_; | 66 int unique_process_id_; |
60 mutable base::string16 title_; | 67 mutable base::string16 title_; |
61 bool network_usage_support_; | 68 bool network_usage_support_; |
| 69 scoped_refptr<ProcessResource> process_resource_; |
62 | 70 |
63 // The icon painted for the child processs. | 71 // The icon painted for the child processs. |
64 // TODO(jcampan): we should have plugin specific icons for well-known | 72 // TODO(jcampan): we should have plugin specific icons for well-known |
65 // plugins. | 73 // plugins. |
66 static gfx::ImageSkia* default_icon_; | 74 static gfx::ImageSkia* default_icon_; |
67 | 75 |
68 DISALLOW_COPY_AND_ASSIGN(ChildProcessResource); | 76 DISALLOW_COPY_AND_ASSIGN(ChildProcessResource); |
69 }; | 77 }; |
70 | 78 |
71 gfx::ImageSkia* ChildProcessResource::default_icon_ = NULL; | 79 gfx::ImageSkia* ChildProcessResource::default_icon_ = NULL; |
72 | 80 |
73 ChildProcessResource::ChildProcessResource( | 81 ChildProcessResource::ChildProcessResource( |
74 int process_type, | 82 int process_type, |
75 const base::string16& name, | 83 const base::string16& name, |
76 base::ProcessHandle handle, | 84 base::ProcessHandle handle, |
77 int unique_process_id) | 85 int unique_process_id, |
| 86 const scoped_refptr<ProcessResource>& process_resource) |
78 : process_type_(process_type), | 87 : process_type_(process_type), |
79 name_(name), | 88 name_(name), |
80 handle_(handle), | 89 handle_(handle), |
81 unique_process_id_(unique_process_id), | 90 unique_process_id_(unique_process_id), |
82 network_usage_support_(false) { | 91 network_usage_support_(false), |
| 92 process_resource_(process_resource) { |
83 // We cache the process id because it's not cheap to calculate, and it won't | 93 // We cache the process id because it's not cheap to calculate, and it won't |
84 // be available when we get the plugin disconnected notification. | 94 // be available when we get the plugin disconnected notification. |
85 pid_ = base::GetProcId(handle); | 95 pid_ = base::GetProcId(handle); |
86 if (!default_icon_) { | 96 if (!default_icon_) { |
87 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 97 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
88 default_icon_ = rb.GetImageSkiaNamed(IDR_PLUGINS_FAVICON); | 98 default_icon_ = rb.GetImageSkiaNamed(IDR_PLUGINS_FAVICON); |
89 // TODO(jabdelmalek): use different icon for web workers. | 99 // TODO(jabdelmalek): use different icon for web workers. |
90 } | 100 } |
91 } | 101 } |
92 | 102 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 case content::PROCESS_TYPE_MAX: | 203 case content::PROCESS_TYPE_MAX: |
194 NOTREACHED(); | 204 NOTREACHED(); |
195 break; | 205 break; |
196 case content::PROCESS_TYPE_UNKNOWN: | 206 case content::PROCESS_TYPE_UNKNOWN: |
197 NOTREACHED() << "Need localized name for child process type."; | 207 NOTREACHED() << "Need localized name for child process type."; |
198 } | 208 } |
199 | 209 |
200 return title; | 210 return title; |
201 } | 211 } |
202 | 212 |
| 213 void ChildProcessResource::Refresh() { |
| 214 if (process_resource_) |
| 215 process_resource_->Refresh(); |
| 216 } |
| 217 |
| 218 bool ChildProcessResource::ReportsV8MemoryStats() const { |
| 219 if (process_resource_) |
| 220 return process_resource_->ReportsV8MemoryStats(); |
| 221 return false; |
| 222 } |
| 223 |
| 224 size_t ChildProcessResource::GetV8MemoryAllocated() const { |
| 225 if (process_resource_) |
| 226 return process_resource_->GetV8MemoryAllocated(); |
| 227 return 0; |
| 228 } |
| 229 |
| 230 size_t ChildProcessResource::GetV8MemoryUsed() const { |
| 231 if (process_resource_) |
| 232 return process_resource_->GetV8MemoryUsed(); |
| 233 return 0; |
| 234 } |
| 235 |
203 //////////////////////////////////////////////////////////////////////////////// | 236 //////////////////////////////////////////////////////////////////////////////// |
204 // ChildProcessResourceProvider class | 237 // ChildProcessResourceProvider class |
205 //////////////////////////////////////////////////////////////////////////////// | 238 //////////////////////////////////////////////////////////////////////////////// |
206 | 239 |
207 ChildProcessResourceProvider:: | 240 ChildProcessResourceProvider:: |
208 ChildProcessResourceProvider(TaskManager* task_manager) | 241 ChildProcessResourceProvider(TaskManager* task_manager) |
209 : task_manager_(task_manager), | 242 : task_manager_(task_manager), |
210 updating_(false) { | 243 updating_(false) { |
211 } | 244 } |
212 | 245 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 delete resource; | 326 delete resource; |
294 } | 327 } |
295 | 328 |
296 void ChildProcessResourceProvider::AddToTaskManager( | 329 void ChildProcessResourceProvider::AddToTaskManager( |
297 const content::ChildProcessData& child_process_data) { | 330 const content::ChildProcessData& child_process_data) { |
298 ChildProcessResource* resource = | 331 ChildProcessResource* resource = |
299 new ChildProcessResource( | 332 new ChildProcessResource( |
300 child_process_data.process_type, | 333 child_process_data.process_type, |
301 child_process_data.name, | 334 child_process_data.name, |
302 child_process_data.handle, | 335 child_process_data.handle, |
303 child_process_data.id); | 336 child_process_data.id, |
| 337 child_process_data.process_resource); |
304 resources_[child_process_data.handle] = resource; | 338 resources_[child_process_data.handle] = resource; |
305 pid_to_resources_[resource->process_id()] = resource; | 339 pid_to_resources_[resource->process_id()] = resource; |
306 task_manager_->AddResource(resource); | 340 task_manager_->AddResource(resource); |
307 } | 341 } |
308 | 342 |
309 // The ChildProcessData::Iterator has to be used from the IO thread. | 343 // The ChildProcessData::Iterator has to be used from the IO thread. |
310 void ChildProcessResourceProvider::RetrieveChildProcessData() { | 344 void ChildProcessResourceProvider::RetrieveChildProcessData() { |
311 std::vector<content::ChildProcessData> child_processes; | 345 std::vector<content::ChildProcessData> child_processes; |
312 for (BrowserChildProcessHostIterator iter; !iter.Done(); ++iter) { | 346 for (BrowserChildProcessHostIterator iter; !iter.Done(); ++iter) { |
313 // Only add processes which are already started, since we need their handle. | 347 // Only add processes which are already started, since we need their handle. |
(...skipping 13 matching lines...) Expand all Loading... |
327 // This is called on the UI thread. | 361 // This is called on the UI thread. |
328 void ChildProcessResourceProvider::ChildProcessDataRetreived( | 362 void ChildProcessResourceProvider::ChildProcessDataRetreived( |
329 const std::vector<content::ChildProcessData>& child_processes) { | 363 const std::vector<content::ChildProcessData>& child_processes) { |
330 for (size_t i = 0; i < child_processes.size(); ++i) | 364 for (size_t i = 0; i < child_processes.size(); ++i) |
331 AddToTaskManager(child_processes[i]); | 365 AddToTaskManager(child_processes[i]); |
332 | 366 |
333 task_manager_->model()->NotifyDataReady(); | 367 task_manager_->model()->NotifyDataReady(); |
334 } | 368 } |
335 | 369 |
336 } // namespace task_manager | 370 } // namespace task_manager |
OLD | NEW |