Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / task_manager_mac.h
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   ~TaskManagerMac() override;
71
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;
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   int RowCount() const override;
84   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   // Hides the task manager if it is showing.
91   static void Hide();
92
93   // Returns the TaskManager observed by |this|.
94   TaskManager* task_manager() { return task_manager_; }
95
96   // Lazily converts the image at the given row and caches it in |icon_cache_|.
97   NSImage* GetImageForRow(int row);
98
99   // Returns the cocoa object. Used for testing.
100   TaskManagerWindowController* cocoa_controller() { return window_controller_; }
101
102  private:
103   // The task manager.
104   TaskManager* const task_manager_;  // weak
105
106   // Our model.
107   TaskManagerModel* const model_;  // weak
108
109   // Controller of our window, destroys itself when the task manager window
110   // is closed.
111   TaskManagerWindowController* window_controller_;  // weak
112
113   // Caches favicons for all rows. Needs to be initalized after |model_|.
114   TableRowNSImageCache icon_cache_;
115
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_;
119
120   DISALLOW_COPY_AND_ASSIGN(TaskManagerMac);
121 };
122
123 #endif  // CHROME_BROWSER_UI_COCOA_TASK_MANAGER_MAC_H_