| 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" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 using content::BrowserThread; | 24 using content::BrowserThread; |
| 25 using content::WebContents; | 25 using content::WebContents; |
| 26 | 26 |
| 27 namespace task_manager { | 27 namespace task_manager { |
| 28 | 28 |
| 29 class ChildProcessResource : public Resource { | 29 class ChildProcessResource : public Resource { |
| 30 public: | 30 public: |
| 31 ChildProcessResource(int process_type, | 31 ChildProcessResource(int process_type, |
| 32 const base::string16& name, | 32 const base::string16& name, |
| 33 base::ProcessHandle handle, | 33 base::ProcessHandle handle, |
| 34 int unique_process_id); | 34 int unique_process_id, |
| 35 int nacl_debug_stub_port); |
| 35 virtual ~ChildProcessResource(); | 36 virtual ~ChildProcessResource(); |
| 36 | 37 |
| 37 // Resource methods: | 38 // Resource methods: |
| 39 virtual int GetNaClDebugStubPort() const OVERRIDE; |
| 38 virtual base::string16 GetTitle() const OVERRIDE; | 40 virtual base::string16 GetTitle() const OVERRIDE; |
| 39 virtual base::string16 GetProfileName() const OVERRIDE; | 41 virtual base::string16 GetProfileName() const OVERRIDE; |
| 40 virtual gfx::ImageSkia GetIcon() const OVERRIDE; | 42 virtual gfx::ImageSkia GetIcon() const OVERRIDE; |
| 41 virtual base::ProcessHandle GetProcess() const OVERRIDE; | 43 virtual base::ProcessHandle GetProcess() const OVERRIDE; |
| 42 virtual int GetUniqueChildProcessId() const OVERRIDE; | 44 virtual int GetUniqueChildProcessId() const OVERRIDE; |
| 43 virtual Type GetType() const OVERRIDE; | 45 virtual Type GetType() const OVERRIDE; |
| 44 virtual bool SupportNetworkUsage() const OVERRIDE; | 46 virtual bool SupportNetworkUsage() const OVERRIDE; |
| 45 virtual void SetSupportNetworkUsage() OVERRIDE; | 47 virtual void SetSupportNetworkUsage() OVERRIDE; |
| 46 | 48 |
| 47 // Returns the pid of the child process. | 49 // Returns the pid of the child process. |
| 48 int process_id() const { return pid_; } | 50 int process_id() const { return pid_; } |
| 49 | 51 |
| 50 private: | 52 private: |
| 51 // Returns a localized title for the child process. For example, a plugin | 53 // Returns a localized title for the child process. For example, a plugin |
| 52 // process would be "Plug-in: Flash" when name is "Flash". | 54 // process would be "Plug-in: Flash" when name is "Flash". |
| 53 base::string16 GetLocalizedTitle() const; | 55 base::string16 GetLocalizedTitle() const; |
| 54 | 56 |
| 55 int process_type_; | 57 int process_type_; |
| 56 base::string16 name_; | 58 base::string16 name_; |
| 57 base::ProcessHandle handle_; | 59 base::ProcessHandle handle_; |
| 58 int pid_; | 60 int pid_; |
| 59 int unique_process_id_; | 61 int unique_process_id_; |
| 62 int nacl_debug_stub_port_; |
| 60 mutable base::string16 title_; | 63 mutable base::string16 title_; |
| 61 bool network_usage_support_; | 64 bool network_usage_support_; |
| 62 | 65 |
| 63 // The icon painted for the child processs. | 66 // The icon painted for the child processs. |
| 64 // TODO(jcampan): we should have plugin specific icons for well-known | 67 // TODO(jcampan): we should have plugin specific icons for well-known |
| 65 // plugins. | 68 // plugins. |
| 66 static gfx::ImageSkia* default_icon_; | 69 static gfx::ImageSkia* default_icon_; |
| 67 | 70 |
| 68 DISALLOW_COPY_AND_ASSIGN(ChildProcessResource); | 71 DISALLOW_COPY_AND_ASSIGN(ChildProcessResource); |
| 69 }; | 72 }; |
| 70 | 73 |
| 71 gfx::ImageSkia* ChildProcessResource::default_icon_ = NULL; | 74 gfx::ImageSkia* ChildProcessResource::default_icon_ = NULL; |
| 72 | 75 |
| 73 ChildProcessResource::ChildProcessResource( | 76 ChildProcessResource::ChildProcessResource( |
| 74 int process_type, | 77 int process_type, |
| 75 const base::string16& name, | 78 const base::string16& name, |
| 76 base::ProcessHandle handle, | 79 base::ProcessHandle handle, |
| 77 int unique_process_id) | 80 int unique_process_id, |
| 81 int nacl_debug_stub_port) |
| 78 : process_type_(process_type), | 82 : process_type_(process_type), |
| 79 name_(name), | 83 name_(name), |
| 80 handle_(handle), | 84 handle_(handle), |
| 81 unique_process_id_(unique_process_id), | 85 unique_process_id_(unique_process_id), |
| 86 nacl_debug_stub_port_(nacl_debug_stub_port), |
| 82 network_usage_support_(false) { | 87 network_usage_support_(false) { |
| 83 // We cache the process id because it's not cheap to calculate, and it won't | 88 // 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. | 89 // be available when we get the plugin disconnected notification. |
| 85 pid_ = base::GetProcId(handle); | 90 pid_ = base::GetProcId(handle); |
| 86 if (!default_icon_) { | 91 if (!default_icon_) { |
| 87 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 92 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 88 default_icon_ = rb.GetImageSkiaNamed(IDR_PLUGINS_FAVICON); | 93 default_icon_ = rb.GetImageSkiaNamed(IDR_PLUGINS_FAVICON); |
| 89 // TODO(jabdelmalek): use different icon for web workers. | 94 // TODO(jabdelmalek): use different icon for web workers. |
| 90 } | 95 } |
| 91 } | 96 } |
| 92 | 97 |
| 93 ChildProcessResource::~ChildProcessResource() { | 98 ChildProcessResource::~ChildProcessResource() { |
| 94 } | 99 } |
| 95 | 100 |
| 96 // Resource methods: | 101 // Resource methods: |
| 102 int ChildProcessResource::GetNaClDebugStubPort() const { |
| 103 return nacl_debug_stub_port_; |
| 104 } |
| 105 |
| 97 base::string16 ChildProcessResource::GetTitle() const { | 106 base::string16 ChildProcessResource::GetTitle() const { |
| 98 if (title_.empty()) | 107 if (title_.empty()) |
| 99 title_ = GetLocalizedTitle(); | 108 title_ = GetLocalizedTitle(); |
| 100 | 109 |
| 101 return title_; | 110 return title_; |
| 102 } | 111 } |
| 103 | 112 |
| 104 base::string16 ChildProcessResource::GetProfileName() const { | 113 base::string16 ChildProcessResource::GetProfileName() const { |
| 105 return base::string16(); | 114 return base::string16(); |
| 106 } | 115 } |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 delete resource; | 311 delete resource; |
| 303 } | 312 } |
| 304 | 313 |
| 305 void ChildProcessResourceProvider::AddToTaskManager( | 314 void ChildProcessResourceProvider::AddToTaskManager( |
| 306 const content::ChildProcessData& child_process_data) { | 315 const content::ChildProcessData& child_process_data) { |
| 307 ChildProcessResource* resource = | 316 ChildProcessResource* resource = |
| 308 new ChildProcessResource( | 317 new ChildProcessResource( |
| 309 child_process_data.process_type, | 318 child_process_data.process_type, |
| 310 child_process_data.name, | 319 child_process_data.name, |
| 311 child_process_data.handle, | 320 child_process_data.handle, |
| 312 child_process_data.id); | 321 child_process_data.id, |
| 322 child_process_data.nacl_debug_stub_port); |
| 313 resources_[child_process_data.handle] = resource; | 323 resources_[child_process_data.handle] = resource; |
| 314 pid_to_resources_[resource->process_id()] = resource; | 324 pid_to_resources_[resource->process_id()] = resource; |
| 315 task_manager_->AddResource(resource); | 325 task_manager_->AddResource(resource); |
| 316 } | 326 } |
| 317 | 327 |
| 318 // The ChildProcessData::Iterator has to be used from the IO thread. | 328 // The ChildProcessData::Iterator has to be used from the IO thread. |
| 319 void ChildProcessResourceProvider::RetrieveChildProcessData() { | 329 void ChildProcessResourceProvider::RetrieveChildProcessData() { |
| 320 std::vector<content::ChildProcessData> child_processes; | 330 std::vector<content::ChildProcessData> child_processes; |
| 321 for (BrowserChildProcessHostIterator iter; !iter.Done(); ++iter) { | 331 for (BrowserChildProcessHostIterator iter; !iter.Done(); ++iter) { |
| 322 // Only add processes which are already started, since we need their handle. | 332 // Only add processes which are already started, since we need their handle. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 338 // This is called on the UI thread. | 348 // This is called on the UI thread. |
| 339 void ChildProcessResourceProvider::ChildProcessDataRetreived( | 349 void ChildProcessResourceProvider::ChildProcessDataRetreived( |
| 340 const std::vector<content::ChildProcessData>& child_processes) { | 350 const std::vector<content::ChildProcessData>& child_processes) { |
| 341 for (size_t i = 0; i < child_processes.size(); ++i) | 351 for (size_t i = 0; i < child_processes.size(); ++i) |
| 342 AddToTaskManager(child_processes[i]); | 352 AddToTaskManager(child_processes[i]); |
| 343 | 353 |
| 344 task_manager_->model()->NotifyDataReady(); | 354 task_manager_->model()->NotifyDataReady(); |
| 345 } | 355 } |
| 346 | 356 |
| 347 } // namespace task_manager | 357 } // namespace task_manager |
| OLD | NEW |