| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_UI_BROWSER_LIST_H_ | 5 #ifndef CHROME_BROWSER_UI_BROWSER_LIST_H_ |
| 6 #define CHROME_BROWSER_UI_BROWSER_LIST_H_ | 6 #define CHROME_BROWSER_UI_BROWSER_LIST_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
| 13 #include "chrome/browser/ui/browser.h" | |
| 14 #include "ui/gfx/native_widget_types.h" | 13 #include "ui/gfx/native_widget_types.h" |
| 15 | 14 |
| 15 class Browser; |
| 16 class Profile; |
| 17 |
| 16 // Stores a list of all Browser objects. | 18 // Stores a list of all Browser objects. |
| 17 class BrowserList { | 19 class BrowserList { |
| 18 public: | 20 public: |
| 19 typedef std::vector<Browser*> BrowserVector; | 21 typedef std::vector<Browser*> BrowserVector; |
| 20 typedef BrowserVector::iterator iterator; | 22 typedef BrowserVector::iterator iterator; |
| 21 typedef BrowserVector::const_iterator const_iterator; | 23 typedef BrowserVector::const_iterator const_iterator; |
| 22 typedef BrowserVector::const_reverse_iterator const_reverse_iterator; | 24 typedef BrowserVector::const_reverse_iterator const_reverse_iterator; |
| 23 | 25 |
| 24 // It is not allowed to change the global window list (add or remove any | 26 // It is not allowed to change the global window list (add or remove any |
| 25 // browser windows while handling observer callbacks. | 27 // browser windows while handling observer callbacks. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 55 // most recently open Browser's window was closed, returns the first Browser | 57 // most recently open Browser's window was closed, returns the first Browser |
| 56 // in the list. If no Browsers exist, returns NULL. | 58 // in the list. If no Browsers exist, returns NULL. |
| 57 // | 59 // |
| 58 // WARNING: this is NULL until a browser becomes active. If during startup | 60 // WARNING: this is NULL until a browser becomes active. If during startup |
| 59 // a browser does not become active (perhaps the user launches Chrome, then | 61 // a browser does not become active (perhaps the user launches Chrome, then |
| 60 // clicks on another app before the first browser window appears) then this | 62 // clicks on another app before the first browser window appears) then this |
| 61 // returns NULL. | 63 // returns NULL. |
| 62 // WARNING #2: this will always be NULL in unit tests run on the bots. | 64 // WARNING #2: this will always be NULL in unit tests run on the bots. |
| 63 static Browser* GetLastActive(); | 65 static Browser* GetLastActive(); |
| 64 | 66 |
| 65 // Identical in behavior to GetLastActive(), except that the most recently | |
| 66 // open browser owned by |profile| is returned. If none exist, returns NULL. | |
| 67 // WARNING: see warnings in GetLastActive(). | |
| 68 static Browser* GetLastActiveWithProfile(Profile* profile); | |
| 69 | |
| 70 // Retrieve the last active tabbed browser with a profile matching |profile|. | |
| 71 // If |match_original_profiles| is true, matching is done based on the | |
| 72 // original profile, eg profile->GetOriginalProfile() == | |
| 73 // browser->profile()->GetOriginalProfile(). This has the effect of matching | |
| 74 // against both non-incognito and incognito profiles. If | |
| 75 // |match_original_profiles| is false, only an exact match may be returned. | |
| 76 static Browser* FindTabbedBrowser(Profile* profile, | |
| 77 bool match_original_profiles); | |
| 78 | |
| 79 // Find an existing browser window with any type. See comment above for | |
| 80 // additional information. | |
| 81 static Browser* FindAnyBrowser(Profile* profile, | |
| 82 bool match_original_profiles); | |
| 83 | |
| 84 // Find an existing browser window that can provide the specified type (this | |
| 85 // uses Browser::CanSupportsWindowFeature, not | |
| 86 // Browser::SupportsWindowFeature). This searches in the order of last | |
| 87 // activation. Only browsers that have been active can be returned. Returns | |
| 88 // NULL if no such browser currently exists. | |
| 89 static Browser* FindBrowserWithFeature(Profile* profile, | |
| 90 Browser::WindowFeature feature); | |
| 91 | |
| 92 // Find an existing browser window with the provided profile. Searches in the | |
| 93 // order of last activation. Only browsers that have been active can be | |
| 94 // returned. Returns NULL if no such browser currently exists. | |
| 95 static Browser* FindBrowserWithProfile(Profile* profile); | |
| 96 | |
| 97 // Find an existing browser with the provided ID. Returns NULL if no such | |
| 98 // browser currently exists. | |
| 99 static Browser* FindBrowserWithID(SessionID::id_type desired_id); | |
| 100 | |
| 101 // Find the browser represented by |window| or NULL if not found. | |
| 102 static Browser* FindBrowserWithWindow(gfx::NativeWindow window); | |
| 103 | |
| 104 // Find the browser containing |web_contents| or NULL if none is found. | |
| 105 // |web_contents| must not be NULL. | |
| 106 static Browser* FindBrowserWithWebContents( | |
| 107 content::WebContents* web_contents); | |
| 108 | |
| 109 // Checks if the browser can be automatically restarted to install upgrades | 67 // Checks if the browser can be automatically restarted to install upgrades |
| 110 // The browser can be automatically restarted when: | 68 // The browser can be automatically restarted when: |
| 111 // 1. It's in the background mode (no visible windows). | 69 // 1. It's in the background mode (no visible windows). |
| 112 // 2. An update exe is present in the install folder. | 70 // 2. An update exe is present in the install folder. |
| 113 static bool CanRestartForUpdate(); | 71 static bool CanRestartForUpdate(); |
| 114 | 72 |
| 115 // Starts a user initiated exit process. Called from Browser::Exit. | 73 // Starts a user initiated exit process. Called from Browser::Exit. |
| 116 // On platforms other than ChromeOS, this is equivalent to | 74 // On platforms other than ChromeOS, this is equivalent to |
| 117 // CloseAllBrowsers() On ChromeOS, this tells session manager | 75 // CloseAllBrowsers() On ChromeOS, this tells session manager |
| 118 // that chrome is signing out, which lets session manager send | 76 // that chrome is signing out, which lets session manager send |
| (...skipping 29 matching lines...) Expand all Loading... |
| 148 // directly. Otherwise the windows are closed by way of posting a WM_CLOSE | 106 // directly. Otherwise the windows are closed by way of posting a WM_CLOSE |
| 149 // message. | 107 // message. |
| 150 static void CloseAllBrowsers(); | 108 static void CloseAllBrowsers(); |
| 151 | 109 |
| 152 // Closes all browsers for |profile|. | 110 // Closes all browsers for |profile|. |
| 153 static void CloseAllBrowsersWithProfile(Profile* profile); | 111 static void CloseAllBrowsersWithProfile(Profile* profile); |
| 154 | 112 |
| 155 // Begins shutdown of the application when the desktop session is ending. | 113 // Begins shutdown of the application when the desktop session is ending. |
| 156 static void SessionEnding(); | 114 static void SessionEnding(); |
| 157 | 115 |
| 158 // Returns true if there is at least one Browser with the specified profile. | |
| 159 static bool HasBrowserWithProfile(Profile* profile); | |
| 160 | |
| 161 // Tells the BrowserList to keep the application alive after the last Browser | 116 // Tells the BrowserList to keep the application alive after the last Browser |
| 162 // closes. This is implemented as a count, so callers should pair their calls | 117 // closes. This is implemented as a count, so callers should pair their calls |
| 163 // to StartKeepAlive() with matching calls to EndKeepAlive() when they no | 118 // to StartKeepAlive() with matching calls to EndKeepAlive() when they no |
| 164 // longer need to keep the application running. | 119 // longer need to keep the application running. |
| 165 static void StartKeepAlive(); | 120 static void StartKeepAlive(); |
| 166 | 121 |
| 167 // Stops keeping the application alive after the last Browser is closed. | 122 // Stops keeping the application alive after the last Browser is closed. |
| 168 // Should match a previous call to StartKeepAlive(). | 123 // Should match a previous call to StartKeepAlive(). |
| 169 static void EndKeepAlive(); | 124 static void EndKeepAlive(); |
| 170 | 125 |
| 171 // Returns true if application will continue running after the last Browser | 126 // Returns true if application will continue running after the last Browser |
| 172 // closes. | 127 // closes. |
| 173 static bool WillKeepAlive(); | 128 static bool WillKeepAlive(); |
| 174 | 129 |
| 175 // Browsers are added to the list before they have constructed windows, | 130 // Browsers are added to the list before they have constructed windows, |
| 176 // so the |window()| member function may return NULL. | 131 // so the |window()| member function may return NULL. |
| 177 static const_iterator begin(); | 132 static const_iterator begin(); |
| 178 static const_iterator end(); | 133 static const_iterator end(); |
| 179 | 134 |
| 180 static bool empty(); | 135 static bool empty(); |
| 181 static size_t size(); | 136 static size_t size(); |
| 182 | 137 |
| 183 // Returns iterated access to list of open browsers ordered by when | 138 // Returns iterated access to list of open browsers ordered by when |
| 184 // they were last active. The underlying data structure is a vector | 139 // they were last active. The underlying data structure is a vector |
| 185 // and we push_back on recent access so a reverse iterator gives the | 140 // and we push_back on recent access so a reverse iterator gives the |
| 186 // latest accessed browser first. | 141 // latest accessed browser first. |
| 187 static const_reverse_iterator begin_last_active(); | 142 static const_reverse_iterator begin_last_active(); |
| 188 static const_reverse_iterator end_last_active(); | 143 static const_reverse_iterator end_last_active(); |
| 189 | 144 |
| 190 // Return the number of browsers with the following profile which are | |
| 191 // currently open. | |
| 192 static size_t GetBrowserCount(Profile* profile); | |
| 193 | |
| 194 // Return the number of browsers with the following profile and type which are | |
| 195 // currently open. | |
| 196 static size_t GetBrowserCountForType(Profile* profile, bool match_tabbed); | |
| 197 | |
| 198 // Returns true if at least one incognito session is active. | 145 // Returns true if at least one incognito session is active. |
| 199 static bool IsOffTheRecordSessionActive(); | 146 static bool IsOffTheRecordSessionActive(); |
| 200 | 147 |
| 201 // Returns true if at least one incognito session is active for |profile|. | 148 // Returns true if at least one incognito session is active for |profile|. |
| 202 static bool IsOffTheRecordSessionActiveForProfile(Profile* profile); | 149 static bool IsOffTheRecordSessionActiveForProfile(Profile* profile); |
| 203 | 150 |
| 204 // Send out notifications. | 151 // Send out notifications. |
| 205 // For ChromeOS, also request session manager to end the session. | 152 // For ChromeOS, also request session manager to end the session. |
| 206 static void NotifyAndTerminate(bool fast_path); | 153 static void NotifyAndTerminate(bool fast_path); |
| 207 | 154 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 // iterator over the TabContentsWrappers doing background printing. | 235 // iterator over the TabContentsWrappers doing background printing. |
| 289 std::set<TabContentsWrapper*>::const_iterator bg_printing_iterator_; | 236 std::set<TabContentsWrapper*>::const_iterator bg_printing_iterator_; |
| 290 | 237 |
| 291 // Current TabContentsWrapper, or NULL if we're at the end of the list. This | 238 // Current TabContentsWrapper, or NULL if we're at the end of the list. This |
| 292 // can be extracted given the browser iterator and index, but it's nice to | 239 // can be extracted given the browser iterator and index, but it's nice to |
| 293 // cache this since the caller may access the current host many times. | 240 // cache this since the caller may access the current host many times. |
| 294 TabContentsWrapper* cur_; | 241 TabContentsWrapper* cur_; |
| 295 }; | 242 }; |
| 296 | 243 |
| 297 #endif // CHROME_BROWSER_UI_BROWSER_LIST_H_ | 244 #endif // CHROME_BROWSER_UI_BROWSER_LIST_H_ |
| OLD | NEW |