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

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: Created 5 years, 4 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 ID of the column.
244 int id;
245
246 // The alignment of the text displayed in this column.
247 ui::TableColumn::Alignment align;
248
249 // |width| and |percent| used to define the size of the column. See
250 // ui::TableColumn::width and ui::TableColumn::percent for details.
251 int width;
252 float percent;
253
254 // Is the column sortable.
255 bool sortable;
256
257 // Is the initial sort order ascending?
258 bool initial_sort_is_ascending;
259
260 // The default visibility of this column at startup of the table if no
261 // visibility is stored for it in the prefs.
262 bool default_visibility;
263 };
264
265 // The task manager table columns and their properties.
266 const TableColumnData kColumns[] = {
Lei Zhang 2015/08/27 01:10:44 kDefaultColumns ?
afakhry 2015/08/27 19:56:52 Not sure. They're not really the default columns.
267 { IDS_TASK_MANAGER_TASK_COLUMN, ui::TableColumn::LEFT, -1, 1, true, true,
268 true },
269 { IDS_TASK_MANAGER_PROFILE_NAME_COLUMN, ui::TableColumn::LEFT, -1, 0, true,
270 true, false },
271 { IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN, ui::TableColumn::RIGHT, -1, 0, true,
272 false, true },
273 { IDS_TASK_MANAGER_SHARED_MEM_COLUMN, ui::TableColumn::RIGHT, -1, 0, true,
274 false, false },
275 { IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN, ui::TableColumn::RIGHT, -1, 0, true,
276 false, false },
277 { IDS_TASK_MANAGER_CPU_COLUMN, ui::TableColumn::RIGHT, -1, 0, true, false,
278 true },
279 { IDS_TASK_MANAGER_NET_COLUMN, ui::TableColumn::RIGHT, -1, 0, true, false,
280 true },
281 { IDS_TASK_MANAGER_PROCESS_ID_COLUMN, ui::TableColumn::RIGHT, -1, 0, true,
282 true, true },
283
284 #if defined(OS_WIN)
285 { IDS_TASK_MANAGER_GDI_HANDLES_COLUMN, ui::TableColumn::RIGHT, -1, 0, true,
286 false, false },
287 { IDS_TASK_MANAGER_USER_HANDLES_COLUMN, ui::TableColumn::RIGHT, -1, 0, true,
288 false, false },
289 #endif
290
291 { IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN, ui::TableColumn::RIGHT, -1, 0,
292 true, false, false },
293 { IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN, ui::TableColumn::RIGHT, -1,
294 0, true, false, false },
295 { IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN, ui::TableColumn::RIGHT, -1, 0,
296 true, false, false },
297 { IDS_TASK_MANAGER_VIDEO_MEMORY_COLUMN, ui::TableColumn::RIGHT, -1, 0, true,
298 false, false },
299 { IDS_TASK_MANAGER_SQLITE_MEMORY_USED_COLUMN, ui::TableColumn::RIGHT, -1, 0,
300 true, false, false },
301
302 #if !defined(DISABLE_NACL)
303 { IDS_TASK_MANAGER_NACL_DEBUG_STUB_PORT_COLUMN, ui::TableColumn::RIGHT, -1, 0,
304 true, true, false },
305 #endif // !defined(DISABLE_NACL)
306
307 { IDS_TASK_MANAGER_JAVASCRIPT_MEMORY_ALLOCATED_COLUMN, ui::TableColumn::RIGHT,
308 -1, 0, true, false, false },
309
310 #if defined(OS_MACOSX) || defined(OS_LINUX)
311 // TODO(port): Port the idle wakeups per second to platforms other than Linux
312 // and MacOS (http://crbug.com/120488).
313 { IDS_TASK_MANAGER_IDLE_WAKEUPS_COLUMN, ui::TableColumn::RIGHT, -1, 0, true,
314 false, false },
315 #endif // defined(OS_MACOSX) || defined(OS_LINUX)
316 };
317
318 const size_t kColumnsSize = arraysize(kColumns);
319
240 } // namespace 320 } // namespace
241 321
242 //////////////////////////////////////////////////////////////////////////////// 322 ////////////////////////////////////////////////////////////////////////////////
243 323
244 // The table model of the task manager table view that will observe the 324 // 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 325 // task manager backend and adapt its interface to match the requirements of the
246 // TableView. 326 // TableView.
247 class NewTaskManagerView::TableModel 327 class NewTaskManagerView::TableModel
248 : public TaskManagerObserver, 328 : public TaskManagerObserver,
249 public ui::TableModel, 329 public ui::TableModel,
(...skipping 23 matching lines...) Expand all
273 353
274 // Activates the browser tab associated with the process in the specified 354 // Activates the browser tab associated with the process in the specified
275 // |row_index|. 355 // |row_index|.
276 void ActivateTask(int row_index); 356 void ActivateTask(int row_index);
277 357
278 // Kills the process on which the task at |row_index| is running. 358 // Kills the process on which the task at |row_index| is running.
279 void KillTask(int row_index); 359 void KillTask(int row_index);
280 360
281 // Called when a column visibility is toggled from the context menu of the 361 // 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 362 // table view. This will result in enabling or disabling some resources
283 // refresh types in the task manager. 363 // refresh types in the task manager. It will also update the
284 void ToggleColumnVisibility(views::TableView* table, int column_id); 364 // |visibility_settings| with the new visibility so that it's stored in the
365 // prefs when the task manager window is closed.
366 void ToggleColumnVisibility(views::TableView* table,
367 base::DictionaryValue* visibility_settings,
368 int column_id);
369
370 // Based on the given |visibility| and the |column_id|, a particular refresh
371 // type will be enabled or disabled. Multiple columns can map to the same
372 // refresh type, for that we need |table| to determine if any is visible.
373 void UpdateRefreshTypes(views::TableView* table,
374 int column_id,
375 bool visibility);
376
285 377
286 // Checks if the task at |row_index| is running on the browser process. 378 // Checks if the task at |row_index| is running on the browser process.
287 bool IsBrowserProcess(int row_index) const; 379 bool IsBrowserProcess(int row_index) const;
288 380
289 private: 381 private:
290 void OnRefresh(); 382 void OnRefresh();
291 383
292 // Checks whether the task at |row_index| is the first task in its process 384 // Checks whether the task at |row_index| is the first task in its process
293 // group of tasks. 385 // group of tasks.
294 bool IsTaskFirstInGroup(int row_index) const; 386 bool IsTaskFirstInGroup(int row_index) const;
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 tasks_[row_index]); 705 tasks_[row_index]);
614 706
615 DCHECK_NE(proc_id, base::GetCurrentProcId()); 707 DCHECK_NE(proc_id, base::GetCurrentProcId());
616 708
617 base::Process process = base::Process::Open(proc_id); 709 base::Process process = base::Process::Open(proc_id);
618 process.Terminate(content::RESULT_CODE_KILLED, false); 710 process.Terminate(content::RESULT_CODE_KILLED, false);
619 } 711 }
620 712
621 void NewTaskManagerView::TableModel::ToggleColumnVisibility( 713 void NewTaskManagerView::TableModel::ToggleColumnVisibility(
622 views::TableView* table, 714 views::TableView* table,
715 base::DictionaryValue* visibility_settings,
623 int column_id) { 716 int column_id) {
624 DCHECK(table); 717 DCHECK(table);
718 DCHECK(visibility_settings);
625 719
626 bool new_visibility = !table->IsColumnVisible(column_id); 720 bool new_visibility = !table->IsColumnVisible(column_id);
627 table->SetColumnVisibility(column_id, new_visibility); 721 table->SetColumnVisibility(column_id, new_visibility);
722 visibility_settings->SetBoolean(base::IntToString(column_id), new_visibility);
628 723
724 UpdateRefreshTypes(table, column_id, new_visibility);
725 }
726
727 void NewTaskManagerView::TableModel::UpdateRefreshTypes(views::TableView* table,
728 int column_id,
729 bool visibility) {
629 RefreshType type = REFRESH_TYPE_NONE; 730 RefreshType type = REFRESH_TYPE_NONE;
630 switch (column_id) { 731 switch (column_id) {
732 case IDS_TASK_MANAGER_PROFILE_NAME_COLUMN:
733 case IDS_TASK_MANAGER_TASK_COLUMN:
734 case IDS_TASK_MANAGER_PROCESS_ID_COLUMN:
735 return;
Lei Zhang 2015/08/27 01:10:44 Add a short comment to say why we return early. /
afakhry 2015/08/27 19:56:52 Done.
736
631 case IDS_TASK_MANAGER_NET_COLUMN: 737 case IDS_TASK_MANAGER_NET_COLUMN:
632 type = REFRESH_TYPE_NETWORK_USAGE; 738 type = REFRESH_TYPE_NETWORK_USAGE;
633 break; 739 break;
634 740
635 case IDS_TASK_MANAGER_CPU_COLUMN: 741 case IDS_TASK_MANAGER_CPU_COLUMN:
636 type = REFRESH_TYPE_CPU; 742 type = REFRESH_TYPE_CPU;
637 break; 743 break;
638 744
745 case IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN:
639 case IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN: 746 case IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN:
640 case IDS_TASK_MANAGER_SHARED_MEM_COLUMN: 747 case IDS_TASK_MANAGER_SHARED_MEM_COLUMN:
641 case IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN:
642 type = REFRESH_TYPE_MEMORY; 748 type = REFRESH_TYPE_MEMORY;
643 if (table->IsColumnVisible(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN) || 749 if (table->IsColumnVisible(IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN) ||
644 table->IsColumnVisible(IDS_TASK_MANAGER_SHARED_MEM_COLUMN) || 750 table->IsColumnVisible(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN) ||
645 table->IsColumnVisible(IDS_TASK_MANAGER_SHARED_MEM_COLUMN)) { 751 table->IsColumnVisible(IDS_TASK_MANAGER_SHARED_MEM_COLUMN)) {
afakhry 2015/08/26 01:16:27 This was a bug as you can see.
Lei Zhang 2015/08/27 01:10:44 Mmm, delicious copy + pasta bug.
646 new_visibility = true; 752 visibility = true;
Lei Zhang 2015/08/27 01:10:44 I don't like changing POD arguments. Can we keep |
afakhry 2015/08/27 19:56:52 Done.
647 } 753 }
648 break; 754 break;
649 755
650 case IDS_TASK_MANAGER_GDI_HANDLES_COLUMN: 756 case IDS_TASK_MANAGER_GDI_HANDLES_COLUMN:
651 case IDS_TASK_MANAGER_USER_HANDLES_COLUMN: 757 case IDS_TASK_MANAGER_USER_HANDLES_COLUMN:
652 type = REFRESH_TYPE_HANDLES; 758 type = REFRESH_TYPE_HANDLES;
653 if (table->IsColumnVisible(IDS_TASK_MANAGER_GDI_HANDLES_COLUMN) || 759 if (table->IsColumnVisible(IDS_TASK_MANAGER_GDI_HANDLES_COLUMN) ||
654 table->IsColumnVisible(IDS_TASK_MANAGER_USER_HANDLES_COLUMN)) { 760 table->IsColumnVisible(IDS_TASK_MANAGER_USER_HANDLES_COLUMN)) {
655 new_visibility = true; 761 visibility = true;
656 } 762 }
657 break; 763 break;
658 764
659 case IDS_TASK_MANAGER_IDLE_WAKEUPS_COLUMN: 765 case IDS_TASK_MANAGER_IDLE_WAKEUPS_COLUMN:
660 type = REFRESH_TYPE_IDLE_WAKEUPS; 766 type = REFRESH_TYPE_IDLE_WAKEUPS;
661 break; 767 break;
662 768
663 case IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN: 769 case IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN:
664 case IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN: 770 case IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN:
665 case IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN: 771 case IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN:
666 type = REFRESH_TYPE_WEBCACHE_STATS; 772 type = REFRESH_TYPE_WEBCACHE_STATS;
667 if (table->IsColumnVisible(IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN) || 773 if (table->IsColumnVisible(IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN) ||
668 table->IsColumnVisible( 774 table->IsColumnVisible(
669 IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN) || 775 IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN) ||
670 table->IsColumnVisible(IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN)) { 776 table->IsColumnVisible(IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN)) {
671 new_visibility = true; 777 visibility = true;
672 } 778 }
673 break; 779 break;
674 780
675 case IDS_TASK_MANAGER_VIDEO_MEMORY_COLUMN: 781 case IDS_TASK_MANAGER_VIDEO_MEMORY_COLUMN:
676 type = REFRESH_TYPE_GPU_MEMORY; 782 type = REFRESH_TYPE_GPU_MEMORY;
677 break; 783 break;
678 784
679 case IDS_TASK_MANAGER_SQLITE_MEMORY_USED_COLUMN: 785 case IDS_TASK_MANAGER_SQLITE_MEMORY_USED_COLUMN:
680 type = REFRESH_TYPE_SQLITE_MEMORY; 786 type = REFRESH_TYPE_SQLITE_MEMORY;
681 break; 787 break;
682 788
683 case IDS_TASK_MANAGER_JAVASCRIPT_MEMORY_ALLOCATED_COLUMN: 789 case IDS_TASK_MANAGER_JAVASCRIPT_MEMORY_ALLOCATED_COLUMN:
684 type = REFRESH_TYPE_V8_MEMORY; 790 type = REFRESH_TYPE_V8_MEMORY;
685 break; 791 break;
686 792
687 case IDS_TASK_MANAGER_NACL_DEBUG_STUB_PORT_COLUMN: 793 case IDS_TASK_MANAGER_NACL_DEBUG_STUB_PORT_COLUMN:
688 type = REFRESH_TYPE_NACL; 794 type = REFRESH_TYPE_NACL;
689 break; 795 break;
690 796
691 default: 797 default:
692 NOTREACHED(); 798 NOTREACHED();
693 return; 799 return;
694 } 800 }
695 801
696 if (new_visibility) 802 if (visibility)
697 AddRefreshType(type); 803 AddRefreshType(type);
698 else 804 else
699 RemoveRefreshType(type); 805 RemoveRefreshType(type);
700 } 806 }
701 807
702 bool NewTaskManagerView::TableModel::IsBrowserProcess(int row_index) const { 808 bool NewTaskManagerView::TableModel::IsBrowserProcess(int row_index) const {
703 return observed_task_manager()->GetProcessId(tasks_[row_index]) == 809 return observed_task_manager()->GetProcessId(tasks_[row_index]) ==
704 base::GetCurrentProcId(); 810 base::GetCurrentProcId();
705 } 811 }
706 812
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 993
888 void NewTaskManagerView::WindowClosing() { 994 void NewTaskManagerView::WindowClosing() {
889 // Now that the window is closed, we can allow a new one to be opened. 995 // 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 996 // (WindowClosing comes in asynchronously from the call to Close() and we
891 // may have already opened a new instance). 997 // may have already opened a new instance).
892 if (g_task_manager_view == this) { 998 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 999 // We don't have to delete |g_task_manager_view| as we don't own it. It's
894 // owned by the Views hierarchy. 1000 // owned by the Views hierarchy.
895 g_task_manager_view = nullptr; 1001 g_task_manager_view = nullptr;
896 } 1002 }
1003 StoreColumnVisibility();
897 table_model_->StopUpdating(); 1004 table_model_->StopUpdating();
898 } 1005 }
899 1006
900 bool NewTaskManagerView::UseNewStyleForThisDialog() const { 1007 bool NewTaskManagerView::UseNewStyleForThisDialog() const {
901 return false; 1008 return false;
902 } 1009 }
903 1010
904 void NewTaskManagerView::OnSelectionChanged() { 1011 void NewTaskManagerView::OnSelectionChanged() {
905 const ui::ListSelectionModel::SelectedIndices& selections( 1012 const ui::ListSelectionModel::SelectedIndices& selections(
906 tab_table_->selection_model().selected_indices()); 1013 tab_table_->selection_model().selected_indices());
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 return true; 1068 return true;
962 } 1069 }
963 1070
964 bool NewTaskManagerView::GetAcceleratorForCommandId( 1071 bool NewTaskManagerView::GetAcceleratorForCommandId(
965 int command_id, 1072 int command_id,
966 ui::Accelerator* accelerator) { 1073 ui::Accelerator* accelerator) {
967 return false; 1074 return false;
968 } 1075 }
969 1076
970 void NewTaskManagerView::ExecuteCommand(int id, int event_flags) { 1077 void NewTaskManagerView::ExecuteCommand(int id, int event_flags) {
971 table_model_->ToggleColumnVisibility(tab_table_, id); 1078 table_model_->ToggleColumnVisibility(tab_table_,
1079 column_visibility_settings_.get(),
1080 id);
972 } 1081 }
973 1082
974 NewTaskManagerView::NewTaskManagerView(chrome::HostDesktopType desktop_type) 1083 NewTaskManagerView::NewTaskManagerView(chrome::HostDesktopType desktop_type)
975 : table_model_( 1084 : table_model_(
976 new NewTaskManagerView::TableModel(REFRESH_TYPE_CPU | 1085 new NewTaskManagerView::TableModel(REFRESH_TYPE_CPU |
977 REFRESH_TYPE_MEMORY | 1086 REFRESH_TYPE_MEMORY |
978 REFRESH_TYPE_NETWORK_USAGE)), 1087 REFRESH_TYPE_NETWORK_USAGE)),
979 menu_runner_(nullptr), 1088 menu_runner_(),
Lei Zhang 2015/08/27 01:10:44 I thought we agreed to just get rid of these in a
afakhry 2015/08/27 19:56:52 Bad habits keep haunting me! :D .. Done.
1089 column_visibility_settings_(),
980 always_on_top_menu_text_(), 1090 always_on_top_menu_text_(),
981 kill_button_(nullptr), 1091 kill_button_(nullptr),
982 about_memory_link_(nullptr), 1092 about_memory_link_(nullptr),
983 tab_table_(nullptr), 1093 tab_table_(nullptr),
984 tab_table_parent_(nullptr), 1094 tab_table_parent_(nullptr),
985 columns_(), 1095 columns_(),
986 desktop_type_(desktop_type), 1096 desktop_type_(desktop_type),
987 is_always_on_top_(false) { 1097 is_always_on_top_(false) {
988 Init(); 1098 Init();
989 } 1099 }
990 1100
991 void NewTaskManagerView::Init() { 1101 void NewTaskManagerView::Init() {
992 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_TASK_COLUMN, 1102 column_visibility_settings_.reset(new base::DictionaryValue);
993 ui::TableColumn::LEFT, -1, 1));
994 columns_.back().sortable = true;
995 1103
996 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_PROFILE_NAME_COLUMN, 1104 // Create the table columns.
997 ui::TableColumn::LEFT, -1, 0)); 1105 for (size_t i = 0; i < kColumnsSize; ++i) {
998 columns_.back().sortable = true; 1106 const auto& col_data = kColumns[i];
1107 columns_.push_back(ui::TableColumn(col_data.id, col_data.align,
1108 col_data.width, col_data.percent));
1109 columns_.back().sortable = col_data.sortable;
1110 columns_.back().initial_sort_is_ascending =
1111 col_data.initial_sort_is_ascending;
999 1112
1000 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN, 1113 column_visibility_settings_->SetBoolean(base::IntToString(col_data.id),
1001 ui::TableColumn::RIGHT, -1, 0)); 1114 col_data.default_visibility);
1002 columns_.back().sortable = true; 1115 }
1003 columns_.back().initial_sort_is_ascending = false;
1004 1116
1005 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_SHARED_MEM_COLUMN, 1117 // 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( 1118 tab_table_ = new views::TableView(
1090 table_model_.get(), columns_, views::ICON_AND_TEXT, false); 1119 table_model_.get(), columns_, views::ICON_AND_TEXT, false);
1091 tab_table_->SetGrouper(table_model_.get()); 1120 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); 1121 tab_table_->SetObserver(this);
1117 tab_table_->set_context_menu_controller(this); 1122 tab_table_->set_context_menu_controller(this);
1118 set_context_menu_controller(this); 1123 set_context_menu_controller(this);
1119 1124
1125 // Retrieve and update the table columns visibilities.
1126 RetrieveSavedColumnVisibility();
1127 UpdateColumnVisibility();
1128
1120 kill_button_ = new views::LabelButton(this, 1129 kill_button_ = new views::LabelButton(this,
1121 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_KILL)); 1130 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_KILL));
1122 kill_button_->SetStyle(views::Button::STYLE_BUTTON); 1131 kill_button_->SetStyle(views::Button::STYLE_BUTTON);
1123 1132
1124 about_memory_link_ = new views::Link( 1133 about_memory_link_ = new views::Link(
1125 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_ABOUT_MEMORY_LINK)); 1134 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_ABOUT_MEMORY_LINK));
1126 about_memory_link_->set_listener(this); 1135 about_memory_link_->set_listener(this);
1127 1136
1128 // Makes sure our state is consistent. 1137 // Makes sure our state is consistent.
1129 OnSelectionChanged(); 1138 OnSelectionChanged();
(...skipping 17 matching lines...) Expand all
1147 1156
1148 if (!g_browser_process->local_state()) 1157 if (!g_browser_process->local_state())
1149 return; 1158 return;
1150 1159
1151 const base::DictionaryValue* dictionary = 1160 const base::DictionaryValue* dictionary =
1152 g_browser_process->local_state()->GetDictionary(GetWindowName()); 1161 g_browser_process->local_state()->GetDictionary(GetWindowName());
1153 if (dictionary) 1162 if (dictionary)
1154 dictionary->GetBoolean("always_on_top", &is_always_on_top_); 1163 dictionary->GetBoolean("always_on_top", &is_always_on_top_);
1155 } 1164 }
1156 1165
1166 void NewTaskManagerView::RetrieveSavedColumnVisibility() {
1167 if (!g_browser_process->local_state())
1168 return;
1169
1170 const base::DictionaryValue* dictionary =
1171 g_browser_process->local_state()->GetDictionary(
1172 prefs::kTaskManagerColumnVisibility);
1173 if (!dictionary)
1174 return;
1175
1176 int stored_num_columns;
1177 if (!dictionary->GetInteger("num_columns", &stored_num_columns))
1178 return;
1179
1180 // If the number of columns change from one version to another, we skip and
Lei Zhang 2015/08/27 01:10:44 Can we use a version number instead. What if: - w
afakhry 2015/08/27 19:56:52 Thanks for pointing this out. I event found out th
1181 // use the default visibility of the columns as defined in |kColumns|.
1182 if (stored_num_columns != static_cast<int>(kColumnsSize))
1183 return;
1184
1185 column_visibility_settings_.reset(dictionary->DeepCopy());
1186 }
1187
1188 void NewTaskManagerView::UpdateColumnVisibility() {
1189 for (size_t i = 0; i < kColumnsSize; ++i) {
1190 const int col_id = kColumns[i].id;
1191 bool visible = false;
1192 bool success = column_visibility_settings_->GetBoolean(
1193 base::IntToString(col_id), &visible);
1194
1195 DCHECK(success);
1196
1197 tab_table_->SetColumnVisibility(col_id, visible);
1198 table_model_->UpdateRefreshTypes(tab_table_, col_id, visible);
1199 }
1200 }
1201
1202 void NewTaskManagerView::StoreColumnVisibility() {
1203 PrefService* local_state = g_browser_process->local_state();
1204
1205 if (!local_state)
1206 return;
1207
1208 DictionaryPrefUpdate dict_update(local_state,
1209 prefs::kTaskManagerColumnVisibility);
1210
1211 base::DictionaryValue::Iterator it(*column_visibility_settings_);
1212 while (!it.IsAtEnd()) {
1213 dict_update->Set(it.key(), it.value().CreateDeepCopy());
1214 it.Advance();
1215 }
1216
1217 dict_update->SetInteger("num_columns", static_cast<int>(kColumnsSize));
1218 }
1219
1157 } // namespace task_management 1220 } // namespace task_management
1158 1221
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698