Chromium Code Reviews| 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" | 7 #import "base/ios/weak_nsobject.h" |
| 8 #import "base/mac/scoped_nsobject.h" | 8 #import "base/mac/scoped_nsobject.h" |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #include "components/browser_sync/profile_sync_service.h" | 10 #include "components/browser_sync/profile_sync_service.h" |
| 11 #include "components/google/core/browser/google_util.h" | 11 #include "components/google/core/browser/google_util.h" |
| 12 #include "components/strings/grit/components_strings.h" | 12 #include "components/strings/grit/components_strings.h" |
| 13 #include "components/sync/base/sync_prefs.h" | 13 #include "components/sync/base/sync_prefs.h" |
| 14 #include "ios/chrome/browser/application_context.h" | 14 #include "ios/chrome/browser/application_context.h" |
| 15 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 15 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 16 #include "ios/chrome/browser/chrome_url_constants.h" | 16 #include "ios/chrome/browser/chrome_url_constants.h" |
| 17 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h" | 17 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h" |
| 18 #import "ios/chrome/browser/sync/sync_observer_bridge.h" | |
| 18 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h" | 19 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h" |
| 19 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item .h" | 20 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item .h" |
| 20 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" | 21 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" |
| 21 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 22 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
| 22 #import "ios/chrome/browser/ui/settings/cells/encryption_item.h" | 23 #import "ios/chrome/browser/ui/settings/cells/encryption_item.h" |
| 23 #import "ios/chrome/browser/ui/settings/settings_utils.h" | 24 #import "ios/chrome/browser/ui/settings/settings_utils.h" |
| 24 #import "ios/chrome/browser/ui/settings/sync_create_passphrase_collection_view_c ontroller.h" | 25 #import "ios/chrome/browser/ui/settings/sync_create_passphrase_collection_view_c ontroller.h" |
| 25 #import "ios/chrome/browser/ui/settings/sync_encryption_passphrase_collection_vi ew_controller.h" | 26 #import "ios/chrome/browser/ui/settings/sync_encryption_passphrase_collection_vi ew_controller.h" |
| 26 #include "ios/chrome/grit/ios_strings.h" | 27 #include "ios/chrome/grit/ios_strings.h" |
| 27 #include "ui/base/l10n/l10n_util_mac.h" | 28 #include "ui/base/l10n/l10n_util_mac.h" |
| 28 #include "url/gurl.h" | 29 #include "url/gurl.h" |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| 31 | 32 |
| 32 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 33 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
| 33 SectionIdentifierEncryption = kSectionIdentifierEnumZero, | 34 SectionIdentifierEncryption = kSectionIdentifierEnumZero, |
| 34 SectionIdentifierFooter, | 35 SectionIdentifierFooter, |
| 35 }; | 36 }; |
| 36 | 37 |
| 37 typedef NS_ENUM(NSInteger, ItemType) { | 38 typedef NS_ENUM(NSInteger, ItemType) { |
| 38 ItemTypeAccount = kItemTypeEnumZero, | 39 ItemTypeAccount = kItemTypeEnumZero, |
| 39 ItemTypePassphrase, | 40 ItemTypePassphrase, |
| 40 ItemTypeFooter, | 41 ItemTypeFooter, |
| 41 }; | 42 }; |
| 42 | 43 |
| 43 } // namespace | 44 } // namespace |
| 44 | 45 |
| 45 @interface SyncEncryptionCollectionViewController () { | 46 @interface SyncEncryptionCollectionViewController ()<SyncObserverModelBridge> { |
| 46 ios::ChromeBrowserState* _browserState; | 47 ios::ChromeBrowserState* _browserState; |
| 48 std::unique_ptr<SyncObserverBridge> _syncObserver; | |
| 49 BOOL _isUsingSecondaryPassphrase; | |
| 47 } | 50 } |
| 48 // Returns an account item. | 51 // Returns an account item. |
| 49 - (CollectionViewItem*)accountItem; | 52 - (CollectionViewItem*)accountItem; |
| 50 | 53 |
| 51 // Returns a passphrase item. | 54 // Returns a passphrase item. |
| 52 - (CollectionViewItem*)passphraseItem; | 55 - (CollectionViewItem*)passphraseItem; |
| 53 | 56 |
| 54 // Returns a footer item with a link. | 57 // Returns a footer item with a link. |
| 55 - (CollectionViewItem*)footerItem; | 58 - (CollectionViewItem*)footerItem; |
| 56 @end | 59 @end |
| 57 | 60 |
| 58 @implementation SyncEncryptionCollectionViewController | 61 @implementation SyncEncryptionCollectionViewController |
| 59 | 62 |
| 60 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState { | 63 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState { |
| 61 DCHECK(browserState); | 64 DCHECK(browserState); |
| 62 self = [super initWithStyle:CollectionViewControllerStyleAppBar]; | 65 self = [super initWithStyle:CollectionViewControllerStyleAppBar]; |
| 63 if (self) { | 66 if (self) { |
| 64 self.title = l10n_util::GetNSString(IDS_IOS_SYNC_ENCRYPTION_TITLE); | 67 self.title = l10n_util::GetNSString(IDS_IOS_SYNC_ENCRYPTION_TITLE); |
| 65 _browserState = browserState; | 68 _browserState = browserState; |
| 69 browser_sync::ProfileSyncService* syncService = | |
| 70 IOSChromeProfileSyncServiceFactory::GetForBrowserState(_browserState); | |
| 71 _isUsingSecondaryPassphrase = syncService->IsEngineInitialized() && | |
| 72 syncService->IsUsingSecondaryPassphrase(); | |
| 73 _syncObserver.reset(new SyncObserverBridge(self, syncService)); | |
|
lpromero
2017/01/06 11:01:07
Use MakeUnique instead of new.
bzanotti
2017/01/06 12:41:26
Done.
| |
| 66 [self loadModel]; | 74 [self loadModel]; |
| 67 } | 75 } |
| 68 return self; | 76 return self; |
| 69 } | 77 } |
| 70 | 78 |
| 71 #pragma mark - SettingsRootCollectionViewController | 79 #pragma mark - SettingsRootCollectionViewController |
| 72 | 80 |
| 73 - (void)loadModel { | 81 - (void)loadModel { |
| 74 [super loadModel]; | 82 [super loadModel]; |
| 75 CollectionViewModel* model = self.collectionViewModel; | 83 CollectionViewModel* model = self.collectionViewModel; |
| 76 | 84 |
| 77 [model addSectionWithIdentifier:SectionIdentifierEncryption]; | 85 [model addSectionWithIdentifier:SectionIdentifierEncryption]; |
| 78 [model addItem:[self accountItem] | 86 [model addItem:[self accountItem] |
| 79 toSectionWithIdentifier:SectionIdentifierEncryption]; | 87 toSectionWithIdentifier:SectionIdentifierEncryption]; |
| 80 [model addItem:[self passphraseItem] | 88 [model addItem:[self passphraseItem] |
| 81 toSectionWithIdentifier:SectionIdentifierEncryption]; | 89 toSectionWithIdentifier:SectionIdentifierEncryption]; |
| 82 | 90 |
| 83 browser_sync::ProfileSyncService* service = | 91 if (_isUsingSecondaryPassphrase) { |
| 84 IOSChromeProfileSyncServiceFactory::GetForBrowserState(_browserState); | |
| 85 if (service->IsEngineInitialized() && service->IsUsingSecondaryPassphrase()) { | |
| 86 [model addSectionWithIdentifier:SectionIdentifierFooter]; | 92 [model addSectionWithIdentifier:SectionIdentifierFooter]; |
| 87 [model addItem:[self footerItem] | 93 [model addItem:[self footerItem] |
| 88 toSectionWithIdentifier:SectionIdentifierFooter]; | 94 toSectionWithIdentifier:SectionIdentifierFooter]; |
| 89 } | 95 } |
| 90 } | 96 } |
| 91 | 97 |
| 92 #pragma mark - Items | 98 #pragma mark - Items |
| 93 | 99 |
| 94 - (CollectionViewItem*)accountItem { | 100 - (CollectionViewItem*)accountItem { |
| 95 DCHECK(browser_sync::ProfileSyncService::IsSyncAllowedByFlag()); | 101 DCHECK(browser_sync::ProfileSyncService::IsSyncAllowedByFlag()); |
| 96 BOOL checkedAndEnabled = YES; | |
| 97 browser_sync::ProfileSyncService* service = | |
| 98 IOSChromeProfileSyncServiceFactory::GetForBrowserState(_browserState); | |
| 99 if (service->IsEngineInitialized() && service->IsUsingSecondaryPassphrase()) { | |
| 100 checkedAndEnabled = NO; | |
| 101 } | |
| 102 NSString* text = l10n_util::GetNSString(IDS_SYNC_BASIC_ENCRYPTION_DATA); | 102 NSString* text = l10n_util::GetNSString(IDS_SYNC_BASIC_ENCRYPTION_DATA); |
| 103 return [self itemWithType:ItemTypeAccount | 103 return [self itemWithType:ItemTypeAccount |
| 104 text:text | 104 text:text |
| 105 checked:checkedAndEnabled | 105 checked:!_isUsingSecondaryPassphrase |
| 106 enabled:checkedAndEnabled]; | 106 enabled:!_isUsingSecondaryPassphrase]; |
| 107 } | 107 } |
| 108 | 108 |
| 109 - (CollectionViewItem*)passphraseItem { | 109 - (CollectionViewItem*)passphraseItem { |
| 110 DCHECK(browser_sync::ProfileSyncService::IsSyncAllowedByFlag()); | 110 DCHECK(browser_sync::ProfileSyncService::IsSyncAllowedByFlag()); |
| 111 BOOL checked = NO; | |
| 112 BOOL enabled = NO; | |
| 113 browser_sync::ProfileSyncService* service = | |
| 114 IOSChromeProfileSyncServiceFactory::GetForBrowserState(_browserState); | |
| 115 if (service->IsEngineInitialized() && service->IsUsingSecondaryPassphrase()) { | |
| 116 checked = YES; | |
| 117 } else { | |
| 118 enabled = YES; | |
| 119 } | |
| 120 NSString* text = l10n_util::GetNSString(IDS_SYNC_FULL_ENCRYPTION_DATA); | 111 NSString* text = l10n_util::GetNSString(IDS_SYNC_FULL_ENCRYPTION_DATA); |
| 121 return [self itemWithType:ItemTypePassphrase | 112 return [self itemWithType:ItemTypePassphrase |
| 122 text:text | 113 text:text |
| 123 checked:checked | 114 checked:_isUsingSecondaryPassphrase |
| 124 enabled:enabled]; | 115 enabled:!_isUsingSecondaryPassphrase]; |
| 125 } | 116 } |
| 126 | 117 |
| 127 - (CollectionViewItem*)footerItem { | 118 - (CollectionViewItem*)footerItem { |
| 128 CollectionViewFooterItem* footerItem = [[[CollectionViewFooterItem alloc] | 119 CollectionViewFooterItem* footerItem = [[[CollectionViewFooterItem alloc] |
| 129 initWithType:ItemTypeFooter] autorelease]; | 120 initWithType:ItemTypeFooter] autorelease]; |
| 130 footerItem.text = | 121 footerItem.text = |
| 131 l10n_util::GetNSString(IDS_IOS_SYNC_ENCRYPTION_PASSPHRASE_HINT); | 122 l10n_util::GetNSString(IDS_IOS_SYNC_ENCRYPTION_PASSPHRASE_HINT); |
| 132 footerItem.linkURL = google_util::AppendGoogleLocaleParam( | 123 footerItem.linkURL = google_util::AppendGoogleLocaleParam( |
| 133 GURL(kSyncGoogleDashboardURL), | 124 GURL(kSyncGoogleDashboardURL), |
| 134 GetApplicationContext()->GetApplicationLocale()); | 125 GetApplicationContext()->GetApplicationLocale()); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 } | 197 } |
| 207 break; | 198 break; |
| 208 } | 199 } |
| 209 case ItemTypeAccount: | 200 case ItemTypeAccount: |
| 210 case ItemTypeFooter: | 201 case ItemTypeFooter: |
| 211 default: | 202 default: |
| 212 break; | 203 break; |
| 213 } | 204 } |
| 214 } | 205 } |
| 215 | 206 |
| 207 #pragma mark SyncObserverModelBridge | |
| 208 | |
| 209 - (void)onSyncStateChanged { | |
| 210 browser_sync::ProfileSyncService* service = | |
| 211 IOSChromeProfileSyncServiceFactory::GetForBrowserState(_browserState); | |
| 212 BOOL isNowUsingSecondaryPassphrase = | |
| 213 service->IsEngineInitialized() && service->IsUsingSecondaryPassphrase(); | |
| 214 if (_isUsingSecondaryPassphrase != isNowUsingSecondaryPassphrase) { | |
| 215 _isUsingSecondaryPassphrase = isNowUsingSecondaryPassphrase; | |
| 216 [self reloadData]; | |
| 217 } | |
| 218 } | |
| 219 | |
| 216 #pragma mark - Private methods | 220 #pragma mark - Private methods |
| 217 | 221 |
| 218 - (CollectionViewItem*)itemWithType:(NSInteger)type | 222 - (CollectionViewItem*)itemWithType:(NSInteger)type |
| 219 text:(NSString*)text | 223 text:(NSString*)text |
| 220 checked:(BOOL)checked | 224 checked:(BOOL)checked |
| 221 enabled:(BOOL)enabled { | 225 enabled:(BOOL)enabled { |
| 222 EncryptionItem* item = | 226 EncryptionItem* item = |
| 223 [[[EncryptionItem alloc] initWithType:type] autorelease]; | 227 [[[EncryptionItem alloc] initWithType:type] autorelease]; |
| 224 item.text = text; | 228 item.text = text; |
| 225 item.accessoryType = checked ? MDCCollectionViewCellAccessoryCheckmark | 229 item.accessoryType = checked ? MDCCollectionViewCellAccessoryCheckmark |
| 226 : MDCCollectionViewCellAccessoryNone; | 230 : MDCCollectionViewCellAccessoryNone; |
| 227 item.enabled = enabled; | 231 item.enabled = enabled; |
| 228 return item; | 232 return item; |
| 229 } | 233 } |
| 230 | 234 |
| 231 @end | 235 @end |
| OLD | NEW |