| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_LIFETIME_APPLICATION_LIFETIME_H_ | 5 #ifndef CHROME_BROWSER_LIFETIME_APPLICATION_LIFETIME_DESKTOP_H_ |
| 6 #define CHROME_BROWSER_LIFETIME_APPLICATION_LIFETIME_H_ | 6 #define CHROME_BROWSER_LIFETIME_APPLICATION_LIFETIME_DESKTOP_H_ |
| 7 | 7 |
| 8 #include "base/compiler_specific.h" | 8 #include "base/basictypes.h" |
| 9 |
| 10 #if defined(OS_ANDROID) || defined(OS_IOS) |
| 11 #error Not used on mobile |
| 12 #endif |
| 9 | 13 |
| 10 class Browser; | 14 class Browser; |
| 11 | 15 |
| 12 namespace chrome { | 16 namespace chrome { |
| 13 | 17 |
| 14 // Starts a user initiated exit process. Called from Browser::Exit. | 18 // Starts a user initiated exit process. Called from Browser::Exit. |
| 15 // On platforms other than ChromeOS, this is equivalent to | 19 // On platforms other than ChromeOS, this is equivalent to |
| 16 // CloseAllBrowsers() On ChromeOS, this tells session manager | 20 // CloseAllBrowsers() On ChromeOS, this tells session manager |
| 17 // that chrome is signing out, which lets session manager send | 21 // that chrome is signing out, which lets session manager send |
| 18 // SIGTERM to start actual exit process. | 22 // SIGTERM to start actual exit process. |
| 19 void AttemptUserExit(); | 23 void AttemptUserExit(); |
| 20 | 24 |
| 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 | |
| 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 | |
| 33 #if defined(OS_WIN) | |
| 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); | |
| 43 | |
| 44 // Windows 7/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 AttemptRestartToDesktopMode(); | |
| 48 // Launches Chrome into Windows 8 metro mode on Windows 8. On Windows 7 it | |
| 49 // launches Chrome into Windows ASH. | |
| 50 void AttemptRestartToMetroMode(); | |
| 51 #endif | |
| 52 | |
| 53 // Attempt to exit by closing all browsers. This is equivalent to | |
| 54 // CloseAllBrowsers() on platforms where the application exits | |
| 55 // when no more windows are remaining. On other platforms (the Mac), | |
| 56 // this will additionally exit the application if all browsers are | |
| 57 // successfully closed. | |
| 58 // Note that he exit process may be interrupted by download or | |
| 59 // unload handler, and the browser may or may not exit. | |
| 60 void AttemptExit(); | |
| 61 | |
| 62 #if defined(OS_CHROMEOS) | |
| 63 // Shutdown chrome cleanly without blocking. This is called | |
| 64 // when SIGTERM is received on Chrome OS, and always sets | |
| 65 // exit-cleanly bit and exits the browser, even if there is | |
| 66 // ongoing downloads or a page with onbeforeunload handler. | |
| 67 // | |
| 68 // If you need to exit or restart in your code on ChromeOS, | |
| 69 // use AttemptExit or AttemptRestart respectively. | |
| 70 void ExitCleanly(); | |
| 71 #endif | |
| 72 | |
| 73 // Closes all browsers and if successful, quits. | 25 // Closes all browsers and if successful, quits. |
| 74 void CloseAllBrowsersAndQuit(); | 26 void CloseAllBrowsersAndQuit(); |
| 75 | 27 |
| 76 // Closes all browsers. If the session is ending the windows are closed | 28 // Closes all browsers. If the session is ending the windows are closed |
| 77 // directly. Otherwise the windows are closed by way of posting a WM_CLOSE | 29 // directly. Otherwise the windows are closed by way of posting a WM_CLOSE |
| 78 // message. This will quit the application if there is nothing other than | 30 // message. This will quit the application if there is nothing other than |
| 79 // browser windows keeping it alive or the application is quitting. | 31 // browser windows keeping it alive or the application is quitting. |
| 80 void CloseAllBrowsers(); | 32 void CloseAllBrowsers(); |
| 81 | 33 |
| 82 // Begins shutdown of the application when the desktop session is ending. | |
| 83 void SessionEnding(); | |
| 84 | |
| 85 // Tells the BrowserList to keep the application alive after the last Browser | 34 // Tells the BrowserList to keep the application alive after the last Browser |
| 86 // closes. This is implemented as a count, so callers should pair their calls | 35 // closes. This is implemented as a count, so callers should pair their calls |
| 87 // to IncrementKeepAliveCount() with matching calls to DecrementKeepAliveCount() | 36 // to IncrementKeepAliveCount() with matching calls to DecrementKeepAliveCount() |
| 88 // when they no | 37 // when they no |
| 89 // longer need to keep the application running. | 38 // longer need to keep the application running. |
| 90 void IncrementKeepAliveCount(); | 39 void IncrementKeepAliveCount(); |
| 91 | 40 |
| 92 // Stops keeping the application alive after the last Browser is closed. | 41 // Stops keeping the application alive after the last Browser is closed. |
| 93 // Should match a previous call to IncrementKeepAliveCount(). | 42 // Should match a previous call to IncrementKeepAliveCount(). |
| 94 void DecrementKeepAliveCount(); | 43 void DecrementKeepAliveCount(); |
| 95 | 44 |
| 96 // Returns true if application will continue running after the last Browser | 45 // Returns true if application will continue running after the last Browser |
| 97 // closes. | 46 // closes. |
| 98 bool WillKeepAlive(); | 47 bool WillKeepAlive(); |
| 99 | 48 |
| 100 // Emits APP_TERMINATING notification. It is guaranteed that the | |
| 101 // notification is sent only once. | |
| 102 void NotifyAppTerminating(); | |
| 103 | |
| 104 // Send out notifications. | |
| 105 // For ChromeOS, also request session manager to end the session. | |
| 106 void NotifyAndTerminate(bool fast_path); | |
| 107 | |
| 108 // Called once the application is exiting. | |
| 109 void OnAppExiting(); | |
| 110 | |
| 111 // Called once the application is exiting to do any platform specific | 49 // Called once the application is exiting to do any platform specific |
| 112 // processing required. | 50 // processing required. |
| 113 void HandleAppExitingForPlatform(); | 51 void HandleAppExitingForPlatform(); |
| 114 | 52 |
| 115 // Returns true if we can start the shutdown sequence for the browser, i.e. the | 53 // Returns true if we can start the shutdown sequence for the browser, i.e. the |
| 116 // last browser window is being closed. | 54 // last browser window is being closed. |
| 117 bool ShouldStartShutdown(Browser* browser); | 55 bool ShouldStartShutdown(Browser* browser); |
| 118 | 56 |
| 119 // Disable browser shutdown for unit tests. | 57 // Disable browser shutdown for unit tests. |
| 120 void DisableShutdownForTesting(bool disable_shutdown_for_testing); | 58 void DisableShutdownForTesting(bool disable_shutdown_for_testing); |
| 121 | 59 |
| 60 #if defined(OS_CHROMEOS) |
| 61 // Shutdown chrome cleanly without blocking. This is called |
| 62 // when SIGTERM is received on Chrome OS, and always sets |
| 63 // exit-cleanly bit and exits the browser, even if there is |
| 64 // ongoing downloads or a page with onbeforeunload handler. |
| 65 // |
| 66 // If you need to exit or restart in your code on ChromeOS, |
| 67 // use AttemptExit or AttemptRestart respectively. |
| 68 void ExitCleanly(); |
| 69 #endif |
| 70 |
| 71 #if defined(OS_WIN) |
| 72 enum AshExecutionStatus { |
| 73 ASH_KEEP_RUNNING, |
| 74 ASH_TERMINATE, |
| 75 }; |
| 76 |
| 77 // Helper function to activate the desktop from Ash mode. The |
| 78 // |ash_execution_status| parameter indicates if we should exit Ash after |
| 79 // activating desktop. |
| 80 void ActivateDesktopHelper(AshExecutionStatus ash_execution_status); |
| 81 |
| 82 // Windows 7/8 specific: Like AttemptRestart but if chrome is running |
| 83 // in desktop mode it starts in metro mode and vice-versa. The switching like |
| 84 // the restarting is controlled by a preference. |
| 85 void AttemptRestartToDesktopMode(); |
| 86 // Launches Chrome into Windows 8 metro mode on Windows 8. On Windows 7 it |
| 87 // launches Chrome into Windows ASH. |
| 88 void AttemptRestartToMetroMode(); |
| 89 #endif |
| 90 |
| 122 } // namespace chrome | 91 } // namespace chrome |
| 123 | 92 |
| 124 #endif // CHROME_BROWSER_LIFETIME_APPLICATION_LIFETIME_H_ | 93 #endif // CHROME_BROWSER_LIFETIME_APPLICATION_LIFETIME_DESKTOP_H_ |
| OLD | NEW |