diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-12 18:12:22 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-12 18:12:22 +0000 |
commit | a9e60072222bce1db00e65a80297f0ee0210a613 (patch) | |
tree | e757d7908a69a3bc115b6be02ce5325859885611 /chrome/browser/cocoa | |
parent | 3fbc8276f724079cb0e0ddd3899c3b49a40e11d9 (diff) | |
download | chromium_src-a9e60072222bce1db00e65a80297f0ee0210a613.zip chromium_src-a9e60072222bce1db00e65a80297f0ee0210a613.tar.gz chromium_src-a9e60072222bce1db00e65a80297f0ee0210a613.tar.bz2 |
Mac: Tell task manager model to stop updating when the task manager window is closed.
Also change how the controller is deallocated, which should fix a valgrind bug.
Nib change: Make TaskManagerWindowController the delegate of the window in the nib, so that its windowWillClose: gets called.
TFR=trungl
BUG=13156,30398
TEST=Open Activity Monitor, look at browser %cpu. Open chrome's task manager, note %cpu goes up slightly. Close task manager again, %cpu should go down again. Open task manager again, should still work.
Review URL: http://codereview.chromium.org/536026
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36020 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa')
-rw-r--r-- | chrome/browser/cocoa/task_manager_mac.h | 21 | ||||
-rw-r--r-- | chrome/browser/cocoa/task_manager_mac.mm | 35 |
2 files changed, 41 insertions, 15 deletions
diff --git a/chrome/browser/cocoa/task_manager_mac.h b/chrome/browser/cocoa/task_manager_mac.h index b0e1481..cbcb5d2 100644 --- a/chrome/browser/cocoa/task_manager_mac.h +++ b/chrome/browser/cocoa/task_manager_mac.h @@ -9,18 +9,21 @@ #include "base/scoped_nsobject.h" #include "chrome/browser/task_manager.h" +class TaskManagerMac; + // This class is responsible for loading the task manager window and for // managing it. @interface TaskManagerWindowController : NSWindowController { @private IBOutlet NSTableView* tableView_; IBOutlet NSButton* endProcessButton_; + TaskManagerMac* taskManagerObserver_; // weak TaskManager* taskManager_; // weak TaskManagerModel* model_; // weak } // Creates and shows the task manager's window. -- (id)initWithTaskManager:(TaskManager*)taskManager; +- (id)initWithTaskManagerObserver:(TaskManagerMac*)taskManagerObserver; // Refreshes all data in the task manager table. - (void)reloadData; @@ -47,19 +50,27 @@ class TaskManagerMac : public TaskManagerModelObserver { virtual void OnItemsAdded(int start, int length); virtual void OnItemsRemoved(int start, int length); + // Called by the cocoa window controller when its window closes and the + // controller destroyed itself. Informs the model to stop updating. + void WindowWasClosed(); + // Creates the task manager if it doesn't exist; otherwise, it activates the // existing task manager window. static void Show(); + // Returns the TaskManager observed by |this|. + TaskManager* task_manager() { return task_manager_; } + private: // The task manager. - TaskManager* task_manager_; // weak + TaskManager* const task_manager_; // weak // Our model. - TaskManagerModel* model_; // weak + TaskManagerModel* const model_; // weak - // Controller of our window. - scoped_nsobject<TaskManagerWindowController> window_controller_; + // Controller of our window, destroys itself when the task manager window + // is closed. + TaskManagerWindowController* window_controller_; // weak // An open task manager window. There can only be one open at a time. This // is reset to NULL when the window is closed. diff --git a/chrome/browser/cocoa/task_manager_mac.mm b/chrome/browser/cocoa/task_manager_mac.mm index 00f0002..71b24f5 100644 --- a/chrome/browser/cocoa/task_manager_mac.mm +++ b/chrome/browser/cocoa/task_manager_mac.mm @@ -15,10 +15,8 @@ // TODO(thakis): Autoremember window size/pos (and selected columns?) // TODO(thakis): Column sort comparator // TODO(thakis): Clicking column header doesn't sort -// TODO(thakis): On window close, stop updating // TODO(thakis): Favicons in rows // TODO(thakis): Default sort column -// TODO(thakis): Metrics for all processes except browser process are missing. @interface TaskManagerWindowController (Private) - (void)addColumnWithId:(int)columnId visible:(BOOL)isVisible; @@ -33,12 +31,13 @@ @implementation TaskManagerWindowController -- (id)initWithTaskManager:(TaskManager*)taskManager { +- (id)initWithTaskManagerObserver:(TaskManagerMac*)taskManagerObserver { NSString* nibpath = [mac_util::MainAppBundle() pathForResource:@"TaskManager" ofType:@"nib"]; if ((self = [super initWithWindowNibPath:nibpath owner:self])) { - taskManager_ = taskManager; + taskManagerObserver_ = taskManagerObserver; + taskManager_ = taskManagerObserver_->task_manager(); model_ = taskManager_->model(); [[self window] makeKeyAndOrderFront:self]; } @@ -175,6 +174,17 @@ [self adjustEndProcessButton]; } +// Called when the window is being closed. Send out a notification that the user +// is done editing preferences. Make sure there are no pending field editors +// by clearing the first responder. +- (void)windowWillClose:(NSNotification*)notification { + if (taskManagerObserver_) { + taskManagerObserver_->WindowWasClosed(); + taskManagerObserver_ = nil; + } + [self autorelease]; +} + @end @implementation TaskManagerWindowController (NSTableDataSource) @@ -259,8 +269,8 @@ TaskManagerMac::TaskManagerMac() : task_manager_(TaskManager::GetInstance()), model_(TaskManager::GetInstance()->model()) { - window_controller_.reset( - [[TaskManagerWindowController alloc] initWithTaskManager:task_manager_]); + window_controller_ = + [[TaskManagerWindowController alloc] initWithTaskManagerObserver:this]; model_->AddObserver(this); } @@ -276,24 +286,29 @@ TaskManagerMac::~TaskManagerMac() { // TaskManagerMac, TaskManagerModelObserver implementation: void TaskManagerMac::OnModelChanged() { - [window_controller_.get() reloadData]; + [window_controller_ reloadData]; } void TaskManagerMac::OnItemsChanged(int start, int length) { - [window_controller_.get() reloadData]; + [window_controller_ reloadData]; } void TaskManagerMac::OnItemsAdded(int start, int length) { - [window_controller_.get() reloadData]; + [window_controller_ reloadData]; } void TaskManagerMac::OnItemsRemoved(int start, int length) { - [window_controller_.get() reloadData]; + [window_controller_ reloadData]; } //////////////////////////////////////////////////////////////////////////////// // TaskManagerMac, public: +void TaskManagerMac::WindowWasClosed() { + delete this; + instance_ = NULL; +} + // static void TaskManagerMac::Show() { if (instance_) { |