| 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/supports_user_data.h" | 12 #include "base/supports_user_data.h" |
| 13 #include "ios/shared/chrome/browser/ui/browser_list/browser.h" | 13 #include "ios/shared/chrome/browser/ui/browser_list/browser.h" |
| 14 | 14 |
| 15 namespace ios { | 15 namespace ios { |
| 16 class ChromeBrowserState; | 16 class ChromeBrowserState; |
| 17 } | 17 } |
| 18 | 18 |
| 19 // BrowserList attaches Browsers instance to a ChromeBrowserState. | 19 // BrowserList attaches Browsers instance to a ChromeBrowserState. |
| 20 class BrowserList : public base::SupportsUserData::Data { | 20 class BrowserList : public base::SupportsUserData::Data { |
| 21 public: | 21 public: |
| 22 explicit BrowserList(ios::ChromeBrowserState* browser_state); | 22 explicit BrowserList(ios::ChromeBrowserState* browser_state); |
| 23 ~BrowserList() override; | 23 ~BrowserList() override; |
| 24 | 24 |
| 25 static BrowserList* FromBrowserState(ios::ChromeBrowserState* browser_state); | 25 static BrowserList* FromBrowserState(ios::ChromeBrowserState* browser_state); |
| 26 | 26 |
| 27 // Returns the number of open Browsers. | 27 // Returns the number of Browsers in the BrowserList. |
| 28 int GetBrowserCount() const; | 28 int count() const { return static_cast<int>(browsers_.size()); } |
| 29 | 29 |
| 30 // Returns whether the specified index is valid. | 30 // Returns whether the specified index is valid. |
| 31 int ContainsIndex(int index) const; | 31 int ContainsIndex(int index) const; |
| 32 | 32 |
| 33 // Returns the Browser at the specified index. | 33 // Returns the Browser at the specified index. |
| 34 Browser* GetBrowserAtIndex(int index) const; | 34 Browser* GetBrowserAtIndex(int index) const; |
| 35 | 35 |
| 36 // Returns the index of the specified Browser, or kInvalidIndex if not found. |
| 37 int GetIndexOfBrowser(const Browser* browser) const; |
| 38 |
| 36 // Creates and returns a new Browser instance. | 39 // Creates and returns a new Browser instance. |
| 37 Browser* CreateNewBrowser(); | 40 Browser* CreateNewBrowser(); |
| 38 | 41 |
| 39 // Closes the Browser at the specified index. | 42 // Closes the Browser at the specified index. |
| 40 void CloseBrowserAtIndex(int index); | 43 void CloseBrowserAtIndex(int index); |
| 41 | 44 |
| 45 // Invalid index. |
| 46 static const int kInvalidIndex = -1; |
| 47 |
| 42 private: | 48 private: |
| 43 ios::ChromeBrowserState* browser_state_; | 49 ios::ChromeBrowserState* browser_state_; |
| 44 std::vector<std::unique_ptr<Browser>> browsers_; | 50 std::vector<std::unique_ptr<Browser>> browsers_; |
| 45 | 51 |
| 46 DISALLOW_COPY_AND_ASSIGN(BrowserList); | 52 DISALLOW_COPY_AND_ASSIGN(BrowserList); |
| 47 }; | 53 }; |
| 48 | 54 |
| 49 #endif // IOS_SHARED_CHROME_BROWSER_UI_BROWSER_LIST_BROWSER_LIST_H_ | 55 #endif // IOS_SHARED_CHROME_BROWSER_UI_BROWSER_LIST_BROWSER_LIST_H_ |
| OLD | NEW |