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

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: Added browser tests 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 } // namespace 240 } // namespace
241 241
242 //////////////////////////////////////////////////////////////////////////////// 242 ////////////////////////////////////////////////////////////////////////////////
243 243
244 // IMPORTANT: Do NOT change the below list without changing the COLUMN_LIST
245 // macro below.
246 const TableColumnData kColumns[] = {
247 { IDS_TASK_MANAGER_TASK_COLUMN, ui::TableColumn::LEFT, -1, 1, true, true,
248 true },
249 { IDS_TASK_MANAGER_PROFILE_NAME_COLUMN, ui::TableColumn::LEFT, -1, 0, true,
250 true, false },
251 { IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN, ui::TableColumn::RIGHT, -1, 0, true,
252 false, true },
253 { IDS_TASK_MANAGER_SHARED_MEM_COLUMN, ui::TableColumn::RIGHT, -1, 0, true,
254 false, false },
255 { IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN, ui::TableColumn::RIGHT, -1, 0, true,
256 false, false },
257 { IDS_TASK_MANAGER_CPU_COLUMN, ui::TableColumn::RIGHT, -1, 0, true, false,
258 true },
259 { IDS_TASK_MANAGER_NET_COLUMN, ui::TableColumn::RIGHT, -1, 0, true, false,
260 true },
261 { IDS_TASK_MANAGER_PROCESS_ID_COLUMN, ui::TableColumn::RIGHT, -1, 0, true,
262 true, true },
263
264 #if defined(OS_WIN)
265 { IDS_TASK_MANAGER_GDI_HANDLES_COLUMN, ui::TableColumn::RIGHT, -1, 0, true,
266 false, false },
267 { IDS_TASK_MANAGER_USER_HANDLES_COLUMN, ui::TableColumn::RIGHT, -1, 0, true,
268 false, false },
269 #endif
270
271 { IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN, ui::TableColumn::RIGHT, -1, 0,
272 true, false, false },
273 { IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN, ui::TableColumn::RIGHT, -1,
274 0, true, false, false },
275 { IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN, ui::TableColumn::RIGHT, -1, 0,
276 true, false, false },
277 { IDS_TASK_MANAGER_VIDEO_MEMORY_COLUMN, ui::TableColumn::RIGHT, -1, 0, true,
278 false, false },
279 { IDS_TASK_MANAGER_SQLITE_MEMORY_USED_COLUMN, ui::TableColumn::RIGHT, -1, 0,
280 true, false, false },
281
282 #if !defined(DISABLE_NACL)
283 { IDS_TASK_MANAGER_NACL_DEBUG_STUB_PORT_COLUMN, ui::TableColumn::RIGHT, -1, 0,
284 true, true, false },
285 #endif // !defined(DISABLE_NACL)
286
287 { IDS_TASK_MANAGER_JAVASCRIPT_MEMORY_ALLOCATED_COLUMN, ui::TableColumn::RIGHT,
288 -1, 0, true, false, false },
289
290 #if defined(OS_MACOSX) || defined(OS_LINUX)
291 // TODO(port): Port the idle wakeups per second to platforms other than Linux
292 // and MacOS (http://crbug.com/120488).
293 { IDS_TASK_MANAGER_IDLE_WAKEUPS_COLUMN, ui::TableColumn::RIGHT, -1, 0, true,
294 false, false },
295 #endif // defined(OS_MACOSX) || defined(OS_LINUX)
296 };
297
298 const size_t kColumnsSize = arraysize(kColumns);
299
300 const char kSortColumnIdKey[] = "sort_column_id";
301 const char kSortIsAscendingKey[] = "sort_is_ascending";
302
303 // We can't use the integer IDs of the columns converted to strings as session
304 // restore keys. These integer values can change from one build to another as
305 // they are generated. Instead we use the literal string value of the column
306 // ID symbol (i.e. for the ID IDS_TASK_MANAGER_TASK_COLUMN, we use the literal
307 // string "IDS_TASK_MANAGER_TASK_COLUMN". The following macros help us
308 // efficiently get the literal ID for the integer value.
309 #define COLUMNS_LITS(def) \
310 def(IDS_TASK_MANAGER_TASK_COLUMN) \
311 def(IDS_TASK_MANAGER_PROFILE_NAME_COLUMN) \
312 def(IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN) \
313 def(IDS_TASK_MANAGER_SHARED_MEM_COLUMN) \
314 def(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN) \
315 def(IDS_TASK_MANAGER_CPU_COLUMN) \
316 def(IDS_TASK_MANAGER_NET_COLUMN) \
317 def(IDS_TASK_MANAGER_PROCESS_ID_COLUMN) \
318 def(IDS_TASK_MANAGER_GDI_HANDLES_COLUMN) \
319 def(IDS_TASK_MANAGER_USER_HANDLES_COLUMN) \
320 def(IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN) \
321 def(IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN) \
322 def(IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN) \
323 def(IDS_TASK_MANAGER_VIDEO_MEMORY_COLUMN) \
324 def(IDS_TASK_MANAGER_SQLITE_MEMORY_USED_COLUMN) \
325 def(IDS_TASK_MANAGER_NACL_DEBUG_STUB_PORT_COLUMN) \
326 def(IDS_TASK_MANAGER_JAVASCRIPT_MEMORY_ALLOCATED_COLUMN) \
327 def(IDS_TASK_MANAGER_IDLE_WAKEUPS_COLUMN)
328 // Add to the above list in the macro any new IDs added in the future. Also
329 // remove the removed ones.
330
331 #define COLUMN_ID_AS_STRING(col_id) case col_id: return std::string(#col_id);
332
333 std::string GetColumnIdAsString(int column_id) {
334 switch (column_id) {
335 COLUMNS_LITS(COLUMN_ID_AS_STRING)
336 default:
337 NOTREACHED();
338 return std::string();
339 }
340 }
341
342 ////////////////////////////////////////////////////////////////////////////////
343
244 // The table model of the task manager table view that will observe the 344 // 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 345 // task manager backend and adapt its interface to match the requirements of the
246 // TableView. 346 // TableView.
247 class NewTaskManagerView::TableModel 347 class NewTaskManagerView::TableModel
248 : public TaskManagerObserver, 348 : public TaskManagerObserver,
249 public ui::TableModel, 349 public ui::TableModel,
250 public views::TableGrouper { 350 public views::TableGrouper {
251 public: 351 public:
252 explicit TableModel(int64 refresh_flags); 352 explicit TableModel(int64 refresh_flags);
253 ~TableModel() override; 353 ~TableModel() override;
(...skipping 17 matching lines...) Expand all
271 void StartUpdating(); 371 void StartUpdating();
272 void StopUpdating(); 372 void StopUpdating();
273 373
274 // Activates the browser tab associated with the process in the specified 374 // Activates the browser tab associated with the process in the specified
275 // |row_index|. 375 // |row_index|.
276 void ActivateTask(int row_index); 376 void ActivateTask(int row_index);
277 377
278 // Kills the process on which the task at |row_index| is running. 378 // Kills the process on which the task at |row_index| is running.
279 void KillTask(int row_index); 379 void KillTask(int row_index);
280 380
281 // Called when a column visibility is toggled from the context menu of the 381 // Based on the given |visibility| and the |column_id|, a particular refresh
282 // table view. This will result in enabling or disabling some resources 382 // type will be enabled or disabled. Multiple columns can map to the same
283 // refresh types in the task manager. 383 // refresh type, for that we need |table| to determine if any is visible.
284 void ToggleColumnVisibility(views::TableView* table, int column_id); 384 void UpdateRefreshTypes(views::TableView* table,
385 int column_id,
386 bool visibility);
387
285 388
286 // Checks if the task at |row_index| is running on the browser process. 389 // Checks if the task at |row_index| is running on the browser process.
287 bool IsBrowserProcess(int row_index) const; 390 bool IsBrowserProcess(int row_index) const;
288 391
289 private: 392 private:
290 void OnRefresh(); 393 void OnRefresh();
291 394
292 // Checks whether the task at |row_index| is the first task in its process 395 // Checks whether the task at |row_index| is the first task in its process
293 // group of tasks. 396 // group of tasks.
294 bool IsTaskFirstInGroup(int row_index) const; 397 bool IsTaskFirstInGroup(int row_index) const;
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 void NewTaskManagerView::TableModel::KillTask(int row_index) { 714 void NewTaskManagerView::TableModel::KillTask(int row_index) {
612 base::ProcessId proc_id = observed_task_manager()->GetProcessId( 715 base::ProcessId proc_id = observed_task_manager()->GetProcessId(
613 tasks_[row_index]); 716 tasks_[row_index]);
614 717
615 DCHECK_NE(proc_id, base::GetCurrentProcId()); 718 DCHECK_NE(proc_id, base::GetCurrentProcId());
616 719
617 base::Process process = base::Process::Open(proc_id); 720 base::Process process = base::Process::Open(proc_id);
618 process.Terminate(content::RESULT_CODE_KILLED, false); 721 process.Terminate(content::RESULT_CODE_KILLED, false);
619 } 722 }
620 723
621 void NewTaskManagerView::TableModel::ToggleColumnVisibility( 724 void NewTaskManagerView::TableModel::UpdateRefreshTypes(views::TableView* table,
622 views::TableView* table, 725 int column_id,
623 int column_id) { 726 bool visibility) {
624 DCHECK(table); 727 bool new_visibility = visibility;
625
626 bool new_visibility = !table->IsColumnVisible(column_id);
627 table->SetColumnVisibility(column_id, new_visibility);
628
629 RefreshType type = REFRESH_TYPE_NONE; 728 RefreshType type = REFRESH_TYPE_NONE;
630 switch (column_id) { 729 switch (column_id) {
730 case IDS_TASK_MANAGER_PROFILE_NAME_COLUMN:
731 case IDS_TASK_MANAGER_TASK_COLUMN:
732 case IDS_TASK_MANAGER_PROCESS_ID_COLUMN:
733 return; // The data is these columns do not change.
734
631 case IDS_TASK_MANAGER_NET_COLUMN: 735 case IDS_TASK_MANAGER_NET_COLUMN:
632 type = REFRESH_TYPE_NETWORK_USAGE; 736 type = REFRESH_TYPE_NETWORK_USAGE;
633 break; 737 break;
634 738
635 case IDS_TASK_MANAGER_CPU_COLUMN: 739 case IDS_TASK_MANAGER_CPU_COLUMN:
636 type = REFRESH_TYPE_CPU; 740 type = REFRESH_TYPE_CPU;
637 break; 741 break;
638 742
743 case IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN:
639 case IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN: 744 case IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN:
640 case IDS_TASK_MANAGER_SHARED_MEM_COLUMN: 745 case IDS_TASK_MANAGER_SHARED_MEM_COLUMN:
641 case IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN:
642 type = REFRESH_TYPE_MEMORY; 746 type = REFRESH_TYPE_MEMORY;
643 if (table->IsColumnVisible(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN) || 747 if (table->IsColumnVisible(IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN) ||
644 table->IsColumnVisible(IDS_TASK_MANAGER_SHARED_MEM_COLUMN) || 748 table->IsColumnVisible(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN) ||
645 table->IsColumnVisible(IDS_TASK_MANAGER_SHARED_MEM_COLUMN)) { 749 table->IsColumnVisible(IDS_TASK_MANAGER_SHARED_MEM_COLUMN)) {
646 new_visibility = true; 750 new_visibility = true;
647 } 751 }
648 break; 752 break;
649 753
650 case IDS_TASK_MANAGER_GDI_HANDLES_COLUMN: 754 case IDS_TASK_MANAGER_GDI_HANDLES_COLUMN:
651 case IDS_TASK_MANAGER_USER_HANDLES_COLUMN: 755 case IDS_TASK_MANAGER_USER_HANDLES_COLUMN:
652 type = REFRESH_TYPE_HANDLES; 756 type = REFRESH_TYPE_HANDLES;
653 if (table->IsColumnVisible(IDS_TASK_MANAGER_GDI_HANDLES_COLUMN) || 757 if (table->IsColumnVisible(IDS_TASK_MANAGER_GDI_HANDLES_COLUMN) ||
654 table->IsColumnVisible(IDS_TASK_MANAGER_USER_HANDLES_COLUMN)) { 758 table->IsColumnVisible(IDS_TASK_MANAGER_USER_HANDLES_COLUMN)) {
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 991
888 void NewTaskManagerView::WindowClosing() { 992 void NewTaskManagerView::WindowClosing() {
889 // Now that the window is closed, we can allow a new one to be opened. 993 // 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 994 // (WindowClosing comes in asynchronously from the call to Close() and we
891 // may have already opened a new instance). 995 // may have already opened a new instance).
892 if (g_task_manager_view == this) { 996 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 997 // We don't have to delete |g_task_manager_view| as we don't own it. It's
894 // owned by the Views hierarchy. 998 // owned by the Views hierarchy.
895 g_task_manager_view = nullptr; 999 g_task_manager_view = nullptr;
896 } 1000 }
1001 StoreColumnsSettings();
897 table_model_->StopUpdating(); 1002 table_model_->StopUpdating();
898 } 1003 }
899 1004
900 bool NewTaskManagerView::UseNewStyleForThisDialog() const { 1005 bool NewTaskManagerView::UseNewStyleForThisDialog() const {
901 return false; 1006 return false;
902 } 1007 }
903 1008
904 void NewTaskManagerView::OnSelectionChanged() { 1009 void NewTaskManagerView::OnSelectionChanged() {
905 const ui::ListSelectionModel::SelectedIndices& selections( 1010 const ui::ListSelectionModel::SelectedIndices& selections(
906 tab_table_->selection_model().selected_indices()); 1011 tab_table_->selection_model().selected_indices());
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 return true; 1066 return true;
962 } 1067 }
963 1068
964 bool NewTaskManagerView::GetAcceleratorForCommandId( 1069 bool NewTaskManagerView::GetAcceleratorForCommandId(
965 int command_id, 1070 int command_id,
966 ui::Accelerator* accelerator) { 1071 ui::Accelerator* accelerator) {
967 return false; 1072 return false;
968 } 1073 }
969 1074
970 void NewTaskManagerView::ExecuteCommand(int id, int event_flags) { 1075 void NewTaskManagerView::ExecuteCommand(int id, int event_flags) {
971 table_model_->ToggleColumnVisibility(tab_table_, id); 1076 ToggleColumnVisibility(id);
972 } 1077 }
973 1078
974 NewTaskManagerView::NewTaskManagerView(chrome::HostDesktopType desktop_type) 1079 NewTaskManagerView::NewTaskManagerView(chrome::HostDesktopType desktop_type)
975 : table_model_( 1080 : table_model_(
976 new NewTaskManagerView::TableModel(REFRESH_TYPE_CPU | 1081 new NewTaskManagerView::TableModel(REFRESH_TYPE_CPU |
977 REFRESH_TYPE_MEMORY | 1082 REFRESH_TYPE_MEMORY |
978 REFRESH_TYPE_NETWORK_USAGE)), 1083 REFRESH_TYPE_NETWORK_USAGE)),
979 menu_runner_(nullptr),
980 always_on_top_menu_text_(),
981 kill_button_(nullptr), 1084 kill_button_(nullptr),
982 about_memory_link_(nullptr), 1085 about_memory_link_(nullptr),
983 tab_table_(nullptr), 1086 tab_table_(nullptr),
984 tab_table_parent_(nullptr), 1087 tab_table_parent_(nullptr),
985 columns_(),
986 desktop_type_(desktop_type), 1088 desktop_type_(desktop_type),
987 is_always_on_top_(false) { 1089 is_always_on_top_(false) {
988 Init(); 1090 Init();
989 } 1091 }
990 1092
1093 // static
1094 NewTaskManagerView* NewTaskManagerView::GetInstanceForTests() {
1095 return g_task_manager_view;
1096 }
1097
991 void NewTaskManagerView::Init() { 1098 void NewTaskManagerView::Init() {
992 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_TASK_COLUMN, 1099 columns_settings_.reset(new base::DictionaryValue);
993 ui::TableColumn::LEFT, -1, 1));
994 columns_.back().sortable = true;
995 1100
996 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_PROFILE_NAME_COLUMN, 1101 // Create the table columns.
997 ui::TableColumn::LEFT, -1, 0)); 1102 for (size_t i = 0; i < kColumnsSize; ++i) {
998 columns_.back().sortable = true; 1103 const auto& col_data = kColumns[i];
1104 columns_.push_back(ui::TableColumn(col_data.id, col_data.align,
1105 col_data.width, col_data.percent));
1106 columns_.back().sortable = col_data.sortable;
1107 columns_.back().initial_sort_is_ascending =
1108 col_data.initial_sort_is_ascending;
1109 }
999 1110
1000 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN, 1111 // 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( 1112 tab_table_ = new views::TableView(
1090 table_model_.get(), columns_, views::ICON_AND_TEXT, false); 1113 table_model_.get(), columns_, views::ICON_AND_TEXT, false);
1091 tab_table_->SetGrouper(table_model_.get()); 1114 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); 1115 tab_table_->SetObserver(this);
1117 tab_table_->set_context_menu_controller(this); 1116 tab_table_->set_context_menu_controller(this);
1118 set_context_menu_controller(this); 1117 set_context_menu_controller(this);
1119 1118
1119 RetrieveSavedColumnsSettingsAndUpdateTable();
1120
1120 kill_button_ = new views::LabelButton(this, 1121 kill_button_ = new views::LabelButton(this,
1121 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_KILL)); 1122 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_KILL));
1122 kill_button_->SetStyle(views::Button::STYLE_BUTTON); 1123 kill_button_->SetStyle(views::Button::STYLE_BUTTON);
1123 1124
1124 about_memory_link_ = new views::Link( 1125 about_memory_link_ = new views::Link(
1125 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_ABOUT_MEMORY_LINK)); 1126 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_ABOUT_MEMORY_LINK));
1126 about_memory_link_->set_listener(this); 1127 about_memory_link_->set_listener(this);
1127 1128
1128 // Makes sure our state is consistent. 1129 // Makes sure our state is consistent.
1129 OnSelectionChanged(); 1130 OnSelectionChanged();
(...skipping 17 matching lines...) Expand all
1147 1148
1148 if (!g_browser_process->local_state()) 1149 if (!g_browser_process->local_state())
1149 return; 1150 return;
1150 1151
1151 const base::DictionaryValue* dictionary = 1152 const base::DictionaryValue* dictionary =
1152 g_browser_process->local_state()->GetDictionary(GetWindowName()); 1153 g_browser_process->local_state()->GetDictionary(GetWindowName());
1153 if (dictionary) 1154 if (dictionary)
1154 dictionary->GetBoolean("always_on_top", &is_always_on_top_); 1155 dictionary->GetBoolean("always_on_top", &is_always_on_top_);
1155 } 1156 }
1156 1157
1158 void NewTaskManagerView::RetrieveSavedColumnsSettingsAndUpdateTable() {
1159 if (!g_browser_process->local_state())
1160 return;
1161
1162 const base::DictionaryValue* dictionary =
1163 g_browser_process->local_state()->GetDictionary(
1164 prefs::kTaskManagerColumnVisibility);
1165 if (!dictionary)
1166 return;
1167
1168 // Do a best effort of retrieving the correct settings from the local state.
1169 // Use the default settings of the value if it fails to be retrieved.
1170 std::string sorted_col_id;
1171 bool sort_is_ascending = true;
1172 dictionary->GetString(kSortColumnIdKey, &sorted_col_id);
1173 dictionary->GetBoolean(kSortIsAscendingKey, &sort_is_ascending);
1174
1175 int current_visible_column_index = 0;
1176 for (size_t i = 0; i < kColumnsSize; ++i) {
1177 const int col_id = kColumns[i].id;
1178 const std::string col_id_key(GetColumnIdAsString(col_id));
1179
1180 if (col_id_key.empty())
1181 continue;
1182
1183 bool col_visibility = kColumns[i].default_visibility;
1184 dictionary->GetBoolean(col_id_key, &col_visibility);
1185
1186 // If the above GetBoolean() fails, the |col_visibility| remains at the
1187 // default visibility.
1188 columns_settings_->SetBoolean(col_id_key, col_visibility);
1189 tab_table_->SetColumnVisibility(col_id, col_visibility);
1190 table_model_->UpdateRefreshTypes(tab_table_, col_id, col_visibility);
1191
1192 if (col_visibility) {
1193 if (sorted_col_id == col_id_key) {
1194 if (sort_is_ascending == kColumns[i].initial_sort_is_ascending) {
1195 tab_table_->ToggleSortOrder(current_visible_column_index);
1196 } else {
1197 // Unfortunately the API of ui::TableView doesn't provide a clean way
1198 // to sort by a particular column ID and a sort direction. If the
1199 // retrieved sort direction is different than the initial one, we have
1200 // to toggle the sort order twice!
1201 // Note that the function takes the visible_column_index rather than
1202 // a column ID.
1203 tab_table_->ToggleSortOrder(current_visible_column_index);
1204 tab_table_->ToggleSortOrder(current_visible_column_index);
1205 }
1206 }
1207
1208 ++current_visible_column_index;
1209 }
1210 }
1211 }
1212
1213 void NewTaskManagerView::StoreColumnsSettings() {
1214 PrefService* local_state = g_browser_process->local_state();
1215 if (!local_state)
1216 return;
1217
1218 DictionaryPrefUpdate dict_update(local_state,
1219 prefs::kTaskManagerColumnVisibility);
1220
1221 base::DictionaryValue::Iterator it(*columns_settings_);
1222 while (!it.IsAtEnd()) {
1223 dict_update->Set(it.key(), it.value().CreateDeepCopy());
1224 it.Advance();
1225 }
1226
1227 // Store the current sort status to be restored again at startup.
1228 if (tab_table_->sort_descriptors().empty()) {
1229 dict_update->SetString(kSortColumnIdKey, "");
1230 } else {
1231 const auto& sort_descriptor = tab_table_->sort_descriptors().front();
1232 dict_update->SetString(kSortColumnIdKey,
1233 GetColumnIdAsString(sort_descriptor.column_id));
1234 dict_update->SetBoolean(kSortIsAscendingKey, sort_descriptor.ascending);
1235 }
1236 }
1237
1238 void NewTaskManagerView::ToggleColumnVisibility(int column_id) {
1239 bool new_visibility = !tab_table_->IsColumnVisible(column_id);
1240 tab_table_->SetColumnVisibility(column_id, new_visibility);
1241 columns_settings_->SetBoolean(GetColumnIdAsString(column_id), new_visibility);
1242 table_model_->UpdateRefreshTypes(tab_table_, column_id, new_visibility);
1243 }
1244
1157 } // namespace task_management 1245 } // namespace task_management
1158 1246
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698