Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: chrome/browser/ui/task_manager/task_manager_table_model.cc

Issue 1992623002: Task Manager: Preserve selection when rows are added (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Self-review fixes. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 int index = std::find(tasks_.begin(), tasks_.end(), id) - tasks_.begin();
587 table_model_observer_->OnItemsAdded(RowCount() - 1, 1); 587 if (table_model_observer_) {
afakhry 2016/05/18 23:12:18 Nit: Please remove the braces.
ncarter (slow) 2016/05/19 00:12:58 Done.
588 table_model_observer_->OnItemsAdded(index, 1);
589 }
588 } 590 }
589 591
590 void TaskManagerTableModel::OnTaskToBeRemoved(TaskId id) { 592 void TaskManagerTableModel::OnTaskToBeRemoved(TaskId id) {
591 auto index = std::find(tasks_.begin(), tasks_.end(), id); 593 auto index = std::find(tasks_.begin(), tasks_.end(), id);
592 if (index == tasks_.end()) 594 if (index == tasks_.end())
593 return; 595 return;
594 auto removed_index = index - tasks_.begin(); 596 auto removed_index = index - tasks_.begin();
595 tasks_.erase(index); 597 tasks_.erase(index);
596 if (table_model_observer_) 598 if (table_model_observer_)
597 table_model_observer_->OnItemsRemoved(removed_index, 1); 599 table_model_observer_->OnItemsRemoved(removed_index, 1);
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 bool TaskManagerTableModel::IsTaskFirstInGroup(int row_index) const { 831 bool TaskManagerTableModel::IsTaskFirstInGroup(int row_index) const {
830 if (row_index == 0) 832 if (row_index == 0)
831 return true; 833 return true;
832 834
833 return observed_task_manager()->GetProcessId(tasks_[row_index - 1]) != 835 return observed_task_manager()->GetProcessId(tasks_[row_index - 1]) !=
834 observed_task_manager()->GetProcessId(tasks_[row_index]); 836 observed_task_manager()->GetProcessId(tasks_[row_index]);
835 } 837 }
836 838
837 839
838 } // namespace task_management 840 } // namespace task_management
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698