Skip to content

Commit

Permalink
[s13n] Convert AccountsTableViewController to IdentityManager
Browse files Browse the repository at this point in the history
This CL only migrates AccountsTableViewController production code
away from OAuth2TokenServiceObserverBridge,
OAuth2TokenServiceObserverBridgeDelegate, ProfileOAuth2TokenService
and AccountTrackerService.

Bug: 910151
Change-Id: I24c1a3ec80d18d7feed7fa2fcff3ed939e629d2d
Reviewed-on: https://chromium-review.googlesource.com/c/1399698
Reviewed-by: Sylvain Defresne <sdefresne@chromium.org>
Reviewed-by: Colin Blundell <blundell@chromium.org>
Commit-Queue: Julie Jeongeun Kim <jkim@igalia.com>
Cr-Commit-Position: refs/heads/master@{#621415}
  • Loading branch information
jkim-julie authored and Commit Bot committed Jan 10, 2019
1 parent 3f7e5ce commit 6591cea
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions ios/chrome/browser/ui/settings/accounts_table_view_controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,13 @@
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "components/browser_sync/profile_sync_service.h"
#include "components/signin/core/browser/account_tracker_service.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#import "components/signin/ios/browser/oauth2_token_service_observer_bridge.h"
#include "components/strings/grit/components_strings.h"
#include "components/unified_consent/feature.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/signin/account_tracker_service_factory.h"
#import "ios/chrome/browser/signin/authentication_service.h"
#include "ios/chrome/browser/signin/authentication_service_factory.h"
#import "ios/chrome/browser/signin/chrome_identity_service_observer_bridge.h"
#include "ios/chrome/browser/signin/identity_manager_factory.h"
#include "ios/chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "ios/chrome/browser/sync/profile_sync_service_factory.h"
#import "ios/chrome/browser/sync/sync_observer_bridge.h"
#include "ios/chrome/browser/sync/sync_setup_service.h"
Expand Down Expand Up @@ -48,6 +43,7 @@
#import "ios/public/provider/chrome/browser/signin/chrome_identity_service.h"
#import "net/base/mac/url_conversions.h"
#import "services/identity/public/cpp/identity_manager.h"
#import "services/identity/public/objc/identity_manager_observer_bridge.h"
#include "ui/base/l10n/l10n_util_mac.h"

#if !defined(__has_feature) || !__has_feature(objc_arc)
Expand Down Expand Up @@ -84,12 +80,13 @@ typedef NS_ENUM(NSInteger, ItemType) {
@interface AccountsTableViewController () <
ChromeIdentityServiceObserver,
ChromeIdentityBrowserOpener,
OAuth2TokenServiceObserverBridgeDelegate,
IdentityManagerObserverBridgeDelegate,
SyncObserverModelBridge> {
ios::ChromeBrowserState* _browserState; // weak
BOOL _closeSettingsOnAddAccount;
std::unique_ptr<SyncObserverBridge> _syncObserver;
std::unique_ptr<OAuth2TokenServiceObserverBridge> _tokenServiceObserver;
std::unique_ptr<identity::IdentityManagerObserverBridge>
_identityManagerObserver;
// Modal alert for sign out.
AlertCoordinator* _alertCoordinator;
// Whether an authentication operation is in progress (e.g switch accounts,
Expand Down Expand Up @@ -138,9 +135,9 @@ - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState
// in the "Google Services and sync" settings.
_syncObserver.reset(new SyncObserverBridge(self, syncService));
}
_tokenServiceObserver.reset(new OAuth2TokenServiceObserverBridge(
ProfileOAuth2TokenServiceFactory::GetForBrowserState(_browserState),
self));
_identityManagerObserver =
std::make_unique<identity::IdentityManagerObserverBridge>(
IdentityManagerFactory::GetForBrowserState(_browserState), self);
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(willStartSwitchAccount)
Expand All @@ -167,7 +164,7 @@ - (void)viewDidLoad {
}

- (void)stopBrowserStateServiceObservers {
_tokenServiceObserver.reset();
_identityManagerObserver.reset();
_syncObserver.reset();
}

Expand Down Expand Up @@ -215,15 +212,12 @@ - (void)loadModel {
[[NSMutableDictionary alloc] init];

// Account cells.
ProfileOAuth2TokenService* oauth2_service =
ProfileOAuth2TokenServiceFactory::GetForBrowserState(_browserState);
AccountTrackerService* accountTracker =
ios::AccountTrackerServiceFactory::GetForBrowserState(_browserState);
[model addSectionWithIdentifier:SectionIdentifierAccounts];
[model setHeader:[self header]
forSectionWithIdentifier:SectionIdentifierAccounts];
for (const std::string& account_id : oauth2_service->GetAccounts()) {
AccountInfo account = accountTracker->GetAccountInfo(account_id);
identity::IdentityManager* identityManager =
IdentityManagerFactory::GetForBrowserState(_browserState);
for (const auto& account : identityManager->GetAccountsWithRefreshTokens()) {
ChromeIdentity* identity = ios::GetChromeBrowserProvider()
->GetChromeIdentityService()
->GetIdentityWithGaiaID(account.gaia);
Expand Down Expand Up @@ -428,9 +422,9 @@ - (void)onSyncStateChanged {
}
}

#pragma mark - OAuth2TokenServiceObserverBridgeDelegate
#pragma mark - IdentityManagerObserverBridgeDelegate

- (void)onEndBatchChanges {
- (void)onEndBatchOfRefreshTokenStateChanges {
[self reloadData];
[self popViewIfSignedOut];
if (![self authService] -> IsAuthenticated() && _settingsDetails) {
Expand Down

0 comments on commit 6591cea

Please sign in to comment.