Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: chrome/browser/app_controller_mac.mm

Issue 2866034: Refactor shutdown code to allow win/linux to run after last browser closes. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Uploaded patch that resolves merge issue Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/automation/automation_provider.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/app_controller_mac.h" 5 #import "chrome/browser/app_controller_mac.h"
6 6
7 #include "app/l10n_util_mac.h" 7 #include "app/l10n_util_mac.h"
8 #include "base/auto_reset.h" 8 #include "base/auto_reset.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/mac_util.h" 10 #include "base/mac_util.h"
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 225
226 - (BOOL)tryToTerminateApplication:(NSApplication*)app { 226 - (BOOL)tryToTerminateApplication:(NSApplication*)app {
227 // Check for in-process downloads, and prompt the user if they really want 227 // Check for in-process downloads, and prompt the user if they really want
228 // to quit (and thus cancel downloads). Only check if we're not already 228 // to quit (and thus cancel downloads). Only check if we're not already
229 // shutting down, else the user might be prompted multiple times if the 229 // shutting down, else the user might be prompted multiple times if the
230 // download isn't stopped before terminate is called again. 230 // download isn't stopped before terminate is called again.
231 if (!browser_shutdown::IsTryingToQuit() && 231 if (!browser_shutdown::IsTryingToQuit() &&
232 ![self shouldQuitWithInProgressDownloads]) 232 ![self shouldQuitWithInProgressDownloads])
233 return NO; 233 return NO;
234 234
235 // Set the state to "trying to quit", so that closing all browser windows will
236 // lead to termination.
237 browser_shutdown::SetTryingToQuit(true);
238
239 // TODO(viettrungluu): Remove Apple Event handlers here? (It's safe to leave 235 // TODO(viettrungluu): Remove Apple Event handlers here? (It's safe to leave
240 // them in, but I'm not sure about UX; we'd also want to disable other things 236 // them in, but I'm not sure about UX; we'd also want to disable other things
241 // though.) http://crbug.com/40861 237 // though.) http://crbug.com/40861
242 238
243 if (!BrowserList::size()) 239 size_t num_browsers = BrowserList::size();
244 return YES;
245 240
246 // Try to close all the windows. 241 // Initiate a shutdown (via BrowserList::CloseAllBrowsers()) if we aren't
247 BrowserList::CloseAllBrowsers(true); 242 // already shutting down.
243 if (!browser_shutdown::IsTryingToQuit())
244 BrowserList::CloseAllBrowsers(true);
248 245
249 return NO; 246 return num_browsers == 0 ? YES : NO;
250 } 247 }
251 248
252 - (void)stopTryingToTerminateApplication:(NSApplication*)app { 249 - (void)stopTryingToTerminateApplication:(NSApplication*)app {
253 if (browser_shutdown::IsTryingToQuit()) { 250 if (browser_shutdown::IsTryingToQuit()) {
254 // Reset the "trying to quit" state, so that closing all browser windows 251 // Reset the "trying to quit" state, so that closing all browser windows
255 // will no longer lead to termination. 252 // will no longer lead to termination.
256 browser_shutdown::SetTryingToQuit(false); 253 browser_shutdown::SetTryingToQuit(false);
257 254
258 // TODO(viettrungluu): Were we to remove Apple Event handlers above, we 255 // TODO(viettrungluu): Were we to remove Apple Event handlers above, we
259 // would have to reinstall them here. http://crbug.com/40861 256 // would have to reinstall them here. http://crbug.com/40861
260 } 257 }
261 } 258 }
262 259
263 // Called when the app is shutting down. Clean-up as appropriate. 260 // Called when the app is shutting down. Clean-up as appropriate.
264 - (void)applicationWillTerminate:(NSNotification*)aNotification { 261 - (void)applicationWillTerminate:(NSNotification*)aNotification {
265 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; 262 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager];
266 [em removeEventHandlerForEventClass:kInternetEventClass 263 [em removeEventHandlerForEventClass:kInternetEventClass
267 andEventID:kAEGetURL]; 264 andEventID:kAEGetURL];
268 [em removeEventHandlerForEventClass:'WWW!' 265 [em removeEventHandlerForEventClass:'WWW!'
269 andEventID:'OURL']; 266 andEventID:'OURL'];
270 267
271 // There better be no browser windows left at this point. 268 // There better be no browser windows left at this point.
272 CHECK_EQ(BrowserList::size(), 0u); 269 CHECK_EQ(BrowserList::size(), 0u);
273 270
274 // Release the reference to the browser process. Once all the browsers get 271 // Tell BrowserList not to keep the browser process alive. Once all the
275 // dealloc'd, it will stop the RunLoop and fall back into main(). 272 // browsers get dealloc'd, it will stop the RunLoop and fall back into main().
276 g_browser_process->ReleaseModule(); 273 BrowserList::EndKeepAlive();
277 274
278 // Close these off if they have open windows. 275 // Close these off if they have open windows.
279 [prefsController_ close]; 276 [prefsController_ close];
280 [aboutController_ close]; 277 [aboutController_ close];
281 278
282 [[NSNotificationCenter defaultCenter] removeObserver:self]; 279 [[NSNotificationCenter defaultCenter] removeObserver:self];
283 } 280 }
284 281
285 - (void)didEndMainMessageLoop { 282 - (void)didEndMainMessageLoop {
286 DCHECK(!BrowserList::HasBrowserWithProfile([self defaultProfile])); 283 DCHECK(!BrowserList::HasBrowserWithProfile([self defaultProfile]));
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 NSNumber* value = [NSNumber numberWithFloat:fiveHoursInSeconds]; 445 NSNumber* value = [NSNumber numberWithFloat:fiveHoursInSeconds];
449 CFPreferencesSetAppValue(checkInterval, value, app); 446 CFPreferencesSetAppValue(checkInterval, value, app);
450 CFPreferencesAppSynchronize(app); 447 CFPreferencesAppSynchronize(app);
451 } 448 }
452 #endif 449 #endif
453 } 450 }
454 451
455 // This is called after profiles have been loaded and preferences registered. 452 // This is called after profiles have been loaded and preferences registered.
456 // It is safe to access the default profile here. 453 // It is safe to access the default profile here.
457 - (void)applicationDidFinishLaunching:(NSNotification*)notify { 454 - (void)applicationDidFinishLaunching:(NSNotification*)notify {
458 // Hold an extra ref to the BrowserProcess singleton so it doesn't go away 455 // Notify BrowserList to keep the application running so it doesn't go away
459 // when all the browser windows get closed. We'll release it on quit which 456 // when all the browser windows get closed.
460 // will be the signal to exit. 457 BrowserList::StartKeepAlive();
461 DCHECK(g_browser_process);
462 g_browser_process->AddRefModule();
463 458
464 bookmarkMenuBridge_.reset(new BookmarkMenuBridge([self defaultProfile])); 459 bookmarkMenuBridge_.reset(new BookmarkMenuBridge([self defaultProfile]));
465 historyMenuBridge_.reset(new HistoryMenuBridge([self defaultProfile])); 460 historyMenuBridge_.reset(new HistoryMenuBridge([self defaultProfile]));
466 461
467 [self setUpdateCheckInterval]; 462 [self setUpdateCheckInterval];
468 463
469 // Build up the encoding menu, the order of the items differs based on the 464 // Build up the encoding menu, the order of the items differs based on the
470 // current locale (see http://crbug.com/7647 for details). 465 // current locale (see http://crbug.com/7647 for details).
471 // We need a valid g_browser_process to get the profile which is why we can't 466 // We need a valid g_browser_process to get the profile which is why we can't
472 // call this from awakeFromNib. 467 // call this from awakeFromNib.
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 [appController showPreferencesWindow:nil page:page profile:profile]; 1060 [appController showPreferencesWindow:nil page:page profile:profile];
1066 } 1061 }
1067 1062
1068 namespace app_controller_mac { 1063 namespace app_controller_mac {
1069 1064
1070 bool IsOpeningNewWindow() { 1065 bool IsOpeningNewWindow() {
1071 return g_is_opening_new_window; 1066 return g_is_opening_new_window;
1072 } 1067 }
1073 1068
1074 } // namespace app_controller_mac 1069 } // namespace app_controller_mac
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/automation/automation_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698