| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 return Value::CreateIntegerValue(tm->GetGoatsTeleported(i)); | 113 return Value::CreateIntegerValue(tm->GetGoatsTeleported(i)); |
| 114 if (column_name == "v8MemoryAllocatedSize") | 114 if (column_name == "v8MemoryAllocatedSize") |
| 115 return Value::CreateStringValue(tm->GetResourceV8MemoryAllocatedSize(i)); | 115 return Value::CreateStringValue(tm->GetResourceV8MemoryAllocatedSize(i)); |
| 116 if (column_name == "v8MemoryAllocatedSizeValue") { | 116 if (column_name == "v8MemoryAllocatedSizeValue") { |
| 117 size_t v8_memory; | 117 size_t v8_memory; |
| 118 tm->GetV8Memory(i, &v8_memory); | 118 tm->GetV8Memory(i, &v8_memory); |
| 119 return Value::CreateDoubleValue(v8_memory); | 119 return Value::CreateDoubleValue(v8_memory); |
| 120 } | 120 } |
| 121 if (column_name == "canInspect") | 121 if (column_name == "canInspect") |
| 122 return Value::CreateBooleanValue(tm->CanInspect(i)); | 122 return Value::CreateBooleanValue(tm->CanInspect(i)); |
| 123 if (column_name == "canActivate") |
| 124 return Value::CreateBooleanValue(tm->CanActivate(i)); |
| 123 | 125 |
| 124 NOTREACHED(); | 126 NOTREACHED(); |
| 125 return NULL; | 127 return NULL; |
| 126 } | 128 } |
| 127 | 129 |
| 128 static void CreateGroupColumnList(const TaskManagerModel* tm, | 130 static void CreateGroupColumnList(const TaskManagerModel* tm, |
| 129 const std::string column_name, | 131 const std::string column_name, |
| 130 const int index, | 132 const int index, |
| 131 const int length, | 133 const int length, |
| 132 DictionaryValue* val) { | 134 DictionaryValue* val) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 CreateGroupColumnList(tm, "icon", index, length, val); | 184 CreateGroupColumnList(tm, "icon", index, length, val); |
| 183 CreateGroupColumnList(tm, "title", index, length, val); | 185 CreateGroupColumnList(tm, "title", index, length, val); |
| 184 CreateGroupColumnList(tm, "profileName", index, length, val); | 186 CreateGroupColumnList(tm, "profileName", index, length, val); |
| 185 CreateGroupColumnList(tm, "networkUsage", index, length, val); | 187 CreateGroupColumnList(tm, "networkUsage", index, length, val); |
| 186 CreateGroupColumnList(tm, "networkUsageValue", index, length, val); | 188 CreateGroupColumnList(tm, "networkUsageValue", index, length, val); |
| 187 CreateGroupColumnList(tm, "fps", index, length, val); | 189 CreateGroupColumnList(tm, "fps", index, length, val); |
| 188 CreateGroupColumnList(tm, "fpsValue", index, length, val); | 190 CreateGroupColumnList(tm, "fpsValue", index, length, val); |
| 189 CreateGroupColumnList(tm, "goatsTeleported", index, length, val); | 191 CreateGroupColumnList(tm, "goatsTeleported", index, length, val); |
| 190 CreateGroupColumnList(tm, "goatsTeleportedValue", index, length, val); | 192 CreateGroupColumnList(tm, "goatsTeleportedValue", index, length, val); |
| 191 CreateGroupColumnList(tm, "canInspect", index, length, val); | 193 CreateGroupColumnList(tm, "canInspect", index, length, val); |
| 194 CreateGroupColumnList(tm, "canActivate", index, length, val); |
| 192 | 195 |
| 193 return val; | 196 return val; |
| 194 } | 197 } |
| 195 | 198 |
| 196 } // namespace | 199 } // namespace |
| 197 | 200 |
| 198 TaskManagerHandler::TaskManagerHandler(TaskManager* tm) | 201 TaskManagerHandler::TaskManagerHandler(TaskManager* tm) |
| 199 : task_manager_(tm), | 202 : task_manager_(tm), |
| 200 model_(tm->model()), | 203 model_(tm->model()), |
| 201 is_enabled_(false) { | 204 is_enabled_(false) { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 void TaskManagerHandler::Init() { | 306 void TaskManagerHandler::Init() { |
| 304 } | 307 } |
| 305 | 308 |
| 306 void TaskManagerHandler::RegisterMessages() { | 309 void TaskManagerHandler::RegisterMessages() { |
| 307 web_ui_->RegisterMessageCallback("killProcess", | 310 web_ui_->RegisterMessageCallback("killProcess", |
| 308 base::Bind(&TaskManagerHandler::HandleKillProcess, | 311 base::Bind(&TaskManagerHandler::HandleKillProcess, |
| 309 base::Unretained(this))); | 312 base::Unretained(this))); |
| 310 web_ui_->RegisterMessageCallback("inspect", | 313 web_ui_->RegisterMessageCallback("inspect", |
| 311 base::Bind(&TaskManagerHandler::HandleInspect, | 314 base::Bind(&TaskManagerHandler::HandleInspect, |
| 312 base::Unretained(this))); | 315 base::Unretained(this))); |
| 316 web_ui_->RegisterMessageCallback("activatePage", |
| 317 base::Bind(&TaskManagerHandler::HandleActivatePage, |
| 318 base::Unretained(this))); |
| 313 web_ui_->RegisterMessageCallback("openAboutMemory", | 319 web_ui_->RegisterMessageCallback("openAboutMemory", |
| 314 base::Bind(&TaskManagerHandler::OpenAboutMemory, | 320 base::Bind(&TaskManagerHandler::OpenAboutMemory, |
| 315 base::Unretained(this))); | 321 base::Unretained(this))); |
| 316 web_ui_->RegisterMessageCallback("enableTaskManager", | 322 web_ui_->RegisterMessageCallback("enableTaskManager", |
| 317 base::Bind(&TaskManagerHandler::EnableTaskManager, | 323 base::Bind(&TaskManagerHandler::EnableTaskManager, |
| 318 base::Unretained(this))); | 324 base::Unretained(this))); |
| 319 web_ui_->RegisterMessageCallback("disableTaskManager", | 325 web_ui_->RegisterMessageCallback("disableTaskManager", |
| 320 base::Bind(&TaskManagerHandler::DisableTaskManager, | 326 base::Bind(&TaskManagerHandler::DisableTaskManager, |
| 321 base::Unretained(this))); | 327 base::Unretained(this))); |
| 322 } | 328 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 344 | 350 |
| 345 int resource_index = model_->GetResourceIndexForGroup(index, 0); | 351 int resource_index = model_->GetResourceIndexForGroup(index, 0); |
| 346 if (resource_index == -1) | 352 if (resource_index == -1) |
| 347 continue; | 353 continue; |
| 348 | 354 |
| 349 LOG(INFO) << "kill PID:" << model_->GetResourceProcessId(resource_index); | 355 LOG(INFO) << "kill PID:" << model_->GetResourceProcessId(resource_index); |
| 350 task_manager_->KillProcess(resource_index); | 356 task_manager_->KillProcess(resource_index); |
| 351 } | 357 } |
| 352 } | 358 } |
| 353 | 359 |
| 360 void TaskManagerHandler::HandleActivatePage(const ListValue* resource_index) { |
| 361 for (ListValue::const_iterator i = resource_index->begin(); |
| 362 i != resource_index->end(); ++i) { |
| 363 int unique_id = parseIndex(*i); |
| 364 if (unique_id == -1) |
| 365 continue; |
| 366 |
| 367 for (int resource_index = 0; resource_index < model_->ResourceCount(); |
| 368 ++resource_index) { |
| 369 if (model_->GetResourceUniqueId(resource_index) == unique_id) { |
| 370 task_manager_->ActivateProcess(resource_index); |
| 371 break; |
| 372 } |
| 373 } |
| 374 |
| 375 break; |
| 376 } |
| 377 } |
| 378 |
| 354 void TaskManagerHandler::HandleInspect(const ListValue* resource_index) { | 379 void TaskManagerHandler::HandleInspect(const ListValue* resource_index) { |
| 355 for (ListValue::const_iterator i = resource_index->begin(); | 380 for (ListValue::const_iterator i = resource_index->begin(); |
| 356 i != resource_index->end(); ++i) { | 381 i != resource_index->end(); ++i) { |
| 357 int unique_id = parseIndex(*i); | 382 int unique_id = parseIndex(*i); |
| 358 if (unique_id == -1) | 383 if (unique_id == -1) |
| 359 continue; | 384 continue; |
| 360 | 385 |
| 361 for (int resource_index = 0; resource_index < model_->ResourceCount(); | 386 for (int resource_index = 0; resource_index < model_->ResourceCount(); |
| 362 ++resource_index) { | 387 ++resource_index) { |
| 363 if (model_->GetResourceUniqueId(resource_index) == unique_id) { | 388 if (model_->GetResourceUniqueId(resource_index) == unique_id) { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 } | 483 } |
| 459 } | 484 } |
| 460 | 485 |
| 461 void TaskManagerHandler::OnGroupRemoved(const int group_start, | 486 void TaskManagerHandler::OnGroupRemoved(const int group_start, |
| 462 const int group_length) { | 487 const int group_length) { |
| 463 base::FundamentalValue start_value(group_start); | 488 base::FundamentalValue start_value(group_start); |
| 464 base::FundamentalValue length_value(group_length); | 489 base::FundamentalValue length_value(group_length); |
| 465 if (is_enabled_ && is_alive()) | 490 if (is_enabled_ && is_alive()) |
| 466 web_ui_->CallJavascriptFunction("taskRemoved", start_value, length_value); | 491 web_ui_->CallJavascriptFunction("taskRemoved", start_value, length_value); |
| 467 } | 492 } |
| OLD | NEW |