| 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 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 rvh->UpdateWebkitPreferences(webkit_prefs); | 394 rvh->UpdateWebkitPreferences(webkit_prefs); |
| 395 } else { | 395 } else { |
| 396 DCHECK(false); | 396 DCHECK(false); |
| 397 } | 397 } |
| 398 | 398 |
| 399 task_manager_->OpenAboutMemory(); | 399 task_manager_->OpenAboutMemory(); |
| 400 } | 400 } |
| 401 | 401 |
| 402 // TaskManagerHandler, private: ----------------------------------------------- | 402 // TaskManagerHandler, private: ----------------------------------------------- |
| 403 | 403 |
| 404 bool TaskManagerHandler::is_alive() { |
| 405 return web_ui_->tab_contents()->render_view_host(); |
| 406 } |
| 407 |
| 404 void TaskManagerHandler::UpdateResourceGroupTable(int start, int length) { | 408 void TaskManagerHandler::UpdateResourceGroupTable(int start, int length) { |
| 405 if (resource_to_group_table_.size() < static_cast<size_t>(start)) { | 409 if (resource_to_group_table_.size() < static_cast<size_t>(start)) { |
| 406 length += start - resource_to_group_table_.size(); | 410 length += start - resource_to_group_table_.size(); |
| 407 start = resource_to_group_table_.size(); | 411 start = resource_to_group_table_.size(); |
| 408 } | 412 } |
| 409 | 413 |
| 410 // Makes room to fill group_index at first since inserting vector is too slow. | 414 // Makes room to fill group_index at first since inserting vector is too slow. |
| 411 std::vector<int>::iterator it = resource_to_group_table_.begin() + start; | 415 std::vector<int>::iterator it = resource_to_group_table_.begin() + start; |
| 412 resource_to_group_table_.insert(it, static_cast<size_t>(length), -1); | 416 resource_to_group_table_.insert(it, static_cast<size_t>(length), -1); |
| 413 | 417 |
| 414 for (int i = start; i < start + length; i++) { | 418 for (int i = start; i < start + length; i++) { |
| 415 const int group_index = model_->GetGroupIndexForResource(i); | 419 const int group_index = model_->GetGroupIndexForResource(i); |
| 416 resource_to_group_table_[i] = group_index; | 420 resource_to_group_table_[i] = group_index; |
| 417 } | 421 } |
| 418 } | 422 } |
| 419 | 423 |
| 420 void TaskManagerHandler::OnGroupChanged(const int group_start, | 424 void TaskManagerHandler::OnGroupChanged(const int group_start, |
| 421 const int group_length) { | 425 const int group_length) { |
| 422 base::FundamentalValue start_value(group_start); | 426 base::FundamentalValue start_value(group_start); |
| 423 base::FundamentalValue length_value(group_length); | 427 base::FundamentalValue length_value(group_length); |
| 424 base::ListValue tasks_value; | 428 base::ListValue tasks_value; |
| 425 | 429 |
| 426 for (int i = 0; i < group_length; ++i) | 430 for (int i = 0; i < group_length; ++i) |
| 427 tasks_value.Append(CreateTaskGroupValue(model_, group_start + i)); | 431 tasks_value.Append(CreateTaskGroupValue(model_, group_start + i)); |
| 428 | 432 |
| 429 if (is_enabled_) { | 433 if (is_enabled_ && is_alive()) { |
| 430 web_ui_->CallJavascriptFunction("taskChanged", | 434 web_ui_->CallJavascriptFunction("taskChanged", |
| 431 start_value, length_value, tasks_value); | 435 start_value, length_value, tasks_value); |
| 432 } | 436 } |
| 433 } | 437 } |
| 434 | 438 |
| 435 void TaskManagerHandler::OnGroupAdded(const int group_start, | 439 void TaskManagerHandler::OnGroupAdded(const int group_start, |
| 436 const int group_length) { | 440 const int group_length) { |
| 437 base::FundamentalValue start_value(group_start); | 441 base::FundamentalValue start_value(group_start); |
| 438 base::FundamentalValue length_value(group_length); | 442 base::FundamentalValue length_value(group_length); |
| 439 base::ListValue tasks_value; | 443 base::ListValue tasks_value; |
| 440 for (int i = 0; i < group_length; ++i) | 444 for (int i = 0; i < group_length; ++i) |
| 441 tasks_value.Append(CreateTaskGroupValue(model_, group_start + i)); | 445 tasks_value.Append(CreateTaskGroupValue(model_, group_start + i)); |
| 442 | 446 |
| 443 if (is_enabled_) { | 447 if (is_enabled_ && is_alive()) { |
| 444 web_ui_->CallJavascriptFunction("taskAdded", | 448 web_ui_->CallJavascriptFunction("taskAdded", |
| 445 start_value, length_value, tasks_value); | 449 start_value, length_value, tasks_value); |
| 446 } | 450 } |
| 447 } | 451 } |
| 448 | 452 |
| 449 void TaskManagerHandler::OnGroupRemoved(const int group_start, | 453 void TaskManagerHandler::OnGroupRemoved(const int group_start, |
| 450 const int group_length) { | 454 const int group_length) { |
| 451 base::FundamentalValue start_value(group_start); | 455 base::FundamentalValue start_value(group_start); |
| 452 base::FundamentalValue length_value(group_length); | 456 base::FundamentalValue length_value(group_length); |
| 453 if (is_enabled_) | 457 if (is_enabled_ && is_alive()) |
| 454 web_ui_->CallJavascriptFunction("taskRemoved", start_value, length_value); | 458 web_ui_->CallJavascriptFunction("taskRemoved", start_value, length_value); |
| 455 } | 459 } |
| OLD | NEW |