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 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
15 #include "chrome/browser/ui/host_desktop.h" | |
16 | 15 |
17 class Browser; | 16 class Browser; |
18 class Profile; | 17 class Profile; |
19 | 18 |
20 namespace base { | 19 namespace base { |
21 class FilePath; | 20 class FilePath; |
22 } | 21 } |
23 | 22 |
24 namespace chrome { | 23 namespace chrome { |
25 class BrowserListObserver; | 24 class BrowserListObserver; |
26 } | 25 } |
27 | 26 |
28 // Maintains a list of Browser objects present in a given HostDesktop (see | 27 // Maintains a list of Browser objects. |
29 // HostDesktopType). | |
30 class BrowserList { | 28 class BrowserList { |
31 public: | 29 public: |
32 typedef std::vector<Browser*> BrowserVector; | 30 typedef std::vector<Browser*> BrowserVector; |
33 typedef BrowserVector::const_iterator const_iterator; | 31 typedef BrowserVector::const_iterator const_iterator; |
34 typedef BrowserVector::const_reverse_iterator const_reverse_iterator; | 32 typedef BrowserVector::const_reverse_iterator const_reverse_iterator; |
35 | 33 |
36 // Returns the last active browser for this list. | 34 // Returns the last active browser for this list. |
37 Browser* GetLastActive() const; | 35 Browser* GetLastActive() const; |
38 | 36 |
39 // Browsers are added to the list before they have constructed windows, | 37 // Browsers are added to the list before they have constructed windows, |
(...skipping 10 matching lines...) Expand all Loading... |
50 // they were last active. The underlying data structure is a vector | 48 // they were last active. The underlying data structure is a vector |
51 // and we push_back on recent access so a reverse iterator gives the | 49 // and we push_back on recent access so a reverse iterator gives the |
52 // latest accessed browser first. | 50 // latest accessed browser first. |
53 const_reverse_iterator begin_last_active() const { | 51 const_reverse_iterator begin_last_active() const { |
54 return last_active_browsers_.rbegin(); | 52 return last_active_browsers_.rbegin(); |
55 } | 53 } |
56 const_reverse_iterator end_last_active() const { | 54 const_reverse_iterator end_last_active() const { |
57 return last_active_browsers_.rend(); | 55 return last_active_browsers_.rend(); |
58 } | 56 } |
59 | 57 |
60 static BrowserList* GetInstance(chrome::HostDesktopType type); | 58 static BrowserList* GetInstance(); |
61 | 59 |
62 // Adds or removes |browser| from the list it is associated with. The browser | 60 // Adds or removes |browser| from the list it is associated with. The browser |
63 // object should be valid BEFORE these calls (for the benefit of observers), | 61 // object should be valid BEFORE these calls (for the benefit of observers), |
64 // so notify and THEN delete the object. | 62 // so notify and THEN delete the object. |
65 static void AddBrowser(Browser* browser); | 63 static void AddBrowser(Browser* browser); |
66 static void RemoveBrowser(Browser* browser); | 64 static void RemoveBrowser(Browser* browser); |
67 | 65 |
68 // Adds and removes |observer| from the observer list for all desktops. | 66 // Adds and removes |observer| from the observer list for all desktops. |
69 // Observers are responsible for making sure the notifying browser is relevant | 67 // Observers are responsible for making sure the notifying browser is relevant |
70 // to them (e.g., on the specific desktop they care about if any). | 68 // to them (e.g., on the specific desktop they care about if any). |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 BrowserVector browsers_; | 129 BrowserVector browsers_; |
132 // A vector of the browsers in this list that have been activated, in the | 130 // A vector of the browsers in this list that have been activated, in the |
133 // reverse order in which they were last activated. | 131 // reverse order in which they were last activated. |
134 BrowserVector last_active_browsers_; | 132 BrowserVector last_active_browsers_; |
135 | 133 |
136 // A list of observers which will be notified of every browser addition and | 134 // A list of observers which will be notified of every browser addition and |
137 // removal across all BrowserLists. | 135 // removal across all BrowserLists. |
138 static base::LazyInstance< | 136 static base::LazyInstance< |
139 base::ObserverList<chrome::BrowserListObserver>>::Leaky observers_; | 137 base::ObserverList<chrome::BrowserListObserver>>::Leaky observers_; |
140 | 138 |
141 // Nothing fancy, since we only have two HDTs. | 139 static BrowserList* instance_; |
142 static BrowserList* native_instance_; | |
143 static BrowserList* ash_instance_; | |
144 | 140 |
145 DISALLOW_COPY_AND_ASSIGN(BrowserList); | 141 DISALLOW_COPY_AND_ASSIGN(BrowserList); |
146 }; | 142 }; |
147 | 143 |
148 #endif // CHROME_BROWSER_UI_BROWSER_LIST_H_ | 144 #endif // CHROME_BROWSER_UI_BROWSER_LIST_H_ |
OLD | NEW |