Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_UI_TASK_MANAGER_TASK_MANAGER_TABLE_MODEL_H_ | |
| 6 #define CHROME_BROWSER_UI_TASK_MANAGER_TASK_MANAGER_TABLE_MODEL_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/values.h" | |
| 11 #include "chrome/browser/task_management/task_manager_observer.h" | |
| 12 #include "ui/base/models/table_model.h" | |
| 13 | |
| 14 namespace task_management { | |
| 15 | |
| 16 class TaskManagerValuesStringifier; | |
| 17 | |
| 18 // Describes how the platform specific table view is sorted. | |
| 19 struct TableSortDescriptor { | |
| 20 TableSortDescriptor(); | |
| 21 TableSortDescriptor(int col_id, bool ascending); | |
| 22 | |
| 23 // The ID of the sorted column, -1 if the table is not sorted. | |
| 24 int sorted_column_id; | |
| 25 | |
| 26 // True if the column is sorted ascending. | |
| 27 bool is_ascending; | |
| 28 }; | |
| 29 | |
| 30 // An interface to be able to communicate with the platform-specific table view | |
| 31 // (Either views::TableView or NSTableView on the Mac). | |
| 32 class TableViewDelegate { | |
| 33 public: | |
| 34 TableViewDelegate() {} | |
| 35 virtual ~TableViewDelegate() {} | |
| 36 | |
| 37 virtual bool IsColumnVisible(int column_id) const = 0; | |
| 38 | |
| 39 virtual void SetColumnVisibility(int column_id, bool new_visibility) = 0; | |
| 40 | |
| 41 virtual bool IsTableSorted() const = 0; | |
| 42 | |
| 43 virtual TableSortDescriptor GetSortDescriptor() const = 0; | |
| 44 | |
| 45 // As the name of |visible_column_index| implies, it must by the index of the | |
| 46 // column in the visible columns array. | |
| 47 virtual void ToggleSortOrder(int visible_column_index) = 0; | |
| 48 | |
| 49 private: | |
| 50 DISALLOW_COPY_AND_ASSIGN(TableViewDelegate); | |
| 51 }; | |
| 52 | |
| 53 class TaskManagerTableModel | |
| 54 : public TaskManagerObserver, | |
| 55 public ui::TableModel { | |
| 56 public: | |
| 57 TaskManagerTableModel(int64 refresh_flags, TableViewDelegate* delegate); | |
|
Lei Zhang
2015/09/24 05:33:58
int64_t (see comments in base/basictypes.h) Also i
afakhry
2015/09/25 16:39:49
Done here! Though I should send a follow-up CL aft
| |
| 58 ~TaskManagerTableModel() override; | |
| 59 | |
| 60 // ui::TableModel: | |
| 61 int RowCount() override; | |
| 62 base::string16 GetText(int row, int column) override; | |
| 63 gfx::ImageSkia GetIcon(int row) override; | |
| 64 void SetObserver(ui::TableModelObserver* observer) override; | |
| 65 int CompareValues(int row1, int row2, int column_id) override; | |
| 66 | |
| 67 // task_management::TaskManagerObserver: | |
| 68 void OnTaskAdded(TaskId id) override; | |
| 69 void OnTaskToBeRemoved(TaskId id) override; | |
| 70 void OnTasksRefreshed(const TaskIdList& task_ids) override; | |
| 71 | |
| 72 // Gets the start index and length of the group to which the task at | |
| 73 // |row_index| belongs. | |
| 74 void GetRowsGroupRange(int row_index, int* out_start, int* out_length); | |
| 75 | |
| 76 // Start / stop observing the task manager. | |
| 77 void StartUpdating(); | |
| 78 void StopUpdating(); | |
| 79 | |
| 80 // Activates the browser tab associated with the process in the specified | |
| 81 // |row_index|. | |
| 82 void ActivateTask(int row_index); | |
| 83 | |
| 84 // Kills the process on which the task at |row_index| is running. | |
| 85 void KillTask(int row_index); | |
| 86 | |
| 87 // Based on the given |visibility| and the |column_id|, a particular refresh | |
| 88 // type will be enabled or disabled. | |
| 89 void UpdateRefreshTypes(int column_id, bool visibility); | |
| 90 | |
|
Lei Zhang
2015/09/24 05:33:58
nit: extra blank line
afakhry
2015/09/25 16:39:49
Done.
| |
| 91 | |
| 92 // Checks if the task at |row_index| is running on the browser process. | |
| 93 bool IsBrowserProcess(int row_index) const; | |
| 94 | |
| 95 // Restores the saved columns settings from a previous session into | |
| 96 // |columns_settings_| and updates the table view. | |
| 97 void RetrieveSavedColumnsSettingsAndUpdateTable(); | |
| 98 | |
| 99 // Stores the current values in |column_settings_| to the user prefs so that | |
| 100 // it can be restored later next time the task manager view is opened. | |
| 101 void StoreColumnsSettings(); | |
| 102 | |
| 103 void ToggleColumnVisibility(int column_id); | |
| 104 | |
| 105 private: | |
| 106 void OnRefresh(); | |
| 107 | |
| 108 // Checks whether the task at |row_index| is the first task in its process | |
| 109 // group of tasks. | |
| 110 bool IsTaskFirstInGroup(int row_index) const; | |
| 111 | |
| 112 // The delegate that will be used to communicate with the platform-specific | |
| 113 // TableView. | |
| 114 TableViewDelegate* table_view_delegate_; | |
| 115 | |
| 116 // Contains either the column settings retrieved from user preferences if it | |
| 117 // exists, or the default column settings. | |
| 118 // The columns settings are the visible columns and the last sorted column | |
| 119 // and the direction of the sort. | |
| 120 scoped_ptr<base::DictionaryValue> columns_settings_; | |
| 121 | |
| 122 // The table model observer that will be set by the table view of the task | |
| 123 // manager. | |
| 124 ui::TableModelObserver* table_model_observer_; | |
| 125 | |
| 126 // The sorted list of task IDs by process ID then by task ID. | |
| 127 std::vector<TaskId> tasks_; | |
| 128 | |
| 129 // The owned task manager values stringifier that will be used to convert the | |
| 130 // values to string16. | |
| 131 scoped_ptr<TaskManagerValuesStringifier> stringifier_; | |
| 132 | |
| 133 DISALLOW_COPY_AND_ASSIGN(TaskManagerTableModel); | |
| 134 }; | |
| 135 | |
| 136 } // namespace task_management | |
| 137 | |
| 138 #endif // CHROME_BROWSER_UI_TASK_MANAGER_TASK_MANAGER_TABLE_MODEL_H_ | |
| OLD | NEW |