blob: 957972459559a47e98a5be8ab316a9bad6875852 [file] [log] [blame]
[email protected]c6dedad2012-06-14 19:33:301// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
thestig028978692015-10-08 07:39:405#ifndef CHROME_BROWSER_BROWSER_SHUTDOWN_H_
6#define CHROME_BROWSER_BROWSER_SHUTDOWN_H_
initial.commit09911bf2008-07-26 23:55:297
avie4d7b6f2015-12-26 00:59:188#include "build/build_config.h"
9
[email protected]b1de2c72013-02-06 02:45:4710class PrefRegistrySimple;
initial.commit09911bf2008-07-26 23:55:2911
12namespace browser_shutdown {
13
dgn3eaf67e2016-07-26 09:01:1214// Shutdown flags
15enum Flags {
16 NO_FLAGS = 0,
17
18 // If |RESTART_LAST_SESSION| is set, the browser will attempt to restart in
19 // in the last session after the shutdown.
20 RESTART_LAST_SESSION = 1 << 0,
21
22 // Makes a panned restart happen in the background. The browser will just come
23 // up in the system tray but not open a new window after restarting. This flag
24 // has no effect if |RESTART_LAST_SESSION| is not set.
25 RESTART_IN_BACKGROUND = 1 << 1
26};
27
initial.commit09911bf2008-07-26 23:55:2928enum ShutdownType {
29 // an uninitialized value
30 NOT_VALID = 0,
31 // the last browser window was closed
32 WINDOW_CLOSE,
33 // user clicked on the Exit menu item
34 BROWSER_EXIT,
35 // windows is logging off or shutting down
36 END_SESSION
37};
38
hashimotodc347b72016-09-16 07:23:4039constexpr int kNumShutdownTypes = END_SESSION + 1;
40
[email protected]b1de2c72013-02-06 02:45:4741void RegisterPrefs(PrefRegistrySimple* registry);
initial.commit09911bf2008-07-26 23:55:2942
43// Called when the browser starts shutting down so that we can measure shutdown
44// time.
45void OnShutdownStarting(ShutdownType type);
46
[email protected]bfe4c1582009-10-02 18:11:0947// Get the current shutdown type.
48ShutdownType GetShutdownType();
49
thestigaf58280d2015-10-02 18:56:4550#if !defined(OS_ANDROID)
[email protected]2e5b60a22011-11-28 15:56:4151// Performs the shutdown tasks that need to be done before
52// BrowserProcess and the various threads go away.
53//
54// Returns true if the session should be restarted.
55bool ShutdownPreThreadsStop();
56
hashimotodc347b72016-09-16 07:23:4057// Records the shutdown related prefs, and returns true if the browser should be
58// restarted on exit.
59bool RecordShutdownInfoPrefs();
60
[email protected]2e5b60a22011-11-28 15:56:4161// Performs the remaining shutdown tasks after all threads but the
62// main thread have been stopped. This includes deleting g_browser_process.
63//
dgn3eaf67e2016-07-26 09:01:1264// See |browser_shutdown::Flags| for the possible flag values and their effects.
65void ShutdownPostThreadsStop(int shutdown_flags);
thestigaf58280d2015-10-02 18:56:4566#endif
initial.commit09911bf2008-07-26 23:55:2967
68// Called at startup to create a histogram from our previous shutdown time.
69void ReadLastShutdownInfo();
70
[email protected]c984d9f2010-07-20 20:52:2071// There are various situations where the browser process should continue to
72// run after the last browser window has closed - the Mac always continues
73// running until the user explicitly quits, and on Windows/Linux the application
74// should not shutdown when the last browser window closes if there are any
75// BackgroundContents running.
76// When the user explicitly chooses to shutdown the app (via the "Exit" or
77// "Quit" menu items) BrowserList will call SetTryingToQuit() to tell itself to
78// initiate a shutdown when the last window closes.
79// If the quit is aborted, then the flag should be reset.
[email protected]7dc8c6b2010-04-09 17:02:5080
[email protected]c984d9f2010-07-20 20:52:2081// This is a low-level mutator; in general, don't call SetTryingToQuit(true),
82// except from appropriate places in BrowserList. To quit, use usual means,
83// e.g., using |chrome_browser_application_mac::Terminate()| on the Mac, or
84// |BrowserList::CloseAllWindowsAndExit()| on other platforms. To stop quitting,
85// use |chrome_browser_application_mac::CancelTerminate()| on the Mac; other
86// platforms can call SetTryingToQuit(false) directly.
[email protected]7dc8c6b2010-04-09 17:02:5087void SetTryingToQuit(bool quitting);
88
89// General accessor.
90bool IsTryingToQuit();
[email protected]7dc8c6b2010-04-09 17:02:5091
thestig028978692015-10-08 07:39:4092// Starts to collect shutdown traces. On ChromeOS this will start immediately
93// on AttemptUserExit() and all other systems will start once all tabs are
94// closed.
95void StartShutdownTracing();
96
initial.commit09911bf2008-07-26 23:55:2997} // namespace browser_shutdown
98
thestig028978692015-10-08 07:39:4099#endif // CHROME_BROWSER_BROWSER_SHUTDOWN_H_