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

Side by Side Diff: chrome/browser/ui/views/new_task_manager_view.cc

Issue 1320563002: Task Manager Should remember the most recently enabled columns. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 5 years, 3 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
« no previous file with comments | « chrome/browser/ui/views/new_task_manager_view.h ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/views/new_task_manager_view.h" 5 #include "chrome/browser/ui/views/new_task_manager_view.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/i18n/number_formatting.h" 9 #include "base/i18n/number_formatting.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 // The string "*" that is used to show that there exists duplicates in the 230 // The string "*" that is used to show that there exists duplicates in the
231 // GPU memory. 231 // GPU memory.
232 const base::string16 asterisk_string_; 232 const base::string16 asterisk_string_;
233 233
234 // The string "Unknown". 234 // The string "Unknown".
235 const base::string16 unknown_string_; 235 const base::string16 unknown_string_;
236 236
237 DISALLOW_COPY_AND_ASSIGN(TaskManagerValuesStringifier); 237 DISALLOW_COPY_AND_ASSIGN(TaskManagerValuesStringifier);
238 }; 238 };
239 239
240 // A collection of data to be used in the construction of a task manager table
241 // column.
242 struct TableColumnData {
243 // The generated ID of the column. These can change from one build to another.
244 // Their values are controlled by the generation from generated_resources.grd.
245 int id;
246
247 // The alignment of the text displayed in this column.
248 ui::TableColumn::Alignment align;
249
250 // |width| and |percent| used to define the size of the column. See
251 // ui::TableColumn::width and ui::TableColumn::percent for details.
252 int width;
253 float percent;
254
255 // Is the column sortable.
256 bool sortable;
257
258 // Is the initial sort order ascending?
259 bool initial_sort_is_ascending;
260
261 // The default visibility of this column at startup of the table if no
262 // visibility is stored for it in the prefs.
263 bool default_visibility;
264 };
265
266 // The task manager table columns and their properties.
267 // IMPORTANT: Do NOT change the below list without changing the COLUMN_LIST
268 // macro below.
269 const TableColumnData kColumns[] = {
270 { IDS_TASK_MANAGER_TASK_COLUMN, ui::TableColumn::LEFT, -1, 1, true, true,
271 true },
272 { IDS_TASK_MANAGER_PROFILE_NAME_COLUMN, ui::TableColumn::LEFT, -1, 0, true,
273 true, false },
274 { IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN, ui::TableColumn::RIGHT, -1, 0, true,
275 false, true },
276 { IDS_TASK_MANAGER_SHARED_MEM_COLUMN, ui::TableColumn::RIGHT, -1, 0, true,
277 false, false },
278 { IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN, ui::TableColumn::RIGHT, -1, 0, true,
279 false, false },
280 { IDS_TASK_MANAGER_CPU_COLUMN, ui::TableColumn::RIGHT, -1, 0, true, false,
281 true },
282 { IDS_TASK_MANAGER_NET_COLUMN, ui::TableColumn::RIGHT, -1, 0, true, false,
283 true },
284 { IDS_TASK_MANAGER_PROCESS_ID_COLUMN, ui::TableColumn::RIGHT, -1, 0, true,
285 true, true },
286
287 #if defined(OS_WIN)
288 { IDS_TASK_MANAGER_GDI_HANDLES_COLUMN, ui::TableColumn::RIGHT, -1, 0, true,
289 false, false },
290 { IDS_TASK_MANAGER_USER_HANDLES_COLUMN, ui::TableColumn::RIGHT, -1, 0, true,
291 false, false },
292 #endif
293
294 { IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN, ui::TableColumn::RIGHT, -1, 0,
295 true, false, false },
296 { IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN, ui::TableColumn::RIGHT, -1,
297 0, true, false, false },
298 { IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN, ui::TableColumn::RIGHT, -1, 0,
299 true, false, false },
300 { IDS_TASK_MANAGER_VIDEO_MEMORY_COLUMN, ui::TableColumn::RIGHT, -1, 0, true,
301 false, false },
302 { IDS_TASK_MANAGER_SQLITE_MEMORY_USED_COLUMN, ui::TableColumn::RIGHT, -1, 0,
303 true, false, false },
304
305 #if !defined(DISABLE_NACL)
306 { IDS_TASK_MANAGER_NACL_DEBUG_STUB_PORT_COLUMN, ui::TableColumn::RIGHT, -1, 0,
307 true, true, false },
308 #endif // !defined(DISABLE_NACL)
309
310 { IDS_TASK_MANAGER_JAVASCRIPT_MEMORY_ALLOCATED_COLUMN, ui::TableColumn::RIGHT,
311 -1, 0, true, false, false },
312
313 #if defined(OS_MACOSX) || defined(OS_LINUX)
314 // TODO(port): Port the idle wakeups per second to platforms other than Linux
315 // and MacOS (http://crbug.com/120488).
316 { IDS_TASK_MANAGER_IDLE_WAKEUPS_COLUMN, ui::TableColumn::RIGHT, -1, 0, true,
317 false, false },
318 #endif // defined(OS_MACOSX) || defined(OS_LINUX)
319 };
320
321 const size_t kColumnsSize = arraysize(kColumns);
322
323 // We can't use the integer IDs of the columns converted to strings as session
324 // restore keys. These integer values can change from one build to another as
325 // they are generated. Instead we use the literal string value of the column
326 // ID symbol (i.e. for the ID IDS_TASK_MANAGER_TASK_COLUMN, we use the literal
327 // string "IDS_TASK_MANAGER_TASK_COLUMN". The following macros help us
328 // efficiently get the literal ID for the integer value.
329 #define COLUMNS_LITS(def) \
330 def(IDS_TASK_MANAGER_TASK_COLUMN) \
331 def(IDS_TASK_MANAGER_PROFILE_NAME_COLUMN) \
332 def(IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN) \
333 def(IDS_TASK_MANAGER_SHARED_MEM_COLUMN) \
334 def(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN) \
335 def(IDS_TASK_MANAGER_CPU_COLUMN) \
336 def(IDS_TASK_MANAGER_NET_COLUMN) \
337 def(IDS_TASK_MANAGER_PROCESS_ID_COLUMN) \
338 def(IDS_TASK_MANAGER_GDI_HANDLES_COLUMN) \
339 def(IDS_TASK_MANAGER_USER_HANDLES_COLUMN) \
340 def(IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN) \
341 def(IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN) \
342 def(IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN) \
343 def(IDS_TASK_MANAGER_VIDEO_MEMORY_COLUMN) \
344 def(IDS_TASK_MANAGER_SQLITE_MEMORY_USED_COLUMN) \
345 def(IDS_TASK_MANAGER_NACL_DEBUG_STUB_PORT_COLUMN) \
346 def(IDS_TASK_MANAGER_JAVASCRIPT_MEMORY_ALLOCATED_COLUMN) \
347 def(IDS_TASK_MANAGER_IDLE_WAKEUPS_COLUMN)
348 // Add to the above list in the macro any new IDs added in the future. Also
349 // remove the removed ones.
350
351 #define COLUMN_ID_AS_STRING(col_id) case col_id: return std::string(#col_id);
352
353 std::string GetColumnIdAsString(int column_id) {
354 switch (column_id) {
355 COLUMNS_LITS(COLUMN_ID_AS_STRING)
356 default:
357 NOTREACHED();
358 return std::string();
359 }
360 }
361
362 // Session Restore Keys.
363 const char kSortColumnIdKey[] = "sort_column_id";
364 const char kSortIsAscendingKey[] = "sort_is_ascending";
365
240 } // namespace 366 } // namespace
241 367
242 //////////////////////////////////////////////////////////////////////////////// 368 ////////////////////////////////////////////////////////////////////////////////
243 369
244 // The table model of the task manager table view that will observe the 370 // The table model of the task manager table view that will observe the
245 // task manager backend and adapt its interface to match the requirements of the 371 // task manager backend and adapt its interface to match the requirements of the
246 // TableView. 372 // TableView.
247 class NewTaskManagerView::TableModel 373 class NewTaskManagerView::TableModel
248 : public TaskManagerObserver, 374 : public TaskManagerObserver,
249 public ui::TableModel, 375 public ui::TableModel,
(...skipping 23 matching lines...) Expand all
273 399
274 // Activates the browser tab associated with the process in the specified 400 // Activates the browser tab associated with the process in the specified
275 // |row_index|. 401 // |row_index|.
276 void ActivateTask(int row_index); 402 void ActivateTask(int row_index);
277 403
278 // Kills the process on which the task at |row_index| is running. 404 // Kills the process on which the task at |row_index| is running.
279 void KillTask(int row_index); 405 void KillTask(int row_index);
280 406
281 // Called when a column visibility is toggled from the context menu of the 407 // Called when a column visibility is toggled from the context menu of the
282 // table view. This will result in enabling or disabling some resources 408 // table view. This will result in enabling or disabling some resources
283 // refresh types in the task manager. 409 // refresh types in the task manager. It will also update the
284 void ToggleColumnVisibility(views::TableView* table, int column_id); 410 // |visibility_settings| with the new visibility so that it's stored in the
411 // prefs when the task manager window is closed.
412 void ToggleColumnVisibility(views::TableView* table,
413 base::DictionaryValue* visibility_settings,
414 int column_id);
415
416 // Based on the given |visibility| and the |column_id|, a particular refresh
417 // type will be enabled or disabled. Multiple columns can map to the same
418 // refresh type, for that we need |table| to determine if any is visible.
419 void UpdateRefreshTypes(views::TableView* table,
420 int column_id,
421 bool visibility);
422
285 423
286 // Checks if the task at |row_index| is running on the browser process. 424 // Checks if the task at |row_index| is running on the browser process.
287 bool IsBrowserProcess(int row_index) const; 425 bool IsBrowserProcess(int row_index) const;
288 426
289 private: 427 private:
290 void OnRefresh(); 428 void OnRefresh();
291 429
292 // Checks whether the task at |row_index| is the first task in its process 430 // Checks whether the task at |row_index| is the first task in its process
293 // group of tasks. 431 // group of tasks.
294 bool IsTaskFirstInGroup(int row_index) const; 432 bool IsTaskFirstInGroup(int row_index) const;
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 tasks_[row_index]); 751 tasks_[row_index]);
614 752
615 DCHECK_NE(proc_id, base::GetCurrentProcId()); 753 DCHECK_NE(proc_id, base::GetCurrentProcId());
616 754
617 base::Process process = base::Process::Open(proc_id); 755 base::Process process = base::Process::Open(proc_id);
618 process.Terminate(content::RESULT_CODE_KILLED, false); 756 process.Terminate(content::RESULT_CODE_KILLED, false);
619 } 757 }
620 758
621 void NewTaskManagerView::TableModel::ToggleColumnVisibility( 759 void NewTaskManagerView::TableModel::ToggleColumnVisibility(
622 views::TableView* table, 760 views::TableView* table,
761 base::DictionaryValue* visibility_settings,
623 int column_id) { 762 int column_id) {
624 DCHECK(table); 763 DCHECK(table);
764 DCHECK(visibility_settings);
625 765
626 bool new_visibility = !table->IsColumnVisible(column_id); 766 bool new_visibility = !table->IsColumnVisible(column_id);
627 table->SetColumnVisibility(column_id, new_visibility); 767 table->SetColumnVisibility(column_id, new_visibility);
768 visibility_settings->SetBoolean(GetColumnIdAsString(column_id),
769 new_visibility);
628 770
771 UpdateRefreshTypes(table, column_id, new_visibility);
772 }
773
774 void NewTaskManagerView::TableModel::UpdateRefreshTypes(views::TableView* table,
775 int column_id,
776 bool visibility) {
777 bool new_visibility = visibility;
629 RefreshType type = REFRESH_TYPE_NONE; 778 RefreshType type = REFRESH_TYPE_NONE;
630 switch (column_id) { 779 switch (column_id) {
780 case IDS_TASK_MANAGER_PROFILE_NAME_COLUMN:
781 case IDS_TASK_MANAGER_TASK_COLUMN:
782 case IDS_TASK_MANAGER_PROCESS_ID_COLUMN:
783 return; // The data is these columns do not change.
784
631 case IDS_TASK_MANAGER_NET_COLUMN: 785 case IDS_TASK_MANAGER_NET_COLUMN:
632 type = REFRESH_TYPE_NETWORK_USAGE; 786 type = REFRESH_TYPE_NETWORK_USAGE;
633 break; 787 break;
634 788
635 case IDS_TASK_MANAGER_CPU_COLUMN: 789 case IDS_TASK_MANAGER_CPU_COLUMN:
636 type = REFRESH_TYPE_CPU; 790 type = REFRESH_TYPE_CPU;
637 break; 791 break;
638 792
793 case IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN:
639 case IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN: 794 case IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN:
640 case IDS_TASK_MANAGER_SHARED_MEM_COLUMN: 795 case IDS_TASK_MANAGER_SHARED_MEM_COLUMN:
641 case IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN:
642 type = REFRESH_TYPE_MEMORY; 796 type = REFRESH_TYPE_MEMORY;
643 if (table->IsColumnVisible(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN) || 797 if (table->IsColumnVisible(IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN) ||
644 table->IsColumnVisible(IDS_TASK_MANAGER_SHARED_MEM_COLUMN) || 798 table->IsColumnVisible(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN) ||
645 table->IsColumnVisible(IDS_TASK_MANAGER_SHARED_MEM_COLUMN)) { 799 table->IsColumnVisible(IDS_TASK_MANAGER_SHARED_MEM_COLUMN)) {
646 new_visibility = true; 800 new_visibility = true;
647 } 801 }
648 break; 802 break;
649 803
650 case IDS_TASK_MANAGER_GDI_HANDLES_COLUMN: 804 case IDS_TASK_MANAGER_GDI_HANDLES_COLUMN:
651 case IDS_TASK_MANAGER_USER_HANDLES_COLUMN: 805 case IDS_TASK_MANAGER_USER_HANDLES_COLUMN:
652 type = REFRESH_TYPE_HANDLES; 806 type = REFRESH_TYPE_HANDLES;
653 if (table->IsColumnVisible(IDS_TASK_MANAGER_GDI_HANDLES_COLUMN) || 807 if (table->IsColumnVisible(IDS_TASK_MANAGER_GDI_HANDLES_COLUMN) ||
654 table->IsColumnVisible(IDS_TASK_MANAGER_USER_HANDLES_COLUMN)) { 808 table->IsColumnVisible(IDS_TASK_MANAGER_USER_HANDLES_COLUMN)) {
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 1041
888 void NewTaskManagerView::WindowClosing() { 1042 void NewTaskManagerView::WindowClosing() {
889 // Now that the window is closed, we can allow a new one to be opened. 1043 // Now that the window is closed, we can allow a new one to be opened.
890 // (WindowClosing comes in asynchronously from the call to Close() and we 1044 // (WindowClosing comes in asynchronously from the call to Close() and we
891 // may have already opened a new instance). 1045 // may have already opened a new instance).
892 if (g_task_manager_view == this) { 1046 if (g_task_manager_view == this) {
893 // We don't have to delete |g_task_manager_view| as we don't own it. It's 1047 // We don't have to delete |g_task_manager_view| as we don't own it. It's
894 // owned by the Views hierarchy. 1048 // owned by the Views hierarchy.
895 g_task_manager_view = nullptr; 1049 g_task_manager_view = nullptr;
896 } 1050 }
1051 StoreColumnsSettings();
897 table_model_->StopUpdating(); 1052 table_model_->StopUpdating();
898 } 1053 }
899 1054
900 bool NewTaskManagerView::UseNewStyleForThisDialog() const { 1055 bool NewTaskManagerView::UseNewStyleForThisDialog() const {
901 return false; 1056 return false;
902 } 1057 }
903 1058
904 void NewTaskManagerView::OnSelectionChanged() { 1059 void NewTaskManagerView::OnSelectionChanged() {
905 const ui::ListSelectionModel::SelectedIndices& selections( 1060 const ui::ListSelectionModel::SelectedIndices& selections(
906 tab_table_->selection_model().selected_indices()); 1061 tab_table_->selection_model().selected_indices());
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 return true; 1116 return true;
962 } 1117 }
963 1118
964 bool NewTaskManagerView::GetAcceleratorForCommandId( 1119 bool NewTaskManagerView::GetAcceleratorForCommandId(
965 int command_id, 1120 int command_id,
966 ui::Accelerator* accelerator) { 1121 ui::Accelerator* accelerator) {
967 return false; 1122 return false;
968 } 1123 }
969 1124
970 void NewTaskManagerView::ExecuteCommand(int id, int event_flags) { 1125 void NewTaskManagerView::ExecuteCommand(int id, int event_flags) {
971 table_model_->ToggleColumnVisibility(tab_table_, id); 1126 table_model_->ToggleColumnVisibility(tab_table_,
1127 columns_settings_.get(),
1128 id);
972 } 1129 }
973 1130
974 NewTaskManagerView::NewTaskManagerView(chrome::HostDesktopType desktop_type) 1131 NewTaskManagerView::NewTaskManagerView(chrome::HostDesktopType desktop_type)
975 : table_model_( 1132 : table_model_(
976 new NewTaskManagerView::TableModel(REFRESH_TYPE_CPU | 1133 new NewTaskManagerView::TableModel(REFRESH_TYPE_CPU |
977 REFRESH_TYPE_MEMORY | 1134 REFRESH_TYPE_MEMORY |
978 REFRESH_TYPE_NETWORK_USAGE)), 1135 REFRESH_TYPE_NETWORK_USAGE)),
979 menu_runner_(nullptr),
980 always_on_top_menu_text_(),
981 kill_button_(nullptr), 1136 kill_button_(nullptr),
982 about_memory_link_(nullptr), 1137 about_memory_link_(nullptr),
983 tab_table_(nullptr), 1138 tab_table_(nullptr),
984 tab_table_parent_(nullptr), 1139 tab_table_parent_(nullptr),
985 columns_(),
986 desktop_type_(desktop_type), 1140 desktop_type_(desktop_type),
987 is_always_on_top_(false) { 1141 is_always_on_top_(false) {
988 Init(); 1142 Init();
989 } 1143 }
990 1144
991 void NewTaskManagerView::Init() { 1145 void NewTaskManagerView::Init() {
992 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_TASK_COLUMN, 1146 columns_settings_.reset(new base::DictionaryValue);
993 ui::TableColumn::LEFT, -1, 1));
994 columns_.back().sortable = true;
995 1147
996 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_PROFILE_NAME_COLUMN, 1148 // Create the table columns.
997 ui::TableColumn::LEFT, -1, 0)); 1149 for (size_t i = 0; i < kColumnsSize; ++i) {
998 columns_.back().sortable = true; 1150 const auto& col_data = kColumns[i];
1151 columns_.push_back(ui::TableColumn(col_data.id, col_data.align,
1152 col_data.width, col_data.percent));
1153 columns_.back().sortable = col_data.sortable;
1154 columns_.back().initial_sort_is_ascending =
1155 col_data.initial_sort_is_ascending;
1156 }
999 1157
1000 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN, 1158 // Create the table view.
1001 ui::TableColumn::RIGHT, -1, 0));
1002 columns_.back().sortable = true;
1003 columns_.back().initial_sort_is_ascending = false;
1004
1005 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_SHARED_MEM_COLUMN,
1006 ui::TableColumn::RIGHT, -1, 0));
1007 columns_.back().sortable = true;
1008 columns_.back().initial_sort_is_ascending = false;
1009
1010 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN,
1011 ui::TableColumn::RIGHT, -1, 0));
1012 columns_.back().sortable = true;
1013 columns_.back().initial_sort_is_ascending = false;
1014
1015 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_CPU_COLUMN,
1016 ui::TableColumn::RIGHT, -1, 0));
1017 columns_.back().sortable = true;
1018 columns_.back().initial_sort_is_ascending = false;
1019
1020 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_NET_COLUMN,
1021 ui::TableColumn::RIGHT, -1, 0));
1022 columns_.back().sortable = true;
1023 columns_.back().initial_sort_is_ascending = false;
1024
1025 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_PROCESS_ID_COLUMN,
1026 ui::TableColumn::RIGHT, -1, 0));
1027 columns_.back().sortable = true;
1028
1029 #if defined(OS_WIN)
1030 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_GDI_HANDLES_COLUMN,
1031 ui::TableColumn::RIGHT, -1, 0));
1032 columns_.back().sortable = true;
1033 columns_.back().initial_sort_is_ascending = false;
1034 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_USER_HANDLES_COLUMN,
1035 ui::TableColumn::RIGHT, -1, 0));
1036 columns_.back().sortable = true;
1037 columns_.back().initial_sort_is_ascending = false;
1038 #endif
1039
1040 columns_.push_back(ui::TableColumn(
1041 IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN,
1042 ui::TableColumn::RIGHT, -1, 0));
1043 columns_.back().sortable = true;
1044 columns_.back().initial_sort_is_ascending = false;
1045
1046 columns_.push_back(ui::TableColumn(
1047 IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN,
1048 ui::TableColumn::RIGHT, -1, 0));
1049 columns_.back().sortable = true;
1050 columns_.back().initial_sort_is_ascending = false;
1051
1052 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN,
1053 ui::TableColumn::RIGHT, -1, 0));
1054 columns_.back().sortable = true;
1055 columns_.back().initial_sort_is_ascending = false;
1056
1057 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_VIDEO_MEMORY_COLUMN,
1058 ui::TableColumn::RIGHT, -1, 0));
1059 columns_.back().sortable = true;
1060 columns_.back().initial_sort_is_ascending = false;
1061
1062 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_SQLITE_MEMORY_USED_COLUMN,
1063 ui::TableColumn::RIGHT, -1, 0));
1064 columns_.back().sortable = true;
1065 columns_.back().initial_sort_is_ascending = false;
1066
1067 #if !defined(DISABLE_NACL)
1068 columns_.push_back(ui::TableColumn(
1069 IDS_TASK_MANAGER_NACL_DEBUG_STUB_PORT_COLUMN,
1070 ui::TableColumn::RIGHT, -1, 0));
1071 columns_.back().sortable = true;
1072 #endif // !defined(DISABLE_NACL)
1073
1074 columns_.push_back(
1075 ui::TableColumn(IDS_TASK_MANAGER_JAVASCRIPT_MEMORY_ALLOCATED_COLUMN,
1076 ui::TableColumn::RIGHT, -1, 0));
1077 columns_.back().sortable = true;
1078 columns_.back().initial_sort_is_ascending = false;
1079
1080 #if defined(OS_MACOSX) || defined(OS_LINUX)
1081 // TODO(port): Port the idle wakeups per second to platforms other than Linux
1082 // and MacOS (http://crbug.com/120488).
1083 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_IDLE_WAKEUPS_COLUMN,
1084 ui::TableColumn::RIGHT, -1, 0));
1085 columns_.back().sortable = true;
1086 columns_.back().initial_sort_is_ascending = false;
1087 #endif // defined(OS_MACOSX) || defined(OS_LINUX)
1088
1089 tab_table_ = new views::TableView( 1159 tab_table_ = new views::TableView(
1090 table_model_.get(), columns_, views::ICON_AND_TEXT, false); 1160 table_model_.get(), columns_, views::ICON_AND_TEXT, false);
1091 tab_table_->SetGrouper(table_model_.get()); 1161 tab_table_->SetGrouper(table_model_.get());
1092
1093 // Hide some columns by default
1094 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_PROFILE_NAME_COLUMN, false);
1095 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_SHARED_MEM_COLUMN, false);
1096 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN, false);
1097 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN,
1098 false);
1099 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN,
1100 false);
1101 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN,
1102 false);
1103 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_VIDEO_MEMORY_COLUMN,
1104 false);
1105 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_SQLITE_MEMORY_USED_COLUMN,
1106 false);
1107 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_NACL_DEBUG_STUB_PORT_COLUMN,
1108 false);
1109 tab_table_->SetColumnVisibility(
1110 IDS_TASK_MANAGER_JAVASCRIPT_MEMORY_ALLOCATED_COLUMN,
1111 false);
1112 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_GDI_HANDLES_COLUMN, false);
1113 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_USER_HANDLES_COLUMN, false);
1114 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_IDLE_WAKEUPS_COLUMN, false);
1115
1116 tab_table_->SetObserver(this); 1162 tab_table_->SetObserver(this);
1117 tab_table_->set_context_menu_controller(this); 1163 tab_table_->set_context_menu_controller(this);
1118 set_context_menu_controller(this); 1164 set_context_menu_controller(this);
1119 1165
1166 RetrieveSavedColumnsSettingsAndUpdateTable();
1167
1120 kill_button_ = new views::LabelButton(this, 1168 kill_button_ = new views::LabelButton(this,
1121 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_KILL)); 1169 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_KILL));
1122 kill_button_->SetStyle(views::Button::STYLE_BUTTON); 1170 kill_button_->SetStyle(views::Button::STYLE_BUTTON);
1123 1171
1124 about_memory_link_ = new views::Link( 1172 about_memory_link_ = new views::Link(
1125 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_ABOUT_MEMORY_LINK)); 1173 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_ABOUT_MEMORY_LINK));
1126 about_memory_link_->set_listener(this); 1174 about_memory_link_->set_listener(this);
1127 1175
1128 // Makes sure our state is consistent. 1176 // Makes sure our state is consistent.
1129 OnSelectionChanged(); 1177 OnSelectionChanged();
(...skipping 17 matching lines...) Expand all
1147 1195
1148 if (!g_browser_process->local_state()) 1196 if (!g_browser_process->local_state())
1149 return; 1197 return;
1150 1198
1151 const base::DictionaryValue* dictionary = 1199 const base::DictionaryValue* dictionary =
1152 g_browser_process->local_state()->GetDictionary(GetWindowName()); 1200 g_browser_process->local_state()->GetDictionary(GetWindowName());
1153 if (dictionary) 1201 if (dictionary)
1154 dictionary->GetBoolean("always_on_top", &is_always_on_top_); 1202 dictionary->GetBoolean("always_on_top", &is_always_on_top_);
1155 } 1203 }
1156 1204
1205 void NewTaskManagerView::RetrieveSavedColumnsSettingsAndUpdateTable() {
1206 if (!g_browser_process->local_state())
1207 return;
1208
1209 const base::DictionaryValue* dictionary =
1210 g_browser_process->local_state()->GetDictionary(
1211 prefs::kTaskManagerColumnVisibility);
1212 if (!dictionary)
1213 return;
1214
1215 // Do a best effort of retrieving the correct settings from the local state.
1216 // Use the default settings of the value if it fails to be retrieved.
1217 std::string sorted_col_id;
1218 bool sort_is_ascending = true;
1219 dictionary->GetString(kSortColumnIdKey, &sorted_col_id);
1220 dictionary->GetBoolean(kSortIsAscendingKey, &sort_is_ascending);
1221
1222 int current_visible_column_index = 0;
1223 for (size_t i = 0; i < kColumnsSize; ++i) {
1224 const int col_id = kColumns[i].id;
1225 const std::string col_id_key(GetColumnIdAsString(col_id));
Lei Zhang 2015/08/29 00:47:09 Continue to the next loop iteration if |col_id_key
afakhry 2015/08/29 01:48:14 Done.
1226
1227 bool col_visibility = kColumns[i].default_visibility;
1228 dictionary->GetBoolean(col_id_key, &col_visibility);
1229
1230 // If the above GetBoolean() fails, the |col_visibility| will remain the
Lei Zhang 2015/08/29 00:47:09 "remain" -> "remain at" ?
afakhry 2015/08/29 01:48:14 Done.
1231 // default visibility.
1232 columns_settings_->SetBoolean(col_id_key, col_visibility);
1233 tab_table_->SetColumnVisibility(col_id, col_visibility);
1234 table_model_->UpdateRefreshTypes(tab_table_, col_id, col_visibility);
1235
1236 if (col_visibility) {
1237 if (sorted_col_id == col_id_key) {
1238 if (sort_is_ascending == kColumns[i].initial_sort_is_ascending) {
1239 tab_table_->ToggleSortOrder(current_visible_column_index);
1240 } else {
1241 // Unfortunately the API of ui::TableView doesn't provide a clean way
1242 // to sort by a particular column ID and a sort direction. If the
1243 // retrieved sort direction is different than the initial one, we have
1244 // to toggle the sort order twice!
1245 // Note that the function takes the visible_column_index rather than
1246 // a column ID.
1247 tab_table_->ToggleSortOrder(current_visible_column_index);
1248 tab_table_->ToggleSortOrder(current_visible_column_index);
1249 }
1250 }
1251
1252 ++current_visible_column_index;
1253 }
1254 }
1255 }
1256
1257 void NewTaskManagerView::StoreColumnsSettings() {
1258 PrefService* local_state = g_browser_process->local_state();
1259
Lei Zhang 2015/08/29 00:47:09 nit: remove blank line
afakhry 2015/08/29 01:48:14 Done.
1260 if (!local_state)
1261 return;
1262
1263 DictionaryPrefUpdate dict_update(local_state,
1264 prefs::kTaskManagerColumnVisibility);
1265
1266 base::DictionaryValue::Iterator it(*columns_settings_);
1267 while (!it.IsAtEnd()) {
1268 dict_update->Set(it.key(), it.value().CreateDeepCopy());
1269 it.Advance();
1270 }
1271
1272 // Store the current sort status to be restored again at startup.
1273 if (tab_table_->sort_descriptors().empty()) {
1274 dict_update->SetString(kSortColumnIdKey, "");
1275 } else {
1276 const auto& sort_descriptor = tab_table_->sort_descriptors().front();
1277 dict_update->SetString(kSortColumnIdKey,
1278 GetColumnIdAsString(sort_descriptor.column_id));
1279 dict_update->SetBoolean(kSortIsAscendingKey, sort_descriptor.ascending);
1280 }
1281 }
1282
1157 } // namespace task_management 1283 } // namespace task_management
1158 1284
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/new_task_manager_view.h ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698