OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 IOS_SHARED_CHROME_BROWSER_UI_BROWSER_LIST_BROWSER_LIST_H_ | 5 #ifndef IOS_SHARED_CHROME_BROWSER_UI_BROWSER_LIST_BROWSER_LIST_H_ |
6 #define IOS_SHARED_CHROME_BROWSER_UI_BROWSER_LIST_BROWSER_LIST_H_ | 6 #define IOS_SHARED_CHROME_BROWSER_UI_BROWSER_LIST_BROWSER_LIST_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/observer_list.h" |
12 #include "base/supports_user_data.h" | 13 #include "base/supports_user_data.h" |
13 #include "ios/shared/chrome/browser/ui/browser_list/browser.h" | 14 #include "ios/shared/chrome/browser/ui/browser_list/browser.h" |
14 | 15 |
| 16 class BrowserListObserver; |
| 17 |
15 namespace ios { | 18 namespace ios { |
16 class ChromeBrowserState; | 19 class ChromeBrowserState; |
17 } | 20 } |
18 | 21 |
19 // BrowserList attaches Browsers instance to a ChromeBrowserState. | 22 // BrowserList attaches Browsers instance to a ChromeBrowserState. |
20 class BrowserList : public base::SupportsUserData::Data { | 23 class BrowserList : public base::SupportsUserData::Data { |
21 public: | 24 public: |
22 explicit BrowserList(ios::ChromeBrowserState* browser_state); | 25 explicit BrowserList(ios::ChromeBrowserState* browser_state); |
23 ~BrowserList() override; | 26 ~BrowserList() override; |
24 | 27 |
(...skipping 10 matching lines...) Expand all Loading... |
35 | 38 |
36 // Returns the index of the specified Browser, or kInvalidIndex if not found. | 39 // Returns the index of the specified Browser, or kInvalidIndex if not found. |
37 int GetIndexOfBrowser(const Browser* browser) const; | 40 int GetIndexOfBrowser(const Browser* browser) const; |
38 | 41 |
39 // Creates and returns a new Browser instance. | 42 // Creates and returns a new Browser instance. |
40 Browser* CreateNewBrowser(); | 43 Browser* CreateNewBrowser(); |
41 | 44 |
42 // Closes the Browser at the specified index. | 45 // Closes the Browser at the specified index. |
43 void CloseBrowserAtIndex(int index); | 46 void CloseBrowserAtIndex(int index); |
44 | 47 |
| 48 // Adds/removes |observer| from the list of observers. |
| 49 void AddObserver(BrowserListObserver* observer); |
| 50 void RemoveObserver(BrowserListObserver* observer); |
| 51 |
45 // Invalid index. | 52 // Invalid index. |
46 static const int kInvalidIndex = -1; | 53 static const int kInvalidIndex = -1; |
47 | 54 |
48 private: | 55 private: |
49 ios::ChromeBrowserState* browser_state_; | 56 ios::ChromeBrowserState* browser_state_; |
50 std::vector<std::unique_ptr<Browser>> browsers_; | 57 std::vector<std::unique_ptr<Browser>> browsers_; |
| 58 base::ObserverList<BrowserListObserver, true> observers_; |
51 | 59 |
52 DISALLOW_COPY_AND_ASSIGN(BrowserList); | 60 DISALLOW_COPY_AND_ASSIGN(BrowserList); |
53 }; | 61 }; |
54 | 62 |
55 #endif // IOS_SHARED_CHROME_BROWSER_UI_BROWSER_LIST_BROWSER_LIST_H_ | 63 #endif // IOS_SHARED_CHROME_BROWSER_UI_BROWSER_LIST_BROWSER_LIST_H_ |
OLD | NEW |