OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ui/settings/time_range_selector_collection_view_cont
roller.h" | 5 #import "ios/chrome/browser/ui/settings/time_range_selector_collection_view_cont
roller.h" |
6 | 6 |
7 #import "base/ios/weak_nsobject.h" | 7 #import "base/ios/weak_nsobject.h" |
8 #import "base/mac/foundation_util.h" | 8 #import "base/mac/foundation_util.h" |
9 #import "base/mac/scoped_nsobject.h" | 9 #import "base/mac/scoped_nsobject.h" |
10 #include "components/browsing_data/core/pref_names.h" | 10 #include "components/browsing_data/core/pref_names.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 ItemTypeBeginningOfTime, | 30 ItemTypeBeginningOfTime, |
31 }; | 31 }; |
32 | 32 |
33 const int kStringIDS[] = { | 33 const int kStringIDS[] = { |
34 IDS_IOS_CLEAR_BROWSING_DATA_TIME_RANGE_OPTION_PAST_HOUR, | 34 IDS_IOS_CLEAR_BROWSING_DATA_TIME_RANGE_OPTION_PAST_HOUR, |
35 IDS_IOS_CLEAR_BROWSING_DATA_TIME_RANGE_OPTION_PAST_DAY, | 35 IDS_IOS_CLEAR_BROWSING_DATA_TIME_RANGE_OPTION_PAST_DAY, |
36 IDS_IOS_CLEAR_BROWSING_DATA_TIME_RANGE_OPTION_PAST_WEEK, | 36 IDS_IOS_CLEAR_BROWSING_DATA_TIME_RANGE_OPTION_PAST_WEEK, |
37 IDS_IOS_CLEAR_BROWSING_DATA_TIME_RANGE_OPTION_LAST_FOUR_WEEKS, | 37 IDS_IOS_CLEAR_BROWSING_DATA_TIME_RANGE_OPTION_LAST_FOUR_WEEKS, |
38 IDS_IOS_CLEAR_BROWSING_DATA_TIME_RANGE_OPTION_BEGINNING_OF_TIME}; | 38 IDS_IOS_CLEAR_BROWSING_DATA_TIME_RANGE_OPTION_BEGINNING_OF_TIME}; |
39 | 39 |
40 static_assert(arraysize(kStringIDS) == browsing_data::TIME_PERIOD_LAST + 1, | 40 static_assert( |
41 "Strings have to match the enum values."); | 41 arraysize(kStringIDS) == |
| 42 static_cast<int>(browsing_data::TimePeriod::TIME_PERIOD_LAST) + 1, |
| 43 "Strings have to match the enum values."); |
42 | 44 |
43 } // namespace | 45 } // namespace |
44 | 46 |
45 @interface TimeRangeSelectorCollectionViewController () { | 47 @interface TimeRangeSelectorCollectionViewController () { |
46 // Instance of the parent view controller needed in order to set the time | 48 // Instance of the parent view controller needed in order to set the time |
47 // range for the browsing data deletion. | 49 // range for the browsing data deletion. |
48 base::WeakNSProtocol<id<TimeRangeSelectorCollectionViewControllerDelegate>> | 50 base::WeakNSProtocol<id<TimeRangeSelectorCollectionViewControllerDelegate>> |
49 _weakDelegate; | 51 _weakDelegate; |
50 IntegerPrefMember timeRangePref_; | 52 IntegerPrefMember timeRangePref_; |
51 } | 53 } |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 } | 145 } |
144 | 146 |
145 #pragma mark - UICollectionViewDelegate | 147 #pragma mark - UICollectionViewDelegate |
146 | 148 |
147 - (void)collectionView:(UICollectionView*)collectionView | 149 - (void)collectionView:(UICollectionView*)collectionView |
148 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { | 150 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { |
149 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; | 151 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; |
150 NSInteger itemType = | 152 NSInteger itemType = |
151 [self.collectionViewModel itemTypeForIndexPath:indexPath]; | 153 [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
152 int timePeriod = itemType - kItemTypeEnumZero; | 154 int timePeriod = itemType - kItemTypeEnumZero; |
153 DCHECK_LE(timePeriod, browsing_data::TIME_PERIOD_LAST); | 155 DCHECK_LE(timePeriod, |
| 156 static_cast<int>(browsing_data::TimePeriod::TIME_PERIOD_LAST)); |
154 [self updatePrefValue:timePeriod]; | 157 [self updatePrefValue:timePeriod]; |
155 [_weakDelegate | 158 [_weakDelegate |
156 timeRangeSelectorViewController:self | 159 timeRangeSelectorViewController:self |
157 didSelectTimePeriod:static_cast<browsing_data::TimePeriod>( | 160 didSelectTimePeriod:static_cast<browsing_data::TimePeriod>( |
158 timePeriod)]; | 161 timePeriod)]; |
159 } | 162 } |
160 | 163 |
161 #pragma mark - Class methods | 164 #pragma mark - Class methods |
162 | 165 |
163 + (NSString*)timePeriodLabelForPrefs:(PrefService*)prefs { | 166 + (NSString*)timePeriodLabelForPrefs:(PrefService*)prefs { |
164 if (!prefs) | 167 if (!prefs) |
165 return nil; | 168 return nil; |
166 int prefValue = prefs->GetInteger(browsing_data::prefs::kDeleteTimePeriod); | 169 int prefValue = prefs->GetInteger(browsing_data::prefs::kDeleteTimePeriod); |
167 if (prefValue < 0 || static_cast<size_t>(prefValue) >= arraysize(kStringIDS)) | 170 if (prefValue < 0 || static_cast<size_t>(prefValue) >= arraysize(kStringIDS)) |
168 return nil; | 171 return nil; |
169 return l10n_util::GetNSString(kStringIDS[prefValue]); | 172 return l10n_util::GetNSString(kStringIDS[prefValue]); |
170 } | 173 } |
171 | 174 |
172 @end | 175 @end |
OLD | NEW |