| OLD | NEW |
| 1 // Copyright (c) 2009 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 "chrome/browser/browser.h" | 11 #include "chrome/browser/browser.h" |
| 11 | 12 |
| 12 // Stores a list of all Browser objects. | 13 // Stores a list of all Browser objects. |
| 13 class BrowserList { | 14 class BrowserList { |
| 14 public: | 15 public: |
| 15 typedef std::vector<Browser*> list_type; | 16 typedef std::vector<Browser*> BrowserVector; |
| 16 typedef list_type::iterator iterator; | 17 typedef BrowserVector::iterator iterator; |
| 17 typedef list_type::const_iterator const_iterator; | 18 typedef BrowserVector::const_iterator const_iterator; |
| 18 typedef list_type::const_reverse_iterator const_reverse_iterator; | 19 typedef BrowserVector::const_reverse_iterator const_reverse_iterator; |
| 19 | 20 |
| 20 // It is not allowed to change the global window list (add or remove any | 21 // It is not allowed to change the global window list (add or remove any |
| 21 // browser windows while handling observer callbacks. | 22 // browser windows while handling observer callbacks. |
| 22 class Observer { | 23 class Observer { |
| 23 public: | 24 public: |
| 24 // Called immediately after a browser is added to the list | 25 // Called immediately after a browser is added to the list |
| 25 virtual void OnBrowserAdded(const Browser* browser) = 0; | 26 virtual void OnBrowserAdded(const Browser* browser) = 0; |
| 26 | 27 |
| 27 // Called immediately before a browser is removed from the list | 28 // Called immediately before a browser is removed from the list |
| 28 virtual void OnBrowserRemoving(const Browser* browser) = 0; | 29 virtual void OnBrowserRemoving(const Browser* browser) = 0; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 | 101 |
| 101 // Begins shutdown of the application when the Windows session is ending. | 102 // Begins shutdown of the application when the Windows session is ending. |
| 102 static void WindowsSessionEnding(); | 103 static void WindowsSessionEnding(); |
| 103 | 104 |
| 104 // Returns true if there is at least one Browser with the specified profile. | 105 // Returns true if there is at least one Browser with the specified profile. |
| 105 static bool HasBrowserWithProfile(Profile* profile); | 106 static bool HasBrowserWithProfile(Profile* profile); |
| 106 | 107 |
| 107 // Returns true if browser is in persistent mode and false otherwise. | 108 // Returns true if browser is in persistent mode and false otherwise. |
| 108 static bool IsInPersistentMode(); | 109 static bool IsInPersistentMode(); |
| 109 | 110 |
| 110 static const_iterator begin() { | 111 static const_iterator begin() { return browsers_.begin(); } |
| 111 return browsers_.begin(); | 112 static const_iterator end() { return browsers_.end(); } |
| 112 } | |
| 113 | 113 |
| 114 static const_iterator end() { | 114 static size_t size() { return browsers_.size(); } |
| 115 return browsers_.end(); | |
| 116 } | |
| 117 | |
| 118 static size_t size() { | |
| 119 return browsers_.size(); | |
| 120 } | |
| 121 | 115 |
| 122 // Returns iterated access to list of open browsers ordered by when | 116 // Returns iterated access to list of open browsers ordered by when |
| 123 // they were last active. The underlying data structure is a vector | 117 // they were last active. The underlying data structure is a vector |
| 124 // and we push_back on recent access so a reverse iterator gives the | 118 // and we push_back on recent access so a reverse iterator gives the |
| 125 // latest accessed browser first. | 119 // latest accessed browser first. |
| 126 static const_reverse_iterator begin_last_active() { | 120 static const_reverse_iterator begin_last_active() { |
| 127 return last_active_browsers_.rbegin(); | 121 return last_active_browsers_.rbegin(); |
| 128 } | 122 } |
| 129 | 123 |
| 130 static const_reverse_iterator end_last_active() { | 124 static const_reverse_iterator end_last_active() { |
| 131 return last_active_browsers_.rend(); | 125 return last_active_browsers_.rend(); |
| 132 } | 126 } |
| 133 | 127 |
| 134 // Return the number of browsers with the following profile which are | 128 // Return the number of browsers with the following profile which are |
| 135 // currently open. | 129 // currently open. |
| 136 static size_t GetBrowserCount(Profile* p); | 130 static size_t GetBrowserCount(Profile* p); |
| 137 | 131 |
| 138 // Return the number of browsers with the following profile and type which are | 132 // Return the number of browsers with the following profile and type which are |
| 139 // currently open. | 133 // currently open. |
| 140 static size_t GetBrowserCountForType(Profile* p, Browser::Type type); | 134 static size_t GetBrowserCountForType(Profile* p, Browser::Type type); |
| 141 | 135 |
| 142 // Returns true if at least one off the record session is active. | 136 // Returns true if at least one off the record session is active. |
| 143 static bool IsOffTheRecordSessionActive(); | 137 static bool IsOffTheRecordSessionActive(); |
| 144 | 138 |
| 145 // Called when the last browser is closed. | 139 // Called when the last browser is closed. |
| 146 static void AllBrowsersClosed(); | 140 static void AllBrowsersClosed(); |
| 147 | 141 |
| 148 private: | 142 private: |
| 149 // Helper method to remove a browser instance from a list of browsers | 143 // Helper method to remove a browser instance from a list of browsers |
| 150 static void RemoveBrowserFrom(Browser* browser, list_type* browser_list); | 144 static void RemoveBrowserFrom(Browser* browser, BrowserVector* browser_list); |
| 151 | 145 |
| 152 static list_type browsers_; | 146 static BrowserVector browsers_; |
| 153 static std::vector<Observer*> observers_; | 147 static BrowserVector last_active_browsers_; |
| 154 static list_type last_active_browsers_; | 148 static ObserverList<Observer> observers_; |
| 155 }; | 149 }; |
| 156 | 150 |
| 157 class TabContents; | 151 class TabContents; |
| 158 | 152 |
| 159 // Iterates through all web view hosts in all browser windows. Because the | 153 // Iterates through all web view hosts in all browser windows. Because the |
| 160 // renderers act asynchronously, getting a host through this interface does | 154 // renderers act asynchronously, getting a host through this interface does |
| 161 // not guarantee that the renderer is ready to go. Doing anything to affect | 155 // not guarantee that the renderer is ready to go. Doing anything to affect |
| 162 // browser windows or tabs while iterating may cause incorrect behavior. | 156 // browser windows or tabs while iterating may cause incorrect behavior. |
| 163 // | 157 // |
| 164 // Example: | 158 // Example: |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 // tab index into the current Browser of the current web view | 202 // tab index into the current Browser of the current web view |
| 209 int web_view_index_; | 203 int web_view_index_; |
| 210 | 204 |
| 211 // Current TabContents, or NULL if we're at the end of the list. This can | 205 // Current TabContents, or NULL if we're at the end of the list. This can |
| 212 // be extracted given the browser iterator and index, but it's nice to cache | 206 // be extracted given the browser iterator and index, but it's nice to cache |
| 213 // this since the caller may access the current host many times. | 207 // this since the caller may access the current host many times. |
| 214 TabContents* cur_; | 208 TabContents* cur_; |
| 215 }; | 209 }; |
| 216 | 210 |
| 217 #endif // CHROME_BROWSER_BROWSER_LIST_H_ | 211 #endif // CHROME_BROWSER_BROWSER_LIST_H_ |
| OLD | NEW |