| 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 #import "ios/shared/chrome/browser/tabs/web_state_list.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 | |
| 9 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 10 #error "This file requires ARC support." | |
| 11 #endif | |
| 12 | |
| 13 @implementation WebStateList { | |
| 14 NSMutableArray<id<WebStateHandle>>* _list; | |
| 15 } | |
| 16 | |
| 17 #pragma mark - Lifecycle | |
| 18 | |
| 19 - (instancetype)init { | |
| 20 if ((self = [super init])) { | |
| 21 _list = [[NSMutableArray alloc] init]; | |
| 22 } | |
| 23 return self; | |
| 24 } | |
| 25 | |
| 26 #pragma mark - NSFastEnumeration | |
| 27 | |
| 28 - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState*)state | |
| 29 objects:(id __unsafe_unretained*)buffer | |
| 30 count:(NSUInteger)len { | |
| 31 return [_list countByEnumeratingWithState:state objects:buffer count:len]; | |
| 32 } | |
| 33 | |
| 34 #pragma mark - Properties | |
| 35 | |
| 36 - (NSUInteger)count { | |
| 37 return _list.count; | |
| 38 } | |
| 39 | |
| 40 - (id<WebStateHandle>)firstWebState { | |
| 41 return _list.firstObject; | |
| 42 } | |
| 43 | |
| 44 #pragma mark - Public methods, mutation | |
| 45 | |
| 46 - (void)addWebState:(id<WebStateHandle>)webState { | |
| 47 [_list addObject:webState]; | |
| 48 } | |
| 49 | |
| 50 - (void)insertWebState:(id<WebStateHandle>)webState atIndex:(NSUInteger)index { | |
| 51 [_list insertObject:webState atIndex:index]; | |
| 52 } | |
| 53 | |
| 54 - (void)replaceWebStateAtIndex:(NSUInteger)index | |
| 55 withWebState:(id<WebStateHandle>)webState { | |
| 56 [_list replaceObjectAtIndex:index withObject:webState]; | |
| 57 } | |
| 58 | |
| 59 - (void)removeWebState:(id<WebStateHandle>)webState { | |
| 60 [_list removeObject:webState]; | |
| 61 } | |
| 62 | |
| 63 #pragma mark - Public methods, queries | |
| 64 | |
| 65 - (BOOL)containsWebState:(id<WebStateHandle>)webState { | |
| 66 return [_list containsObject:webState]; | |
| 67 } | |
| 68 | |
| 69 - (id<WebStateHandle>)webStateAtIndex:(NSUInteger)index { | |
| 70 DCHECK_LT(index, _list.count); | |
| 71 return [_list objectAtIndex:index]; | |
| 72 } | |
| 73 | |
| 74 - (NSUInteger)indexOfWebState:(id<WebStateHandle>)webState { | |
| 75 return [_list indexOfObject:webState]; | |
| 76 } | |
| 77 | |
| 78 @end | |
| OLD | NEW |