[email protected] | 2e6389f | 2012-05-18 19:41:25 | [diff] [blame] | 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 | #ifndef CHROME_BROWSER_LIFETIME_APPLICATION_LIFETIME_H_ |
| 6 | #define CHROME_BROWSER_LIFETIME_APPLICATION_LIFETIME_H_ |
[email protected] | 2e6389f | 2012-05-18 19:41:25 | [diff] [blame] | 7 | |
[email protected] | b9503276a | 2013-12-05 21:44:34 | [diff] [blame] | 8 | #include "base/compiler_specific.h" |
| 9 | |
[email protected] | 3c9185a2 | 2013-04-18 21:12:53 | [diff] [blame] | 10 | class Browser; |
| 11 | |
[email protected] | 0c98ab65 | 2013-02-18 00:39:37 | [diff] [blame] | 12 | namespace chrome { |
[email protected] | 2e6389f | 2012-05-18 19:41:25 | [diff] [blame] | 13 | |
| 14 | // Starts a user initiated exit process. Called from Browser::Exit. |
| 15 | // On platforms other than ChromeOS, this is equivalent to |
| 16 | // CloseAllBrowsers() On ChromeOS, this tells session manager |
| 17 | // that chrome is signing out, which lets session manager send |
| 18 | // SIGTERM to start actual exit process. |
| 19 | void AttemptUserExit(); |
| 20 | |
[email protected] | 89af400 | 2013-09-06 07:47:07 | [diff] [blame] | 21 | // Starts to collect shutdown traces. On ChromeOS this will start immediately |
| 22 | // on AttemptUserExit() and all other systems will start once all tabs are |
| 23 | // closed. |
| 24 | void StartShutdownTracing(); |
| 25 | |
[email protected] | 2e6389f | 2012-05-18 19:41:25 | [diff] [blame] | 26 | // Starts a user initiated restart process. On platforms other than |
| 27 | // chromeos, this sets a restart bit in the preference so that |
| 28 | // chrome will be restarted at the end of shutdown process. On |
| 29 | // ChromeOS, this simply exits the chrome, which lets sesssion |
| 30 | // manager re-launch the browser with restore last session flag. |
| 31 | void AttemptRestart(); |
| 32 | |
[email protected] | 8185255 | 2012-09-07 21:39:29 | [diff] [blame] | 33 | #if defined(OS_WIN) |
[email protected] | b9503276a | 2013-12-05 21:44:34 | [diff] [blame] | 34 | enum AshExecutionStatus { |
| 35 | ASH_KEEP_RUNNING, |
| 36 | ASH_TERMINATE, |
| 37 | }; |
| 38 | |
| 39 | // Helper function to activate the desktop from Ash mode. The |
| 40 | // |ash_execution_status| parameter indicates if we should exit Ash after |
| 41 | // activating desktop. |
| 42 | void ActivateDesktopHelper(AshExecutionStatus ash_execution_status); |
[email protected] | 8393c30 | 2013-12-13 20:21:24 | [diff] [blame] | 43 | |
| 44 | // Windows 8 specific: Like AttemptRestart but if chrome is running |
| 45 | // in desktop mode it starts in metro mode and vice-versa. The switching like |
| 46 | // the restarting is controlled by a preference. |
| 47 | void AttemptRestartWithModeSwitch(); |
| 48 | void AttemptRestartToDesktopMode(); |
| 49 | void AttemptRestartToMetroMode(); |
[email protected] | 8185255 | 2012-09-07 21:39:29 | [diff] [blame] | 50 | #endif |
| 51 | |
[email protected] | 2e6389f | 2012-05-18 19:41:25 | [diff] [blame] | 52 | // Attempt to exit by closing all browsers. This is equivalent to |
| 53 | // CloseAllBrowsers() on platforms where the application exits |
| 54 | // when no more windows are remaining. On other platforms (the Mac), |
| 55 | // this will additionally exit the application if all browsers are |
| 56 | // successfully closed. |
| 57 | // Note that he exit process may be interrupted by download or |
| 58 | // unload handler, and the browser may or may not exit. |
| 59 | void AttemptExit(); |
| 60 | |
| 61 | #if defined(OS_CHROMEOS) |
| 62 | // This is equivalent to AttemptUserExit, except that it always set |
| 63 | // exit cleanly bit. ChromeOS checks if it can exit without user |
| 64 | // interactions, so it will always exit the browser. This is used to |
| 65 | // handle SIGTERM on chromeos which is a signal to force shutdown |
| 66 | // the chrome. |
| 67 | void ExitCleanly(); |
| 68 | #endif |
| 69 | |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 70 | // Closes all browsers and if successful, quits. |
| 71 | void CloseAllBrowsersAndQuit(); |
| 72 | |
[email protected] | 2e6389f | 2012-05-18 19:41:25 | [diff] [blame] | 73 | // Closes all browsers. If the session is ending the windows are closed |
| 74 | // directly. Otherwise the windows are closed by way of posting a WM_CLOSE |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 75 | // message. This will quit the application if there is nothing other than |
| 76 | // browser windows keeping it alive or the application is quitting. |
[email protected] | 2e6389f | 2012-05-18 19:41:25 | [diff] [blame] | 77 | void CloseAllBrowsers(); |
| 78 | |
| 79 | // Begins shutdown of the application when the desktop session is ending. |
| 80 | void SessionEnding(); |
| 81 | |
| 82 | // Tells the BrowserList to keep the application alive after the last Browser |
| 83 | // closes. This is implemented as a count, so callers should pair their calls |
| 84 | // to StartKeepAlive() with matching calls to EndKeepAlive() when they no |
| 85 | // longer need to keep the application running. |
| 86 | void StartKeepAlive(); |
| 87 | |
| 88 | // Stops keeping the application alive after the last Browser is closed. |
| 89 | // Should match a previous call to StartKeepAlive(). |
| 90 | void EndKeepAlive(); |
| 91 | |
| 92 | // Returns true if application will continue running after the last Browser |
| 93 | // closes. |
| 94 | bool WillKeepAlive(); |
| 95 | |
| 96 | // Emits APP_TERMINATING notification. It is guaranteed that the |
| 97 | // notification is sent only once. |
| 98 | void NotifyAppTerminating(); |
| 99 | |
| 100 | // Send out notifications. |
| 101 | // For ChromeOS, also request session manager to end the session. |
| 102 | void NotifyAndTerminate(bool fast_path); |
| 103 | |
| 104 | // Called once the application is exiting. |
| 105 | void OnAppExiting(); |
| 106 | |
| 107 | // Called once the application is exiting to do any platform specific |
| 108 | // processing required. |
| 109 | void HandleAppExitingForPlatform(); |
| 110 | |
[email protected] | 3c9185a2 | 2013-04-18 21:12:53 | [diff] [blame] | 111 | // Returns true if we can start the shutdown sequence for the browser, i.e. the |
| 112 | // last browser window is being closed. |
| 113 | bool ShouldStartShutdown(Browser* browser); |
| 114 | |
[email protected] | 313fce1 | 2013-01-30 17:09:04 | [diff] [blame] | 115 | } // namespace chrome |
[email protected] | 2e6389f | 2012-05-18 19:41:25 | [diff] [blame] | 116 | |
| 117 | #endif // CHROME_BROWSER_LIFETIME_APPLICATION_LIFETIME_H_ |