Commit 9da24aee authored by Nohemi Fernandez's avatar Nohemi Fernandez Committed by Commit Bot

[iOS][MICE] Split Google Services and Sync options into separate sheets.

UI change that moves all Google Services and Sync options into their
respective categories. Ensures that all Sync status updates are
respected.

Bug: 1125631
Change-Id: I30cc039ca924a856b555b6215c9a25f6bcf07188
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2445513
Commit-Queue: Nohemi Fernandez <fernandex@chromium.org>
Reviewed-by: default avatarJérôme Lebel <jlebel@chromium.org>
Reviewed-by: default avatarBrian White <bcwhite@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814726}
parent abb178f2
......@@ -12,6 +12,7 @@
#include "components/prefs/pref_service.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "components/safe_browsing/core/features.h"
#include "components/signin/public/base/account_consistency_method.h"
#import "components/signin/public/identity_manager/objc/identity_manager_observer_bridge.h"
#include "components/sync/driver/sync_service.h"
#include "components/ukm/ios/features.h"
......@@ -122,7 +123,7 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
@property(nonatomic, assign, readonly) BOOL isSyncDisabledByAdministrator;
// Returns YES if the user is allowed to turn on sync (even if there is a sync
// error).
@property(nonatomic, assign, readonly) BOOL isSyncCanBeAvailable;
@property(nonatomic, assign, readonly) BOOL shouldDisplaySync;
// Sync setup service.
@property(nonatomic, assign, readonly) SyncSetupService* syncSetupService;
// ** Identity section.
......@@ -444,7 +445,7 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
// reloaded.
- (BOOL)updateManageSyncItem {
TableViewModel* model = self.consumer.tableViewModel;
if (self.isSyncCanBeAvailable) {
if (self.shouldDisplaySync) {
BOOL needsUpdate = NO;
if (!self.manageSyncItem) {
self.manageSyncItem =
......@@ -478,7 +479,7 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
// updated.
- (BOOL)updateSyncChromeDataItem {
TableViewModel* model = self.consumer.tableViewModel;
if (self.isSyncCanBeAvailable) {
if (self.shouldDisplaySync) {
BOOL needsUpdate = NO;
if (!self.syncChromeDataSwitchItem) {
self.syncChromeDataSwitchItem =
......@@ -594,8 +595,13 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
self.mode == GoogleServicesSettingsModeAdvancedSigninSettings);
}
- (BOOL)isSyncCanBeAvailable {
return self.isAuthenticated && !self.isSyncDisabledByAdministrator;
- (BOOL)shouldDisplaySync {
BOOL experimentEnabled =
base::FeatureList::IsEnabled(signin::kMobileIdentityConsistency);
BOOL firstSetupWithExperiment =
!self.syncSetupService->IsFirstSetupComplete() && experimentEnabled;
return (firstSetupWithExperiment || !experimentEnabled) &&
self.isAuthenticated && !self.isSyncDisabledByAdministrator;
}
- (ItemArray)nonPersonalizedItems {
......
......@@ -63,6 +63,7 @@
#import "ios/chrome/browser/ui/settings/elements/enterprise_info_popover_view_controller.h"
#import "ios/chrome/browser/ui/settings/google_services/accounts_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/google_services/google_services_settings_coordinator.h"
#import "ios/chrome/browser/ui/settings/google_services/manage_sync_settings_coordinator.h"
#import "ios/chrome/browser/ui/settings/language/language_settings_mediator.h"
#import "ios/chrome/browser/ui/settings/language/language_settings_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/password/passwords_coordinator.h"
......@@ -150,6 +151,8 @@ typedef NS_ENUM(NSInteger, ItemType) {
ItemTypeSigninPromo,
ItemTypeAccount,
ItemTypeSyncAndGoogleServices,
ItemTypeGoogleSync,
ItemTypeGoogleServices,
ItemTypeHeader,
ItemTypeSearchEngine,
ItemTypeManagedDefaultSearchEngine,
......@@ -183,6 +186,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
ChromeIdentityServiceObserver,
GoogleServicesSettingsCoordinatorDelegate,
IdentityManagerObserverBridgeDelegate,
ManageSyncSettingsCoordinatorDelegate,
PasswordCheckObserver,
PasswordsCoordinatorDelegate,
PopoverLabelViewControllerDelegate,
......@@ -225,6 +229,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
// identity update notifications.
SigninPromoViewMediator* _signinPromoViewMediator;
GoogleServicesSettingsCoordinator* _googleServicesSettingsCoordinator;
ManageSyncSettingsCoordinator* _manageSyncSettingsCoordinator;
// Privacy coordinator.
PrivacyCoordinator* _privacyCoordinator;
......@@ -437,8 +442,10 @@ NSString* kDevViewSourceKey = @"DevViewSource";
// Adds experimental Google Services item separate from Sync.
if (base::FeatureList::IsEnabled(signin::kMobileIdentityConsistency)) {
[model addItem:[self syncCellItem]
if (authService->IsAuthenticated()) {
[model addItem:[self googleSyncCellItem]
toSectionWithIdentifier:SectionIdentifierAccount];
}
[model addItem:[self googleServicesCellItem]
toSectionWithIdentifier:SectionIdentifierAccount];
} else {
......@@ -559,7 +566,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
- (TableViewItem*)googleServicesCellItem {
TableViewImageItem* googleServicesItem =
[[TableViewImageItem alloc] initWithType:ItemTypeSyncAndGoogleServices];
[[TableViewImageItem alloc] initWithType:ItemTypeGoogleServices];
googleServicesItem.accessoryType =
UITableViewCellAccessoryDisclosureIndicator;
googleServicesItem.title =
......@@ -570,19 +577,18 @@ NSString* kDevViewSourceKey = @"DevViewSource";
return googleServicesItem;
}
- (TableViewItem*)syncCellItem {
- (TableViewItem*)googleSyncCellItem {
// TODO(crbug.com/805214): This branded icon image needs to come from
// BrandedImageProvider.
TableViewImageItem* googleServicesItem =
[[TableViewImageItem alloc] initWithType:ItemTypeSyncAndGoogleServices];
googleServicesItem.accessoryType =
UITableViewCellAccessoryDisclosureIndicator;
googleServicesItem.title =
l10n_util::GetNSString(IDS_IOS_GOOGLE_SYNC_SETTINGS_TITLE);
googleServicesItem.accessibilityIdentifier =
kSettingsGoogleSyncAndServicesCellId;
[self updateSyncAndGoogleServicesItem:googleServicesItem];
return googleServicesItem;
TableViewDetailIconItem* googleSyncCellItem =
[self detailItemWithType:ItemTypeGoogleSync
text:l10n_util::GetNSString(
IDS_IOS_GOOGLE_SYNC_SETTINGS_TITLE)
detailText:l10n_util::GetNSString(IDS_IOS_SETTING_ON)
iconImageName:kSyncAndGoogleServicesSyncOnImageName
accessibilityIdentifier:kSettingsGoogleSyncAndServicesCellId];
[self updateGoogleSyncCellItem:googleSyncCellItem];
return googleSyncCellItem;
}
- (TableViewItem*)syncAndGoogleServicesCellItem {
......@@ -996,8 +1002,13 @@ NSString* kDevViewSourceKey = @"DevViewSource";
closeSettingsOnAddAccount:NO];
break;
case ItemTypeSyncAndGoogleServices:
case ItemTypeGoogleServices:
base::RecordAction(base::UserMetricsAction("Settings.GoogleServices"));
[self showSyncGoogleService];
[self showGoogleServices];
break;
case ItemTypeGoogleSync:
base::RecordAction(base::UserMetricsAction("Settings.Sync"));
[self showGoogleSync];
break;
case ItemTypeDefaultBrowser:
base::RecordAction(
......@@ -1156,7 +1167,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
#pragma mark - Private methods
- (void)showSyncGoogleService {
- (void)showGoogleServices {
DCHECK(!_googleServicesSettingsCoordinator);
_googleServicesSettingsCoordinator =
[[GoogleServicesSettingsCoordinator alloc]
......@@ -1168,6 +1179,15 @@ NSString* kDevViewSourceKey = @"DevViewSource";
[_googleServicesSettingsCoordinator start];
}
- (void)showGoogleSync {
DCHECK(!_manageSyncSettingsCoordinator);
_manageSyncSettingsCoordinator = [[ManageSyncSettingsCoordinator alloc]
initWithBaseNavigationController:self.navigationController
browser:_browser];
_manageSyncSettingsCoordinator.delegate = self;
[_manageSyncSettingsCoordinator start];
}
- (void)showPasswords {
DCHECK(!_passwordsCoordinator);
_passwordsCoordinator = [[PasswordsCoordinator alloc]
......@@ -1318,8 +1338,61 @@ NSString* kDevViewSourceKey = @"DevViewSource";
DCHECK(googleServicesItem.image);
}
// Updates the Sync item to display the right icon and status message in the
// cell.
- (void)updateGoogleSyncCellItem:(TableViewDetailIconItem*)googleSyncItem {
syncer::SyncService* syncService =
ProfileSyncServiceFactory::GetForBrowserState(_browserState);
SyncSetupService* syncSetupService =
SyncSetupServiceFactory::GetForBrowserState(_browserState);
if (syncService->GetDisableReasons().Has(
syncer::SyncService::DISABLE_REASON_ENTERPRISE_POLICY)) {
googleSyncItem.detailText = l10n_util::GetNSString(
IDS_IOS_GOOGLE_SERVICES_SETTINGS_SYNC_DISABLBED_BY_ADMINISTRATOR_STATUS);
googleSyncItem.iconImageName = kSyncAndGoogleServicesSyncOffImageName;
} else if (!IsTransientSyncError(syncSetupService->GetSyncServiceState())) {
googleSyncItem.detailText =
GetSyncErrorDescriptionForSyncSetupService(syncSetupService);
googleSyncItem.iconImageName = kSyncAndGoogleServicesSyncErrorImageName;
} else if (syncSetupService->IsFirstSetupComplete() &&
syncSetupService->IsSyncEnabled()) {
googleSyncItem.detailText = l10n_util::GetNSString(IDS_IOS_SETTING_ON);
googleSyncItem.iconImageName = kSyncAndGoogleServicesSyncOnImageName;
} else {
googleSyncItem.detailText = l10n_util::GetNSString(IDS_IOS_SETTING_OFF);
googleSyncItem.iconImageName = kSyncAndGoogleServicesSyncOffImageName;
}
}
// Updates and reloads the Google service cell.
- (void)reloadSyncAndGoogleServicesCell {
if (base::FeatureList::IsEnabled(signin::kMobileIdentityConsistency)) {
bool googleSyncCellInitialized =
[self.tableViewModel hasItemForItemType:ItemTypeGoogleSync
sectionIdentifier:SectionIdentifierAccount];
AuthenticationService* authService =
AuthenticationServiceFactory::GetForBrowserState(_browserState);
if (authService->IsAuthenticated()) {
if (!googleSyncCellInitialized) {
[self.tableViewModel addItem:[self googleSyncCellItem]
toSectionWithIdentifier:SectionIdentifierAccount];
} else {
NSIndexPath* syncCellIndexPath =
[self.tableViewModel indexPathForItemType:ItemTypeGoogleSync
sectionIdentifier:SectionIdentifierAccount];
TableViewDetailIconItem* detailIconItem =
base::mac::ObjCCast<TableViewDetailIconItem>(
[self.tableViewModel itemAtIndexPath:syncCellIndexPath]);
[self updateGoogleSyncCellItem:detailIconItem];
[self reconfigureCellsForItems:@[ detailIconItem ]];
}
} else {
if (googleSyncCellInitialized) {
[self.tableViewModel removeItemWithType:ItemTypeGoogleSync
fromSectionWithIdentifier:SectionIdentifierAccount];
}
}
} else {
NSIndexPath* googleServicesCellIndexPath =
[self.tableViewModel indexPathForItemType:ItemTypeSyncAndGoogleServices
sectionIdentifier:SectionIdentifierAccount];
......@@ -1329,6 +1402,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
DCHECK(googleServicesItem);
[self updateSyncAndGoogleServicesItem:googleServicesItem];
[self reconfigureCellsForItems:@[ googleServicesItem ]];
}
}
// Check if the default search engine is managed by policy.
......@@ -1663,4 +1737,13 @@ NSString* kDevViewSourceKey = @"DevViewSource";
[self view:nil didTapLinkURL:convertedURL];
}
#pragma mark - ManageSyncSettingsCoordinatorDelegate
- (void)manageSyncSettingsCoordinatorWasRemoved:
(ManageSyncSettingsCoordinator*)coordinator {
DCHECK_EQ(_manageSyncSettingsCoordinator, coordinator);
[_manageSyncSettingsCoordinator stop];
_manageSyncSettingsCoordinator = nil;
}
@end
......@@ -20918,6 +20918,14 @@ should be able to be added at any place in this file.
</description>
</action>
<action name="Settings.Sync">
<owner>jlebel@chromium.org</owner>
<owner>fernandex@chromium.org</owner>
<description>
Reported when user navigates to Google Sync Settings. iOS only.
</description>
</action>
<action name="Settings.VoiceSearch">
<owner>rohitrao@chromium.org</owner>
<owner>sczs@chromium.org</owner>
......
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