| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/sync_encryption_collection_view_controll
er.h" | 5 #import "ios/chrome/browser/ui/settings/sync_encryption_collection_view_controll
er.h" |
| 6 | 6 |
| 7 #import "base/ios/weak_nsobject.h" | |
| 8 #import "base/mac/scoped_nsobject.h" | |
| 9 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 11 #include "components/browser_sync/profile_sync_service.h" | 9 #include "components/browser_sync/profile_sync_service.h" |
| 12 #include "components/google/core/browser/google_util.h" | 10 #include "components/google/core/browser/google_util.h" |
| 13 #include "components/strings/grit/components_strings.h" | 11 #include "components/strings/grit/components_strings.h" |
| 14 #include "components/sync/base/sync_prefs.h" | 12 #include "components/sync/base/sync_prefs.h" |
| 15 #include "ios/chrome/browser/application_context.h" | 13 #include "ios/chrome/browser/application_context.h" |
| 16 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 14 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 17 #include "ios/chrome/browser/chrome_url_constants.h" | 15 #include "ios/chrome/browser/chrome_url_constants.h" |
| 18 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h" | 16 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h" |
| 19 #import "ios/chrome/browser/sync/sync_observer_bridge.h" | 17 #import "ios/chrome/browser/sync/sync_observer_bridge.h" |
| 20 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" | 18 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" |
| 21 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item
.h" | 19 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item
.h" |
| 22 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" | 20 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" |
| 23 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 21 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
| 24 #import "ios/chrome/browser/ui/settings/cells/encryption_item.h" | 22 #import "ios/chrome/browser/ui/settings/cells/encryption_item.h" |
| 25 #import "ios/chrome/browser/ui/settings/settings_utils.h" | 23 #import "ios/chrome/browser/ui/settings/settings_utils.h" |
| 26 #import "ios/chrome/browser/ui/settings/sync_create_passphrase_collection_view_c
ontroller.h" | 24 #import "ios/chrome/browser/ui/settings/sync_create_passphrase_collection_view_c
ontroller.h" |
| 27 #import "ios/chrome/browser/ui/settings/sync_encryption_passphrase_collection_vi
ew_controller.h" | 25 #import "ios/chrome/browser/ui/settings/sync_encryption_passphrase_collection_vi
ew_controller.h" |
| 28 #include "ios/chrome/grit/ios_strings.h" | 26 #include "ios/chrome/grit/ios_strings.h" |
| 29 #include "ui/base/l10n/l10n_util_mac.h" | 27 #include "ui/base/l10n/l10n_util_mac.h" |
| 30 #include "url/gurl.h" | 28 #include "url/gurl.h" |
| 31 | 29 |
| 30 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 31 #error "This file requires ARC support." |
| 32 #endif |
| 33 |
| 32 namespace { | 34 namespace { |
| 33 | 35 |
| 34 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 36 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
| 35 SectionIdentifierEncryption = kSectionIdentifierEnumZero, | 37 SectionIdentifierEncryption = kSectionIdentifierEnumZero, |
| 36 SectionIdentifierFooter, | 38 SectionIdentifierFooter, |
| 37 }; | 39 }; |
| 38 | 40 |
| 39 typedef NS_ENUM(NSInteger, ItemType) { | 41 typedef NS_ENUM(NSInteger, ItemType) { |
| 40 ItemTypeAccount = kItemTypeEnumZero, | 42 ItemTypeAccount = kItemTypeEnumZero, |
| 41 ItemTypePassphrase, | 43 ItemTypePassphrase, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 - (CollectionViewItem*)passphraseItem { | 112 - (CollectionViewItem*)passphraseItem { |
| 111 DCHECK(browser_sync::ProfileSyncService::IsSyncAllowedByFlag()); | 113 DCHECK(browser_sync::ProfileSyncService::IsSyncAllowedByFlag()); |
| 112 NSString* text = l10n_util::GetNSString(IDS_SYNC_FULL_ENCRYPTION_DATA); | 114 NSString* text = l10n_util::GetNSString(IDS_SYNC_FULL_ENCRYPTION_DATA); |
| 113 return [self itemWithType:ItemTypePassphrase | 115 return [self itemWithType:ItemTypePassphrase |
| 114 text:text | 116 text:text |
| 115 checked:_isUsingSecondaryPassphrase | 117 checked:_isUsingSecondaryPassphrase |
| 116 enabled:!_isUsingSecondaryPassphrase]; | 118 enabled:!_isUsingSecondaryPassphrase]; |
| 117 } | 119 } |
| 118 | 120 |
| 119 - (CollectionViewItem*)footerItem { | 121 - (CollectionViewItem*)footerItem { |
| 120 CollectionViewFooterItem* footerItem = [[[CollectionViewFooterItem alloc] | 122 CollectionViewFooterItem* footerItem = |
| 121 initWithType:ItemTypeFooter] autorelease]; | 123 [[CollectionViewFooterItem alloc] initWithType:ItemTypeFooter]; |
| 122 footerItem.text = | 124 footerItem.text = |
| 123 l10n_util::GetNSString(IDS_IOS_SYNC_ENCRYPTION_PASSPHRASE_HINT); | 125 l10n_util::GetNSString(IDS_IOS_SYNC_ENCRYPTION_PASSPHRASE_HINT); |
| 124 footerItem.linkURL = google_util::AppendGoogleLocaleParam( | 126 footerItem.linkURL = google_util::AppendGoogleLocaleParam( |
| 125 GURL(kSyncGoogleDashboardURL), | 127 GURL(kSyncGoogleDashboardURL), |
| 126 GetApplicationContext()->GetApplicationLocale()); | 128 GetApplicationContext()->GetApplicationLocale()); |
| 127 footerItem.linkDelegate = self; | 129 footerItem.linkDelegate = self; |
| 128 return footerItem; | 130 return footerItem; |
| 129 } | 131 } |
| 130 | 132 |
| 131 #pragma mark - MDCCollectionViewStylingDelegate | 133 #pragma mark - MDCCollectionViewStylingDelegate |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 return; | 186 return; |
| 185 } | 187 } |
| 186 | 188 |
| 187 switch (item.type) { | 189 switch (item.type) { |
| 188 case ItemTypePassphrase: { | 190 case ItemTypePassphrase: { |
| 189 DCHECK(browser_sync::ProfileSyncService::IsSyncAllowedByFlag()); | 191 DCHECK(browser_sync::ProfileSyncService::IsSyncAllowedByFlag()); |
| 190 browser_sync::ProfileSyncService* service = | 192 browser_sync::ProfileSyncService* service = |
| 191 IOSChromeProfileSyncServiceFactory::GetForBrowserState(_browserState); | 193 IOSChromeProfileSyncServiceFactory::GetForBrowserState(_browserState); |
| 192 if (service->IsEngineInitialized() && | 194 if (service->IsEngineInitialized() && |
| 193 !service->IsUsingSecondaryPassphrase()) { | 195 !service->IsUsingSecondaryPassphrase()) { |
| 194 base::scoped_nsobject<SyncCreatePassphraseCollectionViewController> | 196 SyncCreatePassphraseCollectionViewController* controller = |
| 195 controller([[SyncCreatePassphraseCollectionViewController alloc] | 197 [[SyncCreatePassphraseCollectionViewController alloc] |
| 196 initWithBrowserState:_browserState]); | 198 initWithBrowserState:_browserState]; |
| 197 [self.navigationController pushViewController:controller animated:YES]; | 199 [self.navigationController pushViewController:controller animated:YES]; |
| 198 } | 200 } |
| 199 break; | 201 break; |
| 200 } | 202 } |
| 201 case ItemTypeAccount: | 203 case ItemTypeAccount: |
| 202 case ItemTypeFooter: | 204 case ItemTypeFooter: |
| 203 default: | 205 default: |
| 204 break; | 206 break; |
| 205 } | 207 } |
| 206 } | 208 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 217 [self reloadData]; | 219 [self reloadData]; |
| 218 } | 220 } |
| 219 } | 221 } |
| 220 | 222 |
| 221 #pragma mark - Private methods | 223 #pragma mark - Private methods |
| 222 | 224 |
| 223 - (CollectionViewItem*)itemWithType:(NSInteger)type | 225 - (CollectionViewItem*)itemWithType:(NSInteger)type |
| 224 text:(NSString*)text | 226 text:(NSString*)text |
| 225 checked:(BOOL)checked | 227 checked:(BOOL)checked |
| 226 enabled:(BOOL)enabled { | 228 enabled:(BOOL)enabled { |
| 227 EncryptionItem* item = | 229 EncryptionItem* item = [[EncryptionItem alloc] initWithType:type]; |
| 228 [[[EncryptionItem alloc] initWithType:type] autorelease]; | |
| 229 item.text = text; | 230 item.text = text; |
| 230 item.accessoryType = checked ? MDCCollectionViewCellAccessoryCheckmark | 231 item.accessoryType = checked ? MDCCollectionViewCellAccessoryCheckmark |
| 231 : MDCCollectionViewCellAccessoryNone; | 232 : MDCCollectionViewCellAccessoryNone; |
| 232 item.enabled = enabled; | 233 item.enabled = enabled; |
| 233 return item; | 234 return item; |
| 234 } | 235 } |
| 235 | 236 |
| 236 @end | 237 @end |
| OLD | NEW |