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

[iOS] Plugging user consent preferences to the Google service settings

When the switch is toggled, the preference is updated, but the cell
should not be reloaded (to let the animation finish).
The UI is reloaded only when a value update notification is received
without user action.

When the user consent is removed, all sections are expanded and all
cells inside are enabled to be modified.

https://drive.google.com/open?id=1hvi5LyGjBDODkRQymvC5sbUjSN9tafFz

Bug: 827072, 849838
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I5bc39e1ee80d8844e56900a7a22e8201a3e2d411
Reviewed-on: https://chromium-review.googlesource.com/1144934
Commit-Queue: Jérôme Lebel <jlebel@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580830}
parent 56d45d48
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
@property(nonatomic, strong, readonly) @property(nonatomic, strong, readonly)
CollectionViewModel<CollectionViewItem*>* collectionViewModel; CollectionViewModel<CollectionViewItem*>* collectionViewModel;
// Reloads |sections|.
- (void)reloadSections:(NSIndexSet*)sections;
@end @end
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_GOOGLE_SERVICES_SETTINGS_CONSUMER_H_ #endif // IOS_CHROME_BROWSER_UI_SETTINGS_GOOGLE_SERVICES_SETTINGS_CONSUMER_H_
...@@ -29,7 +29,7 @@ class PrefService; ...@@ -29,7 +29,7 @@ class PrefService;
// View controller. // View controller.
@property(nonatomic, weak) id<GoogleServicesSettingsConsumer> consumer; @property(nonatomic, weak) id<GoogleServicesSettingsConsumer> consumer;
// Browser state. // Authentication service.
@property(nonatomic, assign) AuthenticationService* authService; @property(nonatomic, assign) AuthenticationService* authService;
@end @end
......
...@@ -4,10 +4,15 @@ ...@@ -4,10 +4,15 @@
#import "ios/chrome/browser/ui/settings/google_services_settings_mediator.h" #import "ios/chrome/browser/ui/settings/google_services_settings_mediator.h"
#include "base/auto_reset.h"
#include "base/mac/foundation_util.h"
#import "components/prefs/ios/pref_observer_bridge.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/unified_consent/pref_names.h" #include "components/unified_consent/pref_names.h"
#import "ios/chrome/browser/signin/authentication_service.h" #import "ios/chrome/browser/signin/authentication_service.h"
#import "ios/chrome/browser/signin/authentication_service_factory.h" #import "ios/chrome/browser/signin/authentication_service_factory.h"
#include "ios/chrome/browser/sync/sync_setup_service.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h" #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h"
#import "ios/chrome/browser/ui/settings/cells/settings_collapsible_item.h" #import "ios/chrome/browser/ui/settings/cells/settings_collapsible_item.h"
...@@ -24,6 +29,8 @@ ...@@ -24,6 +29,8 @@
using l10n_util::GetNSString; using l10n_util::GetNSString;
using unified_consent::prefs::kUnifiedConsentGiven; using unified_consent::prefs::kUnifiedConsentGiven;
typedef NSArray<CollectionViewItem*>* ItemArray;
namespace { namespace {
// List of sections. // List of sections.
...@@ -66,12 +73,35 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -66,12 +73,35 @@ typedef NS_ENUM(NSInteger, ItemType) {
} // namespace } // namespace
@interface GoogleServicesSettingsMediator () @interface GoogleServicesSettingsMediator ()<PrefObserverDelegate> {
// Bridge to listen to pref changes.
std::unique_ptr<PrefObserverBridge> prefObserverBridge_;
// Registrar for pref changes notifications.
PrefChangeRegistrar prefChangeRegistrar_;
}
// Returns YES if the user is authenticated. // Returns YES if the user is authenticated.
@property(nonatomic, readonly) BOOL isAuthenticated; @property(nonatomic, assign, readonly) BOOL isAuthenticated;
// Returns YES if the user has given his consent to use Google services.
@property(nonatomic, assign, readonly) BOOL isConsentGiven;
// Preference service. // Preference service.
@property(nonatomic, readonly) PrefService* prefService; @property(nonatomic, assign, readonly) PrefService* prefService;
// YES if the switch for |syncEverythingItem| is currently animating from one
// state to another.
@property(nonatomic, assign, readwrite) BOOL syncEverythingSwitchBeingAnimated;
// Item for "Sync Everything" section.
@property(nonatomic, strong, readonly) SyncSwitchItem* syncEverythingItem;
// Collapsible item for the personalized section.
@property(nonatomic, strong, readonly)
SettingsCollapsibleItem* syncPersonalizationItem;
// All the items for the personalized section.
@property(nonatomic, strong, readonly) ItemArray personalizedItems;
// Collapsible item for the non-personalized section.
@property(nonatomic, strong, readonly)
SettingsCollapsibleItem* nonPersonalizedServicesItem;
// All the items for the non-personalized section.
@property(nonatomic, strong, readonly) ItemArray nonPersonalizedItems;
@end @end
...@@ -80,6 +110,13 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -80,6 +110,13 @@ typedef NS_ENUM(NSInteger, ItemType) {
@synthesize consumer = _consumer; @synthesize consumer = _consumer;
@synthesize authService = _authService; @synthesize authService = _authService;
@synthesize prefService = _prefService; @synthesize prefService = _prefService;
@synthesize syncEverythingSwitchBeingAnimated =
_syncEverythingSwitchBeingAnimated;
@synthesize syncEverythingItem = _syncEverythingItem;
@synthesize syncPersonalizationItem = _syncPersonalizationItem;
@synthesize personalizedItems = _personalizedItems;
@synthesize nonPersonalizedServicesItem = _nonPersonalizedServicesItem;
@synthesize nonPersonalizedItems = _nonPersonalizedItems;
#pragma mark - Load model #pragma mark - Load model
...@@ -88,6 +125,10 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -88,6 +125,10 @@ typedef NS_ENUM(NSInteger, ItemType) {
if (self) { if (self) {
DCHECK(prefService); DCHECK(prefService);
_prefService = prefService; _prefService = prefService;
prefObserverBridge_ = std::make_unique<PrefObserverBridge>(self);
prefChangeRegistrar_.Init(prefService);
prefObserverBridge_->ObserveChangesForPreference(kUnifiedConsentGiven,
&prefChangeRegistrar_);
} }
return self; return self;
} }
...@@ -96,19 +137,9 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -96,19 +137,9 @@ typedef NS_ENUM(NSInteger, ItemType) {
- (void)loadSyncEverythingSection { - (void)loadSyncEverythingSection {
CollectionViewModel* model = self.consumer.collectionViewModel; CollectionViewModel* model = self.consumer.collectionViewModel;
[model addSectionWithIdentifier:SyncEverythingSectionIdentifier]; [model addSectionWithIdentifier:SyncEverythingSectionIdentifier];
[model addItem:[self syncEverythingItem] [model addItem:self.syncEverythingItem
toSectionWithIdentifier:SyncEverythingSectionIdentifier]; toSectionWithIdentifier:SyncEverythingSectionIdentifier];
} self.syncEverythingItem.on = self.isConsentGiven;
// Creates SyncEverythingItemType item.
- (CollectionViewItem*)syncEverythingItem {
SyncSwitchItem* item =
[[SyncSwitchItem alloc] initWithType:SyncEverythingItemType];
item.text = GetNSString(IDS_IOS_GOOGLE_SERVICES_SETTINGS_SYNC_EVERYTHING);
item.enabled = YES;
item.on = [self isConsentGiven];
item.commandID = GoogleServicesSettingsCommandIDToggleSyncEverything;
return item;
} }
// Loads PersonalizedSectionIdentifier section. // Loads PersonalizedSectionIdentifier section.
...@@ -118,165 +149,16 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -118,165 +149,16 @@ typedef NS_ENUM(NSInteger, ItemType) {
[model setSectionIdentifier:PersonalizedSectionIdentifier [model setSectionIdentifier:PersonalizedSectionIdentifier
collapsedKey:kGoogleServicesSettingsPersonalizedSectionKey]; collapsedKey:kGoogleServicesSettingsPersonalizedSectionKey];
SettingsCollapsibleItem* syncPersonalizationItem = SettingsCollapsibleItem* syncPersonalizationItem =
[self syncPersonalizationItem]; self.syncPersonalizationItem;
[model addItem:syncPersonalizationItem [model addItem:syncPersonalizationItem
toSectionWithIdentifier:PersonalizedSectionIdentifier]; toSectionWithIdentifier:PersonalizedSectionIdentifier];
BOOL collapsed = self.isAuthenticated ? [self isConsentGiven] : YES; BOOL collapsed = self.isAuthenticated ? self.isConsentGiven : YES;
syncPersonalizationItem.collapsed = collapsed; syncPersonalizationItem.collapsed = collapsed;
[model setSection:PersonalizedSectionIdentifier collapsed:collapsed]; [model setSection:PersonalizedSectionIdentifier collapsed:collapsed];
[model addItem:[self syncBookmarksItem] for (CollectionViewItem* item in self.personalizedItems) {
toSectionWithIdentifier:PersonalizedSectionIdentifier]; [model addItem:item toSectionWithIdentifier:PersonalizedSectionIdentifier];
[model addItem:[self syncHistoryItem] }
toSectionWithIdentifier:PersonalizedSectionIdentifier]; [self updatePersonalizedSection];
[model addItem:[self syncPasswordsItem]
toSectionWithIdentifier:PersonalizedSectionIdentifier];
[model addItem:[self syncOpenTabsItem]
toSectionWithIdentifier:PersonalizedSectionIdentifier];
[model addItem:[self syncAutofillItem]
toSectionWithIdentifier:PersonalizedSectionIdentifier];
[model addItem:[self syncReadingListItem]
toSectionWithIdentifier:PersonalizedSectionIdentifier];
[model addItem:[self syncActivityAndInteractionsItem]
toSectionWithIdentifier:PersonalizedSectionIdentifier];
[model addItem:[self syncGoogleActivityControlsItem]
toSectionWithIdentifier:PersonalizedSectionIdentifier];
[model addItem:[self encryptionItem]
toSectionWithIdentifier:PersonalizedSectionIdentifier];
[model addItem:[self manageSyncedDataItem]
toSectionWithIdentifier:PersonalizedSectionIdentifier];
}
// Creates SyncPersonalizationItemType item.
- (SettingsCollapsibleItem*)syncPersonalizationItem {
SettingsCollapsibleItem* item = [[SettingsCollapsibleItem alloc]
initWithType:SyncPersonalizationItemType];
item.text =
GetNSString(IDS_IOS_GOOGLE_SERVICES_SETTINGS_SYNC_PERSONALIZATION_TEXT);
item.numberOfTextLines = 0;
if (!self.isAuthenticated)
item.textColor = [[MDCPalette greyPalette] tint500];
item.detailText =
GetNSString(IDS_IOS_GOOGLE_SERVICES_SETTINGS_SYNC_PERSONALIZATION_DETAIL);
item.numberOfDetailTextLines = 0;
return item;
}
// Creates SyncBookmarksItemType item.
- (CollectionViewItem*)syncBookmarksItem {
SyncSwitchItem* item =
[[SyncSwitchItem alloc] initWithType:SyncBookmarksItemType];
item.text = GetNSString(IDS_IOS_GOOGLE_SERVICES_SETTINGS_BOOKMARKS_TEXT);
item.enabled = self.isAuthenticated;
item.commandID = GoogleServicesSettingsCommandIDToggleBookmarkSync;
return item;
}
// Creates SyncHistoryItemType item.
- (CollectionViewItem*)syncHistoryItem {
SyncSwitchItem* item =
[[SyncSwitchItem alloc] initWithType:SyncHistoryItemType];
item.text = GetNSString(IDS_IOS_GOOGLE_SERVICES_SETTINGS_HISTORY_TEXT);
item.enabled = self.isAuthenticated;
item.commandID = GoogleServicesSettingsCommandIDToggleHistorySync;
return item;
}
// Creates SyncPasswordsItemType item.
- (CollectionViewItem*)syncPasswordsItem {
SyncSwitchItem* item =
[[SyncSwitchItem alloc] initWithType:SyncPasswordsItemType];
item.text = GetNSString(IDS_IOS_GOOGLE_SERVICES_SETTINGS_PASSWORD_TEXT);
item.enabled = self.isAuthenticated;
item.commandID = GoogleServicesSettingsCommandIDTogglePasswordsSync;
return item;
}
// Creates SyncOpenTabsItemType item.
- (CollectionViewItem*)syncOpenTabsItem {
SyncSwitchItem* item =
[[SyncSwitchItem alloc] initWithType:SyncOpenTabsItemType];
item.text = GetNSString(IDS_IOS_GOOGLE_SERVICES_SETTINGS_OPENTABS_TEXT);
item.enabled = self.isAuthenticated;
item.commandID = GoogleServicesSettingsCommandIDToggleOpenTabsSync;
return item;
}
// Creates SyncAutofillItemType item.
- (CollectionViewItem*)syncAutofillItem {
SyncSwitchItem* item =
[[SyncSwitchItem alloc] initWithType:SyncAutofillItemType];
item.text = GetNSString(IDS_IOS_GOOGLE_SERVICES_SETTINGS_AUTOFILL_TEXT);
item.enabled = self.isAuthenticated;
item.commandID = GoogleServicesSettingsCommandIDToggleAutofillSync;
return item;
}
// Creates SyncReadingListItemType item.
- (CollectionViewItem*)syncReadingListItem {
SyncSwitchItem* item =
[[SyncSwitchItem alloc] initWithType:SyncReadingListItemType];
item.text = GetNSString(IDS_IOS_GOOGLE_SERVICES_SETTINGS_READING_LIST_TEXT);
item.enabled = self.isAuthenticated;
item.commandID = GoogleServicesSettingsCommandIDToggleReadingListSync;
return item;
}
// Creates SyncActivityAndInteractionsItemType item.
- (CollectionViewItem*)syncActivityAndInteractionsItem {
SyncSwitchItem* item =
[[SyncSwitchItem alloc] initWithType:SyncActivityAndInteractionsItemType];
item.text = GetNSString(
IDS_IOS_GOOGLE_SERVICES_SETTINGS_ACTIVITY_AND_INTERACTIONS_TEXT);
item.detailText = GetNSString(
IDS_IOS_GOOGLE_SERVICES_SETTINGS_ACTIVITY_AND_INTERACTIONS_DETAIL);
item.enabled = self.isAuthenticated;
item.commandID =
GoogleServicesSettingsCommandIDToggleActivityAndInteractionsService;
return item;
}
// Creates SyncGoogleActivityControlsItemType item.
- (CollectionViewItem*)syncGoogleActivityControlsItem {
CollectionViewTextItem* item = [[CollectionViewTextItem alloc]
initWithType:SyncGoogleActivityControlsItemType];
item.text = GetNSString(
IDS_IOS_GOOGLE_SERVICES_SETTINGS_GOOGLE_ACTIVITY_CONTROL_TEXT);
item.numberOfTextLines = 0;
if (!self.isAuthenticated)
item.textColor = [[MDCPalette greyPalette] tint500];
item.detailText = GetNSString(
IDS_IOS_GOOGLE_SERVICES_SETTINGS_GOOGLE_ACTIVITY_CONTROL_DETAIL);
item.numberOfDetailTextLines = 0;
item.accessoryType = MDCCollectionViewCellAccessoryDisclosureIndicator;
item.commandID = GoogleServicesSettingsCommandIDOpenGoogleActivityPage;
return item;
}
// Creates EncryptionItemType item.
- (CollectionViewItem*)encryptionItem {
CollectionViewTextItem* item =
[[CollectionViewTextItem alloc] initWithType:EncryptionItemType];
item.text = GetNSString(IDS_IOS_GOOGLE_SERVICES_SETTINGS_ENCRYPTION_TEXT);
item.numberOfTextLines = 0;
if (!self.isAuthenticated)
item.textColor = [[MDCPalette greyPalette] tint500];
item.numberOfDetailTextLines = 0;
item.accessoryType = MDCCollectionViewCellAccessoryDisclosureIndicator;
item.commandID = GoogleServicesSettingsCommandIDOpenEncryptionDialog;
return item;
}
// Creates ManageSyncedDataItemType item.
- (CollectionViewItem*)manageSyncedDataItem {
CollectionViewTextItem* item =
[[CollectionViewTextItem alloc] initWithType:ManageSyncedDataItemType];
item.text =
GetNSString(IDS_IOS_GOOGLE_SERVICES_SETTINGS_MANAGED_SYNC_DATA_TEXT);
item.numberOfTextLines = 0;
if (!self.isAuthenticated)
item.textColor = [[MDCPalette greyPalette] tint500];
item.commandID = GoogleServicesSettingsCommandIDOpenManageSyncedDataPage;
return item;
} }
// Loads NonPersonalizedSectionIdentifier section. // Loads NonPersonalizedSectionIdentifier section.
...@@ -286,88 +168,20 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -286,88 +168,20 @@ typedef NS_ENUM(NSInteger, ItemType) {
[model setSectionIdentifier:NonPersonalizedSectionIdentifier [model setSectionIdentifier:NonPersonalizedSectionIdentifier
collapsedKey:kGoogleServicesSettingsNonPersonalizedSectionKey]; collapsedKey:kGoogleServicesSettingsNonPersonalizedSectionKey];
SettingsCollapsibleItem* nonPersonalizedServicesItem = SettingsCollapsibleItem* nonPersonalizedServicesItem =
[self nonPersonalizedServicesItem]; self.nonPersonalizedServicesItem;
[model addItem:nonPersonalizedServicesItem [model addItem:nonPersonalizedServicesItem
toSectionWithIdentifier:NonPersonalizedSectionIdentifier]; toSectionWithIdentifier:NonPersonalizedSectionIdentifier];
BOOL collapsed = self.isAuthenticated ? [self isConsentGiven] : NO; BOOL collapsed = self.isAuthenticated ? self.isConsentGiven : NO;
nonPersonalizedServicesItem.collapsed = collapsed; nonPersonalizedServicesItem.collapsed = collapsed;
[model setSection:NonPersonalizedSectionIdentifier collapsed:collapsed]; [model setSection:NonPersonalizedSectionIdentifier collapsed:collapsed];
[model addItem:[self autocompleteSearchesAndURLsItem] for (CollectionViewItem* item in self.nonPersonalizedItems) {
toSectionWithIdentifier:NonPersonalizedSectionIdentifier]; [model addItem:item
[model addItem:[self preloadPagesItem] toSectionWithIdentifier:NonPersonalizedSectionIdentifier];
toSectionWithIdentifier:NonPersonalizedSectionIdentifier]; }
[model addItem:[self improveChromeItem] [self updateNonPersonalizedSection];
toSectionWithIdentifier:NonPersonalizedSectionIdentifier];
[model addItem:[self betterSearchAndBrowsingItemType]
toSectionWithIdentifier:NonPersonalizedSectionIdentifier];
}
// Creates NonPersonalizedServicesItemType item.
- (SettingsCollapsibleItem*)nonPersonalizedServicesItem {
SettingsCollapsibleItem* item = [[SettingsCollapsibleItem alloc]
initWithType:NonPersonalizedServicesItemType];
item.text = GetNSString(
IDS_IOS_GOOGLE_SERVICES_SETTINGS_NON_PERSONALIZED_SERVICES_TEXT);
item.numberOfTextLines = 0;
item.detailText = GetNSString(
IDS_IOS_GOOGLE_SERVICES_SETTINGS_NON_PERSONALIZED_SERVICES_DETAIL);
item.numberOfDetailTextLines = 0;
return item;
}
// Creates AutocompleteSearchesAndURLsItemType item.
- (CollectionViewItem*)autocompleteSearchesAndURLsItem {
SyncSwitchItem* item =
[[SyncSwitchItem alloc] initWithType:AutocompleteSearchesAndURLsItemType];
item.text = GetNSString(
IDS_IOS_GOOGLE_SERVICES_SETTINGS_AUTOCOMPLETE_SEARCHES_AND_URLS_TEXT);
item.detailText = GetNSString(
IDS_IOS_GOOGLE_SERVICES_SETTINGS_AUTOCOMPLETE_SEARCHES_AND_URLS_DETAIL);
item.commandID =
GoogleServicesSettingsCommandIDToggleAutocompleteSearchesService;
item.enabled = YES;
return item;
}
// Creates PreloadPagesItemType item.
- (CollectionViewItem*)preloadPagesItem {
SyncSwitchItem* item =
[[SyncSwitchItem alloc] initWithType:PreloadPagesItemType];
item.text = GetNSString(IDS_IOS_GOOGLE_SERVICES_SETTINGS_PRELOAD_PAGES_TEXT);
item.detailText =
GetNSString(IDS_IOS_GOOGLE_SERVICES_SETTINGS_PRELOAD_PAGES_DETAIL);
item.enabled = YES;
item.commandID = GoogleServicesSettingsCommandIDTogglePreloadPagesService;
return item;
}
// Creates ImproveChromeItemType item.
- (CollectionViewItem*)improveChromeItem {
SyncSwitchItem* item =
[[SyncSwitchItem alloc] initWithType:ImproveChromeItemType];
item.text = GetNSString(IDS_IOS_GOOGLE_SERVICES_SETTINGS_IMPROVE_CHROME_TEXT);
item.detailText =
GetNSString(IDS_IOS_GOOGLE_SERVICES_SETTINGS_IMPROVE_CHROME_DETAIL);
item.enabled = YES;
item.commandID = GoogleServicesSettingsCommandIDToggleImproveChromeService;
return item;
}
// Creates BetterSearchAndBrowsingItemType item.
- (CollectionViewItem*)betterSearchAndBrowsingItemType {
SyncSwitchItem* item =
[[SyncSwitchItem alloc] initWithType:BetterSearchAndBrowsingItemType];
item.text = GetNSString(
IDS_IOS_GOOGLE_SERVICES_SETTINGS_BETTER_SEARCH_AND_BROWSING_TEXT);
item.detailText = GetNSString(
IDS_IOS_GOOGLE_SERVICES_SETTINGS_BETTER_SEARCH_AND_BROWSING_DETAIL);
item.enabled = YES;
item.commandID =
GoogleServicesSettingsCommandIDToggleBetterSearchAndBrowsingService;
return item;
} }
#pragma mark - Private #pragma mark - Properties
- (BOOL)isAuthenticated { - (BOOL)isAuthenticated {
return self.authService->IsAuthenticated(); return self.authService->IsAuthenticated();
...@@ -377,6 +191,247 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -377,6 +191,247 @@ typedef NS_ENUM(NSInteger, ItemType) {
return self.prefService->GetBoolean(kUnifiedConsentGiven); return self.prefService->GetBoolean(kUnifiedConsentGiven);
} }
- (CollectionViewItem*)syncEverythingItem {
if (!_syncEverythingItem) {
_syncEverythingItem = [self
switchItemWithItemType:SyncEverythingItemType
textStringID:IDS_IOS_GOOGLE_SERVICES_SETTINGS_SYNC_EVERYTHING
detailStringID:0
commandID:
GoogleServicesSettingsCommandIDToggleSyncEverything];
}
return _syncEverythingItem;
}
- (SettingsCollapsibleItem*)syncPersonalizationItem {
if (!_syncPersonalizationItem) {
_syncPersonalizationItem = [self
collapsibleItemWithItemType:SyncPersonalizationItemType
textStringID:
IDS_IOS_GOOGLE_SERVICES_SETTINGS_SYNC_PERSONALIZATION_TEXT
detailStringID:
IDS_IOS_GOOGLE_SERVICES_SETTINGS_SYNC_PERSONALIZATION_DETAIL];
}
return _syncPersonalizationItem;
}
- (ItemArray)personalizedItems {
if (!_personalizedItems) {
SyncSwitchItem* syncBookmarksItem = [self
switchItemWithItemType:SyncBookmarksItemType
textStringID:IDS_IOS_GOOGLE_SERVICES_SETTINGS_BOOKMARKS_TEXT
detailStringID:0
commandID:
GoogleServicesSettingsCommandIDToggleBookmarkSync];
SyncSwitchItem* syncHistoryItem = [self
switchItemWithItemType:SyncHistoryItemType
textStringID:IDS_IOS_GOOGLE_SERVICES_SETTINGS_HISTORY_TEXT
detailStringID:0
commandID:
GoogleServicesSettingsCommandIDToggleHistorySync];
SyncSwitchItem* syncPasswordsItem = [self
switchItemWithItemType:SyncPasswordsItemType
textStringID:IDS_IOS_GOOGLE_SERVICES_SETTINGS_PASSWORD_TEXT
detailStringID:0
commandID:
GoogleServicesSettingsCommandIDTogglePasswordsSync];
SyncSwitchItem* syncOpenTabsItem = [self
switchItemWithItemType:SyncOpenTabsItemType
textStringID:IDS_IOS_GOOGLE_SERVICES_SETTINGS_OPENTABS_TEXT
detailStringID:0
commandID:
GoogleServicesSettingsCommandIDToggleOpenTabsSync];
SyncSwitchItem* syncAutofillItem = [self
switchItemWithItemType:SyncAutofillItemType
textStringID:IDS_IOS_GOOGLE_SERVICES_SETTINGS_AUTOFILL_TEXT
detailStringID:0
commandID:
GoogleServicesSettingsCommandIDToggleAutofillSync];
SyncSwitchItem* syncReadingListItem = [self
switchItemWithItemType:SyncReadingListItemType
textStringID:
IDS_IOS_GOOGLE_SERVICES_SETTINGS_READING_LIST_TEXT
detailStringID:0
commandID:
GoogleServicesSettingsCommandIDToggleReadingListSync];
SyncSwitchItem* syncActivityAndInteractionsItem = [self
switchItemWithItemType:SyncActivityAndInteractionsItemType
textStringID:
IDS_IOS_GOOGLE_SERVICES_SETTINGS_ACTIVITY_AND_INTERACTIONS_TEXT
detailStringID:
IDS_IOS_GOOGLE_SERVICES_SETTINGS_ACTIVITY_AND_INTERACTIONS_DETAIL
commandID:
GoogleServicesSettingsCommandIDToggleActivityAndInteractionsService];
CollectionViewTextItem* syncGoogleActivityControlsItem = [self
textItemWithItemType:SyncGoogleActivityControlsItemType
textStringID:
IDS_IOS_GOOGLE_SERVICES_SETTINGS_GOOGLE_ACTIVITY_CONTROL_TEXT
detailStringID:
IDS_IOS_GOOGLE_SERVICES_SETTINGS_GOOGLE_ACTIVITY_CONTROL_DETAIL
accessoryType:MDCCollectionViewCellAccessoryDisclosureIndicator
commandID:
GoogleServicesSettingsCommandIDOpenGoogleActivityPage];
CollectionViewTextItem* encryptionItem = [self
textItemWithItemType:EncryptionItemType
textStringID:IDS_IOS_GOOGLE_SERVICES_SETTINGS_ENCRYPTION_TEXT
detailStringID:0
accessoryType:MDCCollectionViewCellAccessoryDisclosureIndicator
commandID:
GoogleServicesSettingsCommandIDOpenEncryptionDialog];
CollectionViewTextItem* manageSyncedDataItem = [self
textItemWithItemType:ManageSyncedDataItemType
textStringID:
IDS_IOS_GOOGLE_SERVICES_SETTINGS_MANAGED_SYNC_DATA_TEXT
detailStringID:0
accessoryType:MDCCollectionViewCellAccessoryNone
commandID:
GoogleServicesSettingsCommandIDOpenManageSyncedDataPage];
_personalizedItems = @[
syncBookmarksItem, syncHistoryItem, syncPasswordsItem, syncOpenTabsItem,
syncAutofillItem, syncReadingListItem, syncActivityAndInteractionsItem,
syncGoogleActivityControlsItem, encryptionItem, manageSyncedDataItem
];
}
return _personalizedItems;
}
- (SettingsCollapsibleItem*)nonPersonalizedServicesItem {
if (!_nonPersonalizedServicesItem) {
_nonPersonalizedServicesItem = [self
collapsibleItemWithItemType:NonPersonalizedServicesItemType
textStringID:
IDS_IOS_GOOGLE_SERVICES_SETTINGS_NON_PERSONALIZED_SERVICES_TEXT
detailStringID:
IDS_IOS_GOOGLE_SERVICES_SETTINGS_NON_PERSONALIZED_SERVICES_DETAIL];
}
return _nonPersonalizedServicesItem;
}
- (ItemArray)nonPersonalizedItems {
if (!_nonPersonalizedItems) {
SyncSwitchItem* autocompleteSearchesAndURLsItem = [self
switchItemWithItemType:AutocompleteSearchesAndURLsItemType
textStringID:
IDS_IOS_GOOGLE_SERVICES_SETTINGS_AUTOCOMPLETE_SEARCHES_AND_URLS_TEXT
detailStringID:
IDS_IOS_GOOGLE_SERVICES_SETTINGS_AUTOCOMPLETE_SEARCHES_AND_URLS_DETAIL
commandID:
GoogleServicesSettingsCommandIDToggleAutocompleteSearchesService];
SyncSwitchItem* preloadPagesItem = [self
switchItemWithItemType:PreloadPagesItemType
textStringID:
IDS_IOS_GOOGLE_SERVICES_SETTINGS_PRELOAD_PAGES_TEXT
detailStringID:
IDS_IOS_GOOGLE_SERVICES_SETTINGS_PRELOAD_PAGES_DETAIL
commandID:
GoogleServicesSettingsCommandIDTogglePreloadPagesService];
SyncSwitchItem* improveChromeItem = [self
switchItemWithItemType:ImproveChromeItemType
textStringID:
IDS_IOS_GOOGLE_SERVICES_SETTINGS_IMPROVE_CHROME_TEXT
detailStringID:
IDS_IOS_GOOGLE_SERVICES_SETTINGS_IMPROVE_CHROME_DETAIL
commandID:
GoogleServicesSettingsCommandIDToggleImproveChromeService];
SyncSwitchItem* betterSearchAndBrowsingItemType = [self
switchItemWithItemType:BetterSearchAndBrowsingItemType
textStringID:
IDS_IOS_GOOGLE_SERVICES_SETTINGS_BETTER_SEARCH_AND_BROWSING_TEXT
detailStringID:
IDS_IOS_GOOGLE_SERVICES_SETTINGS_BETTER_SEARCH_AND_BROWSING_DETAIL
commandID:
GoogleServicesSettingsCommandIDToggleBetterSearchAndBrowsingService];
_nonPersonalizedItems = @[
autocompleteSearchesAndURLsItem, preloadPagesItem, improveChromeItem,
betterSearchAndBrowsingItemType
];
}
return _nonPersonalizedItems;
}
#pragma mark - Private
// Creates a SettingsCollapsibleItem instance.
- (SettingsCollapsibleItem*)collapsibleItemWithItemType:(NSInteger)itemType
textStringID:(int)textStringID
detailStringID:(int)detailStringID {
SettingsCollapsibleItem* collapsibleItem =
[[SettingsCollapsibleItem alloc] initWithType:itemType];
collapsibleItem.text = GetNSString(textStringID);
collapsibleItem.numberOfTextLines = 0;
collapsibleItem.detailText = GetNSString(detailStringID);
collapsibleItem.numberOfDetailTextLines = 0;
return collapsibleItem;
}
// Creates a SyncSwitchItem instance.
- (SyncSwitchItem*)switchItemWithItemType:(NSInteger)itemType
textStringID:(int)textStringID
detailStringID:(int)detailStringID
commandID:(NSInteger)commandID {
SyncSwitchItem* switchItem = [[SyncSwitchItem alloc] initWithType:itemType];
switchItem.text = GetNSString(textStringID);
if (detailStringID)
switchItem.detailText = GetNSString(detailStringID);
switchItem.commandID = commandID;
return switchItem;
}
// Creates a CollectionViewTextItem instance.
- (CollectionViewTextItem*)
textItemWithItemType:(NSInteger)itemType
textStringID:(int)textStringID
detailStringID:(int)detailStringID
accessoryType:(MDCCollectionViewCellAccessoryType)accessoryType
commandID:(NSInteger)commandID {
CollectionViewTextItem* textItem =
[[CollectionViewTextItem alloc] initWithType:itemType];
textItem.text = GetNSString(textStringID);
textItem.accessoryType = accessoryType;
if (detailStringID)
textItem.detailText = GetNSString(detailStringID);
textItem.commandID = commandID;
return textItem;
}
// Updates the personalized section according to the user consent.
- (void)updatePersonalizedSection {
BOOL enabled = self.isAuthenticated && !self.isConsentGiven;
[self updateSectionWithCollapsibleItem:self.syncPersonalizationItem
items:self.personalizedItems
enabled:enabled];
}
// Updates the non-personalized section according to the user consent.
- (void)updateNonPersonalizedSection {
BOOL enabled = !self.isAuthenticated || !self.isConsentGiven;
[self updateSectionWithCollapsibleItem:self.nonPersonalizedServicesItem
items:self.nonPersonalizedItems
enabled:enabled];
}
// Set a section (collapsible item, with all the items inside) to be enabled
// or disabled.
- (void)updateSectionWithCollapsibleItem:
(SettingsCollapsibleItem*)collapsibleItem
items:(ItemArray)items
enabled:(BOOL)enabled {
UIColor* textColor = enabled ? nil : [[MDCPalette greyPalette] tint500];
collapsibleItem.textColor = textColor;
for (CollectionViewItem* item in items) {
if ([item isKindOfClass:[SyncSwitchItem class]]) {
SyncSwitchItem* switchItem = base::mac::ObjCCast<SyncSwitchItem>(item);
switchItem.enabled = enabled;
} else if ([item isKindOfClass:[CollectionViewTextItem class]]) {
CollectionViewTextItem* textItem =
base::mac::ObjCCast<CollectionViewTextItem>(item);
textItem.textColor = textColor;
} else {
NOTREACHED();
}
}
}
#pragma mark - GoogleServicesSettingsViewControllerModelDelegate #pragma mark - GoogleServicesSettingsViewControllerModelDelegate
- (void)googleServicesSettingsViewControllerLoadModel: - (void)googleServicesSettingsViewControllerLoadModel:
...@@ -392,8 +447,12 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -392,8 +447,12 @@ typedef NS_ENUM(NSInteger, ItemType) {
#pragma mark - GoogleServicesSettingsCommandHandler #pragma mark - GoogleServicesSettingsCommandHandler
- (void)toggleSyncEverythingWithValue:(BOOL)on { - (void)toggleSyncEverythingWithValue:(BOOL)value {
// Needs to be implemented. if (value == self.isConsentGiven)
return;
// Mark the switch has being animated to avoid being reloaded.
base::AutoReset<BOOL> autoReset(&_syncEverythingSwitchBeingAnimated, YES);
self.prefService->SetBoolean(kUnifiedConsentGiven, value);
} }
- (void)toggleBookmarksSyncWithValue:(BOOL)on { - (void)toggleBookmarksSyncWithValue:(BOOL)on {
...@@ -456,4 +515,36 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -456,4 +515,36 @@ typedef NS_ENUM(NSInteger, ItemType) {
// Needs to be implemented. // Needs to be implemented.
} }
#pragma mark - PrefObserverDelegate
- (void)onPreferenceChanged:(const std::string&)preferenceName {
DCHECK_EQ(kUnifiedConsentGiven, preferenceName);
self.syncEverythingItem.on = self.isConsentGiven;
[self updatePersonalizedSection];
[self updateNonPersonalizedSection];
CollectionViewModel* model = self.consumer.collectionViewModel;
if (!self.isConsentGiven) {
// If the consent is removed, both collapsible sections should be expanded.
[model setSection:PersonalizedSectionIdentifier collapsed:NO];
[self syncPersonalizationItem].collapsed = NO;
[model setSection:NonPersonalizedSectionIdentifier collapsed:NO];
[self nonPersonalizedServicesItem].collapsed = NO;
}
// Reload sections.
NSMutableIndexSet* sectionIndexToReload = [NSMutableIndexSet indexSet];
if (!self.syncEverythingSwitchBeingAnimated) {
// The sync everything section can be reloaded only if the switch for
// syncEverythingItem is not currently animated. Otherwise the animation
// would be stopped before the end.
[sectionIndexToReload addIndex:[model sectionForSectionIdentifier:
SyncEverythingSectionIdentifier]];
}
[sectionIndexToReload
addIndex:[model
sectionForSectionIdentifier:PersonalizedSectionIdentifier]];
[sectionIndexToReload addIndex:[model sectionForSectionIdentifier:
NonPersonalizedSectionIdentifier]];
[self.consumer reloadSections:sectionIndexToReload];
}
@end @end
...@@ -166,6 +166,10 @@ constexpr NSInteger kSectionOffset = 1000; ...@@ -166,6 +166,10 @@ constexpr NSInteger kSectionOffset = 1000;
return cell; return cell;
} }
- (void)reloadSections:(NSIndexSet*)sections {
[self.collectionView reloadSections:sections];
}
#pragma mark - CollectionViewController #pragma mark - CollectionViewController
- (void)loadModel { - (void)loadModel {
......
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