Commit f89aa2c1 authored by Jérôme Lebel's avatar Jérôme Lebel Committed by Commit Bot

[iOS] Adding autofill wallet for Google Pay in Google services

This feature should be disabled when the autofill is disabled.

Bug: 827072
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Idec93340ec0be232d7ad53f4525eee5742f5632a
Reviewed-on: https://chromium-review.googlesource.com/1184715
Commit-Queue: Jérôme Lebel <jlebel@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585443}
parent 0e52eda3
...@@ -777,6 +777,9 @@ locale. The strings in this file are specific to iOS. ...@@ -777,6 +777,9 @@ locale. The strings in this file are specific to iOS.
<message name="IDS_IOS_GOOGLE_SERVICES_SETTINGS_READING_LIST_TEXT" desc="Feature in the settings for the user to enable/disable, to sync reading list links between devices. [iOS only]"> <message name="IDS_IOS_GOOGLE_SERVICES_SETTINGS_READING_LIST_TEXT" desc="Feature in the settings for the user to enable/disable, to sync reading list links between devices. [iOS only]">
Reading List Reading List
</message> </message>
<message name="IDS_IOS_GOOGLE_SERVICES_SETTINGS_AUTOCOMPLETE_WALLET" desc="Label for the checkbox that controls the Autofill/Payments integration feature. 'Google Pay' should not be translated as it is the product name. [iOS only]">
Payment methods and addresses using Google Pay
</message>
<message name="IDS_IOS_GOOGLE_SERVICES_SETTINGS_SETTINGS_TEXT" desc="Feature in the settings for the user to enable/disable, to sync settings data between devices. [iOS only]"> <message name="IDS_IOS_GOOGLE_SERVICES_SETTINGS_SETTINGS_TEXT" desc="Feature in the settings for the user to enable/disable, to sync settings data between devices. [iOS only]">
Settings Settings
</message> </message>
......
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
// Reloads |sections|. // Reloads |sections|.
- (void)reloadSections:(NSIndexSet*)sections; - (void)reloadSections:(NSIndexSet*)sections;
// Reloads only a specific |item|.
- (void)reloadItem:(CollectionViewItem*)item;
@end @end
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_GOOGLE_SERVICES_SETTINGS_CONSUMER_H_ #endif // IOS_CHROME_BROWSER_UI_SETTINGS_GOOGLE_SERVICES_SETTINGS_CONSUMER_H_
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/auto_reset.h" #include "base/auto_reset.h"
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#include "components/autofill/core/common/autofill_prefs.h"
#include "components/browser_sync/profile_sync_service.h" #include "components/browser_sync/profile_sync_service.h"
#include "components/metrics/metrics_pref_names.h" #include "components/metrics/metrics_pref_names.h"
#import "components/prefs/ios/pref_observer_bridge.h" #import "components/prefs/ios/pref_observer_bridge.h"
...@@ -66,6 +67,7 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -66,6 +67,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
SyncAutofillItemType, SyncAutofillItemType,
SyncSettingsItemType, SyncSettingsItemType,
SyncReadingListItemType, SyncReadingListItemType,
AutocompleteWalletItemType,
SyncActivityAndInteractionsItemType, SyncActivityAndInteractionsItemType,
SyncGoogleActivityControlsItemType, SyncGoogleActivityControlsItemType,
EncryptionItemType, EncryptionItemType,
...@@ -99,6 +101,9 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -99,6 +101,9 @@ typedef NS_ENUM(NSInteger, ItemType) {
@property(nonatomic, assign, readonly) BOOL isConsentGiven; @property(nonatomic, assign, readonly) BOOL isConsentGiven;
// Sync setup service. // Sync setup service.
@property(nonatomic, assign, readonly) SyncSetupService* syncSetupService; @property(nonatomic, assign, readonly) SyncSetupService* syncSetupService;
// Preference value for the autocomplete wallet feature.
@property(nonatomic, strong, readonly)
PrefBackedBoolean* autocompleteWalletPreference;
// Preference value for the "Autocomplete searches and URLs" feature. // Preference value for the "Autocomplete searches and URLs" feature.
@property(nonatomic, strong, readonly) @property(nonatomic, strong, readonly)
PrefBackedBoolean* autocompleteSearchPreference; PrefBackedBoolean* autocompleteSearchPreference;
...@@ -135,6 +140,8 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -135,6 +140,8 @@ typedef NS_ENUM(NSInteger, ItemType) {
SettingsCollapsibleItem* syncPersonalizationItem; SettingsCollapsibleItem* syncPersonalizationItem;
// All the items for the personalized section. // All the items for the personalized section.
@property(nonatomic, strong, readonly) ItemArray personalizedItems; @property(nonatomic, strong, readonly) ItemArray personalizedItems;
// Item for the autocomplete wallet feature.
@property(nonatomic, strong, readonly) SyncSwitchItem* autocompleteWalletItem;
// Collapsible item for the non-personalized section. // Collapsible item for the non-personalized section.
@property(nonatomic, strong, readonly) @property(nonatomic, strong, readonly)
SettingsCollapsibleItem* nonPersonalizedServicesItem; SettingsCollapsibleItem* nonPersonalizedServicesItem;
...@@ -149,6 +156,7 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -149,6 +156,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
@synthesize consumer = _consumer; @synthesize consumer = _consumer;
@synthesize authService = _authService; @synthesize authService = _authService;
@synthesize syncSetupService = _syncSetupService; @synthesize syncSetupService = _syncSetupService;
@synthesize autocompleteWalletPreference = _autocompleteWalletPreference;
@synthesize autocompleteSearchPreference = _autocompleteSearchPreference; @synthesize autocompleteSearchPreference = _autocompleteSearchPreference;
@synthesize preloadPagesPreference = _preloadPagesPreference; @synthesize preloadPagesPreference = _preloadPagesPreference;
@synthesize preloadPagesWifiOnlyPreference = _preloadPagesWifiOnlyPreference; @synthesize preloadPagesWifiOnlyPreference = _preloadPagesWifiOnlyPreference;
...@@ -163,6 +171,7 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -163,6 +171,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
@synthesize syncEverythingItem = _syncEverythingItem; @synthesize syncEverythingItem = _syncEverythingItem;
@synthesize syncPersonalizationItem = _syncPersonalizationItem; @synthesize syncPersonalizationItem = _syncPersonalizationItem;
@synthesize personalizedItems = _personalizedItems; @synthesize personalizedItems = _personalizedItems;
@synthesize autocompleteWalletItem = _autocompleteWalletItem;
@synthesize nonPersonalizedServicesItem = _nonPersonalizedServicesItem; @synthesize nonPersonalizedServicesItem = _nonPersonalizedServicesItem;
@synthesize nonPersonalizedItems = _nonPersonalizedItems; @synthesize nonPersonalizedItems = _nonPersonalizedItems;
...@@ -189,21 +198,25 @@ initWithUserPrefService:(PrefService*)userPrefService ...@@ -189,21 +198,25 @@ initWithUserPrefService:(PrefService*)userPrefService
prefChangeRegistrar_.Init(userPrefService); prefChangeRegistrar_.Init(userPrefService);
prefObserverBridge_->ObserveChangesForPreference(kUnifiedConsentGiven, prefObserverBridge_->ObserveChangesForPreference(kUnifiedConsentGiven,
&prefChangeRegistrar_); &prefChangeRegistrar_);
_autocompleteWalletPreference = [[PrefBackedBoolean alloc]
initWithPrefService:userPrefService
prefName:autofill::prefs::kAutofillWalletImportEnabled];
_autocompleteWalletPreference.observer = self;
_autocompleteSearchPreference = [[PrefBackedBoolean alloc] _autocompleteSearchPreference = [[PrefBackedBoolean alloc]
initWithPrefService:userPrefService initWithPrefService:userPrefService
prefName:prefs::kSearchSuggestEnabled]; prefName:prefs::kSearchSuggestEnabled];
[_autocompleteSearchPreference setObserver:self]; _autocompleteSearchPreference.observer = self;
_preloadPagesPreference = [[PrefBackedBoolean alloc] _preloadPagesPreference = [[PrefBackedBoolean alloc]
initWithPrefService:userPrefService initWithPrefService:userPrefService
prefName:prefs::kNetworkPredictionEnabled]; prefName:prefs::kNetworkPredictionEnabled];
[_preloadPagesPreference setObserver:self]; _preloadPagesPreference.observer = self;
_preloadPagesWifiOnlyPreference = [[PrefBackedBoolean alloc] _preloadPagesWifiOnlyPreference = [[PrefBackedBoolean alloc]
initWithPrefService:userPrefService initWithPrefService:userPrefService
prefName:prefs::kNetworkPredictionWifiOnly]; prefName:prefs::kNetworkPredictionWifiOnly];
_sendDataUsagePreference = [[PrefBackedBoolean alloc] _sendDataUsagePreference = [[PrefBackedBoolean alloc]
initWithPrefService:localPrefService initWithPrefService:localPrefService
prefName:metrics::prefs::kMetricsReportingEnabled]; prefName:metrics::prefs::kMetricsReportingEnabled];
[_sendDataUsagePreference setObserver:self]; _sendDataUsagePreference.observer = self;
_sendDataUsageWifiOnlyPreference = [[PrefBackedBoolean alloc] _sendDataUsageWifiOnlyPreference = [[PrefBackedBoolean alloc]
initWithPrefService:localPrefService initWithPrefService:localPrefService
prefName:prefs::kMetricsReportingWifiOnly]; prefName:prefs::kMetricsReportingWifiOnly];
...@@ -211,7 +224,7 @@ initWithUserPrefService:(PrefService*)userPrefService ...@@ -211,7 +224,7 @@ initWithUserPrefService:(PrefService*)userPrefService
initWithPrefService:userPrefService initWithPrefService:userPrefService
prefName:unified_consent::prefs:: prefName:unified_consent::prefs::
kUrlKeyedAnonymizedDataCollectionEnabled]; kUrlKeyedAnonymizedDataCollectionEnabled];
[_anonymizedDataCollectionPreference setObserver:self]; _anonymizedDataCollectionPreference.observer = self;
} }
return self; return self;
} }
...@@ -379,13 +392,27 @@ initWithUserPrefService:(PrefService*)userPrefService ...@@ -379,13 +392,27 @@ initWithUserPrefService:(PrefService*)userPrefService
_personalizedItems = @[ _personalizedItems = @[
syncBookmarksItem, syncHistoryItem, syncPasswordsItem, syncOpenTabsItem, syncBookmarksItem, syncHistoryItem, syncPasswordsItem, syncOpenTabsItem,
syncAutofillItem, syncSettingsItem, syncReadingListItem, syncAutofillItem, syncSettingsItem, syncReadingListItem,
syncActivityAndInteractionsItem, syncGoogleActivityControlsItem, self.autocompleteWalletItem, syncActivityAndInteractionsItem,
encryptionItem, manageSyncedDataItem syncGoogleActivityControlsItem, encryptionItem, manageSyncedDataItem
]; ];
} }
return _personalizedItems; return _personalizedItems;
} }
- (SyncSwitchItem*)autocompleteWalletItem {
if (!_autocompleteWalletItem) {
_autocompleteWalletItem = [self
switchItemWithItemType:AutocompleteWalletItemType
textStringID:
IDS_IOS_GOOGLE_SERVICES_SETTINGS_AUTOCOMPLETE_WALLET
detailStringID:0
commandID:
GoogleServicesSettingsCommandIDAutocompleteWalletService
dataType:0];
}
return _autocompleteWalletItem;
}
- (SettingsCollapsibleItem*)nonPersonalizedServicesItem { - (SettingsCollapsibleItem*)nonPersonalizedServicesItem {
if (!_nonPersonalizedServicesItem) { if (!_nonPersonalizedServicesItem) {
_nonPersonalizedServicesItem = [self _nonPersonalizedServicesItem = [self
...@@ -497,6 +524,14 @@ textItemWithItemType:(NSInteger)itemType ...@@ -497,6 +524,14 @@ textItemWithItemType:(NSInteger)itemType
[self updateSectionWithCollapsibleItem:self.syncPersonalizationItem [self updateSectionWithCollapsibleItem:self.syncPersonalizationItem
items:self.personalizedItems items:self.personalizedItems
enabled:enabled]; enabled:enabled];
syncer::ModelType autofillModelType =
_syncSetupService->GetModelType(SyncSetupService::kSyncAutofill);
BOOL isAutofillOn = _syncSetupService->IsDataTypePreferred(autofillModelType);
self.autocompleteWalletItem.enabled = enabled && isAutofillOn;
if (!isAutofillOn) {
// Autocomplete wallet item should be disabled when autofill is off.
self.autocompleteWalletItem.on = false;
}
} }
// Updates the non-personalized section according to the user consent. // Updates the non-personalized section according to the user consent.
...@@ -528,6 +563,9 @@ textItemWithItemType:(NSInteger)itemType ...@@ -528,6 +563,9 @@ textItemWithItemType:(NSInteger)itemType
switchItem.on = self.syncSetupService->IsDataTypePreferred(modelType); switchItem.on = self.syncSetupService->IsDataTypePreferred(modelType);
break; break;
} }
case GoogleServicesSettingsCommandIDAutocompleteWalletService:
switchItem.on = self.autocompleteWalletPreference.value;
break;
case GoogleServicesSettingsCommandIDToggleAutocompleteSearchesService: case GoogleServicesSettingsCommandIDToggleAutocompleteSearchesService:
switchItem.on = self.autocompleteSearchPreference.value; switchItem.on = self.autocompleteSearchPreference.value;
break; break;
...@@ -588,6 +626,10 @@ textItemWithItemType:(NSInteger)itemType ...@@ -588,6 +626,10 @@ textItemWithItemType:(NSInteger)itemType
self.syncSetupService->SetDataTypeEnabled(modelType, value); self.syncSetupService->SetDataTypeEnabled(modelType, value);
} }
- (void)toggleAutocompleteWalletServiceWithValue:(BOOL)value {
self.autocompleteWalletPreference.value = value;
}
- (void)toggleAutocompleteSearchesServiceWithValue:(BOOL)value { - (void)toggleAutocompleteSearchesServiceWithValue:(BOOL)value {
self.autocompleteSearchPreference.value = value; self.autocompleteSearchPreference.value = value;
} }
...@@ -653,10 +695,15 @@ textItemWithItemType:(NSInteger)itemType ...@@ -653,10 +695,15 @@ textItemWithItemType:(NSInteger)itemType
- (void)onSyncStateChanged { - (void)onSyncStateChanged {
[self updatePersonalizedSection]; [self updatePersonalizedSection];
if (!self.personalizedSectionBeingAnimated) { if (!self.personalizedSectionBeingAnimated) {
CollectionViewModel* model = self.consumer.collectionViewModel;
NSMutableIndexSet* sectionIndexToReload = [NSMutableIndexSet indexSet]; NSMutableIndexSet* sectionIndexToReload = [NSMutableIndexSet indexSet];
[sectionIndexToReload [sectionIndexToReload addIndex:[model sectionForSectionIdentifier:
addIndex:PersonalizedSectionIdentifier - kSectionIdentifierEnumZero]; PersonalizedSectionIdentifier]];
[self.consumer reloadSections:sectionIndexToReload]; [self.consumer reloadSections:sectionIndexToReload];
} else {
// Needs to reload only the autocomplete wallet item (which is part of the
// personalized section), if the autofill feature changed state.
[self.consumer reloadItem:self.autocompleteWalletItem];
} }
} }
......
...@@ -15,6 +15,8 @@ typedef NS_ENUM(NSInteger, GoogleServicesSettingsCommandID) { ...@@ -15,6 +15,8 @@ typedef NS_ENUM(NSInteger, GoogleServicesSettingsCommandID) {
// Personalized section. // Personalized section.
// Enable/disabble bookmark sync. // Enable/disabble bookmark sync.
GoogleServicesSettingsCommandIDToggleDataTypeSync, GoogleServicesSettingsCommandIDToggleDataTypeSync,
// Enable/disable autocomplete wallet for Google Pay.
GoogleServicesSettingsCommandIDAutocompleteWalletService,
// Opens the Google activity controls dialog. // Opens the Google activity controls dialog.
GoogleServicesSettingsCommandIDOpenGoogleActivityControlsDialog, GoogleServicesSettingsCommandIDOpenGoogleActivityControlsDialog,
// Opens the encryption dialog. // Opens the encryption dialog.
...@@ -42,6 +44,9 @@ typedef NS_ENUM(NSInteger, GoogleServicesSettingsCommandID) { ...@@ -42,6 +44,9 @@ typedef NS_ENUM(NSInteger, GoogleServicesSettingsCommandID) {
// Personalized section. // Personalized section.
// Called when GoogleServicesSettingsCommandIDToggleDataTypeSync is triggered. // Called when GoogleServicesSettingsCommandIDToggleDataTypeSync is triggered.
- (void)toggleSyncDataSync:(NSInteger)dataType withValue:(BOOL)value; - (void)toggleSyncDataSync:(NSInteger)dataType withValue:(BOOL)value;
// Called when GoogleServicesSettingsCommandIDAutocompleteWalletService is
// triggered.
- (void)toggleAutocompleteWalletServiceWithValue:(BOOL)value;
// Non-personalized section. // Non-personalized section.
// Called when GoogleServicesSettingsCommandIDToggleAutocompleteSearchesService // Called when GoogleServicesSettingsCommandIDToggleAutocompleteSearchesService
......
...@@ -110,6 +110,9 @@ constexpr NSInteger kSectionOffset = 1000; ...@@ -110,6 +110,9 @@ constexpr NSInteger kSectionOffset = 1000;
[self.serviceDelegate toggleSyncDataSync:syncSwitchItem.dataType [self.serviceDelegate toggleSyncDataSync:syncSwitchItem.dataType
withValue:isOn]; withValue:isOn];
break; break;
case GoogleServicesSettingsCommandIDAutocompleteWalletService:
[self.serviceDelegate toggleAutocompleteWalletServiceWithValue:isOn];
break;
case GoogleServicesSettingsCommandIDToggleAutocompleteSearchesService: case GoogleServicesSettingsCommandIDToggleAutocompleteSearchesService:
[self.serviceDelegate toggleAutocompleteSearchesServiceWithValue:isOn]; [self.serviceDelegate toggleAutocompleteSearchesServiceWithValue:isOn];
break; break;
...@@ -152,6 +155,11 @@ constexpr NSInteger kSectionOffset = 1000; ...@@ -152,6 +155,11 @@ constexpr NSInteger kSectionOffset = 1000;
[self.collectionView reloadSections:sections]; [self.collectionView reloadSections:sections];
} }
- (void)reloadItem:(CollectionViewItem*)item {
NSIndexPath* indexPath = [self.collectionViewModel indexPathForItem:item];
[self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]];
}
#pragma mark - CollectionViewController #pragma mark - CollectionViewController
- (void)loadModel { - (void)loadModel {
...@@ -235,6 +243,7 @@ constexpr NSInteger kSectionOffset = 1000; ...@@ -235,6 +243,7 @@ constexpr NSInteger kSectionOffset = 1000;
case GoogleServicesSettingsCommandIDNoOp: case GoogleServicesSettingsCommandIDNoOp:
case GoogleServicesSettingsCommandIDToggleSyncEverything: case GoogleServicesSettingsCommandIDToggleSyncEverything:
case GoogleServicesSettingsCommandIDToggleDataTypeSync: case GoogleServicesSettingsCommandIDToggleDataTypeSync:
case GoogleServicesSettingsCommandIDAutocompleteWalletService:
case GoogleServicesSettingsCommandIDToggleAutocompleteSearchesService: case GoogleServicesSettingsCommandIDToggleAutocompleteSearchesService:
case GoogleServicesSettingsCommandIDTogglePreloadPagesService: case GoogleServicesSettingsCommandIDTogglePreloadPagesService:
case GoogleServicesSettingsCommandIDToggleImproveChromeService: case GoogleServicesSettingsCommandIDToggleImproveChromeService:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment