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.
<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
</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]">
Settings
</message>
......
......@@ -19,6 +19,9 @@
// Reloads |sections|.
- (void)reloadSections:(NSIndexSet*)sections;
// Reloads only a specific |item|.
- (void)reloadItem:(CollectionViewItem*)item;
@end
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_GOOGLE_SERVICES_SETTINGS_CONSUMER_H_
......@@ -6,6 +6,7 @@
#include "base/auto_reset.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/metrics/metrics_pref_names.h"
#import "components/prefs/ios/pref_observer_bridge.h"
......@@ -66,6 +67,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
SyncAutofillItemType,
SyncSettingsItemType,
SyncReadingListItemType,
AutocompleteWalletItemType,
SyncActivityAndInteractionsItemType,
SyncGoogleActivityControlsItemType,
EncryptionItemType,
......@@ -99,6 +101,9 @@ typedef NS_ENUM(NSInteger, ItemType) {
@property(nonatomic, assign, readonly) BOOL isConsentGiven;
// Sync setup service.
@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.
@property(nonatomic, strong, readonly)
PrefBackedBoolean* autocompleteSearchPreference;
......@@ -135,6 +140,8 @@ typedef NS_ENUM(NSInteger, ItemType) {
SettingsCollapsibleItem* syncPersonalizationItem;
// All the items for the personalized section.
@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.
@property(nonatomic, strong, readonly)
SettingsCollapsibleItem* nonPersonalizedServicesItem;
......@@ -149,6 +156,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
@synthesize consumer = _consumer;
@synthesize authService = _authService;
@synthesize syncSetupService = _syncSetupService;
@synthesize autocompleteWalletPreference = _autocompleteWalletPreference;
@synthesize autocompleteSearchPreference = _autocompleteSearchPreference;
@synthesize preloadPagesPreference = _preloadPagesPreference;
@synthesize preloadPagesWifiOnlyPreference = _preloadPagesWifiOnlyPreference;
......@@ -163,6 +171,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
@synthesize syncEverythingItem = _syncEverythingItem;
@synthesize syncPersonalizationItem = _syncPersonalizationItem;
@synthesize personalizedItems = _personalizedItems;
@synthesize autocompleteWalletItem = _autocompleteWalletItem;
@synthesize nonPersonalizedServicesItem = _nonPersonalizedServicesItem;
@synthesize nonPersonalizedItems = _nonPersonalizedItems;
......@@ -189,21 +198,25 @@ initWithUserPrefService:(PrefService*)userPrefService
prefChangeRegistrar_.Init(userPrefService);
prefObserverBridge_->ObserveChangesForPreference(kUnifiedConsentGiven,
&prefChangeRegistrar_);
_autocompleteWalletPreference = [[PrefBackedBoolean alloc]
initWithPrefService:userPrefService
prefName:autofill::prefs::kAutofillWalletImportEnabled];
_autocompleteWalletPreference.observer = self;
_autocompleteSearchPreference = [[PrefBackedBoolean alloc]
initWithPrefService:userPrefService
prefName:prefs::kSearchSuggestEnabled];
[_autocompleteSearchPreference setObserver:self];
_autocompleteSearchPreference.observer = self;
_preloadPagesPreference = [[PrefBackedBoolean alloc]
initWithPrefService:userPrefService
prefName:prefs::kNetworkPredictionEnabled];
[_preloadPagesPreference setObserver:self];
_preloadPagesPreference.observer = self;
_preloadPagesWifiOnlyPreference = [[PrefBackedBoolean alloc]
initWithPrefService:userPrefService
prefName:prefs::kNetworkPredictionWifiOnly];
_sendDataUsagePreference = [[PrefBackedBoolean alloc]
initWithPrefService:localPrefService
prefName:metrics::prefs::kMetricsReportingEnabled];
[_sendDataUsagePreference setObserver:self];
_sendDataUsagePreference.observer = self;
_sendDataUsageWifiOnlyPreference = [[PrefBackedBoolean alloc]
initWithPrefService:localPrefService
prefName:prefs::kMetricsReportingWifiOnly];
......@@ -211,7 +224,7 @@ initWithUserPrefService:(PrefService*)userPrefService
initWithPrefService:userPrefService
prefName:unified_consent::prefs::
kUrlKeyedAnonymizedDataCollectionEnabled];
[_anonymizedDataCollectionPreference setObserver:self];
_anonymizedDataCollectionPreference.observer = self;
}
return self;
}
......@@ -379,13 +392,27 @@ initWithUserPrefService:(PrefService*)userPrefService
_personalizedItems = @[
syncBookmarksItem, syncHistoryItem, syncPasswordsItem, syncOpenTabsItem,
syncAutofillItem, syncSettingsItem, syncReadingListItem,
syncActivityAndInteractionsItem, syncGoogleActivityControlsItem,
encryptionItem, manageSyncedDataItem
self.autocompleteWalletItem, syncActivityAndInteractionsItem,
syncGoogleActivityControlsItem, encryptionItem, manageSyncedDataItem
];
}
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 {
if (!_nonPersonalizedServicesItem) {
_nonPersonalizedServicesItem = [self
......@@ -497,6 +524,14 @@ textItemWithItemType:(NSInteger)itemType
[self updateSectionWithCollapsibleItem:self.syncPersonalizationItem
items:self.personalizedItems
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.
......@@ -528,6 +563,9 @@ textItemWithItemType:(NSInteger)itemType
switchItem.on = self.syncSetupService->IsDataTypePreferred(modelType);
break;
}
case GoogleServicesSettingsCommandIDAutocompleteWalletService:
switchItem.on = self.autocompleteWalletPreference.value;
break;
case GoogleServicesSettingsCommandIDToggleAutocompleteSearchesService:
switchItem.on = self.autocompleteSearchPreference.value;
break;
......@@ -588,6 +626,10 @@ textItemWithItemType:(NSInteger)itemType
self.syncSetupService->SetDataTypeEnabled(modelType, value);
}
- (void)toggleAutocompleteWalletServiceWithValue:(BOOL)value {
self.autocompleteWalletPreference.value = value;
}
- (void)toggleAutocompleteSearchesServiceWithValue:(BOOL)value {
self.autocompleteSearchPreference.value = value;
}
......@@ -653,10 +695,15 @@ textItemWithItemType:(NSInteger)itemType
- (void)onSyncStateChanged {
[self updatePersonalizedSection];
if (!self.personalizedSectionBeingAnimated) {
CollectionViewModel* model = self.consumer.collectionViewModel;
NSMutableIndexSet* sectionIndexToReload = [NSMutableIndexSet indexSet];
[sectionIndexToReload
addIndex:PersonalizedSectionIdentifier - kSectionIdentifierEnumZero];
[sectionIndexToReload addIndex:[model sectionForSectionIdentifier:
PersonalizedSectionIdentifier]];
[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) {
// Personalized section.
// Enable/disabble bookmark sync.
GoogleServicesSettingsCommandIDToggleDataTypeSync,
// Enable/disable autocomplete wallet for Google Pay.
GoogleServicesSettingsCommandIDAutocompleteWalletService,
// Opens the Google activity controls dialog.
GoogleServicesSettingsCommandIDOpenGoogleActivityControlsDialog,
// Opens the encryption dialog.
......@@ -42,6 +44,9 @@ typedef NS_ENUM(NSInteger, GoogleServicesSettingsCommandID) {
// Personalized section.
// Called when GoogleServicesSettingsCommandIDToggleDataTypeSync is triggered.
- (void)toggleSyncDataSync:(NSInteger)dataType withValue:(BOOL)value;
// Called when GoogleServicesSettingsCommandIDAutocompleteWalletService is
// triggered.
- (void)toggleAutocompleteWalletServiceWithValue:(BOOL)value;
// Non-personalized section.
// Called when GoogleServicesSettingsCommandIDToggleAutocompleteSearchesService
......
......@@ -110,6 +110,9 @@ constexpr NSInteger kSectionOffset = 1000;
[self.serviceDelegate toggleSyncDataSync:syncSwitchItem.dataType
withValue:isOn];
break;
case GoogleServicesSettingsCommandIDAutocompleteWalletService:
[self.serviceDelegate toggleAutocompleteWalletServiceWithValue:isOn];
break;
case GoogleServicesSettingsCommandIDToggleAutocompleteSearchesService:
[self.serviceDelegate toggleAutocompleteSearchesServiceWithValue:isOn];
break;
......@@ -152,6 +155,11 @@ constexpr NSInteger kSectionOffset = 1000;
[self.collectionView reloadSections:sections];
}
- (void)reloadItem:(CollectionViewItem*)item {
NSIndexPath* indexPath = [self.collectionViewModel indexPathForItem:item];
[self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]];
}
#pragma mark - CollectionViewController
- (void)loadModel {
......@@ -235,6 +243,7 @@ constexpr NSInteger kSectionOffset = 1000;
case GoogleServicesSettingsCommandIDNoOp:
case GoogleServicesSettingsCommandIDToggleSyncEverything:
case GoogleServicesSettingsCommandIDToggleDataTypeSync:
case GoogleServicesSettingsCommandIDAutocompleteWalletService:
case GoogleServicesSettingsCommandIDToggleAutocompleteSearchesService:
case GoogleServicesSettingsCommandIDTogglePreloadPagesService:
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