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

[iOS] UnifiedConsentCoordinator.selectedIdentity changed to readwrite

|selectedIdentity| has to be set when starting UnifiedConsentCoordinator.
This API is required to support sign-in promo with the "Continue as"
button.
Also the avatar has to be updated when an update notification is
received by ChromeIdentityServiceObserver.

Related to:
crrev.com/c/1009906
crrev.com/c/1010346

Bug: 827072
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I800294f36178a2776e03d28c625f234e4ecc1d2b
Reviewed-on: https://chromium-review.googlesource.com/1025895
Commit-Queue: Jérôme Lebel <jlebel@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553959}
parent f1482964
......@@ -17,7 +17,7 @@
// Called when the user taps on the settings link.
- (void)unifiedConsentCoordinatorDidTapSettingsLink:
(UnifiedConsentCoordinator*)controller;
(UnifiedConsentCoordinator*)coordinator;
@end
......@@ -29,8 +29,11 @@
@interface UnifiedConsentCoordinator : NSObject
@property(nonatomic, weak) id<UnifiedConsentCoordinatorDelegate> delegate;
// Identity selected by the user to sign-in.
@property(nonatomic, strong, readonly) ChromeIdentity* selectedIdentity;
// Identity selected by the user to sign-in. By default, the first identity from
// GetAllIdentitiesSortedForDisplay() is used. If there is no identity in the
// list, the identity picker will be hidden. Nil is not accepted if at least one
// identity exists.
@property(nonatomic, strong) ChromeIdentity* selectedIdentity;
// String id for text to open the settings (related to record the user consent).
@property(nonatomic, readonly) int openSettingsStringId;
// View controller used to display the view.
......
......@@ -26,12 +26,17 @@
@synthesize unifiedConsentMediator = _unifiedConsentMediator;
@synthesize unifiedConsentViewController = _unifiedConsentViewController;
- (instancetype)init {
if (self) {
_unifiedConsentViewController = [[UnifiedConsentViewController alloc] init];
_unifiedConsentViewController.delegate = self;
_unifiedConsentMediator = [[UnifiedConsentMediator alloc]
initWithUnifiedConsentViewController:_unifiedConsentViewController];
}
return self;
}
- (void)start {
self.unifiedConsentViewController =
[[UnifiedConsentViewController alloc] init];
self.unifiedConsentViewController.delegate = self;
self.unifiedConsentMediator = [[UnifiedConsentMediator alloc]
initWithUnifiedConsentViewController:self.unifiedConsentViewController];
[self.unifiedConsentMediator start];
}
......@@ -39,6 +44,10 @@
return self.unifiedConsentMediator.selectedIdentity;
}
- (void)setSelectedIdentity:(ChromeIdentity*)selectedIdentity {
self.unifiedConsentMediator.selectedIdentity = selectedIdentity;
}
- (UIViewController*)viewController {
return self.unifiedConsentViewController;
}
......
......@@ -14,8 +14,11 @@
// updates the UnifiedConsentViewController.
@interface UnifiedConsentMediator : NSObject
// Identity selected by the user to sign-in.
@property(nonatomic) ChromeIdentity* selectedIdentity;
// Identity selected by the user to sign-in. By default, the first identity from
// GetAllIdentitiesSortedForDisplay() is used. If there is no identity in the
// list, the identity picker will be hidden. Nil is not accepted if at least one
// identity exists.
@property(nonatomic, strong) ChromeIdentity* selectedIdentity;
- (instancetype)initWithUnifiedConsentViewController:
(UnifiedConsentViewController*)viewController NS_DESIGNATED_INITIALIZER;
......
......@@ -37,40 +37,38 @@
self = [super init];
if (self) {
_unifiedConsentViewController = viewController;
_identityServiceObserver =
std::make_unique<ChromeIdentityServiceObserverBridge>(self);
_browserProviderObserver =
std::make_unique<ChromeBrowserProviderObserverBridge>(self);
NSArray* identities = ios::GetChromeBrowserProvider()
->GetChromeIdentityService()
->GetAllIdentitiesSortedForDisplay();
if (identities.count != 0) {
_selectedIdentity = identities[0];
}
}
return self;
}
- (void)setSelectedIdentity:(ChromeIdentity*)selectedIdentity {
if (selectedIdentity == self.selectedIdentity)
if (selectedIdentity == self.selectedIdentity) {
return;
}
// nil is allowed only if there is no other identity.
DCHECK(selectedIdentity || ios::GetChromeBrowserProvider()
->GetChromeIdentityService()
->GetAllIdentitiesSortedForDisplay()
.count == 0);
_selectedIdentity = selectedIdentity;
self.selectedIdentityAvatar = nil;
__weak UnifiedConsentMediator* weakSelf = self;
ios::GetChromeBrowserProvider()
->GetChromeIdentityService()
->GetAvatarForIdentity(self.selectedIdentity, ^(UIImage* identityAvatar) {
if (weakSelf.selectedIdentity != selectedIdentity) {
return;
}
[weakSelf identityAvatarUpdated:identityAvatar];
});
[self updateViewController];
}
- (void)start {
_identityServiceObserver =
std::make_unique<ChromeIdentityServiceObserverBridge>(self);
_browserProviderObserver =
std::make_unique<ChromeBrowserProviderObserverBridge>(self);
NSArray* identities = ios::GetChromeBrowserProvider()
->GetChromeIdentityService()
->GetAllIdentitiesSortedForDisplay();
// Make sure the view is loaded so the mediator can set it up.
[self.unifiedConsentViewController loadViewIfNeeded];
if (identities.count != 0) {
self.selectedIdentity = identities[0];
}
[self updateViewController];
}
#pragma mark - Private
......@@ -84,6 +82,15 @@
.userEmail];
[self.unifiedConsentViewController
updateIdentityPickerViewWithAvatar:self.selectedIdentityAvatar];
ChromeIdentity* selectedIdentity = self.selectedIdentity;
__weak UnifiedConsentMediator* weakSelf = self;
ios::GetChromeBrowserProvider()
->GetChromeIdentityService()
->GetAvatarForIdentity(selectedIdentity, ^(UIImage* identityAvatar) {
if (weakSelf.selectedIdentity != selectedIdentity)
return;
[weakSelf identityAvatarUpdated:identityAvatar];
});
} else {
[self.unifiedConsentViewController hideIdentityPickerView];
}
......@@ -112,14 +119,14 @@
#pragma mark - ChromeIdentityServiceObserver
- (void)identityListChanged {
ChromeIdentity* newIdentity = nil;
NSArray* identities = ios::GetChromeBrowserProvider()
->GetChromeIdentityService()
->GetAllIdentitiesSortedForDisplay();
if (identities.count != 0) {
newIdentity = identities[0];
}
if (newIdentity != self.selectedIdentity) {
if (![identities containsObject:self.selectedIdentity]) {
ChromeIdentity* newIdentity = nil;
if (identities.count != 0) {
newIdentity = identities[0];
}
self.selectedIdentity = newIdentity;
}
}
......
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