| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_settings_collection_view_controller
.h" | 5 #import "ios/chrome/browser/ui/settings/sync_settings_collection_view_controller
.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
| (...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 } | 716 } |
| 717 | 717 |
| 718 - (void)updateCollectionViewInternal { | 718 - (void)updateCollectionViewInternal { |
| 719 NSIndexPath* indexPath = [self.collectionViewModel | 719 NSIndexPath* indexPath = [self.collectionViewModel |
| 720 indexPathForItemType:ItemTypeSyncSwitch | 720 indexPathForItemType:ItemTypeSyncSwitch |
| 721 sectionIdentifier:SectionIdentifierEnableSync]; | 721 sectionIdentifier:SectionIdentifierEnableSync]; |
| 722 | 722 |
| 723 SyncSwitchItem* syncItem = base::mac::ObjCCastStrict<SyncSwitchItem>( | 723 SyncSwitchItem* syncItem = base::mac::ObjCCastStrict<SyncSwitchItem>( |
| 724 [self.collectionViewModel itemAtIndexPath:indexPath]); | 724 [self.collectionViewModel itemAtIndexPath:indexPath]); |
| 725 syncItem.on = _syncSetupService->IsSyncEnabled(); | 725 syncItem.on = _syncSetupService->IsSyncEnabled(); |
| 726 [self reconfigureCellsForItems:@[ syncItem ] | 726 [self reconfigureCellsForItems:@[ syncItem ]]; |
| 727 inSectionWithIdentifier:SectionIdentifierEnableSync]; | |
| 728 | 727 |
| 729 // Update Sync Accounts section. | 728 // Update Sync Accounts section. |
| 730 if ([self hasAccountsSection]) { | 729 if ([self hasAccountsSection]) { |
| 731 NSInteger section = [self.collectionViewModel | 730 NSInteger section = [self.collectionViewModel |
| 732 sectionForSectionIdentifier:SectionIdentifierSyncAccounts]; | 731 sectionForSectionIdentifier:SectionIdentifierSyncAccounts]; |
| 733 NSInteger itemsCount = | 732 NSInteger itemsCount = |
| 734 [self.collectionViewModel numberOfItemsInSection:section]; | 733 [self.collectionViewModel numberOfItemsInSection:section]; |
| 735 NSMutableArray* accountsToReconfigure = | 734 NSMutableArray* accountsToReconfigure = |
| 736 [[[NSMutableArray alloc] init] autorelease]; | 735 [[[NSMutableArray alloc] init] autorelease]; |
| 737 for (NSInteger item = 0; item < itemsCount; ++item) { | 736 for (NSInteger item = 0; item < itemsCount; ++item) { |
| 738 NSIndexPath* indexPath = [self.collectionViewModel | 737 NSIndexPath* indexPath = [self.collectionViewModel |
| 739 indexPathForItemType:ItemTypeAccount | 738 indexPathForItemType:ItemTypeAccount |
| 740 sectionIdentifier:SectionIdentifierSyncAccounts | 739 sectionIdentifier:SectionIdentifierSyncAccounts |
| 741 atIndex:item]; | 740 atIndex:item]; |
| 742 CollectionViewAccountItem* accountItem = | 741 CollectionViewAccountItem* accountItem = |
| 743 base::mac::ObjCCastStrict<CollectionViewAccountItem>( | 742 base::mac::ObjCCastStrict<CollectionViewAccountItem>( |
| 744 [self.collectionViewModel itemAtIndexPath:indexPath]); | 743 [self.collectionViewModel itemAtIndexPath:indexPath]); |
| 745 accountItem.enabled = _syncSetupService->IsSyncEnabled(); | 744 accountItem.enabled = _syncSetupService->IsSyncEnabled(); |
| 746 [accountsToReconfigure addObject:accountItem]; | 745 [accountsToReconfigure addObject:accountItem]; |
| 747 } | 746 } |
| 748 [self reconfigureCellsForItems:accountsToReconfigure | 747 [self reconfigureCellsForItems:accountsToReconfigure]; |
| 749 inSectionWithIdentifier:SectionIdentifierSyncAccounts]; | |
| 750 } | 748 } |
| 751 | 749 |
| 752 // Update Sync Services section. | 750 // Update Sync Services section. |
| 753 indexPath = [self.collectionViewModel | 751 indexPath = [self.collectionViewModel |
| 754 indexPathForItemType:ItemTypeSyncEverything | 752 indexPathForItemType:ItemTypeSyncEverything |
| 755 sectionIdentifier:SectionIdentifierSyncServices]; | 753 sectionIdentifier:SectionIdentifierSyncServices]; |
| 756 SyncSwitchItem* syncEverythingItem = | 754 SyncSwitchItem* syncEverythingItem = |
| 757 base::mac::ObjCCastStrict<SyncSwitchItem>( | 755 base::mac::ObjCCastStrict<SyncSwitchItem>( |
| 758 [self.collectionViewModel itemAtIndexPath:indexPath]); | 756 [self.collectionViewModel itemAtIndexPath:indexPath]); |
| 759 syncEverythingItem.on = _syncSetupService->IsSyncingAllDataTypes(); | 757 syncEverythingItem.on = _syncSetupService->IsSyncingAllDataTypes(); |
| 760 syncEverythingItem.enabled = [self shouldSyncEverythingItemBeEnabled]; | 758 syncEverythingItem.enabled = [self shouldSyncEverythingItemBeEnabled]; |
| 761 [self reconfigureCellsForItems:@[ syncEverythingItem ] | 759 [self reconfigureCellsForItems:@[ syncEverythingItem ]]; |
| 762 inSectionWithIdentifier:SectionIdentifierSyncServices]; | |
| 763 | 760 |
| 764 NSInteger section = [self.collectionViewModel | 761 NSInteger section = [self.collectionViewModel |
| 765 sectionForSectionIdentifier:SectionIdentifierSyncServices]; | 762 sectionForSectionIdentifier:SectionIdentifierSyncServices]; |
| 766 NSInteger itemsCount = | 763 NSInteger itemsCount = |
| 767 [self.collectionViewModel numberOfItemsInSection:section]; | 764 [self.collectionViewModel numberOfItemsInSection:section]; |
| 768 // Syncable data types cells are offset by the Sync Everything cell. | 765 // Syncable data types cells are offset by the Sync Everything cell. |
| 769 NSMutableArray* switchsToReconfigure = | 766 NSMutableArray* switchsToReconfigure = |
| 770 [[[NSMutableArray alloc] init] autorelease]; | 767 [[[NSMutableArray alloc] init] autorelease]; |
| 771 for (NSInteger item = 1; item < itemsCount; ++item) { | 768 for (NSInteger item = 1; item < itemsCount; ++item) { |
| 772 NSUInteger index = item - 1; | 769 NSUInteger index = item - 1; |
| 773 NSIndexPath* indexPath = [self.collectionViewModel | 770 NSIndexPath* indexPath = [self.collectionViewModel |
| 774 indexPathForItemType:ItemTypeSyncableDataType | 771 indexPathForItemType:ItemTypeSyncableDataType |
| 775 sectionIdentifier:SectionIdentifierSyncServices | 772 sectionIdentifier:SectionIdentifierSyncServices |
| 776 atIndex:index]; | 773 atIndex:index]; |
| 777 SyncSwitchItem* syncSwitchItem = base::mac::ObjCCastStrict<SyncSwitchItem>( | 774 SyncSwitchItem* syncSwitchItem = base::mac::ObjCCastStrict<SyncSwitchItem>( |
| 778 [self.collectionViewModel itemAtIndexPath:indexPath]); | 775 [self.collectionViewModel itemAtIndexPath:indexPath]); |
| 779 SyncSetupService::SyncableDatatype dataType = | 776 SyncSetupService::SyncableDatatype dataType = |
| 780 (SyncSetupService::SyncableDatatype)syncSwitchItem.dataType; | 777 (SyncSetupService::SyncableDatatype)syncSwitchItem.dataType; |
| 781 syncer::ModelType modelType = _syncSetupService->GetModelType(dataType); | 778 syncer::ModelType modelType = _syncSetupService->GetModelType(dataType); |
| 782 syncSwitchItem.on = _syncSetupService->IsDataTypeEnabled(modelType); | 779 syncSwitchItem.on = _syncSetupService->IsDataTypeEnabled(modelType); |
| 783 syncSwitchItem.enabled = [self shouldSyncableItemsBeEnabled]; | 780 syncSwitchItem.enabled = [self shouldSyncableItemsBeEnabled]; |
| 784 [switchsToReconfigure addObject:syncSwitchItem]; | 781 [switchsToReconfigure addObject:syncSwitchItem]; |
| 785 } | 782 } |
| 786 [self reconfigureCellsForItems:switchsToReconfigure | 783 [self reconfigureCellsForItems:switchsToReconfigure]; |
| 787 inSectionWithIdentifier:SectionIdentifierSyncServices]; | |
| 788 | 784 |
| 789 // Update Encryption cell. | 785 // Update Encryption cell. |
| 790 [self updateEncryptionCell]; | 786 [self updateEncryptionCell]; |
| 791 | 787 |
| 792 // Add/Remove the Sync Error. This is the only update that can change index | 788 // Add/Remove the Sync Error. This is the only update that can change index |
| 793 // paths. It is done last because self.collectionViewModel isn't aware of | 789 // paths. It is done last because self.collectionViewModel isn't aware of |
| 794 // the performBatchUpdates:completion: order of update/remove/delete. | 790 // the performBatchUpdates:completion: order of update/remove/delete. |
| 795 [self updateSyncError]; | 791 [self updateSyncError]; |
| 796 } | 792 } |
| 797 | 793 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 820 | 816 |
| 821 - (void)updateEncryptionCell { | 817 - (void)updateEncryptionCell { |
| 822 BOOL shouldDisplayEncryptionError = [self shouldDisplayEncryptionError]; | 818 BOOL shouldDisplayEncryptionError = [self shouldDisplayEncryptionError]; |
| 823 NSIndexPath* indexPath = [self.collectionViewModel | 819 NSIndexPath* indexPath = [self.collectionViewModel |
| 824 indexPathForItemType:ItemTypeEncryption | 820 indexPathForItemType:ItemTypeEncryption |
| 825 sectionIdentifier:SectionIdentifierEncryptionAndFooter]; | 821 sectionIdentifier:SectionIdentifierEncryptionAndFooter]; |
| 826 TextAndErrorItem* item = base::mac::ObjCCastStrict<TextAndErrorItem>( | 822 TextAndErrorItem* item = base::mac::ObjCCastStrict<TextAndErrorItem>( |
| 827 [self.collectionViewModel itemAtIndexPath:indexPath]); | 823 [self.collectionViewModel itemAtIndexPath:indexPath]); |
| 828 item.shouldDisplayError = shouldDisplayEncryptionError; | 824 item.shouldDisplayError = shouldDisplayEncryptionError; |
| 829 item.enabled = [self shouldEncryptionItemBeEnabled]; | 825 item.enabled = [self shouldEncryptionItemBeEnabled]; |
| 830 [self reconfigureCellsForItems:@[ item ] | 826 [self reconfigureCellsForItems:@[ item ]]; |
| 831 inSectionWithIdentifier:SectionIdentifierEncryptionAndFooter]; | |
| 832 } | 827 } |
| 833 | 828 |
| 834 - (void)updateAccountItem:(CollectionViewAccountItem*)item | 829 - (void)updateAccountItem:(CollectionViewAccountItem*)item |
| 835 withIdentity:(ChromeIdentity*)identity { | 830 withIdentity:(ChromeIdentity*)identity { |
| 836 item.image = [_avatarCache resizedAvatarForIdentity:identity]; | 831 item.image = [_avatarCache resizedAvatarForIdentity:identity]; |
| 837 item.text = identity.userEmail; | 832 item.text = identity.userEmail; |
| 838 item.chromeIdentity = identity; | 833 item.chromeIdentity = identity; |
| 839 } | 834 } |
| 840 | 835 |
| 841 #pragma mark Helpers | 836 #pragma mark Helpers |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 [_authenticationFlow cancelAndDismiss]; | 953 [_authenticationFlow cancelAndDismiss]; |
| 959 } | 954 } |
| 960 | 955 |
| 961 #pragma mark - ChromeIdentityServiceObserver | 956 #pragma mark - ChromeIdentityServiceObserver |
| 962 | 957 |
| 963 - (void)onProfileUpdate:(ChromeIdentity*)identity { | 958 - (void)onProfileUpdate:(ChromeIdentity*)identity { |
| 964 CollectionViewAccountItem* item = | 959 CollectionViewAccountItem* item = |
| 965 base::mac::ObjCCastStrict<CollectionViewAccountItem>( | 960 base::mac::ObjCCastStrict<CollectionViewAccountItem>( |
| 966 [_identityMap objectForKey:identity.gaiaID]); | 961 [_identityMap objectForKey:identity.gaiaID]); |
| 967 [self updateAccountItem:item withIdentity:identity]; | 962 [self updateAccountItem:item withIdentity:identity]; |
| 968 [self reconfigureCellsForItems:@[ item ] | 963 [self reconfigureCellsForItems:@[ item ]]; |
| 969 inSectionWithIdentifier:SectionIdentifierSyncAccounts]; | |
| 970 } | 964 } |
| 971 | 965 |
| 972 - (void)onChromeIdentityServiceWillBeDestroyed { | 966 - (void)onChromeIdentityServiceWillBeDestroyed { |
| 973 _identityServiceObserver.reset(); | 967 _identityServiceObserver.reset(); |
| 974 } | 968 } |
| 975 | 969 |
| 976 @end | 970 @end |
| OLD | NEW |