Chromium Code Reviews| Index: ios/chrome/browser/tabs/web_state_list.mm |
| diff --git a/ios/chrome/browser/tabs/web_state_list.mm b/ios/chrome/browser/tabs/web_state_list.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..179a14f19a77a95d4981c0d8e14f2d8803762d7e |
| --- /dev/null |
| +++ b/ios/chrome/browser/tabs/web_state_list.mm |
| @@ -0,0 +1,81 @@ |
| +// 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/chrome/browser/tabs/web_state_list.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]; |
|
marq (ping after 24h)
2017/01/19 13:37:46
nit: _list.count
sdefresne
2017/01/20 14:42:09
Done.
|
| +} |
| + |
| +- (id<WebStateHandle>)firstWebState { |
| + return [_list firstObject]; |
|
marq (ping after 24h)
2017/01/19 13:37:46
nit: _list.firstObject
sdefresne
2017/01/20 14:42:09
Done.
|
| +} |
| + |
| +#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>)webSate { |
| + return [_list containsObject:webSate]; |
| +} |
| + |
| +- (id<WebStateHandle>)webStateAtIndex:(NSUInteger)index { |
|
marq (ping after 24h)
2017/01/19 14:35:11
Do we want to guard against range exceptions by re
sdefresne
2017/01/20 14:42:09
I've added a DCHECK, WDYT?
marq (ping after 24h)
2017/01/20 14:49:17
Doesn't that just trade one exception for another?
|
| + return [_list objectAtIndex:index]; |
| +} |
| + |
| +- (NSUInteger)indexOfWebState:(id<WebStateHandle>)webState { |
| + return [_list indexOfObject:webState]; |
| +} |
| + |
| +#pragma mark - Public methods, deprecated |
| + |
| +- (NSArray*)allWebStates { |
| + return [_list copy]; |
| +} |
| + |
| +@end |