application_lifetime_aura.cc revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
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.
4
5#include "chrome/browser/lifetime/application_lifetime.h"
6
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/views/widget/widget.h"
12
13#if defined(USE_ASH)
14#include "ash/shell.h"
15#include "ui/aura/client/capture_client.h"
16#endif
17
18#if defined(OS_CHROMEOS)
19#include "chromeos/display/output_configurator.h"
20#endif
21
22namespace chrome {
23
24void HandleAppExitingForPlatform() {
25  // Close all non browser windows now. Those includes notifications
26  // and windows created by Ash (launcher, background, etc).
27#if defined(USE_ASH)
28  // This may be called before |ash::Shell| is initialized when
29  // XIOError is reported.  crbug.com/150633.
30  if (ash::Shell::HasInstance()) {
31    g_browser_process->notification_ui_manager()->CancelAll();
32    // Releasing the capture will close any menus that might be open:
33    // http://crbug.com/134472
34    aura::client::GetCaptureClient(ash::Shell::GetPrimaryRootWindow())->
35        SetCapture(NULL);
36  }
37#else
38  g_browser_process->notification_ui_manager()->CancelAll();
39#endif
40
41  views::Widget::CloseAllSecondaryWidgets();
42
43#if defined(OS_CHROMEOS)
44  if (!CommandLine::ForCurrentProcess()->HasSwitch(
45      switches::kDisableZeroBrowsersOpenForTests)) {
46    // App is exiting, call EndKeepAlive() on behalf of Aura Shell.
47    EndKeepAlive();
48    // Make sure we have notified the session manager that we are exiting.
49    // This might be called from FastShutdown() or CloseAllBrowsers(), but not
50    // if something prevents a browser from closing before SetTryingToQuit()
51    // gets called (e.g. browser->TabsNeedBeforeUnloadFired() is true).
52    // NotifyAndTerminate does nothing if called more than once.
53    NotifyAndTerminate(true);
54  }
55#endif  // OS_CHROMEOS
56}
57
58}  // namespace chrome
59