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 @@ ...@@ -8,6 +8,7 @@
#import "ios/chrome/browser/ui/coordinators/chrome_coordinator.h" #import "ios/chrome/browser/ui/coordinators/chrome_coordinator.h"
#import "ios/chrome/browser/ui/settings/google_services/google_services_settings_mode.h" #import "ios/chrome/browser/ui/settings/google_services/google_services_settings_mode.h"
@protocol ApplicationCommands;
@class GoogleServicesSettingsCoordinator; @class GoogleServicesSettingsCoordinator;
// Delegate for GoogleServicesSettingsCoordinator. // Delegate for GoogleServicesSettingsCoordinator.
...@@ -30,6 +31,8 @@ ...@@ -30,6 +31,8 @@
// Delegate. // Delegate.
@property(nonatomic, weak) id<GoogleServicesSettingsCoordinatorDelegate> @property(nonatomic, weak) id<GoogleServicesSettingsCoordinatorDelegate>
delegate; delegate;
// Presenter which can show signin UI.
@property(nonatomic, strong) id<ApplicationCommands> dispatcher;
- (instancetype)initWithBaseViewController:(UIViewController*)viewController - (instancetype)initWithBaseViewController:(UIViewController*)viewController
browser:(Browser*)browser NS_UNAVAILABLE; browser:(Browser*)browser NS_UNAVAILABLE;
......
...@@ -21,19 +21,22 @@ ...@@ -21,19 +21,22 @@
#import "ios/chrome/browser/ui/commands/browsing_data_commands.h" #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/command_dispatcher.h"
#import "ios/chrome/browser/ui/commands/open_new_tab_command.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/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_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_mediator.h"
#import "ios/chrome/browser/ui/settings/google_services/google_services_settings_view_controller.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/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/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" #include "ios/chrome/browser/ui/ui_feature_flags.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
using signin_metrics::AccessPoint;
using signin_metrics::PromoAction;
@interface GoogleServicesSettingsCoordinator () < @interface GoogleServicesSettingsCoordinator () <
GoogleServicesSettingsCommandHandler, GoogleServicesSettingsCommandHandler,
GoogleServicesSettingsViewControllerPresentationDelegate, GoogleServicesSettingsViewControllerPresentationDelegate,
...@@ -50,15 +53,16 @@ ...@@ -50,15 +53,16 @@
// View controller presented by this coordinator. // View controller presented by this coordinator.
@property(nonatomic, strong, readonly) @property(nonatomic, strong, readonly)
GoogleServicesSettingsViewController* googleServicesSettingsViewController; 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. // Coordinator to present the manage sync settings.
@property(nonatomic, strong) @property(nonatomic, strong)
ManageSyncSettingsCoordinator* manageSyncSettingsCoordinator; ManageSyncSettingsCoordinator* manageSyncSettingsCoordinator;
// YES if stop has been called. // YES if stop has been called.
@property(nonatomic, assign) BOOL stopDone; @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 @end
...@@ -119,9 +123,8 @@ ...@@ -119,9 +123,8 @@
return; return;
} }
// Sync changes should only be commited if the user is authenticated and // Sync changes should only be commited if the user is authenticated and
// there is no sign-in progress. // the sign-in has not been interrupted.
if (self.authService->IsAuthenticated() && if (self.authService->IsAuthenticated() && !self.signinInterrupted) {
!self.signinInteractionCoordinator) {
SyncSetupService* syncSetupService = SyncSetupService* syncSetupService =
SyncSetupServiceFactory::GetForBrowserState( SyncSetupServiceFactory::GetForBrowserState(
self.browser->GetBrowserState()); self.browser->GetBrowserState());
...@@ -134,13 +137,6 @@ ...@@ -134,13 +137,6 @@
} }
syncSetupService->CommitSyncChanges(); 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; self.stopDone = YES;
} }
...@@ -152,10 +148,6 @@ ...@@ -152,10 +148,6 @@
[self.googleServicesSettingsViewController allowUserInteraction]; [self.googleServicesSettingsViewController allowUserInteraction];
} }
- (void)signInInteractionCoordinatorDidComplete {
self.signinInteractionCoordinator = nil;
}
#pragma mark - Properties #pragma mark - Properties
- (AuthenticationService*)authService { - (AuthenticationService*)authService {
...@@ -221,23 +213,31 @@ ...@@ -221,23 +213,31 @@
} }
- (void)showSignIn { - (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; __weak __typeof(self) weakSelf = self;
[self.signinInteractionCoordinator DCHECK(self.dispatcher);
signInWithIdentity:nil signin_metrics::RecordSigninUserActionForAccessPoint(
accessPoint:signin_metrics::AccessPoint:: AccessPoint::ACCESS_POINT_GOOGLE_SERVICES_SETTINGS,
ACCESS_POINT_GOOGLE_SERVICES_SETTINGS PromoAction::PROMO_ACTION_NO_SIGNIN_PROMO);
promoAction:signin_metrics::PromoAction:: ShowSigninCommand* command = [[ShowSigninCommand alloc]
PROMO_ACTION_NO_SIGNIN_PROMO initWithOperation:AUTHENTICATION_OPERATION_SIGNIN
presentingViewController:self.baseNavigationController identity:nil
completion:^(BOOL success) { accessPoint:AccessPoint::ACCESS_POINT_GOOGLE_SERVICES_SETTINGS
[weakSelf signInInteractionCoordinatorDidComplete]; 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 { - (void)openAccountSettings {
......
...@@ -369,6 +369,8 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId"; ...@@ -369,6 +369,8 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
initWithBaseNavigationController:self initWithBaseNavigationController:self
browser:self.browser browser:self.browser
mode:GoogleServicesSettingsModeSettings]; mode:GoogleServicesSettingsModeSettings];
self.googleServicesSettingsCoordinator.dispatcher =
_settingsNavigationDelegate.handlerForSettings;
self.googleServicesSettingsCoordinator.delegate = self; self.googleServicesSettingsCoordinator.delegate = self;
[self.googleServicesSettingsCoordinator start]; [self.googleServicesSettingsCoordinator start];
} }
......
...@@ -928,6 +928,7 @@ NSString* kDevViewSourceKey = @"DevViewSource"; ...@@ -928,6 +928,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
initWithBaseNavigationController:self.navigationController initWithBaseNavigationController:self.navigationController
browser:_browser browser:_browser
mode:GoogleServicesSettingsModeSettings]; mode:GoogleServicesSettingsModeSettings];
_googleServicesSettingsCoordinator.dispatcher = self.dispatcher;
_googleServicesSettingsCoordinator.delegate = self; _googleServicesSettingsCoordinator.delegate = self;
[_googleServicesSettingsCoordinator start]; [_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