| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/webui/task_manager_handler.h" | 5 #include "chrome/browser/ui/webui/task_manager_handler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 std::vector<int>::iterator it_last = it_first + length - 1; | 300 std::vector<int>::iterator it_last = it_first + length - 1; |
| 301 resource_to_group_table_.erase(it_first, it_last); | 301 resource_to_group_table_.erase(it_first, it_last); |
| 302 | 302 |
| 303 OnGroupRemoved(group_start, group_end - group_start + 1); | 303 OnGroupRemoved(group_start, group_end - group_start + 1); |
| 304 } | 304 } |
| 305 | 305 |
| 306 void TaskManagerHandler::Init() { | 306 void TaskManagerHandler::Init() { |
| 307 } | 307 } |
| 308 | 308 |
| 309 void TaskManagerHandler::RegisterMessages() { | 309 void TaskManagerHandler::RegisterMessages() { |
| 310 web_ui_->RegisterMessageCallback("killProcess", | 310 web_ui_->RegisterMessageCallback("killProcesses", |
| 311 base::Bind(&TaskManagerHandler::HandleKillProcess, | 311 base::Bind(&TaskManagerHandler::HandleKillProcesses, |
| 312 base::Unretained(this))); | 312 base::Unretained(this))); |
| 313 web_ui_->RegisterMessageCallback("inspect", | 313 web_ui_->RegisterMessageCallback("inspect", |
| 314 base::Bind(&TaskManagerHandler::HandleInspect, | 314 base::Bind(&TaskManagerHandler::HandleInspect, |
| 315 base::Unretained(this))); | 315 base::Unretained(this))); |
| 316 web_ui_->RegisterMessageCallback("activatePage", | 316 web_ui_->RegisterMessageCallback("activatePage", |
| 317 base::Bind(&TaskManagerHandler::HandleActivatePage, | 317 base::Bind(&TaskManagerHandler::HandleActivatePage, |
| 318 base::Unretained(this))); | 318 base::Unretained(this))); |
| 319 web_ui_->RegisterMessageCallback("openAboutMemory", | 319 web_ui_->RegisterMessageCallback("openAboutMemory", |
| 320 base::Bind(&TaskManagerHandler::OpenAboutMemory, | 320 base::Bind(&TaskManagerHandler::OpenAboutMemory, |
| 321 base::Unretained(this))); | 321 base::Unretained(this))); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 334 if (value->GetAsString(&string16_index)) { | 334 if (value->GetAsString(&string16_index)) { |
| 335 base::StringToInt(string16_index, &index); | 335 base::StringToInt(string16_index, &index); |
| 336 } else if (value->GetAsDouble(&double_index)) { | 336 } else if (value->GetAsDouble(&double_index)) { |
| 337 index = static_cast<int>(double_index); | 337 index = static_cast<int>(double_index); |
| 338 } else { | 338 } else { |
| 339 value->GetAsInteger(&index); | 339 value->GetAsInteger(&index); |
| 340 } | 340 } |
| 341 return index; | 341 return index; |
| 342 } | 342 } |
| 343 | 343 |
| 344 void TaskManagerHandler::HandleKillProcess(const ListValue* indexes) { | 344 void TaskManagerHandler::HandleKillProcesses(const ListValue* unique_ids) { |
| 345 for (ListValue::const_iterator i = indexes->begin(); | 345 for (ListValue::const_iterator i = unique_ids->begin(); |
| 346 i != indexes->end(); i++) { | 346 i != unique_ids->end(); ++i) { |
| 347 int index = parseIndex(*i); | 347 int unique_id = parseIndex(*i); |
| 348 if (index == -1) | 348 int resource_index = model_->GetResourceIndexByUniqueId(unique_id); |
| 349 continue; | |
| 350 | |
| 351 int resource_index = model_->GetResourceIndexForGroup(index, 0); | |
| 352 if (resource_index == -1) | 349 if (resource_index == -1) |
| 353 continue; | 350 continue; |
| 354 | 351 |
| 355 LOG(INFO) << "kill PID:" << model_->GetResourceProcessId(resource_index); | |
| 356 task_manager_->KillProcess(resource_index); | 352 task_manager_->KillProcess(resource_index); |
| 357 } | 353 } |
| 358 } | 354 } |
| 359 | 355 |
| 360 void TaskManagerHandler::HandleActivatePage(const ListValue* resource_index) { | 356 void TaskManagerHandler::HandleActivatePage(const ListValue* unique_ids) { |
| 361 for (ListValue::const_iterator i = resource_index->begin(); | 357 for (ListValue::const_iterator i = unique_ids->begin(); |
| 362 i != resource_index->end(); ++i) { | 358 i != unique_ids->end(); ++i) { |
| 363 int unique_id = parseIndex(*i); | 359 int unique_id = parseIndex(*i); |
| 364 if (unique_id == -1) | 360 int resource_index = model_->GetResourceIndexByUniqueId(unique_id); |
| 361 if (resource_index == -1) |
| 365 continue; | 362 continue; |
| 366 | 363 |
| 367 for (int resource_index = 0; resource_index < model_->ResourceCount(); | 364 task_manager_->ActivateProcess(resource_index); |
| 368 ++resource_index) { | |
| 369 if (model_->GetResourceUniqueId(resource_index) == unique_id) { | |
| 370 task_manager_->ActivateProcess(resource_index); | |
| 371 break; | |
| 372 } | |
| 373 } | |
| 374 | |
| 375 break; | 365 break; |
| 376 } | 366 } |
| 377 } | 367 } |
| 378 | 368 |
| 379 void TaskManagerHandler::HandleInspect(const ListValue* resource_index) { | 369 void TaskManagerHandler::HandleInspect(const ListValue* unique_ids) { |
| 380 for (ListValue::const_iterator i = resource_index->begin(); | 370 for (ListValue::const_iterator i = unique_ids->begin(); |
| 381 i != resource_index->end(); ++i) { | 371 i != unique_ids->end(); ++i) { |
| 382 int unique_id = parseIndex(*i); | 372 int unique_id = parseIndex(*i); |
| 383 if (unique_id == -1) | 373 int resource_index = model_->GetResourceIndexByUniqueId(unique_id); |
| 374 if (resource_index == -1) |
| 384 continue; | 375 continue; |
| 385 | 376 |
| 386 for (int resource_index = 0; resource_index < model_->ResourceCount(); | 377 if (model_->CanInspect(resource_index)) |
| 387 ++resource_index) { | 378 model_->Inspect(resource_index); |
| 388 if (model_->GetResourceUniqueId(resource_index) == unique_id) { | |
| 389 if (model_->CanInspect(resource_index)) | |
| 390 model_->Inspect(resource_index); | |
| 391 break; | |
| 392 } | |
| 393 } | |
| 394 | |
| 395 break; | 379 break; |
| 396 } | 380 } |
| 397 } | 381 } |
| 398 | 382 |
| 399 void TaskManagerHandler::DisableTaskManager(const ListValue* indexes) { | 383 void TaskManagerHandler::DisableTaskManager(const ListValue* indexes) { |
| 400 if (!is_enabled_) | 384 if (!is_enabled_) |
| 401 return; | 385 return; |
| 402 | 386 |
| 403 is_enabled_ = false; | 387 is_enabled_ = false; |
| 404 model_->StopUpdating(); | 388 model_->StopUpdating(); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 } | 467 } |
| 484 } | 468 } |
| 485 | 469 |
| 486 void TaskManagerHandler::OnGroupRemoved(const int group_start, | 470 void TaskManagerHandler::OnGroupRemoved(const int group_start, |
| 487 const int group_length) { | 471 const int group_length) { |
| 488 base::FundamentalValue start_value(group_start); | 472 base::FundamentalValue start_value(group_start); |
| 489 base::FundamentalValue length_value(group_length); | 473 base::FundamentalValue length_value(group_length); |
| 490 if (is_enabled_ && is_alive()) | 474 if (is_enabled_ && is_alive()) |
| 491 web_ui_->CallJavascriptFunction("taskRemoved", start_value, length_value); | 475 web_ui_->CallJavascriptFunction("taskRemoved", start_value, length_value); |
| 492 } | 476 } |
| OLD | NEW |