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/task_manager/task_manager_table_model.h" | 5 #include "chrome/browser/ui/task_manager/task_manager_table_model.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/i18n/number_formatting.h" | 10 #include "base/i18n/number_formatting.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
26 #include "content/public/common/result_codes.h" | 26 #include "content/public/common/result_codes.h" |
27 #include "third_party/WebKit/public/web/WebCache.h" | 27 #include "third_party/WebKit/public/web/WebCache.h" |
28 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
29 #include "ui/base/models/table_model_observer.h" | 29 #include "ui/base/models/table_model_observer.h" |
30 #include "ui/base/text/bytes_formatting.h" | 30 #include "ui/base/text/bytes_formatting.h" |
31 | 31 |
32 namespace task_management { | 32 namespace task_management { |
33 | 33 |
34 namespace { | 34 namespace { |
35 | 35 |
36 // Captures the first instance of TaskManagerTableModel, for use in | |
37 // browsertests. Nothing prevents other TaskManagerTableModel instances, but in | |
38 // practice this will be model driving the visible task manager dialog. | |
afakhry
2016/05/02 18:58:17
... will be 'the' model driving ...
ncarter (slow)
2016/05/02 23:09:57
Done.
| |
39 TaskManagerTableModel* g_instance_for_testing = nullptr; | |
40 | |
36 #if defined(OS_MACOSX) | 41 #if defined(OS_MACOSX) |
37 // Match Activity Monitor's default refresh rate. | 42 // Match Activity Monitor's default refresh rate. |
38 const int64_t kRefreshTimeMS = 2000; | 43 const int64_t kRefreshTimeMS = 2000; |
39 | 44 |
40 // Activity Monitor shows %cpu with one decimal digit -- be consistent with | 45 // Activity Monitor shows %cpu with one decimal digit -- be consistent with |
41 // that. | 46 // that. |
42 const char kCpuTextFormatString[] = "%.1f"; | 47 const char kCpuTextFormatString[] = "%.1f"; |
43 #else | 48 #else |
44 const int64_t kRefreshTimeMS = 1000; | 49 const int64_t kRefreshTimeMS = 1000; |
45 const char kCpuTextFormatString[] = "%.0f"; | 50 const char kCpuTextFormatString[] = "%.0f"; |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
263 table_view_delegate_(delegate), | 268 table_view_delegate_(delegate), |
264 columns_settings_(new base::DictionaryValue), | 269 columns_settings_(new base::DictionaryValue), |
265 table_model_observer_(nullptr), | 270 table_model_observer_(nullptr), |
266 stringifier_(new TaskManagerValuesStringifier), | 271 stringifier_(new TaskManagerValuesStringifier), |
267 #if !defined(DISABLE_NACL) | 272 #if !defined(DISABLE_NACL) |
268 is_nacl_debugging_flag_enabled_(base::CommandLine::ForCurrentProcess()-> | 273 is_nacl_debugging_flag_enabled_(base::CommandLine::ForCurrentProcess()-> |
269 HasSwitch(switches::kEnableNaClDebug)) { | 274 HasSwitch(switches::kEnableNaClDebug)) { |
270 #else | 275 #else |
271 is_nacl_debugging_flag_enabled_(false) { | 276 is_nacl_debugging_flag_enabled_(false) { |
272 #endif // !defined(DISABLE_NACL) | 277 #endif // !defined(DISABLE_NACL) |
278 | |
279 if (!g_instance_for_testing) | |
280 g_instance_for_testing = this; | |
281 | |
273 DCHECK(delegate); | 282 DCHECK(delegate); |
274 StartUpdating(); | 283 StartUpdating(); |
275 } | 284 } |
276 | 285 |
277 TaskManagerTableModel::~TaskManagerTableModel() { | 286 TaskManagerTableModel::~TaskManagerTableModel() { |
287 if (g_instance_for_testing == this) | |
288 g_instance_for_testing = nullptr; | |
289 | |
278 StopUpdating(); | 290 StopUpdating(); |
279 } | 291 } |
280 | 292 |
281 int TaskManagerTableModel::RowCount() { | 293 int TaskManagerTableModel::RowCount() { |
282 return static_cast<int>(tasks_.size()); | 294 return static_cast<int>(tasks_.size()); |
283 } | 295 } |
284 | 296 |
285 base::string16 TaskManagerTableModel::GetText(int row, int column) { | 297 base::string16 TaskManagerTableModel::GetText(int row, int column) { |
286 if (IsSharedByGroup(column) && !IsTaskFirstInGroup(row)) | 298 if (IsSharedByGroup(column) && !IsTaskFirstInGroup(row)) |
287 return base::string16(); | 299 return base::string16(); |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
797 } | 809 } |
798 } | 810 } |
799 | 811 |
800 void TaskManagerTableModel::ToggleColumnVisibility(int column_id) { | 812 void TaskManagerTableModel::ToggleColumnVisibility(int column_id) { |
801 bool new_visibility = !table_view_delegate_->IsColumnVisible(column_id); | 813 bool new_visibility = !table_view_delegate_->IsColumnVisible(column_id); |
802 table_view_delegate_->SetColumnVisibility(column_id, new_visibility); | 814 table_view_delegate_->SetColumnVisibility(column_id, new_visibility); |
803 columns_settings_->SetBoolean(GetColumnIdAsString(column_id), new_visibility); | 815 columns_settings_->SetBoolean(GetColumnIdAsString(column_id), new_visibility); |
804 UpdateRefreshTypes(column_id, new_visibility); | 816 UpdateRefreshTypes(column_id, new_visibility); |
805 } | 817 } |
806 | 818 |
819 // static | |
820 TaskManagerTableModel* TaskManagerTableModel::GetInstanceForTesting() { | |
821 return g_instance_for_testing; | |
822 } | |
823 | |
807 void TaskManagerTableModel::StartUpdating() { | 824 void TaskManagerTableModel::StartUpdating() { |
808 TaskManagerInterface::GetTaskManager()->AddObserver(this); | 825 TaskManagerInterface::GetTaskManager()->AddObserver(this); |
809 tasks_ = observed_task_manager()->GetTaskIdsList(); | 826 tasks_ = observed_task_manager()->GetTaskIdsList(); |
810 OnRefresh(); | 827 OnRefresh(); |
811 | 828 |
812 // In order for the scrollbar of the TableView to work properly on startup of | 829 // In order for the scrollbar of the TableView to work properly on startup of |
813 // the task manager, we must invoke TableModelObserver::OnModelChanged() which | 830 // the task manager, we must invoke TableModelObserver::OnModelChanged() which |
814 // in turn will invoke TableView::NumRowsChanged(). This will adjust the | 831 // in turn will invoke TableView::NumRowsChanged(). This will adjust the |
815 // vertical scrollbar correctly. crbug.com/570966. | 832 // vertical scrollbar correctly. crbug.com/570966. |
816 if (table_model_observer_) | 833 if (table_model_observer_) |
(...skipping 12 matching lines...) Expand all Loading... | |
829 bool TaskManagerTableModel::IsTaskFirstInGroup(int row_index) const { | 846 bool TaskManagerTableModel::IsTaskFirstInGroup(int row_index) const { |
830 if (row_index == 0) | 847 if (row_index == 0) |
831 return true; | 848 return true; |
832 | 849 |
833 return observed_task_manager()->GetProcessId(tasks_[row_index - 1]) != | 850 return observed_task_manager()->GetProcessId(tasks_[row_index - 1]) != |
834 observed_task_manager()->GetProcessId(tasks_[row_index]); | 851 observed_task_manager()->GetProcessId(tasks_[row_index]); |
835 } | 852 } |
836 | 853 |
837 | 854 |
838 } // namespace task_management | 855 } // namespace task_management |
OLD | NEW |