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

Side by Side Diff: chrome/browser/ui/task_manager/task_manager_table_model.cc

Issue 1922683003: Make old task manager tests work against new task manager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unnecessary friend. Created 4 years, 7 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/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
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 TaskManagerTableModel* g_instance_for_testing = nullptr;
37
36 #if defined(OS_MACOSX) 38 #if defined(OS_MACOSX)
37 // Match Activity Monitor's default refresh rate. 39 // Match Activity Monitor's default refresh rate.
38 const int64_t kRefreshTimeMS = 2000; 40 const int64_t kRefreshTimeMS = 2000;
39 41
40 // Activity Monitor shows %cpu with one decimal digit -- be consistent with 42 // Activity Monitor shows %cpu with one decimal digit -- be consistent with
41 // that. 43 // that.
42 const char kCpuTextFormatString[] = "%.1f"; 44 const char kCpuTextFormatString[] = "%.1f";
43 #else 45 #else
44 const int64_t kRefreshTimeMS = 1000; 46 const int64_t kRefreshTimeMS = 1000;
45 const char kCpuTextFormatString[] = "%.0f"; 47 const char kCpuTextFormatString[] = "%.0f";
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 table_view_delegate_(delegate), 265 table_view_delegate_(delegate),
264 columns_settings_(new base::DictionaryValue), 266 columns_settings_(new base::DictionaryValue),
265 table_model_observer_(nullptr), 267 table_model_observer_(nullptr),
266 stringifier_(new TaskManagerValuesStringifier), 268 stringifier_(new TaskManagerValuesStringifier),
267 #if !defined(DISABLE_NACL) 269 #if !defined(DISABLE_NACL)
268 is_nacl_debugging_flag_enabled_(base::CommandLine::ForCurrentProcess()-> 270 is_nacl_debugging_flag_enabled_(base::CommandLine::ForCurrentProcess()->
269 HasSwitch(switches::kEnableNaClDebug)) { 271 HasSwitch(switches::kEnableNaClDebug)) {
270 #else 272 #else
271 is_nacl_debugging_flag_enabled_(false) { 273 is_nacl_debugging_flag_enabled_(false) {
272 #endif // !defined(DISABLE_NACL) 274 #endif // !defined(DISABLE_NACL)
275
276 if (!g_instance_for_testing)
afakhry 2016/04/28 00:03:13 That's weird! Can that happen? Can we instantiate
ncarter (slow) 2016/05/02 18:33:28 I've added a comment to g_instance_for_testing des
277 g_instance_for_testing = this;
278
273 DCHECK(delegate); 279 DCHECK(delegate);
274 StartUpdating(); 280 StartUpdating();
275 } 281 }
276 282
277 TaskManagerTableModel::~TaskManagerTableModel() { 283 TaskManagerTableModel::~TaskManagerTableModel() {
284 if (g_instance_for_testing == this)
285 g_instance_for_testing = nullptr;
286
278 StopUpdating(); 287 StopUpdating();
279 } 288 }
280 289
281 int TaskManagerTableModel::RowCount() { 290 int TaskManagerTableModel::RowCount() {
282 return static_cast<int>(tasks_.size()); 291 return static_cast<int>(tasks_.size());
283 } 292 }
284 293
285 base::string16 TaskManagerTableModel::GetText(int row, int column) { 294 base::string16 TaskManagerTableModel::GetText(int row, int column) {
286 if (IsSharedByGroup(column) && !IsTaskFirstInGroup(row)) 295 if (IsSharedByGroup(column) && !IsTaskFirstInGroup(row))
287 return base::string16(); 296 return base::string16();
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 } 806 }
798 } 807 }
799 808
800 void TaskManagerTableModel::ToggleColumnVisibility(int column_id) { 809 void TaskManagerTableModel::ToggleColumnVisibility(int column_id) {
801 bool new_visibility = !table_view_delegate_->IsColumnVisible(column_id); 810 bool new_visibility = !table_view_delegate_->IsColumnVisible(column_id);
802 table_view_delegate_->SetColumnVisibility(column_id, new_visibility); 811 table_view_delegate_->SetColumnVisibility(column_id, new_visibility);
803 columns_settings_->SetBoolean(GetColumnIdAsString(column_id), new_visibility); 812 columns_settings_->SetBoolean(GetColumnIdAsString(column_id), new_visibility);
804 UpdateRefreshTypes(column_id, new_visibility); 813 UpdateRefreshTypes(column_id, new_visibility);
805 } 814 }
806 815
816 // static
817 TaskManagerTableModel* TaskManagerTableModel::GetInstanceForTesting() {
818 return g_instance_for_testing;
819 }
820
807 void TaskManagerTableModel::StartUpdating() { 821 void TaskManagerTableModel::StartUpdating() {
808 TaskManagerInterface::GetTaskManager()->AddObserver(this); 822 TaskManagerInterface::GetTaskManager()->AddObserver(this);
809 tasks_ = observed_task_manager()->GetTaskIdsList(); 823 tasks_ = observed_task_manager()->GetTaskIdsList();
810 OnRefresh(); 824 OnRefresh();
811 825
812 // In order for the scrollbar of the TableView to work properly on startup of 826 // In order for the scrollbar of the TableView to work properly on startup of
813 // the task manager, we must invoke TableModelObserver::OnModelChanged() which 827 // the task manager, we must invoke TableModelObserver::OnModelChanged() which
814 // in turn will invoke TableView::NumRowsChanged(). This will adjust the 828 // in turn will invoke TableView::NumRowsChanged(). This will adjust the
815 // vertical scrollbar correctly. crbug.com/570966. 829 // vertical scrollbar correctly. crbug.com/570966.
816 if (table_model_observer_) 830 if (table_model_observer_)
(...skipping 12 matching lines...) Expand all
829 bool TaskManagerTableModel::IsTaskFirstInGroup(int row_index) const { 843 bool TaskManagerTableModel::IsTaskFirstInGroup(int row_index) const {
830 if (row_index == 0) 844 if (row_index == 0)
831 return true; 845 return true;
832 846
833 return observed_task_manager()->GetProcessId(tasks_[row_index - 1]) != 847 return observed_task_manager()->GetProcessId(tasks_[row_index - 1]) !=
834 observed_task_manager()->GetProcessId(tasks_[row_index]); 848 observed_task_manager()->GetProcessId(tasks_[row_index]);
835 } 849 }
836 850
837 851
838 } // namespace task_management 852 } // namespace task_management
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698