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 virtual ~TaskManagerMac();
72 // TaskManagerModelObserver
73 virtual void OnModelChanged() OVERRIDE
;
74 virtual void OnItemsChanged(int start
, int length
) OVERRIDE
;
75 virtual void OnItemsAdded(int start
, int length
) OVERRIDE
;
76 virtual 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 virtual int RowCount() const OVERRIDE
;
84 virtual 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 // Returns the TaskManager observed by |this|.
91 TaskManager
* task_manager() { return task_manager_
; }
93 // Lazily converts the image at the given row and caches it in |icon_cache_|.
94 NSImage
* GetImageForRow(int row
);
96 // Returns the cocoa object. Used for testing.
97 TaskManagerWindowController
* cocoa_controller() { return window_controller_
; }
101 TaskManager
* const task_manager_
; // weak
104 TaskManagerModel
* const model_
; // weak
106 // Controller of our window, destroys itself when the task manager window
108 TaskManagerWindowController
* window_controller_
; // weak
110 // Caches favicons for all rows. Needs to be initalized after |model_|.
111 TableRowNSImageCache icon_cache_
;
113 // An open task manager window. There can only be one open at a time. This
114 // is reset to NULL when the window is closed.
115 static TaskManagerMac
* instance_
;
117 DISALLOW_COPY_AND_ASSIGN(TaskManagerMac
);
120 #endif // CHROME_BROWSER_UI_COCOA_TASK_MANAGER_MAC_H_