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

Side by Side Diff: chrome/browser/ui/cocoa/task_manager_mac.h

Issue 2197483003: Move the Mac Task Manager to the new backend code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_UI_COCOA_TASK_MANAGER_MAC_H_ 5 #ifndef CHROME_BROWSER_UI_COCOA_TASK_MANAGER_MAC_H_
6 #define CHROME_BROWSER_UI_COCOA_TASK_MANAGER_MAC_H_ 6 #define CHROME_BROWSER_UI_COCOA_TASK_MANAGER_MAC_H_
7 7
8 #import <Cocoa/Cocoa.h> 8 #import <Cocoa/Cocoa.h>
9
9 #include <vector> 10 #include <vector>
10 11
11 #include "base/mac/scoped_nsobject.h" 12 #include "base/mac/scoped_nsobject.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "chrome/browser/task_manager/task_manager.h" 14 #include "chrome/browser/ui/task_manager/task_manager_table_model.h"
15 #include "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_registrar.h"
17 #include "ui/base/models/table_model_observer.h"
14 18
15 @class WindowSizeAutosaver; 19 @class WindowSizeAutosaver;
16 class TaskManagerMac;
17 20
18 namespace gfx { 21 namespace gfx {
19 class ImageSkia; 22 class ImageSkia;
20 } 23 }
21 24
25 namespace task_management {
26 class TaskManagerMac;
27 }
28
22 // This class is responsible for loading the task manager window and for 29 // This class is responsible for loading the task manager window and for
23 // managing it. 30 // managing it.
24 @interface TaskManagerWindowController : 31 @interface TaskManagerWindowController
25 NSWindowController<NSTableViewDataSource, 32 : NSWindowController<NSTableViewDataSource,
26 NSTableViewDelegate> { 33 NSTableViewDelegate,
34 NSMenuDelegate> {
27 @private 35 @private
28 IBOutlet NSTableView* tableView_; 36 IBOutlet NSTableView* tableView_;
29 IBOutlet NSButton* endProcessButton_; 37 IBOutlet NSButton* endProcessButton_;
30 TaskManagerMac* taskManagerObserver_; // weak 38 task_management::TaskManagerMac* taskManagerMac_; // weak
31 TaskManager* taskManager_; // weak 39 task_management::TaskManagerTableModel* tableModel_; // weak_
ncarter (slow) 2016/08/02 19:49:36 weak_ ?
Avi (use Gerrit) 2016/08/02 20:06:56 Oh. Typo.
32 TaskManagerModel* model_; // weak
33 40
34 base::scoped_nsobject<WindowSizeAutosaver> size_saver_; 41 base::scoped_nsobject<WindowSizeAutosaver> size_saver_;
35 42
36 // These contain a permutation of [0..|model_->ResourceCount() - 1|]. Used to 43 // These contain a permutation of [0..|tableModel_->RowCount() - 1|]. Used to
37 // implement sorting. 44 // implement sorting.
38 std::vector<int> viewToModelMap_; 45 std::vector<int> viewToModelMap_;
39 std::vector<int> modelToViewMap_; 46 std::vector<int> modelToViewMap_;
40 47
41 // Descriptor of the current sort column. 48 // Descriptor of the current sort column.
42 base::scoped_nsobject<NSSortDescriptor> currentSortDescriptor_; 49 task_management::TableSortDescriptor currentSortDescriptor_;
50
51 // Re-entrancy flag to allow meddling with the sort descriptor.
52 BOOL withinSortDescriptorsDidChange_;
43 } 53 }
44 54
45 // Creates and shows the task manager's window. 55 // Creates and shows the task manager's window.
46 - (id)initWithTaskManagerObserver:(TaskManagerMac*)taskManagerObserver; 56 - (id)initWithTaskManagerMac:(task_management::TaskManagerMac*)taskManagerMac
57 tableModel:
58 (task_management::TaskManagerTableModel*)tableModel;
47 59
48 // Refreshes all data in the task manager table. 60 // Refreshes all data in the task manager table.
49 - (void)reloadData; 61 - (void)reloadData;
50 62
63 // Gets a copy of the current sort descriptor.
64 - (task_management::TableSortDescriptor)sortDescriptor;
65
66 // Sets the current sort descriptor.
67 - (void)setSortDescriptor:
68 (const task_management::TableSortDescriptor&)sortDescriptor;
69
70 // Returns YES if the specified column is visible.
71 - (BOOL)visibilityOfColumnWithId:(int)columnId;
72
73 // Sets the visibility of the specified column.
74 - (void)setColumnWithId:(int)columnId toVisibility:(BOOL)visibility;
75
51 // Callback for "End process" button. 76 // Callback for "End process" button.
52 - (IBAction)killSelectedProcesses:(id)sender; 77 - (IBAction)killSelectedProcesses:(id)sender;
53 78
54 // Callback for double clicks on the table. 79 // Callback for double clicks on the table.
55 - (void)selectDoubleClickedTab:(id)sender; 80 - (void)tableWasDoubleClicked:(id)sender;
56 @end 81 @end
57 82
58 @interface TaskManagerWindowController (TestingAPI) 83 @interface TaskManagerWindowController (TestingAPI)
59 - (NSTableView*)tableView; 84 - (NSTableView*)tableViewForTesting;
85 - (NSButton*)endProcessButtonForTesting;
60 @end 86 @end
61 87
62 // This class listens to task changed events sent by chrome. 88 namespace task_management {
63 class TaskManagerMac : public TaskManagerModelObserver { 89
90 // This class runs the Task Manager on the Mac.
91 class TaskManagerMac : public ui::TableModelObserver,
92 public content::NotificationObserver,
93 public TableViewDelegate {
64 public: 94 public:
65 explicit TaskManagerMac(TaskManager* task_manager); 95 TaskManagerMac();
66 ~TaskManagerMac() override; 96 ~TaskManagerMac() override;
67 97
68 // TaskManagerModelObserver 98 // Called by the TaskManagerWindowController:
99 void WindowWasClosed();
100 NSImage* GetImageForRow(int row);
101
102 // Creates the task manager if it doesn't exist; otherwise, it activates the
103 // existing task manager window.
104 static TaskManagerTableModel* Show();
105
106 // Hides the task manager if it is showing.
107 static void Hide();
108
109 // Various test-only functions.
110 static TaskManagerMac* GetInstanceForTests() { return instance_; }
111 TaskManagerTableModel* GetTableModelForTests() { return table_model_.get(); }
112 TaskManagerWindowController* CocoaControllerForTests() {
113 return window_controller_;
114 }
115
116 private:
117 // ui::TableModelObserver:
69 void OnModelChanged() override; 118 void OnModelChanged() override;
70 void OnItemsChanged(int start, int length) override; 119 void OnItemsChanged(int start, int length) override;
71 void OnItemsAdded(int start, int length) override; 120 void OnItemsAdded(int start, int length) override;
72 void OnItemsRemoved(int start, int length) override; 121 void OnItemsRemoved(int start, int length) override;
73 122
74 // Called by the cocoa window controller when its window closes and the 123 // TableViewDelegate:
75 // controller destroyed itself. Informs the model to stop updating. 124 bool IsColumnVisible(int column_id) const override;
76 void WindowWasClosed(); 125 void SetColumnVisibility(int column_id, bool new_visibility) override;
126 bool IsTableSorted() const override;
127 TableSortDescriptor GetSortDescriptor() const override;
128 void SetSortDescriptor(const TableSortDescriptor& descriptor) override;
77 129
78 // Creates the task manager if it doesn't exist; otherwise, it activates the 130 // content::NotificationObserver overrides:
79 // existing task manager window. 131 void Observe(int type,
80 static void Show(); 132 const content::NotificationSource& source,
81 133 const content::NotificationDetails& details) override;
82 // Hides the task manager if it is showing.
83 static void Hide();
84
85 // Returns the TaskManager observed by |this|.
86 TaskManager* task_manager() { return task_manager_; }
87
88 // Lazily converts the image at the given row and caches it in |icon_cache_|.
89 NSImage* GetImageForRow(int row);
90
91 // Returns the cocoa object. Used for testing.
92 TaskManagerWindowController* cocoa_controller() { return window_controller_; }
93
94 private:
95 // The task manager.
96 TaskManager* const task_manager_; // weak
97 134
98 // Our model. 135 // Our model.
99 TaskManagerModel* const model_; // weak 136 std::unique_ptr<TaskManagerTableModel> table_model_;
100 137
101 // Controller of our window, destroys itself when the task manager window 138 // Controller of our window, destroys itself when the task manager window
102 // is closed. 139 // is closed.
103 TaskManagerWindowController* window_controller_; // weak 140 TaskManagerWindowController* window_controller_; // weak
104 141
142 content::NotificationRegistrar registrar_;
143
105 // An open task manager window. There can only be one open at a time. This 144 // An open task manager window. There can only be one open at a time. This
106 // is reset to NULL when the window is closed. 145 // is reset to be null when the window is closed.
107 static TaskManagerMac* instance_; 146 static TaskManagerMac* instance_;
108 147
109 DISALLOW_COPY_AND_ASSIGN(TaskManagerMac); 148 DISALLOW_COPY_AND_ASSIGN(TaskManagerMac);
110 }; 149 };
111 150
151 } // namespace task_management
152
112 #endif // CHROME_BROWSER_UI_COCOA_TASK_MANAGER_MAC_H_ 153 #endif // CHROME_BROWSER_UI_COCOA_TASK_MANAGER_MAC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698