| 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 case PROCESS_TYPE_NACL_LOADER: | 186 case PROCESS_TYPE_NACL_LOADER: |
| 187 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_NACL_PREFIX, title); | 187 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_NACL_PREFIX, title); |
| 188 // These types don't need display names or get them from elsewhere. | 188 // These types don't need display names or get them from elsewhere. |
| 189 case content::PROCESS_TYPE_BROWSER: | 189 case content::PROCESS_TYPE_BROWSER: |
| 190 case content::PROCESS_TYPE_RENDERER: | 190 case content::PROCESS_TYPE_RENDERER: |
| 191 case content::PROCESS_TYPE_ZYGOTE: | 191 case content::PROCESS_TYPE_ZYGOTE: |
| 192 case content::PROCESS_TYPE_SANDBOX_HELPER: | 192 case content::PROCESS_TYPE_SANDBOX_HELPER: |
| 193 case content::PROCESS_TYPE_MAX: | 193 case content::PROCESS_TYPE_MAX: |
| 194 NOTREACHED(); | 194 NOTREACHED(); |
| 195 break; | 195 break; |
| 196 | |
| 197 case content::PROCESS_TYPE_WORKER: | |
| 198 NOTREACHED() << "Workers are not handled by this provider."; | |
| 199 break; | |
| 200 case content::PROCESS_TYPE_UNKNOWN: | 196 case content::PROCESS_TYPE_UNKNOWN: |
| 201 NOTREACHED() << "Need localized name for child process type."; | 197 NOTREACHED() << "Need localized name for child process type."; |
| 202 } | 198 } |
| 203 | 199 |
| 204 return title; | 200 return title; |
| 205 } | 201 } |
| 206 | 202 |
| 207 //////////////////////////////////////////////////////////////////////////////// | 203 //////////////////////////////////////////////////////////////////////////////// |
| 208 // ChildProcessResourceProvider class | 204 // ChildProcessResourceProvider class |
| 209 //////////////////////////////////////////////////////////////////////////////// | 205 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 resources_.clear(); | 248 resources_.clear(); |
| 253 pid_to_resources_.clear(); | 249 pid_to_resources_.clear(); |
| 254 | 250 |
| 255 BrowserChildProcessObserver::Remove(this); | 251 BrowserChildProcessObserver::Remove(this); |
| 256 } | 252 } |
| 257 | 253 |
| 258 void ChildProcessResourceProvider::BrowserChildProcessHostConnected( | 254 void ChildProcessResourceProvider::BrowserChildProcessHostConnected( |
| 259 const content::ChildProcessData& data) { | 255 const content::ChildProcessData& data) { |
| 260 DCHECK(updating_); | 256 DCHECK(updating_); |
| 261 | 257 |
| 262 // Workers are handled by WorkerResourceProvider. | |
| 263 if (data.process_type == content::PROCESS_TYPE_WORKER) | |
| 264 return; | |
| 265 if (resources_.count(data.handle)) { | 258 if (resources_.count(data.handle)) { |
| 266 // The case may happen that we have added a child_process_info as part of | 259 // The case may happen that we have added a child_process_info as part of |
| 267 // the iteration performed during StartUpdating() call but the notification | 260 // the iteration performed during StartUpdating() call but the notification |
| 268 // that it has connected was not fired yet. So when the notification | 261 // that it has connected was not fired yet. So when the notification |
| 269 // happens, we already know about this plugin and just ignore it. | 262 // happens, we already know about this plugin and just ignore it. |
| 270 return; | 263 return; |
| 271 } | 264 } |
| 272 AddToTaskManager(data); | 265 AddToTaskManager(data); |
| 273 } | 266 } |
| 274 | 267 |
| 275 void ChildProcessResourceProvider:: | 268 void ChildProcessResourceProvider:: |
| 276 BrowserChildProcessHostDisconnected( | 269 BrowserChildProcessHostDisconnected( |
| 277 const content::ChildProcessData& data) { | 270 const content::ChildProcessData& data) { |
| 278 DCHECK(updating_); | 271 DCHECK(updating_); |
| 279 | 272 |
| 280 if (data.process_type == content::PROCESS_TYPE_WORKER) | |
| 281 return; | |
| 282 ChildProcessMap::iterator iter = resources_.find(data.handle); | 273 ChildProcessMap::iterator iter = resources_.find(data.handle); |
| 283 if (iter == resources_.end()) { | 274 if (iter == resources_.end()) { |
| 284 // ChildProcessData disconnection notifications are asynchronous, so we | 275 // ChildProcessData disconnection notifications are asynchronous, so we |
| 285 // might be notified for a plugin we don't know anything about (if it was | 276 // might be notified for a plugin we don't know anything about (if it was |
| 286 // closed before the task manager was shown and destroyed after that). | 277 // closed before the task manager was shown and destroyed after that). |
| 287 return; | 278 return; |
| 288 } | 279 } |
| 289 // Remove the resource from the Task Manager. | 280 // Remove the resource from the Task Manager. |
| 290 ChildProcessResource* resource = iter->second; | 281 ChildProcessResource* resource = iter->second; |
| 291 task_manager_->RemoveResource(resource); | 282 task_manager_->RemoveResource(resource); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 315 task_manager_->AddResource(resource); | 306 task_manager_->AddResource(resource); |
| 316 } | 307 } |
| 317 | 308 |
| 318 // The ChildProcessData::Iterator has to be used from the IO thread. | 309 // The ChildProcessData::Iterator has to be used from the IO thread. |
| 319 void ChildProcessResourceProvider::RetrieveChildProcessData() { | 310 void ChildProcessResourceProvider::RetrieveChildProcessData() { |
| 320 std::vector<content::ChildProcessData> child_processes; | 311 std::vector<content::ChildProcessData> child_processes; |
| 321 for (BrowserChildProcessHostIterator iter; !iter.Done(); ++iter) { | 312 for (BrowserChildProcessHostIterator iter; !iter.Done(); ++iter) { |
| 322 // Only add processes which are already started, since we need their handle. | 313 // Only add processes which are already started, since we need their handle. |
| 323 if (iter.GetData().handle == base::kNullProcessHandle) | 314 if (iter.GetData().handle == base::kNullProcessHandle) |
| 324 continue; | 315 continue; |
| 325 if (iter.GetData().process_type == content::PROCESS_TYPE_WORKER) | |
| 326 continue; | |
| 327 child_processes.push_back(iter.GetData()); | 316 child_processes.push_back(iter.GetData()); |
| 328 } | 317 } |
| 329 // Now notify the UI thread that we have retrieved information about child | 318 // Now notify the UI thread that we have retrieved information about child |
| 330 // processes. | 319 // processes. |
| 331 BrowserThread::PostTask( | 320 BrowserThread::PostTask( |
| 332 BrowserThread::UI, FROM_HERE, | 321 BrowserThread::UI, FROM_HERE, |
| 333 base::Bind( | 322 base::Bind( |
| 334 &ChildProcessResourceProvider::ChildProcessDataRetreived, | 323 &ChildProcessResourceProvider::ChildProcessDataRetreived, |
| 335 this, child_processes)); | 324 this, child_processes)); |
| 336 } | 325 } |
| 337 | 326 |
| 338 // This is called on the UI thread. | 327 // This is called on the UI thread. |
| 339 void ChildProcessResourceProvider::ChildProcessDataRetreived( | 328 void ChildProcessResourceProvider::ChildProcessDataRetreived( |
| 340 const std::vector<content::ChildProcessData>& child_processes) { | 329 const std::vector<content::ChildProcessData>& child_processes) { |
| 341 for (size_t i = 0; i < child_processes.size(); ++i) | 330 for (size_t i = 0; i < child_processes.size(); ++i) |
| 342 AddToTaskManager(child_processes[i]); | 331 AddToTaskManager(child_processes[i]); |
| 343 | 332 |
| 344 task_manager_->model()->NotifyDataReady(); | 333 task_manager_->model()->NotifyDataReady(); |
| 345 } | 334 } |
| 346 | 335 |
| 347 } // namespace task_manager | 336 } // namespace task_manager |
| OLD | NEW |