OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_BROWSER_LIST_H_ | 5 #ifndef CHROME_BROWSER_BROWSER_LIST_H_ |
6 #define CHROME_BROWSER_BROWSER_LIST_H_ | 6 #define CHROME_BROWSER_BROWSER_LIST_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 // more windows are remaining. On other platforms (the Mac), this will | 106 // more windows are remaining. On other platforms (the Mac), this will |
107 // additionally exit the application. | 107 // additionally exit the application. |
108 static void CloseAllBrowsersAndExit(); | 108 static void CloseAllBrowsersAndExit(); |
109 | 109 |
110 // Begins shutdown of the application when the Windows session is ending. | 110 // Begins shutdown of the application when the Windows session is ending. |
111 static void WindowsSessionEnding(); | 111 static void WindowsSessionEnding(); |
112 | 112 |
113 // Returns true if there is at least one Browser with the specified profile. | 113 // Returns true if there is at least one Browser with the specified profile. |
114 static bool HasBrowserWithProfile(Profile* profile); | 114 static bool HasBrowserWithProfile(Profile* profile); |
115 | 115 |
116 // Returns true if browser is in persistent mode and false otherwise. | 116 // Tells the BrowserList to keep the application alive after the last Browser |
117 static bool IsInPersistentMode(); | 117 // closes. This is implemented as a count, so callers should pair their calls |
| 118 // to StartKeepAlive() with matching calls to EndKeepAlive() when they no |
| 119 // longer need to keep the application running. |
| 120 static void StartKeepAlive(); |
| 121 |
| 122 // Stops keeping the application alive after the last Browser is closed. |
| 123 // Should match a previous call to StartKeepAlive(). |
| 124 static void EndKeepAlive(); |
| 125 |
| 126 // Returns true if application will continue running after the last Browser |
| 127 // closes. |
| 128 static bool WillKeepAlive(); |
118 | 129 |
119 static const_iterator begin() { return browsers_.begin(); } | 130 static const_iterator begin() { return browsers_.begin(); } |
120 static const_iterator end() { return browsers_.end(); } | 131 static const_iterator end() { return browsers_.end(); } |
121 | 132 |
122 static size_t size() { return browsers_.size(); } | 133 static size_t size() { return browsers_.size(); } |
123 | 134 |
124 // Returns iterated access to list of open browsers ordered by when | 135 // Returns iterated access to list of open browsers ordered by when |
125 // they were last active. The underlying data structure is a vector | 136 // they were last active. The underlying data structure is a vector |
126 // and we push_back on recent access so a reverse iterator gives the | 137 // and we push_back on recent access so a reverse iterator gives the |
127 // latest accessed browser first. | 138 // latest accessed browser first. |
128 static const_reverse_iterator begin_last_active() { | 139 static const_reverse_iterator begin_last_active() { |
129 return last_active_browsers_.rbegin(); | 140 return last_active_browsers_.rbegin(); |
130 } | 141 } |
131 | 142 |
132 static const_reverse_iterator end_last_active() { | 143 static const_reverse_iterator end_last_active() { |
133 return last_active_browsers_.rend(); | 144 return last_active_browsers_.rend(); |
134 } | 145 } |
135 | 146 |
136 // Return the number of browsers with the following profile which are | 147 // Return the number of browsers with the following profile which are |
137 // currently open. | 148 // currently open. |
138 static size_t GetBrowserCount(Profile* p); | 149 static size_t GetBrowserCount(Profile* p); |
139 | 150 |
140 // Return the number of browsers with the following profile and type which are | 151 // Return the number of browsers with the following profile and type which are |
141 // currently open. | 152 // currently open. |
142 static size_t GetBrowserCountForType(Profile* p, Browser::Type type); | 153 static size_t GetBrowserCountForType(Profile* p, Browser::Type type); |
143 | 154 |
144 // Returns true if at least one off the record session is active. | 155 // Returns true if at least one off the record session is active. |
145 static bool IsOffTheRecordSessionActive(); | 156 static bool IsOffTheRecordSessionActive(); |
146 | 157 |
147 // Called when the last browser is closed. | 158 // Called once there are no more browsers open and the application is exiting. |
148 static void AllBrowsersClosed(); | 159 static void AllBrowsersClosedAndAppExiting(); |
149 | 160 |
150 private: | 161 private: |
151 // Helper method to remove a browser instance from a list of browsers | 162 // Helper method to remove a browser instance from a list of browsers |
152 static void RemoveBrowserFrom(Browser* browser, BrowserVector* browser_list); | 163 static void RemoveBrowserFrom(Browser* browser, BrowserVector* browser_list); |
153 | 164 |
154 static BrowserVector browsers_; | 165 static BrowserVector browsers_; |
155 static BrowserVector last_active_browsers_; | 166 static BrowserVector last_active_browsers_; |
156 static ObserverList<Observer> observers_; | 167 static ObserverList<Observer> observers_; |
| 168 |
| 169 // Counter of calls to StartKeepAlive(). If non-zero, the application will |
| 170 // continue running after the last browser has exited. |
| 171 static int keep_alive_count_; |
157 }; | 172 }; |
158 | 173 |
159 class TabContents; | 174 class TabContents; |
160 | 175 |
161 // Iterates through all web view hosts in all browser windows. Because the | 176 // Iterates through all web view hosts in all browser windows. Because the |
162 // renderers act asynchronously, getting a host through this interface does | 177 // renderers act asynchronously, getting a host through this interface does |
163 // not guarantee that the renderer is ready to go. Doing anything to affect | 178 // not guarantee that the renderer is ready to go. Doing anything to affect |
164 // browser windows or tabs while iterating may cause incorrect behavior. | 179 // browser windows or tabs while iterating may cause incorrect behavior. |
165 // | 180 // |
166 // Example: | 181 // Example: |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 // tab index into the current Browser of the current web view | 225 // tab index into the current Browser of the current web view |
211 int web_view_index_; | 226 int web_view_index_; |
212 | 227 |
213 // Current TabContents, or NULL if we're at the end of the list. This can | 228 // Current TabContents, or NULL if we're at the end of the list. This can |
214 // be extracted given the browser iterator and index, but it's nice to cache | 229 // be extracted given the browser iterator and index, but it's nice to cache |
215 // this since the caller may access the current host many times. | 230 // this since the caller may access the current host many times. |
216 TabContents* cur_; | 231 TabContents* cur_; |
217 }; | 232 }; |
218 | 233 |
219 #endif // CHROME_BROWSER_BROWSER_LIST_H_ | 234 #endif // CHROME_BROWSER_BROWSER_LIST_H_ |
OLD | NEW |