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") {
"//ios/public/provider/chrome/browser",
"//ios/public/provider/chrome/browser/images",
"//ios/public/provider/chrome/browser/signin",
"//services/identity/public/cpp:cpp",
"//services/identity/public/cpp",
"//services/identity/public/objc",
"//ui/base",
"//ui/gfx",
"//url",
......@@ -200,6 +201,6 @@ source_set("eg_test_support") {
"//ios/public/provider/chrome/browser/signin",
"//ios/public/provider/chrome/browser/signin:test_support",
"//ios/third_party/earl_grey:earl_grey+link",
"//services/identity/public/cpp:cpp",
"//services/identity/public/cpp",
]
}
......@@ -5,15 +5,11 @@
#import "ios/chrome/browser/ui/authentication/signed_in_accounts_view_controller.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/signin/account_tracker_service_factory.h"
#include "ios/chrome/browser/signin/authentication_service.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/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/collection_view/cells/collection_view_account_item.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_controller.h"
......@@ -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/Palettes/src/MaterialPalettes.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"
#if !defined(__has_feature) || !__has_feature(objc_arc)
......@@ -39,7 +37,7 @@
namespace {
const int kMaxShownAccounts = 3;
const size_t kMaxShownAccounts = 3;
const CGFloat kAccountsExtraBottomInset = 16;
const CGFloat kVerticalPadding = 24;
const CGFloat kButtonVerticalPadding = 16;
......@@ -110,16 +108,14 @@ BOOL gSignedInAccountsViewControllerIsShown = NO;
- (void)loadModel {
[super loadModel];
CollectionViewModel* model = self.collectionViewModel;
[model addSectionWithIdentifier:SectionIdentifierAccounts];
NSMutableDictionary<NSString*, CollectionViewItem*>* mutableIdentityMap =
[[NSMutableDictionary alloc] init];
[model addSectionWithIdentifier:SectionIdentifierAccounts];
ProfileOAuth2TokenService* oauth2_service =
ProfileOAuth2TokenServiceFactory::GetForBrowserState(_browserState);
AccountTrackerService* accountTracker =
ios::AccountTrackerServiceFactory::GetForBrowserState(_browserState);
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);
......@@ -181,10 +177,11 @@ BOOL gSignedInAccountsViewControllerIsShown = NO;
@end
@interface SignedInAccountsViewController ()<
OAuth2TokenServiceObserverBridgeDelegate> {
@interface SignedInAccountsViewController () <
IdentityManagerObserverBridgeDelegate> {
ios::ChromeBrowserState* _browserState; // Weak.
std::unique_ptr<OAuth2TokenServiceObserverBridge> _tokenServiceObserver;
std::unique_ptr<identity::IdentityManagerObserverBridge>
_identityManagerObserver;
MDCDialogTransitionController* _transitionController;
UILabel* _titleLabel;
......@@ -219,9 +216,9 @@ BOOL gSignedInAccountsViewControllerIsShown = NO;
if (self) {
_browserState = browserState;
_dispatcher = dispatcher;
_tokenServiceObserver.reset(new OAuth2TokenServiceObserverBridge(
ProfileOAuth2TokenServiceFactory::GetForBrowserState(_browserState),
self));
_identityManagerObserver =
std::make_unique<identity::IdentityManagerObserverBridge>(
IdentityManagerFactory::GetForBrowserState(_browserState), self);
_transitionController = [[MDCDialogTransitionController alloc] init];
self.modalPresentationStyle = UIModalPresentationCustom;
self.transitioningDelegate = _transitionController;
......@@ -246,13 +243,14 @@ BOOL gSignedInAccountsViewControllerIsShown = NO;
#pragma mark UIViewController
- (CGSize)preferredContentSize {
CGFloat width = MIN(kDialogMaxWidth,
self.presentingViewController.view.bounds.size.width -
2 * kMDCMinHorizontalPadding);
OAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForBrowserState(_browserState);
CGFloat width = std::min(
kDialogMaxWidth, self.presentingViewController.view.bounds.size.width -
2 * kMDCMinHorizontalPadding);
identity::IdentityManager* identityManager =
IdentityManagerFactory::GetForBrowserState(_browserState);
int shownAccounts =
MIN(kMaxShownAccounts, token_service->GetAccounts().size());
std::min(kMaxShownAccounts,
identityManager->GetAccountsWithRefreshTokens().size());
CGSize maxSize = CGSizeMake(width - 2 * kHorizontalPadding, CGFLOAT_MAX);
CGSize buttonSize = [_primaryButton sizeThatFits:maxSize];
CGSize infoSize = [_infoLabel sizeThatFits:maxSize];
......@@ -388,12 +386,12 @@ BOOL gSignedInAccountsViewControllerIsShown = NO;
}];
}
#pragma mark OAuth2TokenServiceObserverBridgeDelegate
#pragma mark IdentityManagerObserverBridgeDelegate
- (void)onEndBatchChanges {
ProfileOAuth2TokenService* tokenService =
ProfileOAuth2TokenServiceFactory::GetForBrowserState(_browserState);
if (tokenService->GetAccounts().empty()) {
- (void)onEndBatchOfRefreshTokenStateChanges {
identity::IdentityManager* identityManager =
IdentityManagerFactory::GetForBrowserState(_browserState);
if (identityManager->GetAccountsWithRefreshTokens().empty()) {
[self dismissWithCompletion:nil];
return;
}
......
......@@ -23,7 +23,10 @@
// these semantics.
- (void)onPrimaryAccountSet:(const AccountInfo&)primaryAccountInfo;
- (void)onPrimaryAccountSet:(const AccountInfo&)primaryAccountInfo
withPassword:(const std::string&)password;
- (void)onPrimaryAccountCleared:(const AccountInfo&)previousPrimaryAccountInfo;
- (void)onPrimaryAccountSigninFailed:(const GoogleServiceAuthError&)error;
- (void)onRefreshTokenUpdatedForAccount:(const AccountInfo&)accountInfo
valid:(BOOL)isValid;
- (void)onRefreshTokenRemovedForAccount:(const std::string&)accountId;
......@@ -47,8 +50,12 @@ class IdentityManagerObserverBridge : public IdentityManager::Observer {
// IdentityManager::Observer.
void OnPrimaryAccountSet(const AccountInfo& primary_account_info) override;
void OnPrimaryAccountSetWithPassword(const AccountInfo& primary_account_info,
const std::string& password) override;
void OnPrimaryAccountCleared(
const AccountInfo& previous_primary_account_info) override;
void OnPrimaryAccountSigninFailed(
const GoogleServiceAuthError& error) override;
void OnRefreshTokenUpdatedForAccount(const AccountInfo& account_info,
bool is_valid) override;
void OnRefreshTokenRemovedForAccount(const std::string& account_id) override;
......
......@@ -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(
const AccountInfo& previous_primary_account_info) {
if ([delegate_ respondsToSelector:@selector(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(
const AccountInfo& account_info,
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