Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_H_ | |
| 6 #define IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "base/observer_list.h" | |
| 13 | |
| 14 class WebStateListObserver; | |
| 15 | |
| 16 namespace web { | |
| 17 class WebState; | |
| 18 } | |
| 19 | |
| 20 // Manages a list of WebStates. May owns the WebState depending on the ownership | |
| 21 // setting (initialised during construction, should eventually always be "owned" | |
| 22 // once ownership of Tab is sane, see http://crbug.com/546222 for progress). | |
| 23 class WebStateList { | |
| 24 public: | |
| 25 enum WebStateOwnership { | |
| 26 WebStateBorrowed, | |
| 27 WebStateOwned, | |
| 28 }; | |
| 29 | |
| 30 explicit WebStateList(WebStateOwnership ownership = WebStateBorrowed); | |
| 31 ~WebStateList(); | |
| 32 | |
| 33 // Returns whether the model is empty or not. | |
| 34 bool empty() const { return web_state_wrappers_.empty(); } | |
| 35 | |
| 36 // Returns the number of WebStates in the model. | |
| 37 size_t count() const { return web_state_wrappers_.size(); } | |
| 38 | |
| 39 // Returns true if the specified index is contained by the model. | |
| 40 bool ContainsIndex(size_t index) const; | |
| 41 | |
| 42 // Returns the WebState at the specified index. It is invalid to call this | |
| 43 // with an index such that |ContainsIndex(index)| returns fals.e | |
|
marq (ping after 24h)
2017/02/13 16:32:53
s/.e/e./, or f.xp in vi.
sdefresne
2017/02/14 13:39:56
Done (note: that's Ctrl+t when the cursor is after
| |
| 44 web::WebState* GetWebStateAt(size_t index) const; | |
| 45 | |
| 46 // Returns the index of the specified WebState or kInvalidIndex if the | |
| 47 // WebState is not in the model. | |
| 48 size_t GetIndexOfWebState(const web::WebState* web_state) const; | |
| 49 | |
| 50 // Inserts the specified WebState at the specified index. | |
| 51 void InsertWebState(size_t index, web::WebState* web_state); | |
| 52 | |
| 53 // Moves the WebState at the specified index to another index. | |
| 54 void MoveWebStateAt(size_t from_index, size_t to_index); | |
| 55 | |
| 56 // Replaces the WebState at the specified index with new WebState. Returns | |
| 57 // the old WebState at that index to the caller (abandon ownership of the | |
| 58 // returned WebState). | |
| 59 web::WebState* ReplaceWebStateAt(size_t index, web::WebState* web_state); | |
| 60 | |
| 61 // Removes the WebState at the specified index. | |
| 62 void RemoveWebStateAt(size_t index); | |
| 63 | |
| 64 // Adds an observer to the model. | |
| 65 void AddObserver(WebStateListObserver* observer); | |
| 66 | |
| 67 // Removes an observer from the model. | |
| 68 void RemoveObserver(WebStateListObserver* observer); | |
| 69 | |
| 70 // Invalid index. | |
| 71 static const size_t kInvalidIndex = static_cast<size_t>(-1); | |
| 72 | |
| 73 private: | |
| 74 class WebStateWrapper; | |
| 75 const WebStateOwnership web_state_ownership_; | |
| 76 std::vector<std::unique_ptr<WebStateWrapper>> web_state_wrappers_; | |
| 77 | |
| 78 // List of observers notified of changes to the model. | |
| 79 base::ObserverList<WebStateListObserver, true> observers_; | |
| 80 | |
| 81 DISALLOW_COPY_AND_ASSIGN(WebStateList); | |
| 82 }; | |
| 83 | |
| 84 #endif // IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_H_ | |
| OLD | NEW |