OLD | NEW |
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 Loading... |
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 | |
344 // The table model of the task manager table view that will observe the | 244 // The table model of the task manager table view that will observe the |
345 // task manager backend and adapt its interface to match the requirements of the | 245 // task manager backend and adapt its interface to match the requirements of the |
346 // TableView. | 246 // TableView. |
347 class NewTaskManagerView::TableModel | 247 class NewTaskManagerView::TableModel |
348 : public TaskManagerObserver, | 248 : public TaskManagerObserver, |
349 public ui::TableModel, | 249 public ui::TableModel, |
350 public views::TableGrouper { | 250 public views::TableGrouper { |
351 public: | 251 public: |
352 explicit TableModel(int64 refresh_flags); | 252 explicit TableModel(int64 refresh_flags); |
353 ~TableModel() override; | 253 ~TableModel() override; |
(...skipping 17 matching lines...) Expand all Loading... |
371 void StartUpdating(); | 271 void StartUpdating(); |
372 void StopUpdating(); | 272 void StopUpdating(); |
373 | 273 |
374 // Activates the browser tab associated with the process in the specified | 274 // Activates the browser tab associated with the process in the specified |
375 // |row_index|. | 275 // |row_index|. |
376 void ActivateTask(int row_index); | 276 void ActivateTask(int row_index); |
377 | 277 |
378 // Kills the process on which the task at |row_index| is running. | 278 // Kills the process on which the task at |row_index| is running. |
379 void KillTask(int row_index); | 279 void KillTask(int row_index); |
380 | 280 |
381 // Based on the given |visibility| and the |column_id|, a particular refresh | 281 // Called when a column visibility is toggled from the context menu of the |
382 // type will be enabled or disabled. Multiple columns can map to the same | 282 // table view. This will result in enabling or disabling some resources |
383 // refresh type, for that we need |table| to determine if any is visible. | 283 // refresh types in the task manager. |
384 void UpdateRefreshTypes(views::TableView* table, | 284 void ToggleColumnVisibility(views::TableView* table, int column_id); |
385 int column_id, | |
386 bool visibility); | |
387 | |
388 | 285 |
389 // Checks if the task at |row_index| is running on the browser process. | 286 // Checks if the task at |row_index| is running on the browser process. |
390 bool IsBrowserProcess(int row_index) const; | 287 bool IsBrowserProcess(int row_index) const; |
391 | 288 |
392 private: | 289 private: |
393 void OnRefresh(); | 290 void OnRefresh(); |
394 | 291 |
395 // Checks whether the task at |row_index| is the first task in its process | 292 // Checks whether the task at |row_index| is the first task in its process |
396 // group of tasks. | 293 // group of tasks. |
397 bool IsTaskFirstInGroup(int row_index) const; | 294 bool IsTaskFirstInGroup(int row_index) const; |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 void NewTaskManagerView::TableModel::KillTask(int row_index) { | 611 void NewTaskManagerView::TableModel::KillTask(int row_index) { |
715 base::ProcessId proc_id = observed_task_manager()->GetProcessId( | 612 base::ProcessId proc_id = observed_task_manager()->GetProcessId( |
716 tasks_[row_index]); | 613 tasks_[row_index]); |
717 | 614 |
718 DCHECK_NE(proc_id, base::GetCurrentProcId()); | 615 DCHECK_NE(proc_id, base::GetCurrentProcId()); |
719 | 616 |
720 base::Process process = base::Process::Open(proc_id); | 617 base::Process process = base::Process::Open(proc_id); |
721 process.Terminate(content::RESULT_CODE_KILLED, false); | 618 process.Terminate(content::RESULT_CODE_KILLED, false); |
722 } | 619 } |
723 | 620 |
724 void NewTaskManagerView::TableModel::UpdateRefreshTypes(views::TableView* table, | 621 void NewTaskManagerView::TableModel::ToggleColumnVisibility( |
725 int column_id, | 622 views::TableView* table, |
726 bool visibility) { | 623 int column_id) { |
727 bool new_visibility = visibility; | 624 DCHECK(table); |
| 625 |
| 626 bool new_visibility = !table->IsColumnVisible(column_id); |
| 627 table->SetColumnVisibility(column_id, new_visibility); |
| 628 |
728 RefreshType type = REFRESH_TYPE_NONE; | 629 RefreshType type = REFRESH_TYPE_NONE; |
729 switch (column_id) { | 630 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 | |
735 case IDS_TASK_MANAGER_NET_COLUMN: | 631 case IDS_TASK_MANAGER_NET_COLUMN: |
736 type = REFRESH_TYPE_NETWORK_USAGE; | 632 type = REFRESH_TYPE_NETWORK_USAGE; |
737 break; | 633 break; |
738 | 634 |
739 case IDS_TASK_MANAGER_CPU_COLUMN: | 635 case IDS_TASK_MANAGER_CPU_COLUMN: |
740 type = REFRESH_TYPE_CPU; | 636 type = REFRESH_TYPE_CPU; |
741 break; | 637 break; |
742 | 638 |
743 case IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN: | |
744 case IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN: | 639 case IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN: |
745 case IDS_TASK_MANAGER_SHARED_MEM_COLUMN: | 640 case IDS_TASK_MANAGER_SHARED_MEM_COLUMN: |
| 641 case IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN: |
746 type = REFRESH_TYPE_MEMORY; | 642 type = REFRESH_TYPE_MEMORY; |
747 if (table->IsColumnVisible(IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN) || | 643 if (table->IsColumnVisible(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN) || |
748 table->IsColumnVisible(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN) || | 644 table->IsColumnVisible(IDS_TASK_MANAGER_SHARED_MEM_COLUMN) || |
749 table->IsColumnVisible(IDS_TASK_MANAGER_SHARED_MEM_COLUMN)) { | 645 table->IsColumnVisible(IDS_TASK_MANAGER_SHARED_MEM_COLUMN)) { |
750 new_visibility = true; | 646 new_visibility = true; |
751 } | 647 } |
752 break; | 648 break; |
753 | 649 |
754 case IDS_TASK_MANAGER_GDI_HANDLES_COLUMN: | 650 case IDS_TASK_MANAGER_GDI_HANDLES_COLUMN: |
755 case IDS_TASK_MANAGER_USER_HANDLES_COLUMN: | 651 case IDS_TASK_MANAGER_USER_HANDLES_COLUMN: |
756 type = REFRESH_TYPE_HANDLES; | 652 type = REFRESH_TYPE_HANDLES; |
757 if (table->IsColumnVisible(IDS_TASK_MANAGER_GDI_HANDLES_COLUMN) || | 653 if (table->IsColumnVisible(IDS_TASK_MANAGER_GDI_HANDLES_COLUMN) || |
758 table->IsColumnVisible(IDS_TASK_MANAGER_USER_HANDLES_COLUMN)) { | 654 table->IsColumnVisible(IDS_TASK_MANAGER_USER_HANDLES_COLUMN)) { |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
991 | 887 |
992 void NewTaskManagerView::WindowClosing() { | 888 void NewTaskManagerView::WindowClosing() { |
993 // Now that the window is closed, we can allow a new one to be opened. | 889 // Now that the window is closed, we can allow a new one to be opened. |
994 // (WindowClosing comes in asynchronously from the call to Close() and we | 890 // (WindowClosing comes in asynchronously from the call to Close() and we |
995 // may have already opened a new instance). | 891 // may have already opened a new instance). |
996 if (g_task_manager_view == this) { | 892 if (g_task_manager_view == this) { |
997 // We don't have to delete |g_task_manager_view| as we don't own it. It's | 893 // We don't have to delete |g_task_manager_view| as we don't own it. It's |
998 // owned by the Views hierarchy. | 894 // owned by the Views hierarchy. |
999 g_task_manager_view = nullptr; | 895 g_task_manager_view = nullptr; |
1000 } | 896 } |
1001 StoreColumnsSettings(); | |
1002 table_model_->StopUpdating(); | 897 table_model_->StopUpdating(); |
1003 } | 898 } |
1004 | 899 |
1005 bool NewTaskManagerView::UseNewStyleForThisDialog() const { | 900 bool NewTaskManagerView::UseNewStyleForThisDialog() const { |
1006 return false; | 901 return false; |
1007 } | 902 } |
1008 | 903 |
1009 void NewTaskManagerView::OnSelectionChanged() { | 904 void NewTaskManagerView::OnSelectionChanged() { |
1010 const ui::ListSelectionModel::SelectedIndices& selections( | 905 const ui::ListSelectionModel::SelectedIndices& selections( |
1011 tab_table_->selection_model().selected_indices()); | 906 tab_table_->selection_model().selected_indices()); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1066 return true; | 961 return true; |
1067 } | 962 } |
1068 | 963 |
1069 bool NewTaskManagerView::GetAcceleratorForCommandId( | 964 bool NewTaskManagerView::GetAcceleratorForCommandId( |
1070 int command_id, | 965 int command_id, |
1071 ui::Accelerator* accelerator) { | 966 ui::Accelerator* accelerator) { |
1072 return false; | 967 return false; |
1073 } | 968 } |
1074 | 969 |
1075 void NewTaskManagerView::ExecuteCommand(int id, int event_flags) { | 970 void NewTaskManagerView::ExecuteCommand(int id, int event_flags) { |
1076 ToggleColumnVisibility(id); | 971 table_model_->ToggleColumnVisibility(tab_table_, id); |
1077 } | 972 } |
1078 | 973 |
1079 NewTaskManagerView::NewTaskManagerView(chrome::HostDesktopType desktop_type) | 974 NewTaskManagerView::NewTaskManagerView(chrome::HostDesktopType desktop_type) |
1080 : table_model_( | 975 : table_model_( |
1081 new NewTaskManagerView::TableModel(REFRESH_TYPE_CPU | | 976 new NewTaskManagerView::TableModel(REFRESH_TYPE_CPU | |
1082 REFRESH_TYPE_MEMORY | | 977 REFRESH_TYPE_MEMORY | |
1083 REFRESH_TYPE_NETWORK_USAGE)), | 978 REFRESH_TYPE_NETWORK_USAGE)), |
| 979 menu_runner_(nullptr), |
| 980 always_on_top_menu_text_(), |
1084 kill_button_(nullptr), | 981 kill_button_(nullptr), |
1085 about_memory_link_(nullptr), | 982 about_memory_link_(nullptr), |
1086 tab_table_(nullptr), | 983 tab_table_(nullptr), |
1087 tab_table_parent_(nullptr), | 984 tab_table_parent_(nullptr), |
| 985 columns_(), |
1088 desktop_type_(desktop_type), | 986 desktop_type_(desktop_type), |
1089 is_always_on_top_(false) { | 987 is_always_on_top_(false) { |
1090 Init(); | 988 Init(); |
1091 } | 989 } |
1092 | 990 |
1093 // static | 991 void NewTaskManagerView::Init() { |
1094 NewTaskManagerView* NewTaskManagerView::GetInstanceForTests() { | 992 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_TASK_COLUMN, |
1095 return g_task_manager_view; | 993 ui::TableColumn::LEFT, -1, 1)); |
1096 } | 994 columns_.back().sortable = true; |
1097 | 995 |
1098 void NewTaskManagerView::Init() { | 996 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_PROFILE_NAME_COLUMN, |
1099 columns_settings_.reset(new base::DictionaryValue); | 997 ui::TableColumn::LEFT, -1, 0)); |
| 998 columns_.back().sortable = true; |
1100 | 999 |
1101 // Create the table columns. | 1000 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN, |
1102 for (size_t i = 0; i < kColumnsSize; ++i) { | 1001 ui::TableColumn::RIGHT, -1, 0)); |
1103 const auto& col_data = kColumns[i]; | 1002 columns_.back().sortable = true; |
1104 columns_.push_back(ui::TableColumn(col_data.id, col_data.align, | 1003 columns_.back().initial_sort_is_ascending = false; |
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 } | |
1110 | 1004 |
1111 // Create the table view. | 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 |
1112 tab_table_ = new views::TableView( | 1089 tab_table_ = new views::TableView( |
1113 table_model_.get(), columns_, views::ICON_AND_TEXT, false); | 1090 table_model_.get(), columns_, views::ICON_AND_TEXT, false); |
1114 tab_table_->SetGrouper(table_model_.get()); | 1091 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 |
1115 tab_table_->SetObserver(this); | 1116 tab_table_->SetObserver(this); |
1116 tab_table_->set_context_menu_controller(this); | 1117 tab_table_->set_context_menu_controller(this); |
1117 set_context_menu_controller(this); | 1118 set_context_menu_controller(this); |
1118 | 1119 |
1119 RetrieveSavedColumnsSettingsAndUpdateTable(); | |
1120 | |
1121 kill_button_ = new views::LabelButton(this, | 1120 kill_button_ = new views::LabelButton(this, |
1122 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_KILL)); | 1121 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_KILL)); |
1123 kill_button_->SetStyle(views::Button::STYLE_BUTTON); | 1122 kill_button_->SetStyle(views::Button::STYLE_BUTTON); |
1124 | 1123 |
1125 about_memory_link_ = new views::Link( | 1124 about_memory_link_ = new views::Link( |
1126 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_ABOUT_MEMORY_LINK)); | 1125 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_ABOUT_MEMORY_LINK)); |
1127 about_memory_link_->set_listener(this); | 1126 about_memory_link_->set_listener(this); |
1128 | 1127 |
1129 // Makes sure our state is consistent. | 1128 // Makes sure our state is consistent. |
1130 OnSelectionChanged(); | 1129 OnSelectionChanged(); |
(...skipping 17 matching lines...) Expand all Loading... |
1148 | 1147 |
1149 if (!g_browser_process->local_state()) | 1148 if (!g_browser_process->local_state()) |
1150 return; | 1149 return; |
1151 | 1150 |
1152 const base::DictionaryValue* dictionary = | 1151 const base::DictionaryValue* dictionary = |
1153 g_browser_process->local_state()->GetDictionary(GetWindowName()); | 1152 g_browser_process->local_state()->GetDictionary(GetWindowName()); |
1154 if (dictionary) | 1153 if (dictionary) |
1155 dictionary->GetBoolean("always_on_top", &is_always_on_top_); | 1154 dictionary->GetBoolean("always_on_top", &is_always_on_top_); |
1156 } | 1155 } |
1157 | 1156 |
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 | |
1245 } // namespace task_management | 1157 } // namespace task_management |
1246 | 1158 |
OLD | NEW |