diff options
author | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-09 15:35:47 +0000 |
---|---|---|
committer | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-09 15:35:47 +0000 |
commit | 7c32108b22446be27129324ce41d32e9c909e379 (patch) | |
tree | 2b18444c829ae9155036ef3c55ab1fb645b9621e /chrome/browser | |
parent | 54131d25aa7e887f89ba25851b983150cd1384a8 (diff) | |
download | chromium_src-7c32108b22446be27129324ce41d32e9c909e379.zip chromium_src-7c32108b22446be27129324ce41d32e9c909e379.tar.gz chromium_src-7c32108b22446be27129324ce41d32e9c909e379.tar.bz2 |
Add Recycle() method to scoped autorelease pool to allow cleaning out any junk
created at startup before the main runloop. Correct quit on Mac to let the
BrowserProcess shut down the event loop when its refcount goes to zero after
cleaning up all browser windows.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9386 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/app_controller_mac.mm | 21 | ||||
-rw-r--r-- | chrome/browser/browser_main.cc | 7 | ||||
-rw-r--r-- | chrome/browser/browser_window_cocoa.mm | 1 |
3 files changed, 21 insertions, 8 deletions
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm index 3895ece..5a9609a 100644 --- a/chrome/browser/app_controller_mac.mm +++ b/chrome/browser/app_controller_mac.mm @@ -19,10 +19,18 @@ @implementation AppController - (void)awakeFromNib { - // set up the command updater for when there are no windows open + // Set up the command updater for when there are no windows open [self initMenuState]; } +- (void)applicationDidFinishLaunching:(NSNotification*)notify { + // Hold an extra ref to the BrowserProcess singleton so it doesn't go away + // when all the browser windows get closed. We'll release it on quit which + // will be the signal to exit. + DCHECK(g_browser_process); + g_browser_process->AddRefModule(); +} + - (void)dealloc { delete menuState_; [super dealloc]; @@ -41,14 +49,11 @@ // go back to normal. // Close all the windows. - // TODO(pinkerton): the close code assumes that teardown happens - // synchronously, however with autorelease pools and ref-counting, we can't - // guarantee the window controller hits 0 inside this call, and thus the - // number of Browsers still alive will certainly be non-zero. Not sure yet - // how to handle this case. - // BrowserList::CloseAllBrowsers(false); + BrowserList::CloseAllBrowsers(true); - MessageLoopForUI::current()->Quit(); + // Release the reference to the browser process. Once all the browsers get + // dealloc'd, it will stop the RunLoop and fall back into main(). + g_browser_process->ReleaseModule(); } // Called to validate menu items when there are no key windows. All the diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 23a8078..654da338 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -11,6 +11,7 @@ #include "base/file_util.h" #include "base/histogram.h" #include "base/lazy_instance.h" +#include "base/scoped_nsautorelease_pool.h" #include "base/path_service.h" #include "base/process_util.h" #include "base/string_piece.h" @@ -190,6 +191,7 @@ void RunUIMessageLoop(BrowserProcess* browser_process) { // Main routine for running as the Browser process. int BrowserMain(const MainFunctionParams& parameters) { const CommandLine& parsed_command_line = parameters.command_line_; + base::ScopedNSAutoreleasePool* pool = parameters.autorelease_pool_; // WARNING: If we get a WM_ENDSESSION objects created on the stack here // are NOT deleted. If you need something to run during WM_ENDSESSION add it @@ -554,13 +556,18 @@ int BrowserMain(const MainFunctionParams& parameters) { // This should happen before ProcessCommandLine. profile->InitExtensions(); + // Call Recycle() here as late as possible, just before going into the main + // loop. We can't do it any earlier, as ProcessCommandLine() will add things + // to it in the act of creating the initial browser window. int result_code = ResultCodes::NORMAL_EXIT; if (parameters.ui_task) { + if (pool) pool->Recycle(); MessageLoopForUI::current()->PostTask(FROM_HERE, parameters.ui_task); RunUIMessageLoop(browser_process.get()); } else if (BrowserInit::ProcessCommandLine(parsed_command_line, std::wstring(), local_state, true, profile, &result_code)) { + if (pool) pool->Recycle(); RunUIMessageLoop(browser_process.get()); } diff --git a/chrome/browser/browser_window_cocoa.mm b/chrome/browser/browser_window_cocoa.mm index b78b913..c541985 100644 --- a/chrome/browser/browser_window_cocoa.mm +++ b/chrome/browser/browser_window_cocoa.mm @@ -33,6 +33,7 @@ void BrowserWindowCocoa::SetBounds(const gfx::Rect& bounds) { void BrowserWindowCocoa::Close() { [window_ orderOut:controller_]; + [window_ performClose:controller_]; } void BrowserWindowCocoa::Activate() { |