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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_COCOA_TASK_MANAGER_MAC_H_
6 #define CHROME_BROWSER_UI_COCOA_TASK_MANAGER_MAC_H_
8 #import <Cocoa/Cocoa.h>
11 #include "base/mac/scoped_nsobject.h"
12 #include "chrome/browser/task_manager/task_manager.h"
13 #include "chrome/browser/ui/cocoa/table_row_nsimage_cache.h"
15 @
class WindowSizeAutosaver
;
22 // This class is responsible for loading the task manager window and for
24 @interface TaskManagerWindowController
:
25 NSWindowController
<NSTableViewDataSource
,
26 NSTableViewDelegate
> {
28 IBOutlet NSTableView
* tableView_
;
29 IBOutlet NSButton
* endProcessButton_
;
30 TaskManagerMac
* taskManagerObserver_
; // weak
31 TaskManager
* taskManager_
; // weak
32 TaskManagerModel
* model_
; // weak
34 base::scoped_nsobject
<WindowSizeAutosaver
> size_saver_
;
36 // These contain a permutation of [0..|model_->ResourceCount() - 1|]. Used to
38 std::vector
<int> viewToModelMap_
;
39 std::vector
<int> modelToViewMap_
;
41 // Descriptor of the current sort column.
42 base::scoped_nsobject
<NSSortDescriptor
> currentSortDescriptor_
;
45 // Creates and shows the task manager's window.
46 - (id
)initWithTaskManagerObserver
:(TaskManagerMac
*)taskManagerObserver
;
48 // Refreshes all data in the task manager table.
51 // Callback for "Stats for nerds" link.
52 - (IBAction
)statsLinkClicked
:(id
)sender
;
54 // Callback for "End process" button.
55 - (IBAction
)killSelectedProcesses
:(id
)sender
;
57 // Callback for double clicks on the table.
58 - (void)selectDoubleClickedTab
:(id
)sender
;
61 @interface
TaskManagerWindowController (TestingAPI
)
62 - (NSTableView
*)tableView
;
65 // This class listens to task changed events sent by chrome.
66 class TaskManagerMac
: public TaskManagerModelObserver
,
67 public TableRowNSImageCache::Table
{
69 explicit TaskManagerMac(TaskManager
* task_manager
);
70 ~TaskManagerMac() override
;
72 // TaskManagerModelObserver
73 void OnModelChanged() override
;
74 void OnItemsChanged(int start
, int length
) override
;
75 void OnItemsAdded(int start
, int length
) override
;
76 void OnItemsRemoved(int start
, int length
) override
;
78 // Called by the cocoa window controller when its window closes and the
79 // controller destroyed itself. Informs the model to stop updating.
80 void WindowWasClosed();
82 // TableRowNSImageCache::Table
83 int RowCount() const override
;
84 gfx::ImageSkia
GetIcon(int r
) const override
;
86 // Creates the task manager if it doesn't exist; otherwise, it activates the
87 // existing task manager window.
90 // Hides the task manager if it is showing.
93 // Returns the TaskManager observed by |this|.
94 TaskManager
* task_manager() { return task_manager_
; }
96 // Lazily converts the image at the given row and caches it in |icon_cache_|.
97 NSImage
* GetImageForRow(int row
);
99 // Returns the cocoa object. Used for testing.
100 TaskManagerWindowController
* cocoa_controller() { return window_controller_
; }
104 TaskManager
* const task_manager_
; // weak
107 TaskManagerModel
* const model_
; // weak
109 // Controller of our window, destroys itself when the task manager window
111 TaskManagerWindowController
* window_controller_
; // weak
113 // Caches favicons for all rows. Needs to be initalized after |model_|.
114 TableRowNSImageCache icon_cache_
;
116 // An open task manager window. There can only be one open at a time. This
117 // is reset to NULL when the window is closed.
118 static TaskManagerMac
* instance_
;
120 DISALLOW_COPY_AND_ASSIGN(TaskManagerMac
);
123 #endif // CHROME_BROWSER_UI_COCOA_TASK_MANAGER_MAC_H_