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.
5 #include "chrome/browser/lifetime/application_lifetime.h"
7 #include "base/command_line.h"
8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/notifications/notification_ui_manager.h"
10 #include "chrome/common/chrome_switches.h"
11 #include "ui/aura/window_event_dispatcher.h"
12 #include "ui/views/widget/widget.h"
15 #include "ash/shell.h"
16 #include "ui/aura/client/capture_client.h"
21 void HandleAppExitingForPlatform() {
22 // Close all non browser windows now. Those includes notifications
23 // and windows created by Ash (launcher, background, etc).
25 // This may be called before |ash::Shell| is initialized when
26 // XIOError is reported. crbug.com/150633.
27 if (ash::Shell::HasInstance()) {
28 g_browser_process
->notification_ui_manager()->CancelAll();
29 // Releasing the capture will close any menus that might be open:
30 // http://crbug.com/134472
31 aura::client::GetCaptureClient(ash::Shell::GetPrimaryRootWindow())->
35 g_browser_process
->notification_ui_manager()->CancelAll();
38 views::Widget::CloseAllSecondaryWidgets();
40 #if defined(OS_CHROMEOS)
41 if (!CommandLine::ForCurrentProcess()->HasSwitch(
42 switches::kDisableZeroBrowsersOpenForTests
)) {
43 // App is exiting, call DecrementKeepAliveCount() on behalf of Aura Shell.
44 DecrementKeepAliveCount();
45 // Make sure we have notified the session manager that we are exiting.
46 // This might be called from FastShutdown() or CloseAllBrowsers(), but not
47 // if something prevents a browser from closing before SetTryingToQuit()
48 // gets called (e.g. browser->TabsNeedBeforeUnloadFired() is true).
49 // NotifyAndTerminate does nothing if called more than once.
50 NotifyAndTerminate(true);