| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/task_manager/task_manager_table_model.h" | 5 #include "chrome/browser/ui/task_manager/task_manager_table_model.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/i18n/number_formatting.h" | 10 #include "base/i18n/number_formatting.h" |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 } | 576 } |
| 577 | 577 |
| 578 void TaskManagerTableModel::OnTaskAdded(TaskId id) { | 578 void TaskManagerTableModel::OnTaskAdded(TaskId id) { |
| 579 // For the table view scrollbar to behave correctly we must inform it that | 579 // For the table view scrollbar to behave correctly we must inform it that |
| 580 // a new task has been added. | 580 // a new task has been added. |
| 581 | 581 |
| 582 // We will get a newly sorted list from the task manager as opposed to just | 582 // We will get a newly sorted list from the task manager as opposed to just |
| 583 // adding |id| to |tasks_| because we want to keep |tasks_| sorted by proc IDs | 583 // adding |id| to |tasks_| because we want to keep |tasks_| sorted by proc IDs |
| 584 // and then by Task IDs. | 584 // and then by Task IDs. |
| 585 tasks_ = observed_task_manager()->GetTaskIdsList(); | 585 tasks_ = observed_task_manager()->GetTaskIdsList(); |
| 586 if (table_model_observer_) | 586 |
| 587 table_model_observer_->OnItemsAdded(RowCount() - 1, 1); | 587 if (table_model_observer_) { |
| 588 std::vector<TaskId>::difference_type index = |
| 589 std::find(tasks_.begin(), tasks_.end(), id) - tasks_.begin(); |
| 590 table_model_observer_->OnItemsAdded(static_cast<int>(index), 1); |
| 591 } |
| 588 } | 592 } |
| 589 | 593 |
| 590 void TaskManagerTableModel::OnTaskToBeRemoved(TaskId id) { | 594 void TaskManagerTableModel::OnTaskToBeRemoved(TaskId id) { |
| 591 auto index = std::find(tasks_.begin(), tasks_.end(), id); | 595 auto index = std::find(tasks_.begin(), tasks_.end(), id); |
| 592 if (index == tasks_.end()) | 596 if (index == tasks_.end()) |
| 593 return; | 597 return; |
| 594 auto removed_index = index - tasks_.begin(); | 598 auto removed_index = index - tasks_.begin(); |
| 595 tasks_.erase(index); | 599 tasks_.erase(index); |
| 596 if (table_model_observer_) | 600 if (table_model_observer_) |
| 597 table_model_observer_->OnItemsRemoved(removed_index, 1); | 601 table_model_observer_->OnItemsRemoved(removed_index, 1); |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 829 bool TaskManagerTableModel::IsTaskFirstInGroup(int row_index) const { | 833 bool TaskManagerTableModel::IsTaskFirstInGroup(int row_index) const { |
| 830 if (row_index == 0) | 834 if (row_index == 0) |
| 831 return true; | 835 return true; |
| 832 | 836 |
| 833 return observed_task_manager()->GetProcessId(tasks_[row_index - 1]) != | 837 return observed_task_manager()->GetProcessId(tasks_[row_index - 1]) != |
| 834 observed_task_manager()->GetProcessId(tasks_[row_index]); | 838 observed_task_manager()->GetProcessId(tasks_[row_index]); |
| 835 } | 839 } |
| 836 | 840 |
| 837 | 841 |
| 838 } // namespace task_management | 842 } // namespace task_management |
| OLD | NEW |