| 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/memory/weak_ptr.h" |
| 10 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 12 #include "chrome/browser/process_resource_usage.h" |
| 11 #include "chrome/browser/task_manager/resource_provider.h" | 13 #include "chrome/browser/task_manager/resource_provider.h" |
| 12 #include "chrome/browser/task_manager/task_manager.h" | 14 #include "chrome/browser/task_manager/task_manager.h" |
| 13 #include "chrome/grit/generated_resources.h" | 15 #include "chrome/grit/generated_resources.h" |
| 14 #include "components/nacl/common/nacl_process_type.h" | 16 #include "components/nacl/common/nacl_process_type.h" |
| 17 #include "content/public/browser/browser_child_process_host.h" |
| 15 #include "content/public/browser/browser_child_process_host_iterator.h" | 18 #include "content/public/browser/browser_child_process_host_iterator.h" |
| 16 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/child_process_data.h" | 20 #include "content/public/browser/child_process_data.h" |
| 21 #include "content/public/common/service_registry.h" |
| 18 #include "grit/theme_resources.h" | 22 #include "grit/theme_resources.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
| 21 #include "ui/gfx/image/image_skia.h" | 25 #include "ui/gfx/image/image_skia.h" |
| 22 | 26 |
| 23 using content::BrowserChildProcessHostIterator; | 27 using content::BrowserChildProcessHostIterator; |
| 24 using content::BrowserThread; | 28 using content::BrowserThread; |
| 25 using content::WebContents; | 29 using content::WebContents; |
| 26 | 30 |
| 27 namespace task_manager { | 31 namespace task_manager { |
| 28 | 32 |
| 29 class ChildProcessResource : public Resource { | 33 class ChildProcessResource : public Resource { |
| 30 public: | 34 public: |
| 31 ChildProcessResource(int process_type, | 35 ChildProcessResource(int process_type, |
| 32 const base::string16& name, | 36 const base::string16& name, |
| 33 base::ProcessHandle handle, | 37 base::ProcessHandle handle, |
| 34 int unique_process_id); | 38 int unique_process_id); |
| 35 ~ChildProcessResource() override; | 39 ~ChildProcessResource() override; |
| 36 | 40 |
| 37 // Resource methods: | 41 // Resource methods: |
| 38 base::string16 GetTitle() const override; | 42 base::string16 GetTitle() const override; |
| 39 base::string16 GetProfileName() const override; | 43 base::string16 GetProfileName() const override; |
| 40 gfx::ImageSkia GetIcon() const override; | 44 gfx::ImageSkia GetIcon() const override; |
| 41 base::ProcessHandle GetProcess() const override; | 45 base::ProcessHandle GetProcess() const override; |
| 42 int GetUniqueChildProcessId() const override; | 46 int GetUniqueChildProcessId() const override; |
| 43 Type GetType() const override; | 47 Type GetType() const override; |
| 44 bool SupportNetworkUsage() const override; | 48 bool SupportNetworkUsage() const override; |
| 45 void SetSupportNetworkUsage() override; | 49 void SetSupportNetworkUsage() override; |
| 50 void Refresh() override; |
| 51 bool ReportsV8MemoryStats() const override; |
| 52 size_t GetV8MemoryAllocated() const override; |
| 53 size_t GetV8MemoryUsed() const override; |
| 46 | 54 |
| 47 // Returns the pid of the child process. | 55 // Returns the pid of the child process. |
| 48 int process_id() const { return pid_; } | 56 int process_id() const { return pid_; } |
| 49 | 57 |
| 50 private: | 58 private: |
| 51 // Returns a localized title for the child process. For example, a plugin | 59 // Returns a localized title for the child process. For example, a plugin |
| 52 // process would be "Plugin: Flash" when name is "Flash". | 60 // process would be "Plugin: Flash" when name is "Flash". |
| 53 base::string16 GetLocalizedTitle() const; | 61 base::string16 GetLocalizedTitle() const; |
| 54 | 62 |
| 63 static mojo::InterfacePtrInfo<ResourceUsageReporter> |
| 64 GetProcessUsageOnIOThread(int id); |
| 65 |
| 66 void OnGetProcessUsageDone( |
| 67 mojo::InterfacePtrInfo<ResourceUsageReporter> info); |
| 68 |
| 55 int process_type_; | 69 int process_type_; |
| 56 base::string16 name_; | 70 base::string16 name_; |
| 57 base::ProcessHandle handle_; | 71 base::ProcessHandle handle_; |
| 58 int pid_; | 72 int pid_; |
| 59 int unique_process_id_; | 73 int unique_process_id_; |
| 60 mutable base::string16 title_; | 74 mutable base::string16 title_; |
| 61 bool network_usage_support_; | 75 bool network_usage_support_; |
| 76 scoped_ptr<ProcessResourceUsage> resource_usage_; |
| 62 | 77 |
| 63 // The icon painted for the child processs. | 78 // The icon painted for the child processs. |
| 64 // TODO(jcampan): we should have plugin specific icons for well-known | 79 // TODO(jcampan): we should have plugin specific icons for well-known |
| 65 // plugins. | 80 // plugins. |
| 66 static gfx::ImageSkia* default_icon_; | 81 static gfx::ImageSkia* default_icon_; |
| 67 | 82 |
| 83 base::WeakPtrFactory<ChildProcessResource> weak_factory_; |
| 84 |
| 68 DISALLOW_COPY_AND_ASSIGN(ChildProcessResource); | 85 DISALLOW_COPY_AND_ASSIGN(ChildProcessResource); |
| 69 }; | 86 }; |
| 70 | 87 |
| 71 gfx::ImageSkia* ChildProcessResource::default_icon_ = NULL; | 88 gfx::ImageSkia* ChildProcessResource::default_icon_ = NULL; |
| 72 | 89 |
| 73 ChildProcessResource::ChildProcessResource( | 90 // static |
| 74 int process_type, | 91 mojo::InterfacePtrInfo<ResourceUsageReporter> |
| 75 const base::string16& name, | 92 ChildProcessResource::GetProcessUsageOnIOThread(int id) { |
| 76 base::ProcessHandle handle, | 93 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 77 int unique_process_id) | 94 content::BrowserChildProcessHost* host = |
| 95 content::BrowserChildProcessHost::FromID(id); |
| 96 if (!host) |
| 97 return mojo::InterfacePtrInfo<ResourceUsageReporter>(); |
| 98 |
| 99 content::ServiceRegistry* registry = host->GetServiceRegistry(); |
| 100 if (!registry) |
| 101 return mojo::InterfacePtrInfo<ResourceUsageReporter>(); |
| 102 |
| 103 ResourceUsageReporterPtr service; |
| 104 registry->ConnectToRemoteService(&service); |
| 105 return service.PassInterface().Pass(); |
| 106 } |
| 107 |
| 108 ChildProcessResource::ChildProcessResource(int process_type, |
| 109 const base::string16& name, |
| 110 base::ProcessHandle handle, |
| 111 int unique_process_id) |
| 78 : process_type_(process_type), | 112 : process_type_(process_type), |
| 79 name_(name), | 113 name_(name), |
| 80 handle_(handle), | 114 handle_(handle), |
| 81 unique_process_id_(unique_process_id), | 115 unique_process_id_(unique_process_id), |
| 82 network_usage_support_(false) { | 116 network_usage_support_(false), |
| 117 weak_factory_(this) { |
| 83 // We cache the process id because it's not cheap to calculate, and it won't | 118 // 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. | 119 // be available when we get the plugin disconnected notification. |
| 85 pid_ = base::GetProcId(handle); | 120 pid_ = base::GetProcId(handle); |
| 86 if (!default_icon_) { | 121 if (!default_icon_) { |
| 87 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 122 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 88 default_icon_ = rb.GetImageSkiaNamed(IDR_PLUGINS_FAVICON); | 123 default_icon_ = rb.GetImageSkiaNamed(IDR_PLUGINS_FAVICON); |
| 89 // TODO(jabdelmalek): use different icon for web workers. | 124 // TODO(jabdelmalek): use different icon for web workers. |
| 90 } | 125 } |
| 126 BrowserThread::PostTaskAndReplyWithResult( |
| 127 BrowserThread::IO, FROM_HERE, |
| 128 base::Bind(&ChildProcessResource::GetProcessUsageOnIOThread, |
| 129 unique_process_id), |
| 130 base::Bind(&ChildProcessResource::OnGetProcessUsageDone, |
| 131 weak_factory_.GetWeakPtr())); |
| 91 } | 132 } |
| 92 | 133 |
| 93 ChildProcessResource::~ChildProcessResource() { | 134 ChildProcessResource::~ChildProcessResource() { |
| 94 } | 135 } |
| 95 | 136 |
| 137 void ChildProcessResource::OnGetProcessUsageDone( |
| 138 mojo::InterfacePtrInfo<ResourceUsageReporter> info) { |
| 139 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 140 if (info.is_valid()) { |
| 141 ResourceUsageReporterPtr service; |
| 142 service.Bind(info.Pass()); |
| 143 resource_usage_.reset(new ProcessResourceUsage(service.Pass())); |
| 144 } |
| 145 } |
| 146 |
| 96 // Resource methods: | 147 // Resource methods: |
| 97 base::string16 ChildProcessResource::GetTitle() const { | 148 base::string16 ChildProcessResource::GetTitle() const { |
| 98 if (title_.empty()) | 149 if (title_.empty()) |
| 99 title_ = GetLocalizedTitle(); | 150 title_ = GetLocalizedTitle(); |
| 100 | 151 |
| 101 return title_; | 152 return title_; |
| 102 } | 153 } |
| 103 | 154 |
| 104 base::string16 ChildProcessResource::GetProfileName() const { | 155 base::string16 ChildProcessResource::GetProfileName() const { |
| 105 return base::string16(); | 156 return base::string16(); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 case content::PROCESS_TYPE_MAX: | 244 case content::PROCESS_TYPE_MAX: |
| 194 NOTREACHED(); | 245 NOTREACHED(); |
| 195 break; | 246 break; |
| 196 case content::PROCESS_TYPE_UNKNOWN: | 247 case content::PROCESS_TYPE_UNKNOWN: |
| 197 NOTREACHED() << "Need localized name for child process type."; | 248 NOTREACHED() << "Need localized name for child process type."; |
| 198 } | 249 } |
| 199 | 250 |
| 200 return title; | 251 return title; |
| 201 } | 252 } |
| 202 | 253 |
| 254 void ChildProcessResource::Refresh() { |
| 255 if (resource_usage_) |
| 256 resource_usage_->Refresh(); |
| 257 } |
| 258 |
| 259 bool ChildProcessResource::ReportsV8MemoryStats() const { |
| 260 if (resource_usage_) |
| 261 return resource_usage_->ReportsV8MemoryStats(); |
| 262 return false; |
| 263 } |
| 264 |
| 265 size_t ChildProcessResource::GetV8MemoryAllocated() const { |
| 266 if (resource_usage_) |
| 267 return resource_usage_->GetV8MemoryAllocated(); |
| 268 return 0; |
| 269 } |
| 270 |
| 271 size_t ChildProcessResource::GetV8MemoryUsed() const { |
| 272 if (resource_usage_) |
| 273 return resource_usage_->GetV8MemoryUsed(); |
| 274 return 0; |
| 275 } |
| 276 |
| 203 //////////////////////////////////////////////////////////////////////////////// | 277 //////////////////////////////////////////////////////////////////////////////// |
| 204 // ChildProcessResourceProvider class | 278 // ChildProcessResourceProvider class |
| 205 //////////////////////////////////////////////////////////////////////////////// | 279 //////////////////////////////////////////////////////////////////////////////// |
| 206 | 280 |
| 207 ChildProcessResourceProvider:: | 281 ChildProcessResourceProvider:: |
| 208 ChildProcessResourceProvider(TaskManager* task_manager) | 282 ChildProcessResourceProvider(TaskManager* task_manager) |
| 209 : task_manager_(task_manager), | 283 : task_manager_(task_manager), |
| 210 updating_(false) { | 284 updating_(false) { |
| 211 } | 285 } |
| 212 | 286 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 // This is called on the UI thread. | 401 // This is called on the UI thread. |
| 328 void ChildProcessResourceProvider::ChildProcessDataRetreived( | 402 void ChildProcessResourceProvider::ChildProcessDataRetreived( |
| 329 const std::vector<content::ChildProcessData>& child_processes) { | 403 const std::vector<content::ChildProcessData>& child_processes) { |
| 330 for (size_t i = 0; i < child_processes.size(); ++i) | 404 for (size_t i = 0; i < child_processes.size(); ++i) |
| 331 AddToTaskManager(child_processes[i]); | 405 AddToTaskManager(child_processes[i]); |
| 332 | 406 |
| 333 task_manager_->model()->NotifyDataReady(); | 407 task_manager_->model()->NotifyDataReady(); |
| 334 } | 408 } |
| 335 | 409 |
| 336 } // namespace task_manager | 410 } // namespace task_manager |
| OLD | NEW |