Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / task_manager_mac.h
blob093f9f413568753719a30417d3f4305f5c7b2f82
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>
9 #include <vector>
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;
16 class TaskManagerMac;
18 namespace gfx {
19 class ImageSkia;
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
34 base::scoped_nsobject<WindowSizeAutosaver> size_saver_;
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_;
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.
49 - (void)reloadData;
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;
59 @end
61 @interface TaskManagerWindowController (TestingAPI)
62 - (NSTableView*)tableView;
63 @end
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();
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.
88 static void Show();
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_; }
99 private:
100 // The task manager.
101 TaskManager* const task_manager_; // weak
103 // Our model.
104 TaskManagerModel* const model_; // weak
106 // Controller of our window, destroys itself when the task manager window
107 // is closed.
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_