Commit da0c2011 authored by Sylvain Defresne's avatar Sylvain Defresne Committed by Commit Bot

Convert SignedInAccountsViewController to IdentityManager

Uses IdentityManager API instead of using the soon to be
private ProfileOAuth2TokenService and AccountTrackerService
APIs.

Bug: 908855
Change-Id: If533b43a698b2f2ea7c24ad43273b4ecba74091f
Reviewed-on: https://chromium-review.googlesource.com/c/1354447Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612236}
parent ed5ef661
...@@ -63,7 +63,8 @@ source_set("authentication") { ...@@ -63,7 +63,8 @@ source_set("authentication") {
"//ios/public/provider/chrome/browser", "//ios/public/provider/chrome/browser",
"//ios/public/provider/chrome/browser/images", "//ios/public/provider/chrome/browser/images",
"//ios/public/provider/chrome/browser/signin", "//ios/public/provider/chrome/browser/signin",
"//services/identity/public/cpp:cpp", "//services/identity/public/cpp",
"//services/identity/public/objc",
"//ui/base", "//ui/base",
"//ui/gfx", "//ui/gfx",
"//url", "//url",
...@@ -200,6 +201,6 @@ source_set("eg_test_support") { ...@@ -200,6 +201,6 @@ source_set("eg_test_support") {
"//ios/public/provider/chrome/browser/signin", "//ios/public/provider/chrome/browser/signin",
"//ios/public/provider/chrome/browser/signin:test_support", "//ios/public/provider/chrome/browser/signin:test_support",
"//ios/third_party/earl_grey:earl_grey+link", "//ios/third_party/earl_grey:earl_grey+link",
"//services/identity/public/cpp:cpp", "//services/identity/public/cpp",
] ]
} }
...@@ -5,15 +5,11 @@ ...@@ -5,15 +5,11 @@
#import "ios/chrome/browser/ui/authentication/signed_in_accounts_view_controller.h" #import "ios/chrome/browser/ui/authentication/signed_in_accounts_view_controller.h"
#import "base/mac/foundation_util.h" #import "base/mac/foundation_util.h"
#include "components/signin/core/browser/account_tracker_service.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/ios/browser/oauth2_token_service_observer_bridge.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h" #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/signin/account_tracker_service_factory.h"
#include "ios/chrome/browser/signin/authentication_service.h" #include "ios/chrome/browser/signin/authentication_service.h"
#include "ios/chrome/browser/signin/authentication_service_factory.h" #include "ios/chrome/browser/signin/authentication_service_factory.h"
#include "ios/chrome/browser/signin/chrome_identity_service_observer_bridge.h" #include "ios/chrome/browser/signin/chrome_identity_service_observer_bridge.h"
#include "ios/chrome/browser/signin/profile_oauth2_token_service_factory.h" #include "ios/chrome/browser/signin/identity_manager_factory.h"
#import "ios/chrome/browser/ui/authentication/resized_avatar_cache.h" #import "ios/chrome/browser/ui/authentication/resized_avatar_cache.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_account_item.h" #import "ios/chrome/browser/ui/collection_view/cells/collection_view_account_item.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_controller.h" #import "ios/chrome/browser/ui/collection_view/collection_view_controller.h"
...@@ -31,6 +27,8 @@ ...@@ -31,6 +27,8 @@
#import "ios/third_party/material_components_ios/src/components/Dialogs/src/MaterialDialogs.h" #import "ios/third_party/material_components_ios/src/components/Dialogs/src/MaterialDialogs.h"
#import "ios/third_party/material_components_ios/src/components/Palettes/src/MaterialPalettes.h" #import "ios/third_party/material_components_ios/src/components/Palettes/src/MaterialPalettes.h"
#import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h" #import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h"
#include "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" #include "ui/base/l10n/l10n_util_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
...@@ -39,7 +37,7 @@ ...@@ -39,7 +37,7 @@
namespace { namespace {
const int kMaxShownAccounts = 3; const size_t kMaxShownAccounts = 3;
const CGFloat kAccountsExtraBottomInset = 16; const CGFloat kAccountsExtraBottomInset = 16;
const CGFloat kVerticalPadding = 24; const CGFloat kVerticalPadding = 24;
const CGFloat kButtonVerticalPadding = 16; const CGFloat kButtonVerticalPadding = 16;
...@@ -110,16 +108,14 @@ BOOL gSignedInAccountsViewControllerIsShown = NO; ...@@ -110,16 +108,14 @@ BOOL gSignedInAccountsViewControllerIsShown = NO;
- (void)loadModel { - (void)loadModel {
[super loadModel]; [super loadModel];
CollectionViewModel* model = self.collectionViewModel; CollectionViewModel* model = self.collectionViewModel;
[model addSectionWithIdentifier:SectionIdentifierAccounts];
NSMutableDictionary<NSString*, CollectionViewItem*>* mutableIdentityMap = NSMutableDictionary<NSString*, CollectionViewItem*>* mutableIdentityMap =
[[NSMutableDictionary alloc] init]; [[NSMutableDictionary alloc] init];
[model addSectionWithIdentifier:SectionIdentifierAccounts]; identity::IdentityManager* identityManager =
ProfileOAuth2TokenService* oauth2_service = IdentityManagerFactory::GetForBrowserState(_browserState);
ProfileOAuth2TokenServiceFactory::GetForBrowserState(_browserState); for (const auto& account : identityManager->GetAccountsWithRefreshTokens()) {
AccountTrackerService* accountTracker =
ios::AccountTrackerServiceFactory::GetForBrowserState(_browserState);
for (const std::string& account_id : oauth2_service->GetAccounts()) {
AccountInfo account = accountTracker->GetAccountInfo(account_id);
ChromeIdentity* identity = ios::GetChromeBrowserProvider() ChromeIdentity* identity = ios::GetChromeBrowserProvider()
->GetChromeIdentityService() ->GetChromeIdentityService()
->GetIdentityWithGaiaID(account.gaia); ->GetIdentityWithGaiaID(account.gaia);
...@@ -181,10 +177,11 @@ BOOL gSignedInAccountsViewControllerIsShown = NO; ...@@ -181,10 +177,11 @@ BOOL gSignedInAccountsViewControllerIsShown = NO;
@end @end
@interface SignedInAccountsViewController ()< @interface SignedInAccountsViewController () <
OAuth2TokenServiceObserverBridgeDelegate> { IdentityManagerObserverBridgeDelegate> {
ios::ChromeBrowserState* _browserState; // Weak. ios::ChromeBrowserState* _browserState; // Weak.
std::unique_ptr<OAuth2TokenServiceObserverBridge> _tokenServiceObserver; std::unique_ptr<identity::IdentityManagerObserverBridge>
_identityManagerObserver;
MDCDialogTransitionController* _transitionController; MDCDialogTransitionController* _transitionController;
UILabel* _titleLabel; UILabel* _titleLabel;
...@@ -219,9 +216,9 @@ BOOL gSignedInAccountsViewControllerIsShown = NO; ...@@ -219,9 +216,9 @@ BOOL gSignedInAccountsViewControllerIsShown = NO;
if (self) { if (self) {
_browserState = browserState; _browserState = browserState;
_dispatcher = dispatcher; _dispatcher = dispatcher;
_tokenServiceObserver.reset(new OAuth2TokenServiceObserverBridge( _identityManagerObserver =
ProfileOAuth2TokenServiceFactory::GetForBrowserState(_browserState), std::make_unique<identity::IdentityManagerObserverBridge>(
self)); IdentityManagerFactory::GetForBrowserState(_browserState), self);
_transitionController = [[MDCDialogTransitionController alloc] init]; _transitionController = [[MDCDialogTransitionController alloc] init];
self.modalPresentationStyle = UIModalPresentationCustom; self.modalPresentationStyle = UIModalPresentationCustom;
self.transitioningDelegate = _transitionController; self.transitioningDelegate = _transitionController;
...@@ -246,13 +243,14 @@ BOOL gSignedInAccountsViewControllerIsShown = NO; ...@@ -246,13 +243,14 @@ BOOL gSignedInAccountsViewControllerIsShown = NO;
#pragma mark UIViewController #pragma mark UIViewController
- (CGSize)preferredContentSize { - (CGSize)preferredContentSize {
CGFloat width = MIN(kDialogMaxWidth, CGFloat width = std::min(
self.presentingViewController.view.bounds.size.width - kDialogMaxWidth, self.presentingViewController.view.bounds.size.width -
2 * kMDCMinHorizontalPadding); 2 * kMDCMinHorizontalPadding);
OAuth2TokenService* token_service = identity::IdentityManager* identityManager =
ProfileOAuth2TokenServiceFactory::GetForBrowserState(_browserState); IdentityManagerFactory::GetForBrowserState(_browserState);
int shownAccounts = int shownAccounts =
MIN(kMaxShownAccounts, token_service->GetAccounts().size()); std::min(kMaxShownAccounts,
identityManager->GetAccountsWithRefreshTokens().size());
CGSize maxSize = CGSizeMake(width - 2 * kHorizontalPadding, CGFLOAT_MAX); CGSize maxSize = CGSizeMake(width - 2 * kHorizontalPadding, CGFLOAT_MAX);
CGSize buttonSize = [_primaryButton sizeThatFits:maxSize]; CGSize buttonSize = [_primaryButton sizeThatFits:maxSize];
CGSize infoSize = [_infoLabel sizeThatFits:maxSize]; CGSize infoSize = [_infoLabel sizeThatFits:maxSize];
...@@ -388,12 +386,12 @@ BOOL gSignedInAccountsViewControllerIsShown = NO; ...@@ -388,12 +386,12 @@ BOOL gSignedInAccountsViewControllerIsShown = NO;
}]; }];
} }
#pragma mark OAuth2TokenServiceObserverBridgeDelegate #pragma mark IdentityManagerObserverBridgeDelegate
- (void)onEndBatchChanges { - (void)onEndBatchOfRefreshTokenStateChanges {
ProfileOAuth2TokenService* tokenService = identity::IdentityManager* identityManager =
ProfileOAuth2TokenServiceFactory::GetForBrowserState(_browserState); IdentityManagerFactory::GetForBrowserState(_browserState);
if (tokenService->GetAccounts().empty()) { if (identityManager->GetAccountsWithRefreshTokens().empty()) {
[self dismissWithCompletion:nil]; [self dismissWithCompletion:nil];
return; return;
} }
......
...@@ -23,7 +23,10 @@ ...@@ -23,7 +23,10 @@
// these semantics. // these semantics.
- (void)onPrimaryAccountSet:(const AccountInfo&)primaryAccountInfo; - (void)onPrimaryAccountSet:(const AccountInfo&)primaryAccountInfo;
- (void)onPrimaryAccountSet:(const AccountInfo&)primaryAccountInfo
withPassword:(const std::string&)password;
- (void)onPrimaryAccountCleared:(const AccountInfo&)previousPrimaryAccountInfo; - (void)onPrimaryAccountCleared:(const AccountInfo&)previousPrimaryAccountInfo;
- (void)onPrimaryAccountSigninFailed:(const GoogleServiceAuthError&)error;
- (void)onRefreshTokenUpdatedForAccount:(const AccountInfo&)accountInfo - (void)onRefreshTokenUpdatedForAccount:(const AccountInfo&)accountInfo
valid:(BOOL)isValid; valid:(BOOL)isValid;
- (void)onRefreshTokenRemovedForAccount:(const std::string&)accountId; - (void)onRefreshTokenRemovedForAccount:(const std::string&)accountId;
...@@ -47,8 +50,12 @@ class IdentityManagerObserverBridge : public IdentityManager::Observer { ...@@ -47,8 +50,12 @@ class IdentityManagerObserverBridge : public IdentityManager::Observer {
// IdentityManager::Observer. // IdentityManager::Observer.
void OnPrimaryAccountSet(const AccountInfo& primary_account_info) override; void OnPrimaryAccountSet(const AccountInfo& primary_account_info) override;
void OnPrimaryAccountSetWithPassword(const AccountInfo& primary_account_info,
const std::string& password) override;
void OnPrimaryAccountCleared( void OnPrimaryAccountCleared(
const AccountInfo& previous_primary_account_info) override; const AccountInfo& previous_primary_account_info) override;
void OnPrimaryAccountSigninFailed(
const GoogleServiceAuthError& error) override;
void OnRefreshTokenUpdatedForAccount(const AccountInfo& account_info, void OnRefreshTokenUpdatedForAccount(const AccountInfo& account_info,
bool is_valid) override; bool is_valid) override;
void OnRefreshTokenRemovedForAccount(const std::string& account_id) override; void OnRefreshTokenRemovedForAccount(const std::string& account_id) override;
......
...@@ -28,6 +28,15 @@ void IdentityManagerObserverBridge::OnPrimaryAccountSet( ...@@ -28,6 +28,15 @@ void IdentityManagerObserverBridge::OnPrimaryAccountSet(
} }
} }
void IdentityManagerObserverBridge::OnPrimaryAccountSetWithPassword(
const AccountInfo& primary_account_info,
const std::string& password) {
if ([delegate_ respondsToSelector:@selector(onPrimaryAccountSet:
withPassword:)]) {
[delegate_ onPrimaryAccountSet:primary_account_info withPassword:password];
}
}
void IdentityManagerObserverBridge::OnPrimaryAccountCleared( void IdentityManagerObserverBridge::OnPrimaryAccountCleared(
const AccountInfo& previous_primary_account_info) { const AccountInfo& previous_primary_account_info) {
if ([delegate_ respondsToSelector:@selector(onPrimaryAccountCleared:)]) { if ([delegate_ respondsToSelector:@selector(onPrimaryAccountCleared:)]) {
...@@ -35,6 +44,13 @@ void IdentityManagerObserverBridge::OnPrimaryAccountCleared( ...@@ -35,6 +44,13 @@ void IdentityManagerObserverBridge::OnPrimaryAccountCleared(
} }
} }
void IdentityManagerObserverBridge::OnPrimaryAccountSigninFailed(
const GoogleServiceAuthError& error) {
if ([delegate_ respondsToSelector:@selector(onPrimaryAccountSigninFailed:)]) {
[delegate_ onPrimaryAccountSigninFailed:error];
}
}
void IdentityManagerObserverBridge::OnRefreshTokenUpdatedForAccount( void IdentityManagerObserverBridge::OnRefreshTokenUpdatedForAccount(
const AccountInfo& account_info, const AccountInfo& account_info,
bool is_valid) { bool is_valid) {
......
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