[email protected] | c6dedad | 2012-06-14 19:33:30 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
thestig | 02897869 | 2015-10-08 07:39:40 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_BROWSER_SHUTDOWN_H_ |
| 6 | #define CHROME_BROWSER_BROWSER_SHUTDOWN_H_ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 7 | |
avi | e4d7b6f | 2015-12-26 00:59:18 | [diff] [blame] | 8 | #include "build/build_config.h" |
| 9 | |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 10 | class PrefRegistrySimple; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 11 | |
| 12 | namespace browser_shutdown { |
| 13 | |
dgn | 3eaf67e | 2016-07-26 09:01:12 | [diff] [blame] | 14 | // Shutdown flags |
| 15 | enum 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.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 28 | enum 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 | |
hashimoto | dc347b7 | 2016-09-16 07:23:40 | [diff] [blame] | 39 | constexpr int kNumShutdownTypes = END_SESSION + 1; |
| 40 | |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 41 | void RegisterPrefs(PrefRegistrySimple* registry); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 42 | |
| 43 | // Called when the browser starts shutting down so that we can measure shutdown |
| 44 | // time. |
| 45 | void OnShutdownStarting(ShutdownType type); |
| 46 | |
[email protected] | bfe4c158 | 2009-10-02 18:11:09 | [diff] [blame] | 47 | // Get the current shutdown type. |
| 48 | ShutdownType GetShutdownType(); |
| 49 | |
thestig | af58280d | 2015-10-02 18:56:45 | [diff] [blame] | 50 | #if !defined(OS_ANDROID) |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 51 | // 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. |
| 55 | bool ShutdownPreThreadsStop(); |
| 56 | |
hashimoto | dc347b7 | 2016-09-16 07:23:40 | [diff] [blame] | 57 | // Records the shutdown related prefs, and returns true if the browser should be |
| 58 | // restarted on exit. |
| 59 | bool RecordShutdownInfoPrefs(); |
| 60 | |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 61 | // Performs the remaining shutdown tasks after all threads but the |
| 62 | // main thread have been stopped. This includes deleting g_browser_process. |
| 63 | // |
dgn | 3eaf67e | 2016-07-26 09:01:12 | [diff] [blame] | 64 | // See |browser_shutdown::Flags| for the possible flag values and their effects. |
| 65 | void ShutdownPostThreadsStop(int shutdown_flags); |
thestig | af58280d | 2015-10-02 18:56:45 | [diff] [blame] | 66 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 67 | |
| 68 | // Called at startup to create a histogram from our previous shutdown time. |
| 69 | void ReadLastShutdownInfo(); |
| 70 | |
[email protected] | c984d9f | 2010-07-20 20:52:20 | [diff] [blame] | 71 | // 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] | 7dc8c6b | 2010-04-09 17:02:50 | [diff] [blame] | 80 | |
[email protected] | c984d9f | 2010-07-20 20:52:20 | [diff] [blame] | 81 | // 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] | 7dc8c6b | 2010-04-09 17:02:50 | [diff] [blame] | 87 | void SetTryingToQuit(bool quitting); |
| 88 | |
| 89 | // General accessor. |
| 90 | bool IsTryingToQuit(); |
[email protected] | 7dc8c6b | 2010-04-09 17:02:50 | [diff] [blame] | 91 | |
thestig | 02897869 | 2015-10-08 07:39:40 | [diff] [blame] | 92 | // 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. |
| 95 | void StartShutdownTracing(); |
| 96 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 97 | } // namespace browser_shutdown |
| 98 | |
thestig | 02897869 | 2015-10-08 07:39:40 | [diff] [blame] | 99 | #endif // CHROME_BROWSER_BROWSER_SHUTDOWN_H_ |