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

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: thestig's 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
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 version number we manually assign for the list of columns. Any addition/
267 // removal to/from the columns list must be accompanied by incrementing the
268 // version number. This is needed so that we can restore the visible columns
269 // correctly.
270 const int kColumnsVersion = 1;
271
272 // The task manager table columns and their properties.
273 // IMPORTANT: Do NOT change the below list without changing the above version
274 // number.
Lei Zhang 2015/08/28 22:47:44 Remind readers about COLUMNS_LITS too?
afakhry 2015/08/29 00:30:29 Done.
275 const TableColumnData kColumns[] = {
276 { IDS_TASK_MANAGER_TASK_COLUMN, ui::TableColumn::LEFT, -1, 1, true, true,
277 true },
278 { IDS_TASK_MANAGER_PROFILE_NAME_COLUMN, ui::TableColumn::LEFT, -1, 0, true,
279 true, false },
280 { IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN, ui::TableColumn::RIGHT, -1, 0, true,
281 false, true },
282 { IDS_TASK_MANAGER_SHARED_MEM_COLUMN, ui::TableColumn::RIGHT, -1, 0, true,
283 false, false },
284 { IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN, ui::TableColumn::RIGHT, -1, 0, true,
285 false, false },
286 { IDS_TASK_MANAGER_CPU_COLUMN, ui::TableColumn::RIGHT, -1, 0, true, false,
287 true },
288 { IDS_TASK_MANAGER_NET_COLUMN, ui::TableColumn::RIGHT, -1, 0, true, false,
289 true },
290 { IDS_TASK_MANAGER_PROCESS_ID_COLUMN, ui::TableColumn::RIGHT, -1, 0, true,
291 true, true },
292
293 #if defined(OS_WIN)
294 { IDS_TASK_MANAGER_GDI_HANDLES_COLUMN, ui::TableColumn::RIGHT, -1, 0, true,
295 false, false },
296 { IDS_TASK_MANAGER_USER_HANDLES_COLUMN, ui::TableColumn::RIGHT, -1, 0, true,
297 false, false },
298 #endif
299
300 { IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN, ui::TableColumn::RIGHT, -1, 0,
301 true, false, false },
302 { IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN, ui::TableColumn::RIGHT, -1,
303 0, true, false, false },
304 { IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN, ui::TableColumn::RIGHT, -1, 0,
305 true, false, false },
306 { IDS_TASK_MANAGER_VIDEO_MEMORY_COLUMN, ui::TableColumn::RIGHT, -1, 0, true,
307 false, false },
308 { IDS_TASK_MANAGER_SQLITE_MEMORY_USED_COLUMN, ui::TableColumn::RIGHT, -1, 0,
309 true, false, false },
310
311 #if !defined(DISABLE_NACL)
312 { IDS_TASK_MANAGER_NACL_DEBUG_STUB_PORT_COLUMN, ui::TableColumn::RIGHT, -1, 0,
313 true, true, false },
314 #endif // !defined(DISABLE_NACL)
315
316 { IDS_TASK_MANAGER_JAVASCRIPT_MEMORY_ALLOCATED_COLUMN, ui::TableColumn::RIGHT,
317 -1, 0, true, false, false },
318
319 #if defined(OS_MACOSX) || defined(OS_LINUX)
320 // TODO(port): Port the idle wakeups per second to platforms other than Linux
321 // and MacOS (http://crbug.com/120488).
322 { IDS_TASK_MANAGER_IDLE_WAKEUPS_COLUMN, ui::TableColumn::RIGHT, -1, 0, true,
323 false, false },
324 #endif // defined(OS_MACOSX) || defined(OS_LINUX)
325 };
326
327 const size_t kColumnsSize = arraysize(kColumns);
328
329 // We can't use the integer IDs of the columns converted to strings as session
330 // restore keys. These integer values can change from one build to another as
331 // they are generated. Instead we use the literal string value of the column
332 // ID symbol (i.e. for the ID IDS_TASK_MANAGER_TASK_COLUMN, we use the literal
333 // string "IDS_TASK_MANAGER_TASK_COLUMN". The following macros help us
334 // efficiently get the literal ID for the integer value.
335 #define COLUMNS_LITS(def) \
336 def(IDS_TASK_MANAGER_TASK_COLUMN) \
337 def(IDS_TASK_MANAGER_PROFILE_NAME_COLUMN) \
338 def(IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN) \
339 def(IDS_TASK_MANAGER_SHARED_MEM_COLUMN) \
340 def(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN) \
341 def(IDS_TASK_MANAGER_CPU_COLUMN) \
342 def(IDS_TASK_MANAGER_NET_COLUMN) \
343 def(IDS_TASK_MANAGER_PROCESS_ID_COLUMN) \
344 def(IDS_TASK_MANAGER_GDI_HANDLES_COLUMN) \
345 def(IDS_TASK_MANAGER_USER_HANDLES_COLUMN) \
346 def(IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN) \
347 def(IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN) \
348 def(IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN) \
349 def(IDS_TASK_MANAGER_VIDEO_MEMORY_COLUMN) \
350 def(IDS_TASK_MANAGER_SQLITE_MEMORY_USED_COLUMN) \
351 def(IDS_TASK_MANAGER_NACL_DEBUG_STUB_PORT_COLUMN) \
352 def(IDS_TASK_MANAGER_JAVASCRIPT_MEMORY_ALLOCATED_COLUMN) \
353 def(IDS_TASK_MANAGER_IDLE_WAKEUPS_COLUMN)
354 // Add to the above list in the macro any new IDs added in the future. Also
355 // remove the removed ones.
356
357 #define COLUMN_ID_AS_STRING(col_id) case col_id: return std::string(#col_id);
358
359 std::string GetColumnIdAsString(int column_id) {
360 switch (column_id) {
361 COLUMNS_LITS(COLUMN_ID_AS_STRING)
362 default:
363 NOTREACHED();
364 return std::string();
365 }
366 }
367
368 // Session Restore Keys.
369 const char kColumnVersionKey[] = "columns_version";
370 const char kSortColumnIdKey[] = "sort_column_id";
371 const char kSortIsAscendingKey[] = "sort_is_ascending";
372
240 } // namespace 373 } // namespace
241 374
242 //////////////////////////////////////////////////////////////////////////////// 375 ////////////////////////////////////////////////////////////////////////////////
243 376
244 // The table model of the task manager table view that will observe the 377 // 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 378 // task manager backend and adapt its interface to match the requirements of the
246 // TableView. 379 // TableView.
247 class NewTaskManagerView::TableModel 380 class NewTaskManagerView::TableModel
248 : public TaskManagerObserver, 381 : public TaskManagerObserver,
249 public ui::TableModel, 382 public ui::TableModel,
(...skipping 23 matching lines...) Expand all
273 406
274 // Activates the browser tab associated with the process in the specified 407 // Activates the browser tab associated with the process in the specified
275 // |row_index|. 408 // |row_index|.
276 void ActivateTask(int row_index); 409 void ActivateTask(int row_index);
277 410
278 // Kills the process on which the task at |row_index| is running. 411 // Kills the process on which the task at |row_index| is running.
279 void KillTask(int row_index); 412 void KillTask(int row_index);
280 413
281 // Called when a column visibility is toggled from the context menu of the 414 // 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 415 // table view. This will result in enabling or disabling some resources
283 // refresh types in the task manager. 416 // refresh types in the task manager. It will also update the
284 void ToggleColumnVisibility(views::TableView* table, int column_id); 417 // |visibility_settings| with the new visibility so that it's stored in the
418 // prefs when the task manager window is closed.
419 void ToggleColumnVisibility(views::TableView* table,
420 base::DictionaryValue* visibility_settings,
421 int column_id);
422
423 // Based on the given |visibility| and the |column_id|, a particular refresh
424 // type will be enabled or disabled. Multiple columns can map to the same
425 // refresh type, for that we need |table| to determine if any is visible.
426 void UpdateRefreshTypes(views::TableView* table,
427 int column_id,
428 bool visibility);
429
285 430
286 // Checks if the task at |row_index| is running on the browser process. 431 // Checks if the task at |row_index| is running on the browser process.
287 bool IsBrowserProcess(int row_index) const; 432 bool IsBrowserProcess(int row_index) const;
288 433
289 private: 434 private:
290 void OnRefresh(); 435 void OnRefresh();
291 436
292 // Checks whether the task at |row_index| is the first task in its process 437 // Checks whether the task at |row_index| is the first task in its process
293 // group of tasks. 438 // group of tasks.
294 bool IsTaskFirstInGroup(int row_index) const; 439 bool IsTaskFirstInGroup(int row_index) const;
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 tasks_[row_index]); 758 tasks_[row_index]);
614 759
615 DCHECK_NE(proc_id, base::GetCurrentProcId()); 760 DCHECK_NE(proc_id, base::GetCurrentProcId());
616 761
617 base::Process process = base::Process::Open(proc_id); 762 base::Process process = base::Process::Open(proc_id);
618 process.Terminate(content::RESULT_CODE_KILLED, false); 763 process.Terminate(content::RESULT_CODE_KILLED, false);
619 } 764 }
620 765
621 void NewTaskManagerView::TableModel::ToggleColumnVisibility( 766 void NewTaskManagerView::TableModel::ToggleColumnVisibility(
622 views::TableView* table, 767 views::TableView* table,
768 base::DictionaryValue* visibility_settings,
623 int column_id) { 769 int column_id) {
624 DCHECK(table); 770 DCHECK(table);
771 DCHECK(visibility_settings);
625 772
626 bool new_visibility = !table->IsColumnVisible(column_id); 773 bool new_visibility = !table->IsColumnVisible(column_id);
627 table->SetColumnVisibility(column_id, new_visibility); 774 table->SetColumnVisibility(column_id, new_visibility);
775 visibility_settings->SetBoolean(GetColumnIdAsString(column_id),
776 new_visibility);
628 777
778 UpdateRefreshTypes(table, column_id, new_visibility);
779 }
780
781 void NewTaskManagerView::TableModel::UpdateRefreshTypes(views::TableView* table,
782 int column_id,
783 bool visibility) {
784 bool new_visibility = visibility;
629 RefreshType type = REFRESH_TYPE_NONE; 785 RefreshType type = REFRESH_TYPE_NONE;
630 switch (column_id) { 786 switch (column_id) {
787 case IDS_TASK_MANAGER_PROFILE_NAME_COLUMN:
788 case IDS_TASK_MANAGER_TASK_COLUMN:
789 case IDS_TASK_MANAGER_PROCESS_ID_COLUMN:
790 return; // The data is these columns do not change.
791
631 case IDS_TASK_MANAGER_NET_COLUMN: 792 case IDS_TASK_MANAGER_NET_COLUMN:
632 type = REFRESH_TYPE_NETWORK_USAGE; 793 type = REFRESH_TYPE_NETWORK_USAGE;
633 break; 794 break;
634 795
635 case IDS_TASK_MANAGER_CPU_COLUMN: 796 case IDS_TASK_MANAGER_CPU_COLUMN:
636 type = REFRESH_TYPE_CPU; 797 type = REFRESH_TYPE_CPU;
637 break; 798 break;
638 799
800 case IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN:
639 case IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN: 801 case IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN:
640 case IDS_TASK_MANAGER_SHARED_MEM_COLUMN: 802 case IDS_TASK_MANAGER_SHARED_MEM_COLUMN:
641 case IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN:
642 type = REFRESH_TYPE_MEMORY; 803 type = REFRESH_TYPE_MEMORY;
643 if (table->IsColumnVisible(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN) || 804 if (table->IsColumnVisible(IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN) ||
644 table->IsColumnVisible(IDS_TASK_MANAGER_SHARED_MEM_COLUMN) || 805 table->IsColumnVisible(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN) ||
645 table->IsColumnVisible(IDS_TASK_MANAGER_SHARED_MEM_COLUMN)) { 806 table->IsColumnVisible(IDS_TASK_MANAGER_SHARED_MEM_COLUMN)) {
646 new_visibility = true; 807 new_visibility = true;
647 } 808 }
648 break; 809 break;
649 810
650 case IDS_TASK_MANAGER_GDI_HANDLES_COLUMN: 811 case IDS_TASK_MANAGER_GDI_HANDLES_COLUMN:
651 case IDS_TASK_MANAGER_USER_HANDLES_COLUMN: 812 case IDS_TASK_MANAGER_USER_HANDLES_COLUMN:
652 type = REFRESH_TYPE_HANDLES; 813 type = REFRESH_TYPE_HANDLES;
653 if (table->IsColumnVisible(IDS_TASK_MANAGER_GDI_HANDLES_COLUMN) || 814 if (table->IsColumnVisible(IDS_TASK_MANAGER_GDI_HANDLES_COLUMN) ||
654 table->IsColumnVisible(IDS_TASK_MANAGER_USER_HANDLES_COLUMN)) { 815 table->IsColumnVisible(IDS_TASK_MANAGER_USER_HANDLES_COLUMN)) {
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 1048
888 void NewTaskManagerView::WindowClosing() { 1049 void NewTaskManagerView::WindowClosing() {
889 // Now that the window is closed, we can allow a new one to be opened. 1050 // 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 1051 // (WindowClosing comes in asynchronously from the call to Close() and we
891 // may have already opened a new instance). 1052 // may have already opened a new instance).
892 if (g_task_manager_view == this) { 1053 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 1054 // We don't have to delete |g_task_manager_view| as we don't own it. It's
894 // owned by the Views hierarchy. 1055 // owned by the Views hierarchy.
895 g_task_manager_view = nullptr; 1056 g_task_manager_view = nullptr;
896 } 1057 }
1058 StoreColumnsSettings();
897 table_model_->StopUpdating(); 1059 table_model_->StopUpdating();
898 } 1060 }
899 1061
900 bool NewTaskManagerView::UseNewStyleForThisDialog() const { 1062 bool NewTaskManagerView::UseNewStyleForThisDialog() const {
901 return false; 1063 return false;
902 } 1064 }
903 1065
904 void NewTaskManagerView::OnSelectionChanged() { 1066 void NewTaskManagerView::OnSelectionChanged() {
905 const ui::ListSelectionModel::SelectedIndices& selections( 1067 const ui::ListSelectionModel::SelectedIndices& selections(
906 tab_table_->selection_model().selected_indices()); 1068 tab_table_->selection_model().selected_indices());
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 return true; 1123 return true;
962 } 1124 }
963 1125
964 bool NewTaskManagerView::GetAcceleratorForCommandId( 1126 bool NewTaskManagerView::GetAcceleratorForCommandId(
965 int command_id, 1127 int command_id,
966 ui::Accelerator* accelerator) { 1128 ui::Accelerator* accelerator) {
967 return false; 1129 return false;
968 } 1130 }
969 1131
970 void NewTaskManagerView::ExecuteCommand(int id, int event_flags) { 1132 void NewTaskManagerView::ExecuteCommand(int id, int event_flags) {
971 table_model_->ToggleColumnVisibility(tab_table_, id); 1133 table_model_->ToggleColumnVisibility(tab_table_,
1134 columns_settings_.get(),
1135 id);
972 } 1136 }
973 1137
974 NewTaskManagerView::NewTaskManagerView(chrome::HostDesktopType desktop_type) 1138 NewTaskManagerView::NewTaskManagerView(chrome::HostDesktopType desktop_type)
975 : table_model_( 1139 : table_model_(
976 new NewTaskManagerView::TableModel(REFRESH_TYPE_CPU | 1140 new NewTaskManagerView::TableModel(REFRESH_TYPE_CPU |
977 REFRESH_TYPE_MEMORY | 1141 REFRESH_TYPE_MEMORY |
978 REFRESH_TYPE_NETWORK_USAGE)), 1142 REFRESH_TYPE_NETWORK_USAGE)),
979 menu_runner_(nullptr),
980 always_on_top_menu_text_(),
981 kill_button_(nullptr), 1143 kill_button_(nullptr),
982 about_memory_link_(nullptr), 1144 about_memory_link_(nullptr),
983 tab_table_(nullptr), 1145 tab_table_(nullptr),
984 tab_table_parent_(nullptr), 1146 tab_table_parent_(nullptr),
985 columns_(),
986 desktop_type_(desktop_type), 1147 desktop_type_(desktop_type),
987 is_always_on_top_(false) { 1148 is_always_on_top_(false) {
988 Init(); 1149 Init();
989 } 1150 }
990 1151
991 void NewTaskManagerView::Init() { 1152 void NewTaskManagerView::Init() {
992 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_TASK_COLUMN, 1153 columns_settings_.reset(new base::DictionaryValue);
993 ui::TableColumn::LEFT, -1, 1));
994 columns_.back().sortable = true;
995 1154
996 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_PROFILE_NAME_COLUMN, 1155 // Create the table columns.
997 ui::TableColumn::LEFT, -1, 0)); 1156 for (size_t i = 0; i < kColumnsSize; ++i) {
998 columns_.back().sortable = true; 1157 const auto& col_data = kColumns[i];
1158 columns_.push_back(ui::TableColumn(col_data.id, col_data.align,
1159 col_data.width, col_data.percent));
1160 columns_.back().sortable = col_data.sortable;
1161 columns_.back().initial_sort_is_ascending =
1162 col_data.initial_sort_is_ascending;
999 1163
1000 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN, 1164 columns_settings_->SetBoolean(GetColumnIdAsString(col_data.id),
1001 ui::TableColumn::RIGHT, -1, 0)); 1165 col_data.default_visibility);
Lei Zhang 2015/08/28 22:47:45 nit: indentation
afakhry 2015/08/29 00:30:29 Done.
1002 columns_.back().sortable = true; 1166 }
1003 columns_.back().initial_sort_is_ascending = false;
1004 1167
1005 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_SHARED_MEM_COLUMN, 1168 // Create the table view.
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( 1169 tab_table_ = new views::TableView(
1090 table_model_.get(), columns_, views::ICON_AND_TEXT, false); 1170 table_model_.get(), columns_, views::ICON_AND_TEXT, false);
1091 tab_table_->SetGrouper(table_model_.get()); 1171 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); 1172 tab_table_->SetObserver(this);
1117 tab_table_->set_context_menu_controller(this); 1173 tab_table_->set_context_menu_controller(this);
1118 set_context_menu_controller(this); 1174 set_context_menu_controller(this);
1119 1175
1176 // Retrieve and update the table columns visibilities.
1177 RetrieveSavedColumnsSettings();
1178 UpdateTableFromColumnsSettings();
1179
1120 kill_button_ = new views::LabelButton(this, 1180 kill_button_ = new views::LabelButton(this,
1121 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_KILL)); 1181 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_KILL));
1122 kill_button_->SetStyle(views::Button::STYLE_BUTTON); 1182 kill_button_->SetStyle(views::Button::STYLE_BUTTON);
1123 1183
1124 about_memory_link_ = new views::Link( 1184 about_memory_link_ = new views::Link(
1125 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_ABOUT_MEMORY_LINK)); 1185 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_ABOUT_MEMORY_LINK));
1126 about_memory_link_->set_listener(this); 1186 about_memory_link_->set_listener(this);
1127 1187
1128 // Makes sure our state is consistent. 1188 // Makes sure our state is consistent.
1129 OnSelectionChanged(); 1189 OnSelectionChanged();
(...skipping 17 matching lines...) Expand all
1147 1207
1148 if (!g_browser_process->local_state()) 1208 if (!g_browser_process->local_state())
1149 return; 1209 return;
1150 1210
1151 const base::DictionaryValue* dictionary = 1211 const base::DictionaryValue* dictionary =
1152 g_browser_process->local_state()->GetDictionary(GetWindowName()); 1212 g_browser_process->local_state()->GetDictionary(GetWindowName());
1153 if (dictionary) 1213 if (dictionary)
1154 dictionary->GetBoolean("always_on_top", &is_always_on_top_); 1214 dictionary->GetBoolean("always_on_top", &is_always_on_top_);
1155 } 1215 }
1156 1216
1217 void NewTaskManagerView::RetrieveSavedColumnsSettings() {
1218 if (!g_browser_process->local_state())
1219 return;
1220
1221 const base::DictionaryValue* dictionary =
1222 g_browser_process->local_state()->GetDictionary(
1223 prefs::kTaskManagerColumnVisibility);
1224 if (!dictionary)
1225 return;
1226
1227 int columns_version;
1228 if (!dictionary->GetInteger(kColumnVersionKey, &columns_version))
1229 return;
1230
1231 // If the number of columns changes from one version to another (i.e. the
Lei Zhang 2015/08/28 22:47:44 So the other possible way of doing this is to be v
afakhry 2015/08/29 00:30:29 I agree. I actually combined the Retrieve() and Up
1232 // columns version number changes), we skip and use the default visibility of
1233 // the columns as defined in |kColumns|.
1234 if (columns_version != kColumnsVersion)
1235 return;
1236
1237 columns_settings_.reset(dictionary->DeepCopy());
1238 }
1239
1240 void NewTaskManagerView::UpdateTableFromColumnsSettings() {
1241 std::string sorted_col_id;
1242 bool sort_is_ascending = true;
1243 columns_settings_->GetString(kSortColumnIdKey, &sorted_col_id);
1244 columns_settings_->GetBoolean(kSortIsAscendingKey, &sort_is_ascending);
1245
1246 int current_visible_column_index = 0;
1247 for (size_t i = 0; i < kColumnsSize; ++i) {
1248 const int col_id = kColumns[i].id;
1249 bool visible = false;
1250 bool success = columns_settings_->GetBoolean(
1251 GetColumnIdAsString(col_id), &visible);
1252
1253 DCHECK(success);
Lei Zhang 2015/08/28 22:47:44 Given the existence of malware and other external
afakhry 2015/08/29 00:30:29 Done.
1254
1255 tab_table_->SetColumnVisibility(col_id, visible);
1256 table_model_->UpdateRefreshTypes(tab_table_, col_id, visible);
1257
1258 if (visible) {
1259 if (sorted_col_id == GetColumnIdAsString(col_id)) {
1260 if (sort_is_ascending == kColumns[i].initial_sort_is_ascending) {
1261 tab_table_->ToggleSortOrder(current_visible_column_index);
1262 } else {
1263 // Unfortunately the API of ui::TableView doesn't provide a clean way
1264 // to sort by a particular column ID and a sort direction. If the
1265 // retrieved sort direction is different than the initial one, we have
1266 // to toggle the sort order twice!
1267 // Note that the function takes the visible_column_index rather than
1268 // a column ID.
afakhry 2015/08/27 19:56:52 Obviously not a big fan of the TableView API. I pe
1269 tab_table_->ToggleSortOrder(current_visible_column_index);
1270 tab_table_->ToggleSortOrder(current_visible_column_index);
1271 }
1272 }
1273
1274 ++current_visible_column_index;
1275 }
1276 }
1277 }
1278
1279 void NewTaskManagerView::StoreColumnsSettings() {
1280 PrefService* local_state = g_browser_process->local_state();
1281
1282 if (!local_state)
1283 return;
1284
1285 DictionaryPrefUpdate dict_update(local_state,
1286 prefs::kTaskManagerColumnVisibility);
1287
1288 base::DictionaryValue::Iterator it(*columns_settings_);
1289 while (!it.IsAtEnd()) {
1290 dict_update->Set(it.key(), it.value().CreateDeepCopy());
1291 it.Advance();
1292 }
1293
1294 // Store the current sort status to be restored again at startup.
1295 if (tab_table_->sort_descriptors().empty()) {
1296 dict_update->SetString(kSortColumnIdKey, "");
1297 } else {
1298 const auto& sort_descriptor = tab_table_->sort_descriptors().front();
1299 dict_update->SetString(kSortColumnIdKey,
1300 GetColumnIdAsString(sort_descriptor.column_id));
1301 dict_update->SetBoolean(kSortIsAscendingKey, sort_descriptor.ascending);
1302 }
1303
1304 dict_update->SetInteger(kColumnVersionKey, kColumnsVersion);
1305 }
1306
1157 } // namespace task_management 1307 } // namespace task_management
1158 1308
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698