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

[iOS] Adding implementation for 'Settings' link in first run

This patch implements the advanced settings sign-in for the first run
sign-in.

SigninCoordinatorCompletionCallback is updated from:
 typedef void (^SigninCoordinatorCompletionCallback)(
     SigninCoordinatorResult signinResult,
     ChromeIdentity* identity);
to:
using SigninCoordinatorCompletionCallback =
    void (^)(SigninCoordinatorResult result,
             SigninCompletionInfo* info);

The |SigninCompletionInfo| is a class that owns 2 values:
 + |identity|
 + |signinCompletionAction|

SigninCompletionAction is an enum 2 values:
 + SigninCompletionActionNone
 + SigninCompletionActionNeedsAdvancedSettingsSignin

The seconde value is only used for the first run sign-in since it
can't open the advanced settings sign-in as long as the first run is
not finished.

Bug: 971989
Change-Id: Id9041def2bf872c0c10b7d21d7bcfe42eff7960e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2130852
Commit-Queue: Jérôme Lebel <jlebel@chromium.org>
Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarNohemi Fernandez <fernandex@chromium.org>
Cr-Commit-Position: refs/heads/master@{#757020}
parent 21274196
......@@ -185,7 +185,9 @@ using signin_metrics::PromoAction;
identity:(ChromeIdentity*)identity {
DCHECK(!self.alertCoordinator);
DCHECK(!self.userSigninCoordinator);
[self runCompletionCallbackWithSigninResult:signinResult identity:identity];
[self runCompletionCallbackWithSigninResult:signinResult
identity:identity
showAdvancedSettingsSignin:NO];
}
// Presents the user consent screen with |identity| pre-selected.
......@@ -200,12 +202,14 @@ using signin_metrics::PromoAction;
promoAction:self.promoAction];
__weak AddAccountSigninCoordinator* weakSelf = self;
self.userSigninCoordinator.signinCompletion = ^(
SigninCoordinatorResult signinResult, ChromeIdentity* identity) {
[weakSelf.userSigninCoordinator stop];
weakSelf.userSigninCoordinator = nil;
[weakSelf addAccountDoneWithSigninResult:signinResult identity:identity];
};
self.userSigninCoordinator.signinCompletion =
^(SigninCoordinatorResult signinResult,
SigninCompletionInfo* signinCompletionInfo) {
[weakSelf.userSigninCoordinator stop];
weakSelf.userSigninCoordinator = nil;
[weakSelf addAccountDoneWithSigninResult:signinResult
identity:signinCompletionInfo.identity];
};
[self.userSigninCoordinator start];
}
......
......@@ -181,7 +181,9 @@ using l10n_util::GetNSString;
AuthenticationService* authService =
AuthenticationServiceFactory::GetForBrowserState(self.browserState);
ChromeIdentity* identity = authService->GetAuthenticatedIdentity();
[self runCompletionCallbackWithSigninResult:signinResult identity:identity];
[self runCompletionCallbackWithSigninResult:signinResult
identity:identity
showAdvancedSettingsSignin:NO];
}
- (void)showCancelConfirmationAlert {
......
......@@ -7,6 +7,8 @@
#import <Foundation/Foundation.h>
@class ChromeIdentity;
// Sign-in result returned Sign-in result.
typedef NS_ENUM(NSUInteger, SigninCoordinatorResult) {
// Sign-in has been canceled by the user or by another reason.
......@@ -31,4 +33,42 @@ typedef NS_ENUM(NSUInteger, SigninCoordinatorInterruptAction) {
// Name of notification sent when the user has attempted a sign-in.
extern NSString* const kUserSigninAttemptedNotification;
// Action that is required to do to complete the sign-in. This action is in
// charge of the SigninCoordinator's owner.
typedef NS_ENUM(NSUInteger, SigninCompletionAction) {
// No action needed.
SigninCompletionActionNone,
// The advanced settings sign-in view is needed to finish the sign-in.
// This case is only used for the first run sign-in.
SigninCompletionActionShowAdvancedSettingsSignin,
};
// Embed different values related to the sign-in completion.
@interface SigninCompletionInfo : NSObject
- (instancetype)init NS_UNAVAILABLE;
// Designated initializer.
// |identity| is the identity chosen by the user to sign-in.
// |signinCompletionAction| is the action required to complete the sign-in.
- (instancetype)initWithIdentity:(ChromeIdentity*)identity
signinCompletionAction:(SigninCompletionAction)signinCompletionAction
NS_DESIGNATED_INITIALIZER;
// Identity used by the user to sign-in.
@property(nonatomic, strong, readonly) ChromeIdentity* identity;
// Action to take to finish the sign-in. This action is in charged of the
// SigninCoordinator's owner.
@property(nonatomic, assign, readonly)
SigninCompletionAction signinCompletionAction;
@end
// Called when the sign-in dialog is closed.
// |result| is the sign-in result state.
// |signinCompletionInfo| different values related to the sign-in, see
// SigninCompletionInfo class.
using SigninCoordinatorCompletionCallback =
void (^)(SigninCoordinatorResult result, SigninCompletionInfo* info);
#endif // IOS_CHROME_BROWSER_UI_AUTHENTICATION_SIGNIN_SIGNIN_CONSTANTS_H_
......@@ -9,3 +9,18 @@
#endif
NSString* const kUserSigninAttemptedNotification = @"kUserSigninAttempted";
@implementation SigninCompletionInfo
- (instancetype)initWithIdentity:(ChromeIdentity*)identity
signinCompletionAction:
(SigninCompletionAction)signinCompletionAction {
self = [super init];
if (self) {
_identity = identity;
_signinCompletionAction = signinCompletionAction;
}
return self;
}
@end
......@@ -15,9 +15,12 @@
// Runs the sign-in completion callback.
// |signinResult| is the state of sign-in at add account flow completion.
// |identity| is the identity of the added account.
// |showAdvancedSettingsSignin| is YES if the user wants to open the
// advanced settings signin.
- (void)runCompletionCallbackWithSigninResult:
(SigninCoordinatorResult)signinResult
identity:(ChromeIdentity*)identity
showAdvancedSettingsSignin:(BOOL)showAdvancedSettingsSignin
NS_REQUIRES_SUPER;
@end
......
......@@ -15,13 +15,6 @@
class Browser;
@class ChromeIdentity;
// Called when the sign-in dialog is closed.
// |result| is the sign-in result state.
// |identity| is the identity chosen by the user during the sign-in.
typedef void (^SigninCoordinatorCompletionCallback)(
SigninCoordinatorResult signinResult,
ChromeIdentity* identity);
// Main class for sign-in coordinator. This class should not be instantiated
// directly, this should be done using the class methods.
@interface SigninCoordinator : ChromeCoordinator
......@@ -51,7 +44,10 @@ typedef void (^SigninCoordinatorCompletionCallback)(
promoAction:(signin_metrics::PromoAction)
promoAction;
// Returns a coordinator for first run sign-in workflow.
// Returns a coordinator for first run sign-in workflow. If the user tap on the
// settings link to open the advanced settings sign-in, the SigninCoordinator
// owner is in charge open this view, according to -[SigninCompletionInfo
// signinCompletionAction] in |signinCompletionInfo| from |signinCompletion|.
// |navigationController| presents the sign-in. Will be responsible for
// dismissing itself upon sign-in completion.
+ (instancetype)firstRunCoordinatorWithBaseNavigationController:
......
......@@ -104,8 +104,9 @@ using signin_metrics::PromoAction;
}
- (void)dealloc {
// -[SigninCoordinator runCompletionCallbackWithSigninResult:identity:] has
// to be called by the subclass before the coordinator is deallocated.
// -[SigninCoordinator runCompletionCallbackWithSigninResult:identity:
// showAdvancedSettingsSignin:] has to be called by the subclass before
// the coordinator is deallocated.
DCHECK(!self.signinCompletion);
}
......@@ -124,8 +125,9 @@ using signin_metrics::PromoAction;
}
- (void)stop {
// -[SigninCoordinator runCompletionCallbackWithSigninResult:identity:] has
// to be called by the subclass before -[SigninCoordinator stop] is called.
// -[SigninCoordinator runCompletionCallbackWithSigninResult:identity:
// showAdvancedSettingsSignin:] has to be called by the subclass before
// -[SigninCoordinator stop] is called.
DCHECK(!self.signinCompletion);
}
......@@ -140,15 +142,23 @@ using signin_metrics::PromoAction;
- (void)runCompletionCallbackWithSigninResult:
(SigninCoordinatorResult)signinResult
identity:(ChromeIdentity*)identity {
identity:(ChromeIdentity*)identity
showAdvancedSettingsSignin:(BOOL)showAdvancedSettingsSignin {
SigninCompletionAction signinCompletionAction =
showAdvancedSettingsSignin
? SigninCompletionActionShowAdvancedSettingsSignin
: SigninCompletionActionNone;
SigninCompletionInfo* signinCompletionInfo =
[[SigninCompletionInfo alloc] initWithIdentity:identity
signinCompletionAction:signinCompletionAction];
// If |self.signinCompletion| is nil, this method has been probably called
// twice.
DCHECK(self.signinCompletion);
SigninCoordinatorCompletionCallback signinCompletion = self.signinCompletion;
self.signinCompletion = nil;
// The owner should call the stop method, during the callback.
// |self.signinCompletion| needs to be set to nil before calling it.
signinCompletion(signinResult, identity);
self.signinCompletion = nil;
signinCompletion(signinResult, signinCompletionInfo);
}
@end
......@@ -232,9 +232,11 @@ const CGFloat kFadeOutAnimationDuration = 0.16f;
__weak UserSigninCoordinator* weakSelf = self;
self.addAccountSigninCoordinator.signinCompletion =
^(SigninCoordinatorResult signinResult, ChromeIdentity* identity) {
^(SigninCoordinatorResult signinResult,
SigninCompletionInfo* signinCompletionInfo) {
if (signinResult == SigninCoordinatorResultSuccess) {
weakSelf.unifiedConsentCoordinator.selectedIdentity = identity;
weakSelf.unifiedConsentCoordinator.selectedIdentity =
signinCompletionInfo.identity;
weakSelf.addedAccount = YES;
}
[weakSelf.addAccountSigninCoordinator stop];
......@@ -342,8 +344,12 @@ const CGFloat kFadeOutAnimationDuration = 0.16f;
self.unifiedConsentCoordinator = nil;
self.mediator = nil;
self.viewController = nil;
if (!settingsWasTapped) {
[self runCompletionCallbackWithSigninResult:signinResult identity:identity];
if (!settingsWasTapped || self.signinIntent == UserSigninIntentFirstRun) {
// For first run intent, the UserSigninCoordinator owner is reponsible to
// open the advanced settings sign-in.
[self runCompletionCallbackWithSigninResult:signinResult
identity:identity
showAdvancedSettingsSignin:settingsWasTapped];
return;
}
self.advancedSettingsSigninCoordinator = [SigninCoordinator
......@@ -353,11 +359,11 @@ const CGFloat kFadeOutAnimationDuration = 0.16f;
__weak UserSigninCoordinator* weakSelf = self;
self.advancedSettingsSigninCoordinator.signinCompletion = ^(
SigninCoordinatorResult advancedSigninResult,
ChromeIdentity* advancedSigninIdentity) {
SigninCompletionInfo* signinCompletionInfo) {
[weakSelf
advancedSettingsSigninCoordinatorFinishedWithResult:advancedSigninResult
identity:
advancedSigninIdentity];
identity:signinCompletionInfo
.identity];
};
[self.advancedSettingsSigninCoordinator start];
}
......@@ -395,7 +401,8 @@ const CGFloat kFadeOutAnimationDuration = 0.16f;
runCompletionCallbackWithSigninResult:
SigninCoordinatorResultInterrupted
identity:self.unifiedConsentCoordinator
.selectedIdentity];
.selectedIdentity
showAdvancedSettingsSignin:NO];
return;
}
......@@ -432,7 +439,8 @@ const CGFloat kFadeOutAnimationDuration = 0.16f;
[weakSelf
runCompletionCallbackWithSigninResult:SigninCoordinatorResultInterrupted
identity:self.unifiedConsentCoordinator
.selectedIdentity];
.selectedIdentity
showAdvancedSettingsSignin:NO];
if (completion) {
completion();
}
......@@ -497,7 +505,9 @@ const CGFloat kFadeOutAnimationDuration = 0.16f;
DCHECK(self.advancedSettingsSigninCoordinator);
[self.advancedSettingsSigninCoordinator stop];
self.advancedSettingsSigninCoordinator = nil;
[self runCompletionCallbackWithSigninResult:signinResult identity:identity];
[self runCompletionCallbackWithSigninResult:signinResult
identity:identity
showAdvancedSettingsSignin:NO];
}
@end
......@@ -20,6 +20,7 @@
#include "ios/chrome/browser/main/browser.h"
#import "ios/chrome/browser/ui/authentication/signin/signin_constants.h"
#import "ios/chrome/browser/ui/authentication/signin/signin_coordinator.h"
#include "ios/chrome/browser/ui/commands/application_commands.h"
#include "ios/chrome/browser/ui/fancy_ui/primary_action_button.h"
#import "ios/chrome/browser/ui/first_run/first_run_chrome_signin_view_controller.h"
#import "ios/chrome/browser/ui/first_run/first_run_constants.h"
......@@ -201,10 +202,12 @@ const BOOL kDefaultStatsCheckboxValue = YES;
object:self.coordinator];
__weak WelcomeToChromeViewController* weakSelf = self;
self.coordinator.signinCompletion =
^(SigninCoordinatorResult signinResult, ChromeIdentity* identity) {
^(SigninCoordinatorResult signinResult,
SigninCompletionInfo* signinCompletionInfo) {
[weakSelf.coordinator stop];
weakSelf.coordinator = nil;
[weakSelf finishFirstRunWithSigninResult:signinResult];
[weakSelf finishFirstRunWithSigninResult:signinResult
signinCompletionInfo:signinCompletionInfo];
};
[self.coordinator start];
......@@ -227,7 +230,9 @@ const BOOL kDefaultStatsCheckboxValue = YES;
}
// Completes the first run operation depending on the |signinResult| state.
- (void)finishFirstRunWithSigninResult:(SigninCoordinatorResult)signinResult {
- (void)finishFirstRunWithSigninResult:(SigninCoordinatorResult)signinResult
signinCompletionInfo:
(SigninCompletionInfo*)signinCompletionInfo {
switch (signinResult) {
case SigninCoordinatorResultSuccess: {
// User is considered done with First Run only after successful sign-in.
......@@ -251,10 +256,20 @@ const BOOL kDefaultStatsCheckboxValue = YES;
NOTREACHED();
}
}
UIViewController* presentingViewController =
self.navigationController.presentingViewController;
BOOL needsAvancedSettingsSignin =
signinCompletionInfo.signinCompletionAction ==
SigninCompletionActionShowAdvancedSettingsSignin;
[self.navigationController.presentingViewController
dismissViewControllerAnimated:YES
completion:^{
FirstRunDismissed();
if (needsAvancedSettingsSignin) {
[self.dispatcher
showAdvancedSigninSettingsFromViewController:
presentingViewController];
}
}];
}
......
......@@ -526,7 +526,7 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
browser:browser];
__weak SceneController* weakSelf = self;
self.signinCoordinator.signinCompletion =
^(SigninCoordinatorResult signinResult, ChromeIdentity* identity) {
^(SigninCoordinatorResult signinResult, SigninCompletionInfo*) {
[weakSelf.signinCoordinator stop];
weakSelf.signinCoordinator = nil;
};
......
......@@ -71,7 +71,7 @@
__weak SigninInteractionCoordinator* weakSelf = self;
self.coordinator.signinCompletion =
^(SigninCoordinatorResult signinResult, ChromeIdentity* identity) {
^(SigninCoordinatorResult signinResult, SigninCompletionInfo*) {
if (completion) {
completion(signinResult == SigninCoordinatorResultSuccess);
}
......@@ -110,7 +110,7 @@
__weak SigninInteractionCoordinator* weakSelf = self;
self.coordinator.signinCompletion =
^(SigninCoordinatorResult signinResult, ChromeIdentity* identity) {
^(SigninCoordinatorResult signinResult, SigninCompletionInfo*) {
if (completion) {
completion(signinResult == SigninCoordinatorResultSuccess);
}
......@@ -145,7 +145,7 @@
__weak SigninInteractionCoordinator* weakSelf = self;
self.coordinator.signinCompletion =
^(SigninCoordinatorResult signinResult, ChromeIdentity* identity) {
^(SigninCoordinatorResult signinResult, SigninCompletionInfo*) {
if (completion) {
completion(signinResult == SigninCoordinatorResultSuccess);
}
......@@ -309,7 +309,7 @@
browser:self.browser];
__weak SigninInteractionCoordinator* weakSelf = self;
self.coordinator.signinCompletion =
^(SigninCoordinatorResult signinResult, ChromeIdentity* identity) {
^(SigninCoordinatorResult signinResult, SigninCompletionInfo*) {
[weakSelf advancedSigninDoneWithSigninResult:signinResult];
};
[self.coordinator 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