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. 4 5 #ifndef CHROME_BROWSER_UI_COCOA_TASK_MANAGER_MAC_H_ 6 #define CHROME_BROWSER_UI_COCOA_TASK_MANAGER_MAC_H_ 7 8 #import <Cocoa/Cocoa.h> 9 #include <vector> 10 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" 14 15 @class WindowSizeAutosaver; 16 class TaskManagerMac; 17 18 namespace gfx { 19 class ImageSkia; 20 } 21 22 // This class is responsible for loading the task manager window and for 23 // managing it. 24 @interface TaskManagerWindowController : 25 NSWindowController<NSTableViewDataSource, 26 NSTableViewDelegate> { 27 @private 28 IBOutlet NSTableView* tableView_; 29 IBOutlet NSButton* endProcessButton_; 30 TaskManagerMac* taskManagerObserver_; // weak 31 TaskManager* taskManager_; // weak 32 TaskManagerModel* model_; // weak 33 34 base::scoped_nsobject<WindowSizeAutosaver> size_saver_; 35 36 // These contain a permutation of [0..|model_->ResourceCount() - 1|]. Used to 37 // implement sorting. 38 std::vector<int> viewToModelMap_; 39 std::vector<int> modelToViewMap_; 40 41 // Descriptor of the current sort column. 42 base::scoped_nsobject<NSSortDescriptor> currentSortDescriptor_; 43 } 44 45 // Creates and shows the task manager's window. 46 - (id)initWithTaskManagerObserver:(TaskManagerMac*)taskManagerObserver; 47 48 // Refreshes all data in the task manager table. 49 - (void)reloadData; 50 51 // Callback for "Stats for nerds" link. 52 - (IBAction)statsLinkClicked:(id)sender; 53 54 // Callback for "End process" button. 55 - (IBAction)killSelectedProcesses:(id)sender; 56 57 // Callback for double clicks on the table. 58 - (void)selectDoubleClickedTab:(id)sender; 59 @end 60 61 @interface TaskManagerWindowController (TestingAPI) 62 - (NSTableView*)tableView; 63 @end 64 65 // This class listens to task changed events sent by chrome. 66 class TaskManagerMac : public TaskManagerModelObserver, 67 public TableRowNSImageCache::Table { 68 public: 69 explicit TaskManagerMac(TaskManager* task_manager); 70 virtual ~TaskManagerMac(); 71 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; 77 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(); 81 82 // TableRowNSImageCache::Table 83 virtual int RowCount() const OVERRIDE; 84 virtual gfx::ImageSkia GetIcon(int r) const OVERRIDE; 85 86 // Creates the task manager if it doesn't exist; otherwise, it activates the 87 // existing task manager window. 88 static void Show(); 89 90 // Returns the TaskManager observed by |this|. 91 TaskManager* task_manager() { return task_manager_; } 92 93 // Lazily converts the image at the given row and caches it in |icon_cache_|. 94 NSImage* GetImageForRow(int row); 95 96 // Returns the cocoa object. Used for testing. 97 TaskManagerWindowController* cocoa_controller() { return window_controller_; } 98 99 private: 100 // The task manager. 101 TaskManager* const task_manager_; // weak 102 103 // Our model. 104 TaskManagerModel* const model_; // weak 105 106 // Controller of our window, destroys itself when the task manager window 107 // is closed. 108 TaskManagerWindowController* window_controller_; // weak 109 110 // Caches favicons for all rows. Needs to be initalized after |model_|. 111 TableRowNSImageCache icon_cache_; 112 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_; 116 117 DISALLOW_COPY_AND_ASSIGN(TaskManagerMac); 118 }; 119 120 #endif // CHROME_BROWSER_UI_COCOA_TASK_MANAGER_MAC_H_ 121