Commit 485ff7a3 authored by Jérôme Lebel's avatar Jérôme Lebel Committed by Chromium LUCI CQ

[iOS] Cleanup account table view controller

This patch makes the alert coordinator to show the account details more
readable.
Also this patch makes the _alertCoordinator variable lifetime more
explicit.

Bug: 1166148
Change-Id: I7a0fcf61b83573dc2d99244a2df639832a75fef2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2627322Reviewed-by: default avatarNohemi Fernandez <fernandex@chromium.org>
Commit-Queue: Jérôme Lebel <jlebel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#844005}
parent ec1e8f94
...@@ -399,8 +399,7 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -399,8 +399,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
#pragma mark - Authentication operations #pragma mark - Authentication operations
- (void)showAddAccount { - (void)showAddAccount {
if ([_alertCoordinator isVisible]) DCHECK(!_alertCoordinator);
return;
_authenticationOperationInProgress = YES; _authenticationOperationInProgress = YES;
__weak __typeof(self) weakSelf = self; __weak __typeof(self) weakSelf = self;
...@@ -425,10 +424,7 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -425,10 +424,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
- (void)showAccountDetails:(ChromeIdentity*)identity - (void)showAccountDetails:(ChromeIdentity*)identity
itemView:(UIView*)itemView { itemView:(UIView*)itemView {
if (_alertCoordinator.isVisible) { DCHECK(!_alertCoordinator);
return;
}
_alertCoordinator = [[ActionSheetCoordinator alloc] _alertCoordinator = [[ActionSheetCoordinator alloc]
initWithBaseViewController:self initWithBaseViewController:self
browser:_browser browser:_browser
...@@ -436,63 +432,87 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -436,63 +432,87 @@ typedef NS_ENUM(NSInteger, ItemType) {
message:identity.userEmail message:identity.userEmail
rect:itemView.frame rect:itemView.frame
view:itemView]; view:itemView];
__weak __typeof(self) weakSelf = self;
[_alertCoordinator [_alertCoordinator
addItemWithTitle:l10n_util::GetNSString( addItemWithTitle:l10n_util::GetNSString(
IDS_IOS_MANAGE_YOUR_GOOGLE_ACCOUNT_TITLE) IDS_IOS_MANAGE_YOUR_GOOGLE_ACCOUNT_TITLE)
action:^{ action:^{
_dimissAccountDetailsViewControllerBlock = [weakSelf handleManageGoogleAccountWithIdentity:identity];
ios::GetChromeBrowserProvider()
->GetChromeIdentityService()
->PresentAccountDetailsController(identity, self,
/*animated=*/YES);
} }
style:UIAlertActionStyleDefault]; style:UIAlertActionStyleDefault];
self.removeAccountCoordinator = [[AlertCoordinator alloc]
initWithBaseViewController:self
browser:_browser
title:l10n_util::GetNSStringF(
IDS_IOS_REMOVE_ACCOUNT_ALERT_TITLE,
base::SysNSStringToUTF16(
identity.userEmail))
message:
l10n_util::GetNSString(
IDS_IOS_REMOVE_ACCOUNT_CONFIRMATION_MESSAGE)];
__weak AccountsTableViewController* weakSelf = self;
[_alertCoordinator [_alertCoordinator
addItemWithTitle:l10n_util::GetNSString( addItemWithTitle:l10n_util::GetNSString(
IDS_IOS_REMOVE_GOOGLE_ACCOUNT_TITLE) IDS_IOS_REMOVE_GOOGLE_ACCOUNT_TITLE)
action:^{ action:^{
[weakSelf.removeAccountCoordinator [weakSelf handleRemoveSecondaryAccountWithIdentity:identity];
addItemWithTitle:l10n_util::GetNSString(IDS_CANCEL)
action:nil
style:UIAlertActionStyleCancel];
[weakSelf.removeAccountCoordinator
addItemWithTitle:l10n_util::GetNSString(
IDS_IOS_REMOVE_ACCOUNT_LABEL)
action:^{
weakSelf.uiDisabled = YES;
ios::GetChromeBrowserProvider()
->GetChromeIdentityService()
->ForgetIdentity(
identity, ^(NSError* error) {
weakSelf.uiDisabled = NO;
});
}
style:UIAlertActionStyleDestructive];
[weakSelf.removeAccountCoordinator start];
} }
style:UIAlertActionStyleDestructive]; style:UIAlertActionStyleDestructive];
[_alertCoordinator addItemWithTitle:l10n_util::GetNSString(IDS_CANCEL)
action:^() {
[weakSelf handleAlertCoordinatorCancel];
}
style:UIAlertActionStyleCancel];
[_alertCoordinator start]; [_alertCoordinator start];
} }
// Handles the manage Google account action from |_alertCoordinator|.
// Action sheet created in |showAccountDetails:itemView:|
- (void)handleManageGoogleAccountWithIdentity:(ChromeIdentity*)identity {
DCHECK(_alertCoordinator);
// |_alertCoordinator| should not be stopped, since the coordinator has been
// confirmed.
_alertCoordinator = nil;
_dimissAccountDetailsViewControllerBlock =
ios::GetChromeBrowserProvider()
->GetChromeIdentityService()
->PresentAccountDetailsController(identity, self,
/*animated=*/YES);
}
// Handles the secondary account remove action from |_alertCoordinator|.
// Action sheet created in |showAccountDetails:itemView:|
- (void)handleRemoveSecondaryAccountWithIdentity:(ChromeIdentity*)identity {
DCHECK(_alertCoordinator);
// |_alertCoordinator| should not be stopped, since the coordinator has been
// confirmed.
_alertCoordinator = nil;
DCHECK(!self.removeAccountCoordinator);
NSString* title =
l10n_util::GetNSStringF(IDS_IOS_REMOVE_ACCOUNT_ALERT_TITLE,
base::SysNSStringToUTF16(identity.userEmail));
NSString* message =
l10n_util::GetNSString(IDS_IOS_REMOVE_ACCOUNT_CONFIRMATION_MESSAGE);
self.removeAccountCoordinator =
[[AlertCoordinator alloc] initWithBaseViewController:self
browser:_browser
title:title
message:message];
[self.removeAccountCoordinator
addItemWithTitle:l10n_util::GetNSString(IDS_CANCEL)
action:nil
style:UIAlertActionStyleCancel];
__weak __typeof(self) weakSelf = self;
[self.removeAccountCoordinator
addItemWithTitle:l10n_util::GetNSString(IDS_IOS_REMOVE_ACCOUNT_LABEL)
action:^{
[weakSelf removeSecondaryIdentity:identity];
}
style:UIAlertActionStyleDestructive];
[self.removeAccountCoordinator start];
}
- (void)removeSecondaryIdentity:(ChromeIdentity*)identity {
self.uiDisabled = YES;
ios::GetChromeBrowserProvider()->GetChromeIdentityService()->ForgetIdentity(
identity, ^(NSError* error) {
self.uiDisabled = NO;
});
}
- (void)showSignOutWithClearData:(BOOL)forceClearData - (void)showSignOutWithClearData:(BOOL)forceClearData
itemView:(UIView*)itemView { itemView:(UIView*)itemView {
if (_authenticationOperationInProgress || [_alertCoordinator isVisible] || DCHECK(!_alertCoordinator);
if (_authenticationOperationInProgress ||
self != [self.navigationController topViewController]) { self != [self.navigationController topViewController]) {
// An action is already in progress, ignore user's request. // An action is already in progress, ignore user's request.
return; return;
...@@ -532,12 +552,18 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -532,12 +552,18 @@ typedef NS_ENUM(NSInteger, ItemType) {
} }
style:actionStyle]; style:actionStyle];
[_alertCoordinator addItemWithTitle:l10n_util::GetNSString(IDS_CANCEL) [_alertCoordinator addItemWithTitle:l10n_util::GetNSString(IDS_CANCEL)
action:nil action:^() {
[weakSelf handleAlertCoordinatorCancel];
}
style:UIAlertActionStyleCancel]; style:UIAlertActionStyleCancel];
[_alertCoordinator start]; [_alertCoordinator start];
} }
- (void)handleSignOutWithForceClearData:(BOOL)forceClearData { - (void)handleSignOutWithForceClearData:(BOOL)forceClearData {
DCHECK(_alertCoordinator);
// |_alertCoordinator| should not be stopped, since the coordinator has been
// confirmed.
_alertCoordinator = nil;
AuthenticationService* authService = [self authService]; AuthenticationService* authService = [self authService];
if (authService->IsAuthenticated()) { if (authService->IsAuthenticated()) {
_authenticationOperationInProgress = YES; _authenticationOperationInProgress = YES;
...@@ -563,6 +589,14 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -563,6 +589,14 @@ typedef NS_ENUM(NSInteger, ItemType) {
} }
} }
// Handles the cancel action for |_alertCoordinator|.
- (void)handleAlertCoordinatorCancel {
DCHECK(_alertCoordinator);
// |_alertCoordinator| should not be stopped, since the coordinator has been
// cancelled.
_alertCoordinator = nil;
}
// Sets |_authenticationOperationInProgress| to NO and pops this accounts // Sets |_authenticationOperationInProgress| to NO and pops this accounts
// table view controller if the user is signed out. // table view controller if the user is signed out.
- (void)handleAuthenticationOperationDidFinish { - (void)handleAuthenticationOperationDidFinish {
......
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