OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "ios/chrome/browser/sessions/session_window_ios.h" | 5 #import "ios/chrome/browser/sessions/session_window_ios.h" |
6 | 6 |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #import "base/mac/foundation_util.h" | 9 #import "base/mac/foundation_util.h" |
10 #import "ios/chrome/browser/sessions/NSCoder+Compatibility.h" | 10 #import "ios/chrome/browser/sessions/NSCoder+Compatibility.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 DCHECK(sessions); | 42 DCHECK(sessions); |
43 DCHECK(IsIndexValidForSessionCount(selectedIndex, [sessions count])); | 43 DCHECK(IsIndexValidForSessionCount(selectedIndex, [sessions count])); |
44 self = [super init]; | 44 self = [super init]; |
45 if (self) { | 45 if (self) { |
46 _sessions = [sessions copy]; | 46 _sessions = [sessions copy]; |
47 _selectedIndex = selectedIndex; | 47 _selectedIndex = selectedIndex; |
48 } | 48 } |
49 return self; | 49 return self; |
50 } | 50 } |
51 | 51 |
52 - (void)clearSessions { | |
53 _sessions = @[]; | |
54 _selectedIndex = NSNotFound; | |
55 } | |
56 | |
57 #pragma mark - NSCoding | 52 #pragma mark - NSCoding |
58 | 53 |
59 - (instancetype)initWithCoder:(NSCoder*)aDecoder { | 54 - (instancetype)initWithCoder:(NSCoder*)aDecoder { |
60 NSUInteger selectedIndex = [aDecoder cr_decodeIndexForKey:kSelectedIndexKey]; | 55 NSUInteger selectedIndex = [aDecoder cr_decodeIndexForKey:kSelectedIndexKey]; |
61 NSArray<CRWSessionStorage*>* sessions = | 56 NSArray<CRWSessionStorage*>* sessions = |
62 base::mac::ObjCCast<NSArray<CRWSessionStorage*>>( | 57 base::mac::ObjCCast<NSArray<CRWSessionStorage*>>( |
63 [aDecoder decodeObjectForKey:kSessionsKey]); | 58 [aDecoder decodeObjectForKey:kSessionsKey]); |
64 | 59 |
65 if (!sessions) { | 60 if (!sessions) { |
66 sessions = @[]; | 61 sessions = @[]; |
(...skipping 17 matching lines...) Expand all Loading... |
84 | 79 |
85 #pragma mark - Debugging | 80 #pragma mark - Debugging |
86 | 81 |
87 - (NSString*)description { | 82 - (NSString*)description { |
88 return [NSString stringWithFormat:@"selected index: %" PRIuNS | 83 return [NSString stringWithFormat:@"selected index: %" PRIuNS |
89 "\nsessions:\n%@\n", | 84 "\nsessions:\n%@\n", |
90 _selectedIndex, _sessions]; | 85 _selectedIndex, _sessions]; |
91 } | 86 } |
92 | 87 |
93 @end | 88 @end |
OLD | NEW |