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