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

[iOS] Using sign-in commands from GoogleServices

Sign-in UI cannot be dismiss without asynchronous calls. This was
previously ignored. The new architecture is more strict, don't allow
to ignore callbacks.
To prepare the transition to the new architecture, all sign-in UI has
to be managed by the SceneController.
The SceneController already supports asynchronous dismiss of the sign-in
UI.

Adding support for to asynchronously dismissing the sign-in UI on top
of the settings view.

=> crrev.com/c/2161007 GoogleServicesCoordinator
   crrev.com/c/2160911 AccountTableViewController
   crrev.com/c/2161027 SettingsTableViewController
   crrev.com/c/2165732 Fixing tests

Bug: 971989
Change-Id: I29718d306fd4b35e48eaadb90834cd0626ddb22f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2161007
Commit-Queue: Jérôme Lebel <jlebel@chromium.org>
Reviewed-by: default avatarNohemi Fernandez <fernandex@chromium.org>
Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#763450}
parent 16a53959
......@@ -8,6 +8,7 @@
#import "ios/chrome/browser/ui/coordinators/chrome_coordinator.h"
#import "ios/chrome/browser/ui/settings/google_services/google_services_settings_mode.h"
@protocol ApplicationCommands;
@class GoogleServicesSettingsCoordinator;
// Delegate for GoogleServicesSettingsCoordinator.
......@@ -30,6 +31,8 @@
// Delegate.
@property(nonatomic, weak) id<GoogleServicesSettingsCoordinatorDelegate>
delegate;
// Presenter which can show signin UI.
@property(nonatomic, strong) id<ApplicationCommands> dispatcher;
- (instancetype)initWithBaseViewController:(UIViewController*)viewController
browser:(Browser*)browser NS_UNAVAILABLE;
......
......@@ -21,19 +21,22 @@
#import "ios/chrome/browser/ui/commands/browsing_data_commands.h"
#import "ios/chrome/browser/ui/commands/command_dispatcher.h"
#import "ios/chrome/browser/ui/commands/open_new_tab_command.h"
#import "ios/chrome/browser/ui/commands/show_signin_command.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_command_handler.h"
#import "ios/chrome/browser/ui/settings/google_services/google_services_settings_mediator.h"
#import "ios/chrome/browser/ui/settings/google_services/google_services_settings_view_controller.h"
#import "ios/chrome/browser/ui/settings/google_services/manage_sync_settings_coordinator.h"
#import "ios/chrome/browser/ui/settings/sync/sync_encryption_passphrase_table_view_controller.h"
#import "ios/chrome/browser/ui/signin_interaction/signin_interaction_coordinator.h"
#include "ios/chrome/browser/ui/ui_feature_flags.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using signin_metrics::AccessPoint;
using signin_metrics::PromoAction;
@interface GoogleServicesSettingsCoordinator () <
GoogleServicesSettingsCommandHandler,
GoogleServicesSettingsViewControllerPresentationDelegate,
......@@ -50,15 +53,16 @@
// View controller presented by this coordinator.
@property(nonatomic, strong, readonly)
GoogleServicesSettingsViewController* googleServicesSettingsViewController;
// The SigninInteractionCoordinator that presents Sign In UI for the
// Settings page.
@property(nonatomic, strong)
SigninInteractionCoordinator* signinInteractionCoordinator;
// Coordinator to present the manage sync settings.
@property(nonatomic, strong)
ManageSyncSettingsCoordinator* manageSyncSettingsCoordinator;
// YES if stop has been called.
@property(nonatomic, assign) BOOL stopDone;
// YES if the last sign-in has been interrupted. In that case, the coordinator
// is going to be stopped, and the sync setup flag should not be marked as done.
// And the sync should not be marked as disabled. The sync should be kept
// undecided.
@property(nonatomic, assign) BOOL signinInterrupted;
@end
......@@ -119,9 +123,8 @@
return;
}
// Sync changes should only be commited if the user is authenticated and
// there is no sign-in progress.
if (self.authService->IsAuthenticated() &&
!self.signinInteractionCoordinator) {
// the sign-in has not been interrupted.
if (self.authService->IsAuthenticated() && !self.signinInterrupted) {
SyncSetupService* syncSetupService =
SyncSetupServiceFactory::GetForBrowserState(
self.browser->GetBrowserState());
......@@ -134,13 +137,6 @@
}
syncSetupService->CommitSyncChanges();
}
if (self.signinInteractionCoordinator) {
[self.signinInteractionCoordinator cancel];
// |self.signinInteractionCoordinator| is set to nil by
// the completion block called by -[GoogleServicesSettingsCoordinator
// signInInteractionCoordinatorDidComplete]
DCHECK(!self.signinInteractionCoordinator);
}
self.stopDone = YES;
}
......@@ -152,10 +148,6 @@
[self.googleServicesSettingsViewController allowUserInteraction];
}
- (void)signInInteractionCoordinatorDidComplete {
self.signinInteractionCoordinator = nil;
}
#pragma mark - Properties
- (AuthenticationService*)authService {
......@@ -221,23 +213,31 @@
}
- (void)showSignIn {
signin_metrics::RecordSigninUserActionForAccessPoint(
signin_metrics::AccessPoint::ACCESS_POINT_GOOGLE_SERVICES_SETTINGS,
signin_metrics::PromoAction::PROMO_ACTION_NO_SIGNIN_PROMO);
DCHECK(!self.signinInteractionCoordinator);
self.signinInteractionCoordinator =
[[SigninInteractionCoordinator alloc] initWithBrowser:self.browser];
__weak __typeof(self) weakSelf = self;
[self.signinInteractionCoordinator
signInWithIdentity:nil
accessPoint:signin_metrics::AccessPoint::
ACCESS_POINT_GOOGLE_SERVICES_SETTINGS
promoAction:signin_metrics::PromoAction::
PROMO_ACTION_NO_SIGNIN_PROMO
presentingViewController:self.baseNavigationController
completion:^(BOOL success) {
[weakSelf signInInteractionCoordinatorDidComplete];
DCHECK(self.dispatcher);
signin_metrics::RecordSigninUserActionForAccessPoint(
AccessPoint::ACCESS_POINT_GOOGLE_SERVICES_SETTINGS,
PromoAction::PROMO_ACTION_NO_SIGNIN_PROMO);
ShowSigninCommand* command = [[ShowSigninCommand alloc]
initWithOperation:AUTHENTICATION_OPERATION_SIGNIN
identity:nil
accessPoint:AccessPoint::ACCESS_POINT_GOOGLE_SERVICES_SETTINGS
promoAction:PromoAction::PROMO_ACTION_NO_SIGNIN_PROMO
callback:^(BOOL success) {
[weakSelf signinFinishedWithSuccess:success];
}];
[self.dispatcher showSignin:command
baseViewController:self.googleServicesSettingsViewController];
}
- (void)signinFinishedWithSuccess:(BOOL)success {
// TODO(crbug.com/971989): SigninCoordinatorResult should be received instead
// of guessing if the sign-in has been interrupted.
ChromeIdentity* primaryAccount =
AuthenticationServiceFactory::GetForBrowserState(
self.browser->GetBrowserState())
->GetAuthenticatedIdentity();
self.signinInterrupted = !success && primaryAccount;
}
- (void)openAccountSettings {
......
......@@ -369,6 +369,8 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
initWithBaseNavigationController:self
browser:self.browser
mode:GoogleServicesSettingsModeSettings];
self.googleServicesSettingsCoordinator.dispatcher =
_settingsNavigationDelegate.handlerForSettings;
self.googleServicesSettingsCoordinator.delegate = self;
[self.googleServicesSettingsCoordinator start];
}
......
......@@ -928,6 +928,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
initWithBaseNavigationController:self.navigationController
browser:_browser
mode:GoogleServicesSettingsModeSettings];
_googleServicesSettingsCoordinator.dispatcher = self.dispatcher;
_googleServicesSettingsCoordinator.delegate = self;
[_googleServicesSettingsCoordinator start];
}
......
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