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_ 7 8 #include "base/compiler_specific.h" 9 10 class Browser; 11 12 namespace chrome { 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 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 AttemptRestartWithModeSwitch(); 48 void AttemptRestartToDesktopMode(); 49 // Launches Chrome into Windows 8 metro mode on Windows 8. On Windows 7 it 50 // launches Chrome into Windows ASH. 51 void AttemptRestartToMetroMode(); 52 #endif 53 54 // Attempt to exit by closing all browsers. This is equivalent to 55 // CloseAllBrowsers() on platforms where the application exits 56 // when no more windows are remaining. On other platforms (the Mac), 57 // this will additionally exit the application if all browsers are 58 // successfully closed. 59 // Note that he exit process may be interrupted by download or 60 // unload handler, and the browser may or may not exit. 61 void AttemptExit(); 62 63 #if defined(OS_CHROMEOS) 64 // Shutdown chrome cleanly without blocking. This is called 65 // when SIGTERM is received on Chrome OS, and always sets 66 // exit-cleanly bit and exits the browser, even if there is 67 // ongoing downloads or a page with onbeforeunload handler. 68 // 69 // If you need to exit or restart in your code on ChromeOS, 70 // use AttemptExit or AttemptRestart respectively. 71 void ExitCleanly(); 72 #endif 73 74 // Closes all browsers and if successful, quits. 75 void CloseAllBrowsersAndQuit(); 76 77 // Closes all browsers. If the session is ending the windows are closed 78 // directly. Otherwise the windows are closed by way of posting a WM_CLOSE 79 // message. This will quit the application if there is nothing other than 80 // browser windows keeping it alive or the application is quitting. 81 void CloseAllBrowsers(); 82 83 // Begins shutdown of the application when the desktop session is ending. 84 void SessionEnding(); 85 86 // Tells the BrowserList to keep the application alive after the last Browser 87 // closes. This is implemented as a count, so callers should pair their calls 88 // to IncrementKeepAliveCount() with matching calls to DecrementKeepAliveCount() 89 // when they no 90 // longer need to keep the application running. 91 void IncrementKeepAliveCount(); 92 93 // Stops keeping the application alive after the last Browser is closed. 94 // Should match a previous call to IncrementKeepAliveCount(). 95 void DecrementKeepAliveCount(); 96 97 // Returns true if application will continue running after the last Browser 98 // closes. 99 bool WillKeepAlive(); 100 101 // Emits APP_TERMINATING notification. It is guaranteed that the 102 // notification is sent only once. 103 void NotifyAppTerminating(); 104 105 // Send out notifications. 106 // For ChromeOS, also request session manager to end the session. 107 void NotifyAndTerminate(bool fast_path); 108 109 // Called once the application is exiting. 110 void OnAppExiting(); 111 112 // Called once the application is exiting to do any platform specific 113 // processing required. 114 void HandleAppExitingForPlatform(); 115 116 // Returns true if we can start the shutdown sequence for the browser, i.e. the 117 // last browser window is being closed. 118 bool ShouldStartShutdown(Browser* browser); 119 120 } // namespace chrome 121 122 #endif // CHROME_BROWSER_LIFETIME_APPLICATION_LIFETIME_H_ 123