| OLD | NEW |
| (Empty) | |
| 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_UI_BROWSER_LIST_IMPL_H_ |
| 6 #define CHROME_BROWSER_UI_BROWSER_LIST_IMPL_H_ |
| 7 |
| 8 #include "base/observer_list.h" |
| 9 #include "chrome/browser/ui/host_desktop.h" |
| 10 |
| 11 class Browser; |
| 12 class BrowserList; |
| 13 class Profile; |
| 14 |
| 15 namespace chrome { |
| 16 |
| 17 class BrowserListObserver; |
| 18 |
| 19 // Maintains a list of Browser objects present in a given HostDesktop (see |
| 20 // HostDesktopType). |
| 21 class BrowserListImpl { |
| 22 public: |
| 23 typedef std::vector<Browser*> BrowserVector; |
| 24 typedef BrowserVector::iterator iterator; |
| 25 typedef BrowserVector::const_iterator const_iterator; |
| 26 typedef BrowserVector::const_reverse_iterator const_reverse_iterator; |
| 27 |
| 28 static BrowserListImpl* GetInstance(HostDesktopType type); |
| 29 |
| 30 // Adds and removes browsers from the global list. The browser object should |
| 31 // be valid BEFORE these calls (for the benefit of observers), so notify and |
| 32 // THEN delete the object. |
| 33 void AddBrowser(Browser* browser); |
| 34 void RemoveBrowser(Browser* browser); |
| 35 |
| 36 void AddObserver(BrowserListObserver* observer); |
| 37 void RemoveObserver(BrowserListObserver* observer); |
| 38 |
| 39 // Called by Browser objects when their window is activated (focused). This |
| 40 // allows us to determine what the last active Browser was. |
| 41 void SetLastActive(Browser* browser); |
| 42 |
| 43 Browser* GetLastActive(); |
| 44 |
| 45 // Closes all browsers for |profile|. |
| 46 void CloseAllBrowsersWithProfile(Profile* profile); |
| 47 |
| 48 // Browsers are added to the list before they have constructed windows, |
| 49 // so the |window()| member function may return NULL. |
| 50 const_iterator begin() const { return browsers_.begin(); } |
| 51 const_iterator end() const { return browsers_.end(); } |
| 52 |
| 53 bool empty() const { return browsers_.empty(); } |
| 54 size_t size() const { return browsers_.size(); } |
| 55 |
| 56 // Returns iterated access to list of open browsers ordered by when |
| 57 // they were last active. The underlying data structure is a vector |
| 58 // and we push_back on recent access so a reverse iterator gives the |
| 59 // latest accessed browser first. |
| 60 const_reverse_iterator begin_last_active() { |
| 61 return last_active_browsers_.rbegin(); |
| 62 } |
| 63 const_reverse_iterator end_last_active() { |
| 64 return last_active_browsers_.rend(); |
| 65 } |
| 66 |
| 67 // Returns true if at least one incognito window is open. |
| 68 bool IsIncognitoWindowOpen(); |
| 69 |
| 70 // Returns true if at least one incognito window is open for |profile|. |
| 71 bool IsIncognitoWindowOpenForProfile(Profile* profile); |
| 72 |
| 73 private: |
| 74 BrowserListImpl(); |
| 75 ~BrowserListImpl(); |
| 76 |
| 77 // Helper method to remove a browser instance from a list of browsers |
| 78 void RemoveBrowserFrom(Browser* browser, BrowserVector* browser_list); |
| 79 |
| 80 ObserverList<BrowserListObserver> observers_; |
| 81 |
| 82 BrowserVector browsers_; |
| 83 BrowserVector last_active_browsers_; |
| 84 |
| 85 // Nothing fancy, since we only have two HDTs. |
| 86 static BrowserListImpl* native_instance_; |
| 87 static BrowserListImpl* ash_instance_; |
| 88 |
| 89 DISALLOW_COPY_AND_ASSIGN(BrowserListImpl); |
| 90 }; |
| 91 |
| 92 } // namespace chrome |
| 93 |
| 94 #endif // CHROME_BROWSER_UI_BROWSER_LIST_IMPL_H_ |
| OLD | NEW |