Index: ios/shared/chrome/browser/tabs/web_state_list.h |
diff --git a/ios/shared/chrome/browser/tabs/web_state_list.h b/ios/shared/chrome/browser/tabs/web_state_list.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c434a5af8e5ec7bc56bbcbc62c30d55155dde704 |
--- /dev/null |
+++ b/ios/shared/chrome/browser/tabs/web_state_list.h |
@@ -0,0 +1,84 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_H_ |
+#define IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_H_ |
+ |
+#include <memory> |
+#include <vector> |
+ |
+#include "base/macros.h" |
+#include "base/observer_list.h" |
+ |
+class WebStateListObserver; |
+ |
+namespace web { |
+class WebState; |
+} |
+ |
+// Manages a list of WebStates. May owns the WebState depending on the ownership |
+// setting (initialised during construction, should eventually always be "owned" |
+// once ownership of Tab is sane, see http://crbug.com/546222 for progress). |
+class WebStateList { |
+ public: |
+ enum WebStateOwnership { |
+ WebStateBorrowed, |
+ WebStateOwned, |
+ }; |
+ |
+ explicit WebStateList(WebStateOwnership ownership = WebStateBorrowed); |
+ ~WebStateList(); |
+ |
+ // Returns whether the model is empty or not. |
+ bool empty() const { return web_state_wrappers_.empty(); } |
+ |
+ // Returns the number of WebStates in the model. |
+ size_t count() const { return web_state_wrappers_.size(); } |
+ |
+ // Returns true if the specified index is contained by the model. |
+ bool ContainsIndex(size_t index) const; |
+ |
+ // Returns the WebState at the specified index. It is invalid to call this |
+ // 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
|
+ web::WebState* GetWebStateAt(size_t index) const; |
+ |
+ // Returns the index of the specified WebState or kInvalidIndex if the |
+ // WebState is not in the model. |
+ size_t GetIndexOfWebState(const web::WebState* web_state) const; |
+ |
+ // Inserts the specified WebState at the specified index. |
+ void InsertWebState(size_t index, web::WebState* web_state); |
+ |
+ // Moves the WebState at the specified index to another index. |
+ void MoveWebStateAt(size_t from_index, size_t to_index); |
+ |
+ // Replaces the WebState at the specified index with new WebState. Returns |
+ // the old WebState at that index to the caller (abandon ownership of the |
+ // returned WebState). |
+ web::WebState* ReplaceWebStateAt(size_t index, web::WebState* web_state); |
+ |
+ // Removes the WebState at the specified index. |
+ void RemoveWebStateAt(size_t index); |
+ |
+ // Adds an observer to the model. |
+ void AddObserver(WebStateListObserver* observer); |
+ |
+ // Removes an observer from the model. |
+ void RemoveObserver(WebStateListObserver* observer); |
+ |
+ // Invalid index. |
+ static const size_t kInvalidIndex = static_cast<size_t>(-1); |
+ |
+ private: |
+ class WebStateWrapper; |
+ const WebStateOwnership web_state_ownership_; |
+ std::vector<std::unique_ptr<WebStateWrapper>> web_state_wrappers_; |
+ |
+ // List of observers notified of changes to the model. |
+ base::ObserverList<WebStateListObserver, true> observers_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(WebStateList); |
+}; |
+ |
+#endif // IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_H_ |