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