Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5859)

Unified Diff: chrome/browser/lifetime/application_lifetime.h

Issue 10409022: Move application lifetime functionality off BrowserList. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/lifetime/application_lifetime.h
===================================================================
--- chrome/browser/lifetime/application_lifetime.h (revision 0)
+++ chrome/browser/lifetime/application_lifetime.h (working copy)
@@ -2,243 +2,81 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_UI_BROWSER_LIST_H_
-#define CHROME_BROWSER_UI_BROWSER_LIST_H_
+#ifndef CHROME_BROWSER_LIFETIME_APPLICATION_LIFETIME_H_
+#define CHROME_BROWSER_LIFETIME_APPLICATION_LIFETIME_H_
#pragma once
-#include <set>
-#include <vector>
+namespace browser {
-#include "base/observer_list.h"
-#include "ui/gfx/native_widget_types.h"
+// Starts a user initiated exit process. Called from Browser::Exit.
+// On platforms other than ChromeOS, this is equivalent to
+// CloseAllBrowsers() On ChromeOS, this tells session manager
+// that chrome is signing out, which lets session manager send
+// SIGTERM to start actual exit process.
+void AttemptUserExit();
-class Browser;
-class Profile;
+// Starts a user initiated restart process. On platforms other than
+// chromeos, this sets a restart bit in the preference so that
+// chrome will be restarted at the end of shutdown process. On
+// ChromeOS, this simply exits the chrome, which lets sesssion
+// manager re-launch the browser with restore last session flag.
+void AttemptRestart();
-// Stores a list of all Browser objects.
-class BrowserList {
- public:
- typedef std::vector<Browser*> BrowserVector;
- typedef BrowserVector::iterator iterator;
- typedef BrowserVector::const_iterator const_iterator;
- typedef BrowserVector::const_reverse_iterator const_reverse_iterator;
+// Attempt to exit by closing all browsers. This is equivalent to
+// CloseAllBrowsers() on platforms where the application exits
+// when no more windows are remaining. On other platforms (the Mac),
+// this will additionally exit the application if all browsers are
+// successfully closed.
+// Note that he exit process may be interrupted by download or
+// unload handler, and the browser may or may not exit.
+void AttemptExit();
- // It is not allowed to change the global window list (add or remove any
- // browser windows while handling observer callbacks.
- class Observer {
- public:
- // Called immediately after a browser is added to the list
- virtual void OnBrowserAdded(const Browser* browser) = 0;
-
- // Called immediately after a browser is removed from the list
- virtual void OnBrowserRemoved(const Browser* browser) = 0;
-
- // Called immediately after a browser is set active (SetLastActive)
- virtual void OnBrowserSetLastActive(const Browser* browser) {}
-
- protected:
- virtual ~Observer() {}
- };
-
- // Adds and removes browsers from the global list. The browser object should
- // be valid BEFORE these calls (for the benefit of observers), so notify and
- // THEN delete the object.
- static void AddBrowser(Browser* browser);
- static void RemoveBrowser(Browser* browser);
-
- static void AddObserver(Observer* observer);
- static void RemoveObserver(Observer* observer);
-
- // Called by Browser objects when their window is activated (focused). This
- // allows us to determine what the last active Browser was.
- static void SetLastActive(Browser* browser);
-
- // Returns the Browser object whose window was most recently active. If the
- // most recently open Browser's window was closed, returns the first Browser
- // in the list. If no Browsers exist, returns NULL.
- //
- // WARNING: this is NULL until a browser becomes active. If during startup
- // a browser does not become active (perhaps the user launches Chrome, then
- // clicks on another app before the first browser window appears) then this
- // returns NULL.
- // WARNING #2: this will always be NULL in unit tests run on the bots.
- static Browser* GetLastActive();
-
- // Checks if the browser can be automatically restarted to install upgrades
- // The browser can be automatically restarted when:
- // 1. It's in the background mode (no visible windows).
- // 2. An update exe is present in the install folder.
- static bool CanRestartForUpdate();
-
- // Starts a user initiated exit process. Called from Browser::Exit.
- // On platforms other than ChromeOS, this is equivalent to
- // CloseAllBrowsers() On ChromeOS, this tells session manager
- // that chrome is signing out, which lets session manager send
- // SIGTERM to start actual exit process.
- static void AttemptUserExit();
-
- // Starts a user initiated restart process. On platforms other than
- // chromeos, this sets a restart bit in the preference so that
- // chrome will be restarted at the end of shutdown process. On
- // ChromeOS, this simply exits the chrome, which lets sesssion
- // manager re-launch the browser with restore last session flag.
- static void AttemptRestart();
-
- // Attempt to exit by closing all browsers. This is equivalent to
- // CloseAllBrowsers() on platforms where the application exits
- // when no more windows are remaining. On other platforms (the Mac),
- // this will additionally exit the application if all browsers are
- // successfully closed.
- // Note that he exit process may be interrupted by download or
- // unload handler, and the browser may or may not exit.
- static void AttemptExit();
-
#if defined(OS_CHROMEOS)
- // This is equivalent to AttemptUserExit, except that it always set
- // exit cleanly bit. ChromeOS checks if it can exit without user
- // interactions, so it will always exit the browser. This is used to
- // handle SIGTERM on chromeos which is a signal to force shutdown
- // the chrome.
- static void ExitCleanly();
+// This is equivalent to AttemptUserExit, except that it always set
+// exit cleanly bit. ChromeOS checks if it can exit without user
+// interactions, so it will always exit the browser. This is used to
+// handle SIGTERM on chromeos which is a signal to force shutdown
+// the chrome.
+void ExitCleanly();
#endif
- // Closes all browsers. If the session is ending the windows are closed
- // directly. Otherwise the windows are closed by way of posting a WM_CLOSE
- // message.
- static void CloseAllBrowsers();
+// Closes all browsers. If the session is ending the windows are closed
+// directly. Otherwise the windows are closed by way of posting a WM_CLOSE
+// message.
+void CloseAllBrowsers();
- // Closes all browsers for |profile|.
- static void CloseAllBrowsersWithProfile(Profile* profile);
+// Begins shutdown of the application when the desktop session is ending.
+void SessionEnding();
- // Begins shutdown of the application when the desktop session is ending.
- static void SessionEnding();
+// Tells the BrowserList to keep the application alive after the last Browser
+// closes. This is implemented as a count, so callers should pair their calls
+// to StartKeepAlive() with matching calls to EndKeepAlive() when they no
+// longer need to keep the application running.
+void StartKeepAlive();
- // Tells the BrowserList to keep the application alive after the last Browser
- // closes. This is implemented as a count, so callers should pair their calls
- // to StartKeepAlive() with matching calls to EndKeepAlive() when they no
- // longer need to keep the application running.
- static void StartKeepAlive();
+// Stops keeping the application alive after the last Browser is closed.
+// Should match a previous call to StartKeepAlive().
+void EndKeepAlive();
- // Stops keeping the application alive after the last Browser is closed.
- // Should match a previous call to StartKeepAlive().
- static void EndKeepAlive();
+// Returns true if application will continue running after the last Browser
+// closes.
+bool WillKeepAlive();
- // Returns true if application will continue running after the last Browser
- // closes.
- static bool WillKeepAlive();
+// Emits APP_TERMINATING notification. It is guaranteed that the
+// notification is sent only once.
+void NotifyAppTerminating();
- // Browsers are added to the list before they have constructed windows,
- // so the |window()| member function may return NULL.
- static const_iterator begin();
- static const_iterator end();
+// Send out notifications.
+// For ChromeOS, also request session manager to end the session.
+void NotifyAndTerminate(bool fast_path);
- static bool empty();
- static size_t size();
+// Called once the application is exiting.
+void OnAppExiting();
- // Returns iterated access to list of open browsers ordered by when
- // they were last active. The underlying data structure is a vector
- // and we push_back on recent access so a reverse iterator gives the
- // latest accessed browser first.
- static const_reverse_iterator begin_last_active();
- static const_reverse_iterator end_last_active();
+// Called once the application is exiting to do any platform specific
+// processing required.
+void HandleAppExitingForPlatform();
- // Returns true if at least one incognito session is active.
- static bool IsOffTheRecordSessionActive();
+} // namespace browser
- // Returns true if at least one incognito session is active for |profile|.
- static bool IsOffTheRecordSessionActiveForProfile(Profile* profile);
-
- // Send out notifications.
- // For ChromeOS, also request session manager to end the session.
- static void NotifyAndTerminate(bool fast_path);
-
- // Called once the application is exiting.
- static void OnAppExiting();
-
- // Called once the application is exiting to do any platform specific
- // processing required.
- static void HandleAppExitingForPlatform();
-
- private:
- // Helper method to remove a browser instance from a list of browsers
- static void RemoveBrowserFrom(Browser* browser, BrowserVector* browser_list);
- static void MarkAsCleanShutdown();
- static void AttemptExitInternal();
-
- // Counter of calls to StartKeepAlive(). If non-zero, the application will
- // continue running after the last browser has exited.
- static int keep_alive_count_;
-};
-
-class TabContentsWrapper;
-
-// Iterates through all web view hosts in all browser windows. Because the
-// renderers act asynchronously, getting a host through this interface does
-// not guarantee that the renderer is ready to go. Doing anything to affect
-// browser windows or tabs while iterating may cause incorrect behavior.
-//
-// Example:
-// for (TabContentsIterator iterator; !iterator.done(); ++iterator) {
-// TabContentsWrapper* cur = *iterator;
-// -or-
-// iterator->operationOnTabContents();
-// ...
-// }
-class TabContentsIterator {
- public:
- TabContentsIterator();
-
- // Returns true if we are past the last Browser.
- bool done() const {
- return cur_ == NULL;
- }
-
- // Returns the Browser instance associated with the current
- // TabContentsWrapper. Valid as long as !done()
- Browser* browser() const {
- if (browser_iterator_ != BrowserList::end())
- return *browser_iterator_;
- return NULL;
- }
-
- // Returns the current TabContentsWrapper, valid as long as !Done()
- TabContentsWrapper* operator->() const {
- return cur_;
- }
- TabContentsWrapper* operator*() const {
- return cur_;
- }
-
- // Incrementing operators, valid as long as !Done()
- TabContentsWrapper* operator++() { // ++preincrement
- Advance();
- return cur_;
- }
- TabContentsWrapper* operator++(int) { // postincrement++
- TabContentsWrapper* tmp = cur_;
- Advance();
- return tmp;
- }
-
- private:
- // Loads the next host into Cur. This is designed so that for the initial
- // call when browser_iterator_ points to the first browser and
- // web_view_index_ is -1, it will fill the first host.
- void Advance();
-
- // iterator over all the Browser objects
- BrowserList::const_iterator browser_iterator_;
-
- // tab index into the current Browser of the current web view
- int web_view_index_;
-
- // iterator over the TabContentsWrappers doing background printing.
- std::set<TabContentsWrapper*>::const_iterator bg_printing_iterator_;
-
- // Current TabContentsWrapper, or NULL if we're at the end of the list. This
- // can be extracted given the browser iterator and index, but it's nice to
- // cache this since the caller may access the current host many times.
- TabContentsWrapper* cur_;
-};
-
-#endif // CHROME_BROWSER_UI_BROWSER_LIST_H_
+#endif // CHROME_BROWSER_LIFETIME_APPLICATION_LIFETIME_H_
« no previous file with comments | « chrome/browser/chromeos/system/ash_system_tray_delegate.cc ('k') | chrome/browser/lifetime/application_lifetime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698