| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extensions/api/processes/processes_api.h" | 5 #include "chrome/browser/extensions/api/processes/processes_api.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 namespace extensions { | 38 namespace extensions { |
| 39 | 39 |
| 40 namespace keys = processes_api_constants; | 40 namespace keys = processes_api_constants; |
| 41 namespace errors = processes_api_constants; | 41 namespace errors = processes_api_constants; |
| 42 | 42 |
| 43 namespace { | 43 namespace { |
| 44 | 44 |
| 45 #if defined(ENABLE_TASK_MANAGER) | 45 #if defined(ENABLE_TASK_MANAGER) |
| 46 | 46 |
| 47 DictionaryValue* CreateCacheData( | 47 base::DictionaryValue* CreateCacheData( |
| 48 const WebKit::WebCache::ResourceTypeStat& stat) { | 48 const WebKit::WebCache::ResourceTypeStat& stat) { |
| 49 | 49 |
| 50 DictionaryValue* cache = new DictionaryValue(); | 50 base::DictionaryValue* cache = new base::DictionaryValue(); |
| 51 cache->SetDouble(keys::kCacheSize, static_cast<double>(stat.size)); | 51 cache->SetDouble(keys::kCacheSize, static_cast<double>(stat.size)); |
| 52 cache->SetDouble(keys::kCacheLiveSize, static_cast<double>(stat.liveSize)); | 52 cache->SetDouble(keys::kCacheLiveSize, static_cast<double>(stat.liveSize)); |
| 53 return cache; | 53 return cache; |
| 54 } | 54 } |
| 55 | 55 |
| 56 void SetProcessType(DictionaryValue* result, | 56 void SetProcessType(base::DictionaryValue* result, |
| 57 TaskManagerModel* model, | 57 TaskManagerModel* model, |
| 58 int index) { | 58 int index) { |
| 59 // Determine process type. | 59 // Determine process type. |
| 60 std::string type = keys::kProcessTypeOther; | 60 std::string type = keys::kProcessTypeOther; |
| 61 task_manager::Resource::Type resource_type = model->GetResourceType(index); | 61 task_manager::Resource::Type resource_type = model->GetResourceType(index); |
| 62 switch (resource_type) { | 62 switch (resource_type) { |
| 63 case task_manager::Resource::BROWSER: | 63 case task_manager::Resource::BROWSER: |
| 64 type = keys::kProcessTypeBrowser; | 64 type = keys::kProcessTypeBrowser; |
| 65 break; | 65 break; |
| 66 case task_manager::Resource::RENDERER: | 66 case task_manager::Resource::RENDERER: |
| (...skipping 25 matching lines...) Expand all Loading... |
| 92 case task_manager::Resource::SANDBOX_HELPER: | 92 case task_manager::Resource::SANDBOX_HELPER: |
| 93 case task_manager::Resource::UNKNOWN: | 93 case task_manager::Resource::UNKNOWN: |
| 94 type = keys::kProcessTypeOther; | 94 type = keys::kProcessTypeOther; |
| 95 break; | 95 break; |
| 96 default: | 96 default: |
| 97 NOTREACHED() << "Unknown resource type."; | 97 NOTREACHED() << "Unknown resource type."; |
| 98 } | 98 } |
| 99 result->SetString(keys::kTypeKey, type); | 99 result->SetString(keys::kTypeKey, type); |
| 100 } | 100 } |
| 101 | 101 |
| 102 ListValue* GetTabsForProcess(int process_id) { | 102 base::ListValue* GetTabsForProcess(int process_id) { |
| 103 ListValue* tabs_list = new ListValue(); | 103 base::ListValue* tabs_list = new base::ListValue(); |
| 104 | 104 |
| 105 // The tabs list only makes sense for render processes, so if we don't find | 105 // The tabs list only makes sense for render processes, so if we don't find |
| 106 // one, just return the empty list. | 106 // one, just return the empty list. |
| 107 content::RenderProcessHost* rph = | 107 content::RenderProcessHost* rph = |
| 108 content::RenderProcessHost::FromID(process_id); | 108 content::RenderProcessHost::FromID(process_id); |
| 109 if (rph == NULL) | 109 if (rph == NULL) |
| 110 return tabs_list; | 110 return tabs_list; |
| 111 | 111 |
| 112 int tab_id = -1; | 112 int tab_id = -1; |
| 113 // We need to loop through all the RVHs to ensure we collect the set of all | 113 // We need to loop through all the RVHs to ensure we collect the set of all |
| (...skipping 16 matching lines...) Expand all Loading... |
| 130 tabs_list->Append(Value::CreateIntegerValue(tab_id)); | 130 tabs_list->Append(Value::CreateIntegerValue(tab_id)); |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 | 133 |
| 134 return tabs_list; | 134 return tabs_list; |
| 135 } | 135 } |
| 136 | 136 |
| 137 // This function creates a Process object to be returned to the extensions | 137 // This function creates a Process object to be returned to the extensions |
| 138 // using these APIs. For memory details, which are not added by this function, | 138 // using these APIs. For memory details, which are not added by this function, |
| 139 // the callers need to use AddMemoryDetails. | 139 // the callers need to use AddMemoryDetails. |
| 140 DictionaryValue* CreateProcessFromModel(int process_id, | 140 base::DictionaryValue* CreateProcessFromModel(int process_id, |
| 141 TaskManagerModel* model, | 141 TaskManagerModel* model, |
| 142 int index, | 142 int index, |
| 143 bool include_optional) { | 143 bool include_optional) { |
| 144 DictionaryValue* result = new DictionaryValue(); | 144 base::DictionaryValue* result = new base::DictionaryValue(); |
| 145 size_t mem; | 145 size_t mem; |
| 146 | 146 |
| 147 result->SetInteger(keys::kIdKey, process_id); | 147 result->SetInteger(keys::kIdKey, process_id); |
| 148 result->SetInteger(keys::kOsProcessIdKey, model->GetProcessId(index)); | 148 result->SetInteger(keys::kOsProcessIdKey, model->GetProcessId(index)); |
| 149 SetProcessType(result, model, index); | 149 SetProcessType(result, model, index); |
| 150 result->SetString(keys::kProfileKey, | 150 result->SetString(keys::kProfileKey, |
| 151 model->GetResourceProfileName(index)); | 151 model->GetResourceProfileName(index)); |
| 152 | 152 |
| 153 result->Set(keys::kTabsListKey, GetTabsForProcess(process_id)); | 153 result->Set(keys::kTabsListKey, GetTabsForProcess(process_id)); |
| 154 | 154 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 } | 193 } |
| 194 result->SetDouble(keys::kFPSKey, static_cast<double>(fps)); | 194 result->SetDouble(keys::kFPSKey, static_cast<double>(fps)); |
| 195 result->SetDouble(keys::kNetworkKey, static_cast<double>(net)); | 195 result->SetDouble(keys::kNetworkKey, static_cast<double>(net)); |
| 196 | 196 |
| 197 return result; | 197 return result; |
| 198 } | 198 } |
| 199 | 199 |
| 200 // Since memory details are expensive to gather, we don't do it by default. | 200 // Since memory details are expensive to gather, we don't do it by default. |
| 201 // This function is a helper to add memory details data to an existing | 201 // This function is a helper to add memory details data to an existing |
| 202 // Process object representation. | 202 // Process object representation. |
| 203 void AddMemoryDetails(DictionaryValue* result, | 203 void AddMemoryDetails(base::DictionaryValue* result, |
| 204 TaskManagerModel* model, | 204 TaskManagerModel* model, |
| 205 int index) { | 205 int index) { |
| 206 size_t mem; | 206 size_t mem; |
| 207 int64 pr_mem = model->GetPrivateMemory(index, &mem) ? | 207 int64 pr_mem = model->GetPrivateMemory(index, &mem) ? |
| 208 static_cast<int64>(mem) : -1; | 208 static_cast<int64>(mem) : -1; |
| 209 result->SetDouble(keys::kPrivateMemoryKey, static_cast<double>(pr_mem)); | 209 result->SetDouble(keys::kPrivateMemoryKey, static_cast<double>(pr_mem)); |
| 210 } | 210 } |
| 211 | 211 |
| 212 #endif // defined(ENABLE_TASK_MANAGER) | 212 #endif // defined(ENABLE_TASK_MANAGER) |
| 213 | 213 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 std::string event(keys::kOnCreated); | 300 std::string event(keys::kOnCreated); |
| 301 if (!HasEventListeners(event)) | 301 if (!HasEventListeners(event)) |
| 302 return; | 302 return; |
| 303 | 303 |
| 304 // If the item being added is not the first one in the group, find the base | 304 // If the item being added is not the first one in the group, find the base |
| 305 // index and use it for retrieving the process data. | 305 // index and use it for retrieving the process data. |
| 306 if (!model_->IsResourceFirstInGroup(start)) { | 306 if (!model_->IsResourceFirstInGroup(start)) { |
| 307 index = model_->GetGroupIndexForResource(start); | 307 index = model_->GetGroupIndexForResource(start); |
| 308 } | 308 } |
| 309 | 309 |
| 310 scoped_ptr<ListValue> args(new ListValue()); | 310 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 311 DictionaryValue* process = CreateProcessFromModel( | 311 base::DictionaryValue* process = CreateProcessFromModel( |
| 312 model_->GetUniqueChildProcessId(index), model_, index, false); | 312 model_->GetUniqueChildProcessId(index), model_, index, false); |
| 313 DCHECK(process != NULL); | 313 DCHECK(process != NULL); |
| 314 | 314 |
| 315 if (process == NULL) | 315 if (process == NULL) |
| 316 return; | 316 return; |
| 317 | 317 |
| 318 args->Append(process); | 318 args->Append(process); |
| 319 | 319 |
| 320 DispatchEvent(keys::kOnCreated, args.Pass()); | 320 DispatchEvent(keys::kOnCreated, args.Pass()); |
| 321 #endif // defined(ENABLE_TASK_MANAGER) | 321 #endif // defined(ENABLE_TASK_MANAGER) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 332 | 332 |
| 333 // We need to know which type of onUpdated events to fire and whether to | 333 // We need to know which type of onUpdated events to fire and whether to |
| 334 // collect memory or not. | 334 // collect memory or not. |
| 335 std::string updated_event(keys::kOnUpdated); | 335 std::string updated_event(keys::kOnUpdated); |
| 336 std::string updated_event_memory(keys::kOnUpdatedWithMemory); | 336 std::string updated_event_memory(keys::kOnUpdatedWithMemory); |
| 337 bool updated = HasEventListeners(updated_event); | 337 bool updated = HasEventListeners(updated_event); |
| 338 bool updated_memory = HasEventListeners(updated_event_memory); | 338 bool updated_memory = HasEventListeners(updated_event_memory); |
| 339 | 339 |
| 340 DCHECK(updated || updated_memory); | 340 DCHECK(updated || updated_memory); |
| 341 | 341 |
| 342 IDMap<DictionaryValue> processes_map; | 342 IDMap<base::DictionaryValue> processes_map; |
| 343 for (int i = start; i < start + length; i++) { | 343 for (int i = start; i < start + length; i++) { |
| 344 if (model_->IsResourceFirstInGroup(i)) { | 344 if (model_->IsResourceFirstInGroup(i)) { |
| 345 int id = model_->GetUniqueChildProcessId(i); | 345 int id = model_->GetUniqueChildProcessId(i); |
| 346 DictionaryValue* process = CreateProcessFromModel(id, model_, i, true); | 346 base::DictionaryValue* process = CreateProcessFromModel(id, model_, i, tru
e); |
| 347 processes_map.AddWithID(process, i); | 347 processes_map.AddWithID(process, i); |
| 348 } | 348 } |
| 349 } | 349 } |
| 350 | 350 |
| 351 int id; | 351 int id; |
| 352 std::string idkey(keys::kIdKey); | 352 std::string idkey(keys::kIdKey); |
| 353 DictionaryValue* processes = new DictionaryValue(); | 353 base::DictionaryValue* processes = new base::DictionaryValue(); |
| 354 | 354 |
| 355 if (updated) { | 355 if (updated) { |
| 356 IDMap<DictionaryValue>::iterator it(&processes_map); | 356 IDMap<base::DictionaryValue>::iterator it(&processes_map); |
| 357 for (; !it.IsAtEnd(); it.Advance()) { | 357 for (; !it.IsAtEnd(); it.Advance()) { |
| 358 if (!it.GetCurrentValue()->GetInteger(idkey, &id)) | 358 if (!it.GetCurrentValue()->GetInteger(idkey, &id)) |
| 359 continue; | 359 continue; |
| 360 | 360 |
| 361 // Store each process indexed by the string version of its id. | 361 // Store each process indexed by the string version of its id. |
| 362 processes->Set(base::IntToString(id), it.GetCurrentValue()); | 362 processes->Set(base::IntToString(id), it.GetCurrentValue()); |
| 363 } | 363 } |
| 364 | 364 |
| 365 scoped_ptr<ListValue> args(new ListValue()); | 365 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 366 args->Append(processes); | 366 args->Append(processes); |
| 367 DispatchEvent(keys::kOnUpdated, args.Pass()); | 367 DispatchEvent(keys::kOnUpdated, args.Pass()); |
| 368 } | 368 } |
| 369 | 369 |
| 370 if (updated_memory) { | 370 if (updated_memory) { |
| 371 IDMap<DictionaryValue>::iterator it(&processes_map); | 371 IDMap<base::DictionaryValue>::iterator it(&processes_map); |
| 372 for (; !it.IsAtEnd(); it.Advance()) { | 372 for (; !it.IsAtEnd(); it.Advance()) { |
| 373 if (!it.GetCurrentValue()->GetInteger(idkey, &id)) | 373 if (!it.GetCurrentValue()->GetInteger(idkey, &id)) |
| 374 continue; | 374 continue; |
| 375 | 375 |
| 376 AddMemoryDetails(it.GetCurrentValue(), model_, it.GetCurrentKey()); | 376 AddMemoryDetails(it.GetCurrentValue(), model_, it.GetCurrentKey()); |
| 377 | 377 |
| 378 // Store each process indexed by the string version of its id if we didn't | 378 // Store each process indexed by the string version of its id if we didn't |
| 379 // already insert it as part of the onUpdated processing above. | 379 // already insert it as part of the onUpdated processing above. |
| 380 if (!updated) | 380 if (!updated) |
| 381 processes->Set(base::IntToString(id), it.GetCurrentValue()); | 381 processes->Set(base::IntToString(id), it.GetCurrentValue()); |
| 382 } | 382 } |
| 383 | 383 |
| 384 scoped_ptr<ListValue> args(new ListValue()); | 384 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 385 args->Append(processes); | 385 args->Append(processes); |
| 386 DispatchEvent(keys::kOnUpdatedWithMemory, args.Pass()); | 386 DispatchEvent(keys::kOnUpdatedWithMemory, args.Pass()); |
| 387 } | 387 } |
| 388 #endif // defined(ENABLE_TASK_MANAGER) | 388 #endif // defined(ENABLE_TASK_MANAGER) |
| 389 } | 389 } |
| 390 | 390 |
| 391 void ProcessesEventRouter::OnItemsToBeRemoved(int start, int length) { | 391 void ProcessesEventRouter::OnItemsToBeRemoved(int start, int length) { |
| 392 #if defined(ENABLE_TASK_MANAGER) | 392 #if defined(ENABLE_TASK_MANAGER) |
| 393 DCHECK_EQ(length, 1); | 393 DCHECK_EQ(length, 1); |
| 394 | 394 |
| 395 // Process exit for renderer processes has the data about exit code and | 395 // Process exit for renderer processes has the data about exit code and |
| 396 // termination status, therefore we will rely on notifications and not on | 396 // termination status, therefore we will rely on notifications and not on |
| 397 // the Task Manager data. We do use the rest of this method for non-renderer | 397 // the Task Manager data. We do use the rest of this method for non-renderer |
| 398 // processes. | 398 // processes. |
| 399 if (model_->GetResourceType(start) == task_manager::Resource::RENDERER) | 399 if (model_->GetResourceType(start) == task_manager::Resource::RENDERER) |
| 400 return; | 400 return; |
| 401 | 401 |
| 402 // The callback function parameters. | 402 // The callback function parameters. |
| 403 scoped_ptr<ListValue> args(new ListValue()); | 403 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 404 | 404 |
| 405 // First arg: The id of the process that was closed. | 405 // First arg: The id of the process that was closed. |
| 406 args->Append(Value::CreateIntegerValue( | 406 args->Append(Value::CreateIntegerValue( |
| 407 model_->GetUniqueChildProcessId(start))); | 407 model_->GetUniqueChildProcessId(start))); |
| 408 | 408 |
| 409 // Second arg: The exit type for the process. | 409 // Second arg: The exit type for the process. |
| 410 args->Append(Value::CreateIntegerValue(0)); | 410 args->Append(Value::CreateIntegerValue(0)); |
| 411 | 411 |
| 412 // Third arg: The exit code for the process. | 412 // Third arg: The exit code for the process. |
| 413 args->Append(Value::CreateIntegerValue(0)); | 413 args->Append(Value::CreateIntegerValue(0)); |
| 414 | 414 |
| 415 DispatchEvent(keys::kOnExited, args.Pass()); | 415 DispatchEvent(keys::kOnExited, args.Pass()); |
| 416 #endif // defined(ENABLE_TASK_MANAGER) | 416 #endif // defined(ENABLE_TASK_MANAGER) |
| 417 } | 417 } |
| 418 | 418 |
| 419 void ProcessesEventRouter::ProcessHangEvent(content::RenderWidgetHost* widget) { | 419 void ProcessesEventRouter::ProcessHangEvent(content::RenderWidgetHost* widget) { |
| 420 #if defined(ENABLE_TASK_MANAGER) | 420 #if defined(ENABLE_TASK_MANAGER) |
| 421 std::string event(keys::kOnUnresponsive); | 421 std::string event(keys::kOnUnresponsive); |
| 422 if (!HasEventListeners(event)) | 422 if (!HasEventListeners(event)) |
| 423 return; | 423 return; |
| 424 | 424 |
| 425 DictionaryValue* process = NULL; | 425 base::DictionaryValue* process = NULL; |
| 426 int count = model_->ResourceCount(); | 426 int count = model_->ResourceCount(); |
| 427 int id = widget->GetProcess()->GetID(); | 427 int id = widget->GetProcess()->GetID(); |
| 428 | 428 |
| 429 for (int i = 0; i < count; ++i) { | 429 for (int i = 0; i < count; ++i) { |
| 430 if (model_->IsResourceFirstInGroup(i)) { | 430 if (model_->IsResourceFirstInGroup(i)) { |
| 431 if (id == model_->GetUniqueChildProcessId(i)) { | 431 if (id == model_->GetUniqueChildProcessId(i)) { |
| 432 process = CreateProcessFromModel(id, model_, i, false); | 432 process = CreateProcessFromModel(id, model_, i, false); |
| 433 break; | 433 break; |
| 434 } | 434 } |
| 435 } | 435 } |
| 436 } | 436 } |
| 437 | 437 |
| 438 DCHECK(process); | 438 DCHECK(process); |
| 439 if (process == NULL) | 439 if (process == NULL) |
| 440 return; | 440 return; |
| 441 | 441 |
| 442 scoped_ptr<ListValue> args(new ListValue()); | 442 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 443 args->Append(process); | 443 args->Append(process); |
| 444 | 444 |
| 445 DispatchEvent(keys::kOnUnresponsive, args.Pass()); | 445 DispatchEvent(keys::kOnUnresponsive, args.Pass()); |
| 446 #endif // defined(ENABLE_TASK_MANAGER) | 446 #endif // defined(ENABLE_TASK_MANAGER) |
| 447 } | 447 } |
| 448 | 448 |
| 449 void ProcessesEventRouter::ProcessClosedEvent( | 449 void ProcessesEventRouter::ProcessClosedEvent( |
| 450 content::RenderProcessHost* rph, | 450 content::RenderProcessHost* rph, |
| 451 content::RenderProcessHost::RendererClosedDetails* details) { | 451 content::RenderProcessHost::RendererClosedDetails* details) { |
| 452 #if defined(ENABLE_TASK_MANAGER) | 452 #if defined(ENABLE_TASK_MANAGER) |
| 453 // The callback function parameters. | 453 // The callback function parameters. |
| 454 scoped_ptr<ListValue> args(new ListValue()); | 454 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 455 | 455 |
| 456 // First arg: The id of the process that was closed. | 456 // First arg: The id of the process that was closed. |
| 457 args->Append(Value::CreateIntegerValue(rph->GetID())); | 457 args->Append(Value::CreateIntegerValue(rph->GetID())); |
| 458 | 458 |
| 459 // Second arg: The exit type for the process. | 459 // Second arg: The exit type for the process. |
| 460 args->Append(Value::CreateIntegerValue(details->status)); | 460 args->Append(Value::CreateIntegerValue(details->status)); |
| 461 | 461 |
| 462 // Third arg: The exit code for the process. | 462 // Third arg: The exit code for the process. |
| 463 args->Append(Value::CreateIntegerValue(details->exit_code)); | 463 args->Append(Value::CreateIntegerValue(details->exit_code)); |
| 464 | 464 |
| 465 DispatchEvent(keys::kOnExited, args.Pass()); | 465 DispatchEvent(keys::kOnExited, args.Pass()); |
| 466 #endif // defined(ENABLE_TASK_MANAGER) | 466 #endif // defined(ENABLE_TASK_MANAGER) |
| 467 } | 467 } |
| 468 | 468 |
| 469 void ProcessesEventRouter::DispatchEvent(const char* event_name, | 469 void ProcessesEventRouter::DispatchEvent( |
| 470 scoped_ptr<ListValue> event_args) { | 470 const char* event_name, |
| 471 scoped_ptr<base::ListValue> event_args) { |
| 471 if (extensions::ExtensionSystem::Get(profile_)->event_router()) { | 472 if (extensions::ExtensionSystem::Get(profile_)->event_router()) { |
| 472 scoped_ptr<extensions::Event> event(new extensions::Event( | 473 scoped_ptr<extensions::Event> event(new extensions::Event( |
| 473 event_name, event_args.Pass())); | 474 event_name, event_args.Pass())); |
| 474 extensions::ExtensionSystem::Get(profile_)->event_router()-> | 475 extensions::ExtensionSystem::Get(profile_)->event_router()-> |
| 475 BroadcastEvent(event.Pass()); | 476 BroadcastEvent(event.Pass()); |
| 476 } | 477 } |
| 477 } | 478 } |
| 478 | 479 |
| 479 bool ProcessesEventRouter::HasEventListeners(const std::string& event_name) { | 480 bool ProcessesEventRouter::HasEventListeners(const std::string& event_name) { |
| 480 extensions::EventRouter* router = | 481 extensions::EventRouter* router = |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 const content::NotificationSource& source, | 726 const content::NotificationSource& source, |
| 726 const content::NotificationDetails& details) { | 727 const content::NotificationDetails& details) { |
| 727 DCHECK_EQ(type, chrome::NOTIFICATION_TASK_MANAGER_CHILD_PROCESSES_DATA_READY); | 728 DCHECK_EQ(type, chrome::NOTIFICATION_TASK_MANAGER_CHILD_PROCESSES_DATA_READY); |
| 728 registrar_.RemoveAll(); | 729 registrar_.RemoveAll(); |
| 729 GatherProcessInfo(); | 730 GatherProcessInfo(); |
| 730 } | 731 } |
| 731 | 732 |
| 732 void GetProcessInfoFunction::GatherProcessInfo() { | 733 void GetProcessInfoFunction::GatherProcessInfo() { |
| 733 #if defined(ENABLE_TASK_MANAGER) | 734 #if defined(ENABLE_TASK_MANAGER) |
| 734 TaskManagerModel* model = TaskManager::GetInstance()->model(); | 735 TaskManagerModel* model = TaskManager::GetInstance()->model(); |
| 735 DictionaryValue* processes = new DictionaryValue(); | 736 base::DictionaryValue* processes = new base::DictionaryValue(); |
| 736 | 737 |
| 737 // If there are no process IDs specified, it means we need to return all of | 738 // If there are no process IDs specified, it means we need to return all of |
| 738 // the ones we know of. | 739 // the ones we know of. |
| 739 if (process_ids_.size() == 0) { | 740 if (process_ids_.size() == 0) { |
| 740 int resources = model->ResourceCount(); | 741 int resources = model->ResourceCount(); |
| 741 for (int i = 0; i < resources; ++i) { | 742 for (int i = 0; i < resources; ++i) { |
| 742 if (model->IsResourceFirstInGroup(i)) { | 743 if (model->IsResourceFirstInGroup(i)) { |
| 743 int id = model->GetUniqueChildProcessId(i); | 744 int id = model->GetUniqueChildProcessId(i); |
| 744 DictionaryValue* d = CreateProcessFromModel(id, model, i, false); | 745 base::DictionaryValue* d = CreateProcessFromModel(id, model, i, false); |
| 745 if (memory_) | 746 if (memory_) |
| 746 AddMemoryDetails(d, model, i); | 747 AddMemoryDetails(d, model, i); |
| 747 processes->Set(base::IntToString(id), d); | 748 processes->Set(base::IntToString(id), d); |
| 748 } | 749 } |
| 749 } | 750 } |
| 750 } else { | 751 } else { |
| 751 int resources = model->ResourceCount(); | 752 int resources = model->ResourceCount(); |
| 752 for (int i = 0; i < resources; ++i) { | 753 for (int i = 0; i < resources; ++i) { |
| 753 if (model->IsResourceFirstInGroup(i)) { | 754 if (model->IsResourceFirstInGroup(i)) { |
| 754 int id = model->GetUniqueChildProcessId(i); | 755 int id = model->GetUniqueChildProcessId(i); |
| 755 std::vector<int>::iterator proc_id = std::find(process_ids_.begin(), | 756 std::vector<int>::iterator proc_id = std::find(process_ids_.begin(), |
| 756 process_ids_.end(), id); | 757 process_ids_.end(), id); |
| 757 if (proc_id != process_ids_.end()) { | 758 if (proc_id != process_ids_.end()) { |
| 758 DictionaryValue* d = CreateProcessFromModel(id, model, i, false); | 759 base::DictionaryValue* d = |
| 760 CreateProcessFromModel(id, model, i, false); |
| 759 if (memory_) | 761 if (memory_) |
| 760 AddMemoryDetails(d, model, i); | 762 AddMemoryDetails(d, model, i); |
| 761 processes->Set(base::IntToString(id), d); | 763 processes->Set(base::IntToString(id), d); |
| 762 | 764 |
| 763 process_ids_.erase(proc_id); | 765 process_ids_.erase(proc_id); |
| 764 if (process_ids_.size() == 0) | 766 if (process_ids_.size() == 0) |
| 765 break; | 767 break; |
| 766 } | 768 } |
| 767 } | 769 } |
| 768 } | 770 } |
| 769 DCHECK_EQ(process_ids_.size(), 0U); | 771 DCHECK_EQ(process_ids_.size(), 0U); |
| 770 } | 772 } |
| 771 | 773 |
| 772 SetResult(processes); | 774 SetResult(processes); |
| 773 SendResponse(true); | 775 SendResponse(true); |
| 774 | 776 |
| 775 // Balance the AddRef in the RunImpl. | 777 // Balance the AddRef in the RunImpl. |
| 776 Release(); | 778 Release(); |
| 777 #endif // defined(ENABLE_TASK_MANAGER) | 779 #endif // defined(ENABLE_TASK_MANAGER) |
| 778 } | 780 } |
| 779 | 781 |
| 780 } // namespace extensions | 782 } // namespace extensions |
| OLD | NEW |