Commit 3c9d1ca6 authored by Nohemi Fernandez's avatar Nohemi Fernandez Committed by Commit Bot

[iOS] Create add account flow for sign-in architecture migration.

This CL is part of a series of refactors to move the existing sign-in
architecture to the Coordinator-Mediator design paradigm.

Fore more information, see go/chrome-ios-signin-migration.

Bug: 971989
Change-Id: Iba4a27f8b763697348cbd3f7c5a670fecbabf624
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2033145
Commit-Queue: Nohemi Fernandez <fernandex@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737849}
parent 38a224c7
......@@ -10,6 +10,18 @@ source_set("add_account_signin") {
"add_account_signin_coordinator.h",
"add_account_signin_coordinator.mm",
]
deps = [
"//components/signin/public/identity_manager",
"//ios/chrome/browser/browser_state",
"//ios/chrome/browser/main",
"//ios/chrome/browser/signin",
"//ios/chrome/browser/signin",
"//ios/chrome/browser/ui/alert_coordinator",
"//ios/chrome/browser/ui/authentication",
"//ios/public/provider/chrome/browser",
"//ios/public/provider/chrome/browser/signin",
"//ios/public/provider/chrome/browser/signin",
]
public_deps =
[ "//ios/chrome/browser/ui/authentication/signin:signin_headers" ]
}
......@@ -4,23 +4,136 @@
#import "ios/chrome/browser/ui/authentication/signin/add_account_signin/add_account_signin_coordinator.h"
#include "components/signin/public/base/signin_metrics.h"
#import "ios/chrome/browser/browser_state/chrome_browser_state.h"
#import "ios/chrome/browser/main/browser.h"
#import "ios/chrome/browser/signin/signin_util.h"
#import "ios/chrome/browser/ui/alert_coordinator/alert_coordinator.h"
#import "ios/chrome/browser/ui/authentication/authentication_ui_util.h"
#import "ios/public/provider/chrome/browser/chrome_browser_provider.h"
#import "ios/public/provider/chrome/browser/signin/chrome_identity_interaction_manager.h"
#import "ios/public/provider/chrome/browser/signin/chrome_identity_service.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 AddAccountSigninCoordinator () <
ChromeIdentityInteractionManagerDelegate>
// Coordinator to display modal alerts to the user.
@property(nonatomic, strong) AlertCoordinator* alertCoordinator;
// Manager that handles interactions to add identities.
@property(nonatomic, strong)
ChromeIdentityInteractionManager* identityInteractionManager;
@end
@implementation AddAccountSigninCoordinator
- (instancetype)
initWithBaseViewController:(UIViewController*)viewController
browser:(Browser*)browser
accessPoint:(signin_metrics::AccessPoint)accessPoint
promoAction:(signin_metrics::PromoAction)promoAction {
self = [super initWithBaseViewController:viewController browser:browser];
if (self) {
// TODO(crbug.com/971989): Needs implementation.
NOTIMPLEMENTED();
- (instancetype)initWithBaseViewController:(UIViewController*)viewController
browser:(Browser*)browser
accessPoint:(AccessPoint)accessPoint
promoAction:(PromoAction)promoAction {
return [super initWithBaseViewController:viewController browser:browser];
}
#pragma mark - ChromeCoordinator
- (void)start {
self.identityInteractionManager =
ios::GetChromeBrowserProvider()
->GetChromeIdentityService()
->CreateChromeIdentityInteractionManager(
self.browser->GetBrowserState(), self);
__weak AddAccountSigninCoordinator* weakSelf = self;
[self.identityInteractionManager
addAccountWithCompletion:^(ChromeIdentity* identity, NSError* error) {
[weakSelf completeAddAccountFlow:identity error:error];
}];
}
- (void)stop {
[self.identityInteractionManager cancelAndDismissAnimated:NO];
[self.alertCoordinator executeCancelHandler];
[self.alertCoordinator stop];
self.alertCoordinator = nil;
}
#pragma mark - ChromeIdentityInteractionManagerDelegate
- (void)interactionManager:(ChromeIdentityInteractionManager*)interactionManager
dismissViewControllerAnimated:(BOOL)animated
completion:(ProceduralBlock)completion {
[self.baseViewController.presentedViewController
dismissViewControllerAnimated:animated
completion:completion];
}
- (void)interactionManager:(ChromeIdentityInteractionManager*)interactionManager
presentViewController:(UIViewController*)viewController
animated:(BOOL)animated
completion:(ProceduralBlock)completion {
[self.baseViewController presentViewController:viewController
animated:animated
completion:completion];
}
#pragma mark - Utility methods
// Completes the add account flow including handling any errors that have not
// been handled internally by ChromeIdentity.
// |identity| is the identity of the added account.
// |error| is an error reported by the SSOAuth following adding an account.
- (void)completeAddAccountFlow:(ChromeIdentity*)identity error:(NSError*)error {
if (!self.identityInteractionManager) {
return;
}
if (error) {
// Filter out errors handled internally by ChromeIdentity.
if (!ShouldHandleSigninError(error)) {
[self runCompletionCallbackWithSigninResult:
SigninCoordinatorResultCanceledByUser
identity:identity];
return;
}
__weak AddAccountSigninCoordinator* weakSelf = self;
ProceduralBlock dismissAction = ^{
[weakSelf runCompletionCallbackWithSigninResult:
SigninCoordinatorResultCanceledByUser
identity:identity];
};
self.alertCoordinator =
ErrorCoordinator(error, dismissAction, self.baseViewController);
[self.alertCoordinator start];
return;
}
[self runCompletionCallbackWithSigninResult:SigninCoordinatorResultSuccess
identity:identity];
}
// Clears the state of this coordinator following the completion of the add
// account flow. |signinResult| is the state of sign-in at add account flow
// completion. |identity| is the identity of the added account.
- (void)runCompletionCallbackWithSigninResult:
(SigninCoordinatorResult)signinResult
identity:(ChromeIdentity*)identity {
// Cleaning up and calling the |signinCompletion| should be done last.
self.identityInteractionManager = nil;
self.alertCoordinator = nil;
if (self.signinCompletion) {
self.signinCompletion(signinResult, identity);
self.signinCompletion = nil;
}
return self;
}
@end
......@@ -64,10 +64,6 @@ typedef void (^SigninInteractionControllerCompletionCallback)(
- (void)reAuthenticateWithCompletion:
(SigninInteractionControllerCompletionCallback)completion;
// Starts the flow to add an identity via ChromeIdentityInteractionManager.
- (void)addAccountWithCompletion:
(SigninInteractionControllerCompletionCallback)completion;
// Cancels any current process. Calls the completion callback when done.
- (void)cancel;
......
......@@ -149,20 +149,6 @@
}];
}
- (void)addAccountWithCompletion:
(SigninInteractionControllerCompletionCallback)completion {
_completionCallback = [completion copy];
_identityInteractionManager = ios::GetChromeBrowserProvider()
->GetChromeIdentityService()
->CreateChromeIdentityInteractionManager(
_browser->GetBrowserState(), self);
__weak SigninInteractionController* weakSelf = self;
[_identityInteractionManager
addAccountWithCompletion:^(ChromeIdentity* identity, NSError* error) {
[weakSelf handleIdentityAdded:identity error:error shouldSignIn:NO];
}];
}
#pragma mark - ChromeIdentityInteractionManager operations
- (void)handleIdentityAdded:(ChromeIdentity*)identity
......
......@@ -9,6 +9,7 @@
#import "ios/chrome/browser/main/browser.h"
#import "ios/chrome/browser/ui/alert_coordinator/alert_coordinator.h"
#import "ios/chrome/browser/ui/authentication/authentication_ui_util.h"
#import "ios/chrome/browser/ui/authentication/signin/signin_coordinator.h"
#import "ios/chrome/browser/ui/commands/application_commands.h"
#import "ios/chrome/browser/ui/settings/google_services/advanced_signin_settings_coordinator.h"
#import "ios/chrome/browser/ui/signin_interaction/signin_interaction_controller.h"
......@@ -28,6 +29,11 @@
// The controller managed by this coordinator.
@property(nonatomic, strong) SigninInteractionController* controller;
// The coordinator used to control sign-in UI flows.
// See https://crbug.com/971989 for the migration plan to exclusively use
// SigninCoordinator to trigger sign-in UI.
@property(nonatomic, strong) SigninCoordinator* coordinator;
// The UIViewController upon which UI should be presented.
@property(nonatomic, strong) UIViewController* presentingViewController;
......@@ -57,7 +63,7 @@
presentingViewController:(UIViewController*)viewController
completion:(signin_ui::CompletionCallback)completion {
// Ensure that nothing is done if a sign in operation is already in progress.
if (self.controller) {
if (self.coordinator || self.controller) {
return;
}
......@@ -76,7 +82,7 @@
completion:
(signin_ui::CompletionCallback)completion {
// Ensure that nothing is done if a sign in operation is already in progress.
if (self.controller) {
if (self.coordinator || self.controller) {
return;
}
......@@ -93,16 +99,23 @@
presentingViewController:(UIViewController*)viewController
completion:(signin_ui::CompletionCallback)completion {
// Ensure that nothing is done if a sign in operation is already in progress.
if (self.controller) {
if (self.coordinator || self.controller) {
return;
}
[self setupForSigninOperationWithAccessPoint:accessPoint
promoAction:promoAction
presentingViewController:viewController
completion:completion];
self.coordinator = [SigninCoordinator
addAccountCoordinatorWithBaseViewController:viewController
browser:self.browser
accessPoint:accessPoint];
__weak SigninInteractionCoordinator* weakSelf = self;
self.coordinator.signinCompletion =
^(SigninCoordinatorResult signinResult, ChromeIdentity* identity) {
completion(signinResult == SigninCoordinatorResultSuccess);
weakSelf.coordinator = nil;
};
[self.controller addAccountWithCompletion:[self callbackToClearState]];
[self.coordinator start];
}
- (void)showAdvancedSigninSettingsWithPresentingViewController:
......@@ -113,6 +126,8 @@
- (void)cancel {
[self.controller cancel];
[self.coordinator stop];
self.coordinator = nil;
[self.advancedSigninSettingsCoordinator abortWithDismiss:NO
animated:YES
completion:nil];
......@@ -120,6 +135,8 @@
- (void)cancelAndDismiss {
[self.controller cancelAndDismiss];
[self.coordinator stop];
self.coordinator = nil;
[self.advancedSigninSettingsCoordinator abortWithDismiss:YES
animated:YES
completion:nil];
......
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