| 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/memory/weak_ptr.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 size_t GetV8MemoryUsed() const override; | 53 size_t GetV8MemoryUsed() const override; |
| 54 | 54 |
| 55 // Returns the pid of the child process. | 55 // Returns the pid of the child process. |
| 56 int process_id() const { return pid_; } | 56 int process_id() const { return pid_; } |
| 57 | 57 |
| 58 private: | 58 private: |
| 59 // 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 |
| 60 // process would be "Plugin: Flash" when name is "Flash". | 60 // process would be "Plugin: Flash" when name is "Flash". |
| 61 base::string16 GetLocalizedTitle() const; | 61 base::string16 GetLocalizedTitle() const; |
| 62 | 62 |
| 63 static mojo::InterfacePtrInfo<ResourceUsageReporter> | 63 static void ConnectResourceReporterOnIOThread( |
| 64 GetProcessUsageOnIOThread(int id); | 64 int id, mojo::InterfaceRequest<ResourceUsageReporter> req); |
| 65 | |
| 66 void OnGetProcessUsageDone( | |
| 67 mojo::InterfacePtrInfo<ResourceUsageReporter> info); | |
| 68 | 65 |
| 69 int process_type_; | 66 int process_type_; |
| 70 base::string16 name_; | 67 base::string16 name_; |
| 71 base::ProcessHandle handle_; | 68 base::ProcessHandle handle_; |
| 72 int pid_; | 69 int pid_; |
| 73 int unique_process_id_; | 70 int unique_process_id_; |
| 74 mutable base::string16 title_; | 71 mutable base::string16 title_; |
| 75 bool network_usage_support_; | 72 bool network_usage_support_; |
| 76 scoped_ptr<ProcessResourceUsage> resource_usage_; | 73 scoped_ptr<ProcessResourceUsage> resource_usage_; |
| 77 | 74 |
| 78 // The icon painted for the child processs. | 75 // The icon painted for the child processs. |
| 79 // TODO(jcampan): we should have plugin specific icons for well-known | 76 // TODO(jcampan): we should have plugin specific icons for well-known |
| 80 // plugins. | 77 // plugins. |
| 81 static gfx::ImageSkia* default_icon_; | 78 static gfx::ImageSkia* default_icon_; |
| 82 | 79 |
| 83 base::WeakPtrFactory<ChildProcessResource> weak_factory_; | 80 base::WeakPtrFactory<ChildProcessResource> weak_factory_; |
| 84 | 81 |
| 85 DISALLOW_COPY_AND_ASSIGN(ChildProcessResource); | 82 DISALLOW_COPY_AND_ASSIGN(ChildProcessResource); |
| 86 }; | 83 }; |
| 87 | 84 |
| 88 gfx::ImageSkia* ChildProcessResource::default_icon_ = NULL; | 85 gfx::ImageSkia* ChildProcessResource::default_icon_ = NULL; |
| 89 | 86 |
| 90 // static | 87 // static |
| 91 mojo::InterfacePtrInfo<ResourceUsageReporter> | 88 void ChildProcessResource::ConnectResourceReporterOnIOThread( |
| 92 ChildProcessResource::GetProcessUsageOnIOThread(int id) { | 89 int id, mojo::InterfaceRequest<ResourceUsageReporter> req) { |
| 93 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 90 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 94 content::BrowserChildProcessHost* host = | 91 content::BrowserChildProcessHost* host = |
| 95 content::BrowserChildProcessHost::FromID(id); | 92 content::BrowserChildProcessHost::FromID(id); |
| 96 if (!host) | 93 if (!host) |
| 97 return mojo::InterfacePtrInfo<ResourceUsageReporter>(); | 94 return; |
| 98 | 95 |
| 99 content::ServiceRegistry* registry = host->GetServiceRegistry(); | 96 content::ServiceRegistry* registry = host->GetServiceRegistry(); |
| 100 if (!registry) | 97 if (!registry) |
| 101 return mojo::InterfacePtrInfo<ResourceUsageReporter>(); | 98 return; |
| 102 | 99 |
| 103 ResourceUsageReporterPtr service; | 100 registry->ConnectToRemoteService(req.Pass()); |
| 104 registry->ConnectToRemoteService(&service); | |
| 105 return service.PassInterface().Pass(); | |
| 106 } | 101 } |
| 107 | 102 |
| 108 ChildProcessResource::ChildProcessResource(int process_type, | 103 ChildProcessResource::ChildProcessResource(int process_type, |
| 109 const base::string16& name, | 104 const base::string16& name, |
| 110 base::ProcessHandle handle, | 105 base::ProcessHandle handle, |
| 111 int unique_process_id) | 106 int unique_process_id) |
| 112 : process_type_(process_type), | 107 : process_type_(process_type), |
| 113 name_(name), | 108 name_(name), |
| 114 handle_(handle), | 109 handle_(handle), |
| 115 unique_process_id_(unique_process_id), | 110 unique_process_id_(unique_process_id), |
| 116 network_usage_support_(false), | 111 network_usage_support_(false), |
| 117 weak_factory_(this) { | 112 weak_factory_(this) { |
| 118 // We cache the process id because it's not cheap to calculate, and it won't | 113 // We cache the process id because it's not cheap to calculate, and it won't |
| 119 // be available when we get the plugin disconnected notification. | 114 // be available when we get the plugin disconnected notification. |
| 120 pid_ = base::GetProcId(handle); | 115 pid_ = base::GetProcId(handle); |
| 121 if (!default_icon_) { | 116 if (!default_icon_) { |
| 122 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 117 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 123 default_icon_ = rb.GetImageSkiaNamed(IDR_PLUGINS_FAVICON); | 118 default_icon_ = rb.GetImageSkiaNamed(IDR_PLUGINS_FAVICON); |
| 124 // TODO(jabdelmalek): use different icon for web workers. | 119 // TODO(jabdelmalek): use different icon for web workers. |
| 125 } | 120 } |
| 126 BrowserThread::PostTaskAndReplyWithResult( | 121 ResourceUsageReporterPtr service; |
| 122 mojo::InterfaceRequest<ResourceUsageReporter> request = |
| 123 mojo::GetProxy(&service); |
| 124 BrowserThread::PostTask( |
| 127 BrowserThread::IO, FROM_HERE, | 125 BrowserThread::IO, FROM_HERE, |
| 128 base::Bind(&ChildProcessResource::GetProcessUsageOnIOThread, | 126 base::Bind(&ChildProcessResource::ConnectResourceReporterOnIOThread, |
| 129 unique_process_id), | 127 unique_process_id, base::Passed(&request))); |
| 130 base::Bind(&ChildProcessResource::OnGetProcessUsageDone, | 128 resource_usage_.reset(new ProcessResourceUsage(service.Pass())); |
| 131 weak_factory_.GetWeakPtr())); | |
| 132 } | 129 } |
| 133 | 130 |
| 134 ChildProcessResource::~ChildProcessResource() { | 131 ChildProcessResource::~ChildProcessResource() { |
| 135 } | 132 } |
| 136 | 133 |
| 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 | |
| 147 // Resource methods: | 134 // Resource methods: |
| 148 base::string16 ChildProcessResource::GetTitle() const { | 135 base::string16 ChildProcessResource::GetTitle() const { |
| 149 if (title_.empty()) | 136 if (title_.empty()) |
| 150 title_ = GetLocalizedTitle(); | 137 title_ = GetLocalizedTitle(); |
| 151 | 138 |
| 152 return title_; | 139 return title_; |
| 153 } | 140 } |
| 154 | 141 |
| 155 base::string16 ChildProcessResource::GetProfileName() const { | 142 base::string16 ChildProcessResource::GetProfileName() const { |
| 156 return base::string16(); | 143 return base::string16(); |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 // This is called on the UI thread. | 388 // This is called on the UI thread. |
| 402 void ChildProcessResourceProvider::ChildProcessDataRetreived( | 389 void ChildProcessResourceProvider::ChildProcessDataRetreived( |
| 403 const std::vector<content::ChildProcessData>& child_processes) { | 390 const std::vector<content::ChildProcessData>& child_processes) { |
| 404 for (size_t i = 0; i < child_processes.size(); ++i) | 391 for (size_t i = 0; i < child_processes.size(); ++i) |
| 405 AddToTaskManager(child_processes[i]); | 392 AddToTaskManager(child_processes[i]); |
| 406 | 393 |
| 407 task_manager_->model()->NotifyDataReady(); | 394 task_manager_->model()->NotifyDataReady(); |
| 408 } | 395 } |
| 409 | 396 |
| 410 } // namespace task_manager | 397 } // namespace task_manager |
| OLD | NEW |