Chromium Code Reviews| Index: chrome/browser/task_manager/child_process_resource_provider.cc |
| diff --git a/chrome/browser/task_manager/child_process_resource_provider.cc b/chrome/browser/task_manager/child_process_resource_provider.cc |
| index bf74138859e5f6f83281fd1ff163b236542c0d3f..2273305436f4358c4561ed9c932c597fd5fa408d 100644 |
| --- a/chrome/browser/task_manager/child_process_resource_provider.cc |
| +++ b/chrome/browser/task_manager/child_process_resource_provider.cc |
| @@ -7,14 +7,18 @@ |
| #include <vector> |
| #include "base/i18n/rtl.h" |
| +#include "base/memory/weak_ptr.h" |
| #include "base/strings/string16.h" |
| #include "chrome/browser/task_manager/resource_provider.h" |
| #include "chrome/browser/task_manager/task_manager.h" |
| #include "chrome/grit/generated_resources.h" |
| #include "components/nacl/common/nacl_process_type.h" |
| +#include "content/public/browser/browser_child_process_host.h" |
| #include "content/public/browser/browser_child_process_host_iterator.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/child_process_data.h" |
| +#include "content/public/browser/process_resource_usage.h" |
| +#include "content/public/common/service_registry.h" |
| #include "grit/theme_resources.h" |
| #include "ui/base/l10n/l10n_util.h" |
| #include "ui/base/resource/resource_bundle.h" |
| @@ -22,6 +26,7 @@ |
| using content::BrowserChildProcessHostIterator; |
| using content::BrowserThread; |
| +using content::ProcessResourceUsage; |
| using content::WebContents; |
| namespace task_manager { |
| @@ -43,6 +48,10 @@ class ChildProcessResource : public Resource { |
| Type GetType() const override; |
| bool SupportNetworkUsage() const override; |
| void SetSupportNetworkUsage() override; |
| + void Refresh() override; |
| + bool ReportsV8MemoryStats() const override; |
| + size_t GetV8MemoryAllocated() const override; |
| + size_t GetV8MemoryUsed() const override; |
| // Returns the pid of the child process. |
| int process_id() const { return pid_; } |
| @@ -52,6 +61,12 @@ class ChildProcessResource : public Resource { |
| // process would be "Plugin: Flash" when name is "Flash". |
| base::string16 GetLocalizedTitle() const; |
| + static void GetProcessUsageOnIOThread( |
| + int id, base::WeakPtr<ChildProcessResource> weak_ptr); |
| + |
| + void OnGetProcessUsageDone( |
| + mojo::InterfacePtrInfo<content::ResourceUsageReporter> info); |
| + |
| int process_type_; |
| base::string16 name_; |
| base::ProcessHandle handle_; |
| @@ -59,17 +74,43 @@ class ChildProcessResource : public Resource { |
| int unique_process_id_; |
| mutable base::string16 title_; |
| bool network_usage_support_; |
| + scoped_ptr<ProcessResourceUsage> resource_usage_; |
| // The icon painted for the child processs. |
| // TODO(jcampan): we should have plugin specific icons for well-known |
| // plugins. |
| static gfx::ImageSkia* default_icon_; |
| + base::WeakPtrFactory<ChildProcessResource> weak_factory_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(ChildProcessResource); |
| }; |
| gfx::ImageSkia* ChildProcessResource::default_icon_ = NULL; |
| +// static |
| +void ChildProcessResource::GetProcessUsageOnIOThread( |
|
afakhry
2015/05/06 17:16:27
What do you think of moving the functionality of:
ncarter (slow)
2015/05/07 20:12:44
GetProcessUsageInfo probably can move into Process
Anand Mistry (off Chromium)
2015/05/11 05:41:31
Apart from PostTaskAndReplyWithResult, I'm going t
ncarter (slow)
2015/05/11 20:35:39
I'm fine with the compromise you've struck. My ini
|
| + int id, base::WeakPtr<ChildProcessResource> weak_ptr) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + content::BrowserChildProcessHost* host = |
| + content::BrowserChildProcessHost::Get(id); |
| + if (!host) |
| + return; |
| + |
| + content::ServiceRegistry* registry = host->GetServiceRegistry(); |
| + if (!registry) |
| + return; |
| + |
| + content::ResourceUsageReporterPtr service; |
| + registry->ConnectToRemoteService(&service); |
| + auto interface_info = service.PassInterface(); |
| + BrowserThread::PostTask( |
| + BrowserThread::UI, FROM_HERE, |
| + base::Bind( |
| + &ChildProcessResource::OnGetProcessUsageDone, |
| + weak_ptr, base::Passed(&interface_info))); |
| +} |
| + |
| ChildProcessResource::ChildProcessResource( |
| int process_type, |
| const base::string16& name, |
| @@ -79,7 +120,8 @@ ChildProcessResource::ChildProcessResource( |
| name_(name), |
| handle_(handle), |
| unique_process_id_(unique_process_id), |
| - network_usage_support_(false) { |
| + network_usage_support_(false), |
| + weak_factory_(this) { |
| // We cache the process id because it's not cheap to calculate, and it won't |
| // be available when we get the plugin disconnected notification. |
| pid_ = base::GetProcId(handle); |
| @@ -88,11 +130,26 @@ ChildProcessResource::ChildProcessResource( |
| default_icon_ = rb.GetImageSkiaNamed(IDR_PLUGINS_FAVICON); |
| // TODO(jabdelmalek): use different icon for web workers. |
| } |
| + BrowserThread::PostTask( |
|
ncarter (slow)
2015/05/07 20:12:43
It might work well to structure this as a PostTask
Anand Mistry (off Chromium)
2015/05/11 05:41:31
Done.
Aside: Many of Mojo's types are move-only,
ncarter (slow)
2015/05/11 20:35:40
Great to know, thanks!
|
| + BrowserThread::IO, FROM_HERE, |
| + base::Bind( |
| + &ChildProcessResource::GetProcessUsageOnIOThread, |
| + unique_process_id, weak_factory_.GetWeakPtr())); |
| } |
| ChildProcessResource::~ChildProcessResource() { |
| } |
| +void ChildProcessResource::OnGetProcessUsageDone( |
| + mojo::InterfacePtrInfo<content::ResourceUsageReporter> info) { |
|
ncarter (slow)
2015/05/07 20:12:43
Just curious -- do we expect that this approach wi
Anand Mistry (off Chromium)
2015/05/11 05:41:31
Yes. I see no reason why this wouldn't work. Creat
ncarter (slow)
2015/05/11 20:35:40
Excellent.
|
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + if (info.is_valid()) { |
| + content::ResourceUsageReporterPtr service; |
| + service.Bind(info.Pass()); |
| + resource_usage_ = content::ProcessResourceUsage::Create(service.Pass()); |
| + } |
| +} |
| + |
| // Resource methods: |
| base::string16 ChildProcessResource::GetTitle() const { |
| if (title_.empty()) |
| @@ -200,6 +257,29 @@ base::string16 ChildProcessResource::GetLocalizedTitle() const { |
| return title; |
| } |
| +void ChildProcessResource::Refresh() { |
| + if (resource_usage_) |
| + resource_usage_->Refresh(); |
|
afakhry
2015/05/06 17:16:27
Is it possible if you add a callback of type:
void
ncarter (slow)
2015/05/07 20:12:43
amistry has addressed this to my satisfaction in a
|
| +} |
| + |
| +bool ChildProcessResource::ReportsV8MemoryStats() const { |
| + if (resource_usage_) |
|
ncarter (slow)
2015/05/07 20:12:43
It's not clear if a |resource_usage_| will be succ
Anand Mistry (off Chromium)
2015/05/11 05:41:31
If the process host has a ServiceRegistry, then ye
ncarter (slow)
2015/05/11 20:35:40
Acknowledged.
|
| + return resource_usage_->ReportsV8MemoryStats(); |
| + return false; |
| +} |
| + |
| +size_t ChildProcessResource::GetV8MemoryAllocated() const { |
| + if (resource_usage_) |
| + return resource_usage_->GetV8MemoryAllocated(); |
| + return 0; |
| +} |
| + |
| +size_t ChildProcessResource::GetV8MemoryUsed() const { |
| + if (resource_usage_) |
| + return resource_usage_->GetV8MemoryUsed(); |
| + return 0; |
| +} |
| + |
| //////////////////////////////////////////////////////////////////////////////// |
| // ChildProcessResourceProvider class |
| //////////////////////////////////////////////////////////////////////////////// |