Skip to content

Commit

Permalink
[iOS][10/N] Adds ChromeAccountManagerServiceObserver
Browse files Browse the repository at this point in the history
This CL adds ChromeAccountManagerServiceObserver to
AccountsTableViewController.

Bug: 1220345
Change-Id: Ia80b91ef3f36d66cf3d670b8ea15d5f982915c84
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3077483
Commit-Queue: Ewann Pellé <ewannpv@chromium.org>
Reviewed-by: Jérôme <jlebel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#909734}
  • Loading branch information
Ewann authored and Chromium LUCI CQ committed Aug 9, 2021
1 parent 1f719c5 commit 541e9d3
Showing 1 changed file with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "ios/chrome/browser/signin/authentication_service_factory.h"
#import "ios/chrome/browser/signin/chrome_account_manager_service.h"
#import "ios/chrome/browser/signin/chrome_account_manager_service_factory.h"
#import "ios/chrome/browser/signin/chrome_identity_service_observer_bridge.h"
#import "ios/chrome/browser/signin/chrome_account_manager_service_observer_bridge.h"
#include "ios/chrome/browser/signin/identity_manager_factory.h"
#include "ios/chrome/browser/sync/sync_setup_service.h"
#include "ios/chrome/browser/sync/sync_setup_service_factory.h"
Expand Down Expand Up @@ -91,12 +91,14 @@ typedef NS_ENUM(NSInteger, ItemType) {
} // namespace

@interface AccountsTableViewController () <
ChromeIdentityServiceObserver,
ChromeAccountManagerServiceObserver,
ChromeIdentityBrowserOpener,
IdentityManagerObserverBridgeDelegate,
SignoutActionSheetCoordinatorDelegate> {
Browser* _browser;
BOOL _closeSettingsOnAddAccount;
std::unique_ptr<ChromeAccountManagerServiceObserverBridge>
_accountManagerServiceObserver;
std::unique_ptr<signin::IdentityManagerObserverBridge>
_identityManagerObserver;
// Whether an authentication operation is in progress (e.g switch accounts,
Expand All @@ -106,7 +108,6 @@ @interface AccountsTableViewController () <
// requests should be ignored.
BOOL _isBeingDismissed;
ResizedAvatarCache* _avatarCache;
std::unique_ptr<ChromeIdentityServiceObserverBridge> _identityServiceObserver;

// Enable lookup of item corresponding to a given identity GAIA ID string.
NSDictionary<NSString*, TableViewItem*>* _identityMap;
Expand All @@ -128,6 +129,9 @@ @interface AccountsTableViewController () <
// If YES, the UI elements are disabled.
@property(nonatomic, assign) BOOL uiDisabled;

// AccountManager Service used to retrive identities.
@property(nonatomic, assign) ChromeAccountManagerService* accountManagerService;

// Stops observing browser state services. This is required during the shutdown
// phase to avoid observing services for a browser state that is being killed.
- (void)stopBrowserStateServiceObservers;
Expand All @@ -147,14 +151,18 @@ - (instancetype)initWithBrowser:(Browser*)browser
if (self) {
_browser = browser;
_closeSettingsOnAddAccount = closeSettingsOnAddAccount;
_accountManagerService =
ChromeAccountManagerServiceFactory::GetForBrowserState(
_browser->GetBrowserState());
_identityManagerObserver =
std::make_unique<signin::IdentityManagerObserverBridge>(
IdentityManagerFactory::GetForBrowserState(
_browser->GetBrowserState()),
self);
_avatarCache = [[ResizedAvatarCache alloc] initWithDefaultTableView];
_identityServiceObserver.reset(
new ChromeIdentityServiceObserverBridge(self));
_accountManagerServiceObserver =
std::make_unique<ChromeAccountManagerServiceObserverBridge>(
self, _accountManagerService);
}

return self;
Expand Down Expand Up @@ -240,14 +248,10 @@ - (void)loadModel {
signin::IdentityManager* identityManager =
IdentityManagerFactory::GetForBrowserState(_browser->GetBrowserState());

ChromeAccountManagerService* accountManagerService =
ChromeAccountManagerServiceFactory::GetForBrowserState(
_browser->GetBrowserState());

NSString* authenticatedEmail = [authenticatedIdentity userEmail];
for (const auto& account : identityManager->GetAccountsWithRefreshTokens()) {
ChromeIdentity* identity =
accountManagerService->GetIdentityWithGaiaID(account.gaia);
self.accountManagerService->GetIdentityWithGaiaID(account.gaia);
if (!identity) {
// Ignore the case in which the identity is invalid at lookup time. This
// may be due to inconsistencies between the identity service and
Expand Down Expand Up @@ -800,9 +804,9 @@ - (void)openURL:(NSURL*)url
[self.dispatcher closeSettingsUIAndOpenURL:command];
}

#pragma mark - ChromeIdentityServiceObserver
#pragma mark - ChromeAccountManagerServiceObserver

- (void)profileUpdate:(ChromeIdentity*)identity {
- (void)identityChanged:(ChromeIdentity*)identity {
TableViewAccountItem* item = base::mac::ObjCCastStrict<TableViewAccountItem>(
[_identityMap objectForKey:identity.gaiaID]);
if (!item) {
Expand All @@ -814,10 +818,6 @@ - (void)profileUpdate:(ChromeIdentity*)identity {
withRowAnimation:UITableViewRowAnimationAutomatic];
}

- (void)chromeIdentityServiceWillBeDestroyed {
_identityServiceObserver.reset();
}

#pragma mark - UIAdaptivePresentationControllerDelegate

- (void)presentationControllerDidDismiss:
Expand Down

0 comments on commit 541e9d3

Please sign in to comment.