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

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

Issue 2640093004: WebStateList is an array of web::WebState* wrappers. (Closed)
Patch Set: Fix leaks (caught by unit tests). Created 3 years, 11 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
« no previous file with comments | « ios/shared/chrome/browser/tabs/web_state_list.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/shared/chrome/browser/tabs/web_state_list.mm
diff --git a/ios/shared/chrome/browser/tabs/web_state_list.mm b/ios/shared/chrome/browser/tabs/web_state_list.mm
new file mode 100644
index 0000000000000000000000000000000000000000..2536117e9c6295dc7e62b96123c445fdbb5aa06f
--- /dev/null
+++ b/ios/shared/chrome/browser/tabs/web_state_list.mm
@@ -0,0 +1,78 @@
+// 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.
+
+#import "ios/shared/chrome/browser/tabs/web_state_list.h"
+
+#include "base/logging.h"
+
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+@implementation WebStateList {
+ NSMutableArray<id<WebStateHandle>>* _list;
+}
+
+#pragma mark - Lifecycle
+
+- (instancetype)init {
+ if ((self = [super init])) {
+ _list = [[NSMutableArray alloc] init];
+ }
+ return self;
+}
+
+#pragma mark - NSFastEnumeration
+
+- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState*)state
+ objects:(id __unsafe_unretained*)buffer
+ count:(NSUInteger)len {
+ return [_list countByEnumeratingWithState:state objects:buffer count:len];
+}
+
+#pragma mark - Properties
+
+- (NSUInteger)count {
+ return _list.count;
+}
+
+- (id<WebStateHandle>)firstWebState {
+ return _list.firstObject;
+}
+
+#pragma mark - Public methods, mutation
+
+- (void)addWebState:(id<WebStateHandle>)webState {
+ [_list addObject:webState];
+}
+
+- (void)insertWebState:(id<WebStateHandle>)webState atIndex:(NSUInteger)index {
+ [_list insertObject:webState atIndex:index];
+}
+
+- (void)replaceWebStateAtIndex:(NSUInteger)index
+ withWebState:(id<WebStateHandle>)webState {
+ [_list replaceObjectAtIndex:index withObject:webState];
+}
+
+- (void)removeWebState:(id<WebStateHandle>)webState {
+ [_list removeObject:webState];
+}
+
+#pragma mark - Public methods, queries
+
+- (BOOL)containsWebState:(id<WebStateHandle>)webState {
+ return [_list containsObject:webState];
+}
+
+- (id<WebStateHandle>)webStateAtIndex:(NSUInteger)index {
+ DCHECK_LT(index, _list.count);
+ return [_list objectAtIndex:index];
+}
+
+- (NSUInteger)indexOfWebState:(id<WebStateHandle>)webState {
+ return [_list indexOfObject:webState];
+}
+
+@end
« no previous file with comments | « ios/shared/chrome/browser/tabs/web_state_list.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698