1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_COCOA_TASK_MANAGER_MAC_H_
#define CHROME_BROWSER_UI_COCOA_TASK_MANAGER_MAC_H_
#import <Cocoa/Cocoa.h>
#include "base/callback_list.h"
#include "chrome/browser/task_manager/task_manager_metrics_recorder.h"
#include "chrome/browser/ui/task_manager/task_manager_table_model.h"
#include "ui/base/models/table_model_observer.h"
@class WindowSizeAutosaver;
namespace task_manager {
class TaskManagerMac;
}
// This class is responsible for loading the task manager window and for
// managing it.
@interface TaskManagerWindowController
: NSWindowController <NSWindowDelegate,
NSTableViewDataSource,
NSTableViewDelegate,
NSMenuDelegate>
// The current sort descriptor.
@property(nonatomic) task_manager::TableSortDescriptor sortDescriptor;
// Creates and shows the task manager's window.
- (instancetype)
initWithTaskManagerMac:(task_manager::TaskManagerMac*)taskManagerMac
tableModel:(task_manager::TaskManagerTableModel*)tableModel;
// Refreshes all data in the task manager table.
- (void)reloadData;
// Returns YES if the specified column is visible.
- (BOOL)visibilityOfColumnWithId:(int)columnId;
// Sets the visibility of the specified column.
- (void)setVisibility:(BOOL)visibility ofColumnWithId:(int)columnId;
// Callback for "End process" button.
- (IBAction)killSelectedProcesses:(id)sender;
// Callback for double clicks on the table.
- (void)tableWasDoubleClicked:(id)sender;
@end
@interface TaskManagerWindowController (TestingAPI)
@property(readonly) NSTableView* tableViewForTesting;
@property(readonly) NSButton* endProcessButtonForTesting;
@end
namespace task_manager {
// This class runs the Task Manager on the Mac.
class TaskManagerMac : public ui::TableModelObserver, public TableViewDelegate {
public:
TaskManagerMac(const TaskManagerMac&) = delete;
TaskManagerMac& operator=(const TaskManagerMac&) = delete;
// Called by the TaskManagerWindowController:
void WindowWasClosed();
NSImage* GetImageForRow(int row);
// Creates the task manager if it doesn't exist and records the location it
// was started from; otherwise, it activates the existing task manager window.
static TaskManagerTableModel* Show(
StartAction start_action = StartAction::kOther);
// Hides the task manager if it is showing.
static void Hide();
// Various test-only functions.
static TaskManagerMac* GetInstanceForTests() { return instance_; }
TaskManagerTableModel* GetTableModelForTests() { return &table_model_; }
TaskManagerWindowController* CocoaControllerForTests() {
return window_controller_;
}
private:
TaskManagerMac(StartAction start_action = StartAction::kOther);
~TaskManagerMac() override;
// ui::TableModelObserver:
void OnModelChanged() override;
void OnItemsChanged(size_t start, size_t length) override;
void OnItemsAdded(size_t start, size_t length) override;
void OnItemsRemoved(size_t start, size_t length) override;
// TableViewDelegate:
bool IsColumnVisible(int column_id) const override;
bool SetColumnVisibility(int column_id, bool new_visibility) override;
bool IsTableSorted() const override;
TableSortDescriptor GetSortDescriptor() const override;
void SetSortDescriptor(const TableSortDescriptor& descriptor) override;
void OnAppTerminating();
// The model holding the data for the table.
TaskManagerTableModel table_model_;
// The window controller that runs the window.
TaskManagerWindowController* __strong window_controller_;
// The first time this instance of the task manager was initialized.
const base::TimeTicks start_time_ = base::TimeTicks::Now();
base::CallbackListSubscription on_app_terminating_subscription_;
// An open task manager window. There can only be one open at a time. This
// is reset to be null when the window is closed.
static TaskManagerMac* instance_;
};
} // namespace task_manager
#endif // CHROME_BROWSER_UI_COCOA_TASK_MANAGER_MAC_H_
|