OLD | NEW |
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 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 // managing it. | 23 // managing it. |
24 @interface TaskManagerWindowController : | 24 @interface TaskManagerWindowController : |
25 NSWindowController<NSTableViewDataSource, | 25 NSWindowController<NSTableViewDataSource, |
26 NSTableViewDelegate> { | 26 NSTableViewDelegate> { |
27 @private | 27 @private |
28 IBOutlet NSTableView* tableView_; | 28 IBOutlet NSTableView* tableView_; |
29 IBOutlet NSButton* endProcessButton_; | 29 IBOutlet NSButton* endProcessButton_; |
30 TaskManagerMac* taskManagerObserver_; // weak | 30 TaskManagerMac* taskManagerObserver_; // weak |
31 TaskManager* taskManager_; // weak | 31 TaskManager* taskManager_; // weak |
32 TaskManagerModel* model_; // weak | 32 TaskManagerModel* model_; // weak |
33 bool highlightBackgroundResources_; | |
34 | 33 |
35 scoped_nsobject<WindowSizeAutosaver> size_saver_; | 34 scoped_nsobject<WindowSizeAutosaver> size_saver_; |
36 | 35 |
37 // These contain a permutation of [0..|model_->ResourceCount() - 1|]. Used to | 36 // These contain a permutation of [0..|model_->ResourceCount() - 1|]. Used to |
38 // implement sorting. | 37 // implement sorting. |
39 std::vector<int> viewToModelMap_; | 38 std::vector<int> viewToModelMap_; |
40 std::vector<int> modelToViewMap_; | 39 std::vector<int> modelToViewMap_; |
41 | 40 |
42 // Descriptor of the current sort column. | 41 // Descriptor of the current sort column. |
43 scoped_nsobject<NSSortDescriptor> currentSortDescriptor_; | 42 scoped_nsobject<NSSortDescriptor> currentSortDescriptor_; |
44 | |
45 // Color we use for background resources. | |
46 scoped_nsobject<NSColor> backgroundResourceColor_; | |
47 } | 43 } |
48 | 44 |
49 // Creates and shows the task manager's window. | 45 // Creates and shows the task manager's window. |
50 - (id)initWithTaskManagerObserver:(TaskManagerMac*)taskManagerObserver | 46 - (id)initWithTaskManagerObserver:(TaskManagerMac*)taskManagerObserver; |
51 highlightBackgroundResources:(bool)highlightBackgroundResources; | |
52 | 47 |
53 // Refreshes all data in the task manager table. | 48 // Refreshes all data in the task manager table. |
54 - (void)reloadData; | 49 - (void)reloadData; |
55 | 50 |
56 // Callback for "Stats for nerds" link. | 51 // Callback for "Stats for nerds" link. |
57 - (IBAction)statsLinkClicked:(id)sender; | 52 - (IBAction)statsLinkClicked:(id)sender; |
58 | 53 |
59 // Callback for "End process" button. | 54 // Callback for "End process" button. |
60 - (IBAction)killSelectedProcesses:(id)sender; | 55 - (IBAction)killSelectedProcesses:(id)sender; |
61 | 56 |
62 // Callback for double clicks on the table. | 57 // Callback for double clicks on the table. |
63 - (void)selectDoubleClickedTab:(id)sender; | 58 - (void)selectDoubleClickedTab:(id)sender; |
64 @end | 59 @end |
65 | 60 |
66 @interface TaskManagerWindowController (TestingAPI) | 61 @interface TaskManagerWindowController (TestingAPI) |
67 - (NSTableView*)tableView; | 62 - (NSTableView*)tableView; |
68 @end | 63 @end |
69 | 64 |
70 // This class listens to task changed events sent by chrome. | 65 // This class listens to task changed events sent by chrome. |
71 class TaskManagerMac : public TaskManagerModelObserver, | 66 class TaskManagerMac : public TaskManagerModelObserver, |
72 public TableRowNSImageCache::Table { | 67 public TableRowNSImageCache::Table { |
73 public: | 68 public: |
74 TaskManagerMac(TaskManager* task_manager, bool highlight_background); | 69 explicit TaskManagerMac(TaskManager* task_manager); |
75 virtual ~TaskManagerMac(); | 70 virtual ~TaskManagerMac(); |
76 | 71 |
77 // TaskManagerModelObserver | 72 // TaskManagerModelObserver |
78 virtual void OnModelChanged() OVERRIDE; | 73 virtual void OnModelChanged() OVERRIDE; |
79 virtual void OnItemsChanged(int start, int length) OVERRIDE; | 74 virtual void OnItemsChanged(int start, int length) OVERRIDE; |
80 virtual void OnItemsAdded(int start, int length) OVERRIDE; | 75 virtual void OnItemsAdded(int start, int length) OVERRIDE; |
81 virtual void OnItemsRemoved(int start, int length) OVERRIDE; | 76 virtual void OnItemsRemoved(int start, int length) OVERRIDE; |
82 | 77 |
83 // Called by the cocoa window controller when its window closes and the | 78 // Called by the cocoa window controller when its window closes and the |
84 // controller destroyed itself. Informs the model to stop updating. | 79 // controller destroyed itself. Informs the model to stop updating. |
85 void WindowWasClosed(); | 80 void WindowWasClosed(); |
86 | 81 |
87 // TableRowNSImageCache::Table | 82 // TableRowNSImageCache::Table |
88 virtual int RowCount() const OVERRIDE; | 83 virtual int RowCount() const OVERRIDE; |
89 virtual gfx::ImageSkia GetIcon(int r) const OVERRIDE; | 84 virtual gfx::ImageSkia GetIcon(int r) const OVERRIDE; |
90 | 85 |
91 // Creates the task manager if it doesn't exist; otherwise, it activates the | 86 // Creates the task manager if it doesn't exist; otherwise, it activates the |
92 // existing task manager window. Highlights background resources if | 87 // existing task manager window. |
93 // |highlight_background_resources| is true. | 88 static void Show(); |
94 static void Show(bool highlight_background_resources); | |
95 | 89 |
96 // Returns the TaskManager observed by |this|. | 90 // Returns the TaskManager observed by |this|. |
97 TaskManager* task_manager() { return task_manager_; } | 91 TaskManager* task_manager() { return task_manager_; } |
98 | 92 |
99 // Lazily converts the image at the given row and caches it in |icon_cache_|. | 93 // Lazily converts the image at the given row and caches it in |icon_cache_|. |
100 NSImage* GetImageForRow(int row); | 94 NSImage* GetImageForRow(int row); |
101 | 95 |
102 // Returns the cocoa object. Used for testing. | 96 // Returns the cocoa object. Used for testing. |
103 TaskManagerWindowController* cocoa_controller() { return window_controller_; } | 97 TaskManagerWindowController* cocoa_controller() { return window_controller_; } |
104 | 98 |
105 // Returns true if the resource at this location is a background resource. | |
106 bool IsBackgroundRow(int row) const; | |
107 private: | 99 private: |
108 // The task manager. | 100 // The task manager. |
109 TaskManager* const task_manager_; // weak | 101 TaskManager* const task_manager_; // weak |
110 | 102 |
111 // Our model. | 103 // Our model. |
112 TaskManagerModel* const model_; // weak | 104 TaskManagerModel* const model_; // weak |
113 | 105 |
114 // Controller of our window, destroys itself when the task manager window | 106 // Controller of our window, destroys itself when the task manager window |
115 // is closed. | 107 // is closed. |
116 TaskManagerWindowController* window_controller_; // weak | 108 TaskManagerWindowController* window_controller_; // weak |
117 | 109 |
118 // Caches favicons for all rows. Needs to be initalized after |model_|. | 110 // Caches favicons for all rows. Needs to be initalized after |model_|. |
119 TableRowNSImageCache icon_cache_; | 111 TableRowNSImageCache icon_cache_; |
120 | 112 |
121 // If true, highlight background resources. | |
122 bool highlight_background_resources_; | |
123 | |
124 // An open task manager window. There can only be one open at a time. This | 113 // An open task manager window. There can only be one open at a time. This |
125 // is reset to NULL when the window is closed. | 114 // is reset to NULL when the window is closed. |
126 static TaskManagerMac* instance_; | 115 static TaskManagerMac* instance_; |
127 | 116 |
128 DISALLOW_COPY_AND_ASSIGN(TaskManagerMac); | 117 DISALLOW_COPY_AND_ASSIGN(TaskManagerMac); |
129 }; | 118 }; |
130 | 119 |
131 #endif // CHROME_BROWSER_UI_COCOA_TASK_MANAGER_MAC_H_ | 120 #endif // CHROME_BROWSER_UI_COCOA_TASK_MANAGER_MAC_H_ |
OLD | NEW |