Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Unified Diff: ios/shared/chrome/browser/tabs/web_state_list.h

Issue 2680403005: Introduce WebStateList to manage a list of web::WebState. (Closed)
Patch Set: Rebase && address comments. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..ff6965e3ed0d53d68b4f3265dd311ba49a1bcb67
--- /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 false.
+ 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);
+
+ // Detachs the WebState at the specified index.
rohitrao (ping after 24h) 2017/02/14 13:49:31 Detaches.
sdefresne 2017/02/14 15:26:35 Done.
+ void DetachWebStateAt(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_

Powered by Google App Engine
This is Rietveld 408576698