Commit cb9b7020 authored by Sergio Villar Senin's avatar Sergio Villar Senin Committed by Commit Bot

AboutSigninInternals: remove the SigninManagerBase::Observer dependency

It can observe IdentityManager::Observer instead. This is a step
forward in the migration to IdentityManager API.

Most usages of SigninManager were also replaced by their equivalent
IdentityManager API. It's also observing
IdentityManager::DiagnosticsObserver from now on.

BUG: 809539

Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: I9e7319a522f298298ab6a1a512bad73675050e70
Reviewed-on: https://chromium-review.googlesource.com/c/1276606Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Commit-Queue: Sergio Villar <svillar@igalia.com>
Cr-Commit-Position: refs/heads/master@{#609640}
parent 62757da8
......@@ -9,6 +9,7 @@
#include "chrome/browser/signin/account_tracker_service_factory.h"
#include "chrome/browser/signin/chrome_signin_client_factory.h"
#include "chrome/browser/signin/gaia_cookie_manager_service_factory.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_error_controller_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
......@@ -54,6 +55,7 @@ KeyedService* AboutSigninInternalsFactory::BuildServiceInstanceFor(
AboutSigninInternals* service = new AboutSigninInternals(
ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
AccountTrackerServiceFactory::GetForProfile(profile),
IdentityManagerFactory::GetForProfile(profile),
SigninManagerFactory::GetForProfile(profile),
SigninErrorControllerFactory::GetForProfile(profile),
GaiaCookieManagerServiceFactory::GetForProfile(profile),
......
......@@ -139,6 +139,7 @@ class DiceResponseHandlerTest : public testing::Test,
&cookie_service_),
about_signin_internals_(&token_service_,
&account_tracker_service_,
identity_test_env_.identity_manager(),
&signin_manager_,
&signin_error_controller_,
&cookie_service_,
......
......@@ -29,6 +29,7 @@
#include "components/signin/core/browser/signin_switches.h"
#include "google_apis/gaia/oauth2_token_service_delegate.h"
#include "net/base/backoff_entry.h"
#include "services/identity/public/cpp/identity_manager.h"
namespace {
......@@ -188,12 +189,14 @@ std::string GetAccountConsistencyDescription(
AboutSigninInternals::AboutSigninInternals(
ProfileOAuth2TokenService* token_service,
AccountTrackerService* account_tracker,
identity::IdentityManager* identity_manager,
SigninManagerBase* signin_manager,
SigninErrorController* signin_error_controller,
GaiaCookieManagerService* cookie_manager_service,
signin::AccountConsistencyMethod account_consistency)
: token_service_(token_service),
account_tracker_(account_tracker),
identity_manager_(identity_manager),
signin_manager_(signin_manager),
client_(nullptr),
signin_error_controller_(signin_error_controller),
......@@ -308,7 +311,8 @@ void AboutSigninInternals::Initialize(SigninClient* client) {
RefreshSigninPrefs();
signin_error_controller_->AddObserver(this);
signin_manager_->AddObserver(this);
identity_manager_->AddObserver(this);
identity_manager_->AddDiagnosticsObserver(this);
signin_manager_->AddSigninDiagnosticsObserver(this);
token_service_->AddObserver(this);
token_service_->AddDiagnosticsObserver(this);
......@@ -317,7 +321,8 @@ void AboutSigninInternals::Initialize(SigninClient* client) {
void AboutSigninInternals::Shutdown() {
signin_error_controller_->RemoveObserver(this);
signin_manager_->RemoveObserver(this);
identity_manager_->RemoveObserver(this);
identity_manager_->RemoveDiagnosticsObserver(this);
signin_manager_->RemoveSigninDiagnosticsObserver(this);
token_service_->RemoveObserver(this);
token_service_->RemoveDiagnosticsObserver(this);
......@@ -329,7 +334,7 @@ void AboutSigninInternals::NotifyObservers() {
return;
std::unique_ptr<base::DictionaryValue> signin_status_value =
signin_status_.ToValue(account_tracker_, signin_manager_,
signin_status_.ToValue(account_tracker_, identity_manager_,
signin_error_controller_, token_service_,
cookie_manager_service_, client_,
account_consistency_);
......@@ -340,14 +345,14 @@ void AboutSigninInternals::NotifyObservers() {
std::unique_ptr<base::DictionaryValue> AboutSigninInternals::GetSigninStatus() {
return signin_status_.ToValue(
account_tracker_, signin_manager_, signin_error_controller_,
account_tracker_, identity_manager_, signin_error_controller_,
token_service_, cookie_manager_service_, client_, account_consistency_);
}
void AboutSigninInternals::OnAccessTokenRequested(
const std::string& account_id,
const std::string& consumer_id,
const OAuth2TokenService::ScopeSet& scopes) {
const identity::ScopeSet& scopes) {
TokenInfo* token = signin_status_.FindToken(account_id, consumer_id, scopes);
if (token) {
*token = TokenInfo(consumer_id, scopes);
......@@ -440,18 +445,18 @@ void AboutSigninInternals::OnErrorChanged() {
NotifyObservers();
}
void AboutSigninInternals::GoogleSigninFailed(
void AboutSigninInternals::OnPrimaryAccountSigninFailed(
const GoogleServiceAuthError& error) {
NotifyObservers();
}
void AboutSigninInternals::GoogleSigninSucceeded(const std::string& account_id,
const std::string& username) {
void AboutSigninInternals::OnPrimaryAccountSet(
const AccountInfo& primary_account_info) {
NotifyObservers();
}
void AboutSigninInternals::GoogleSignedOut(const std::string& account_id,
const std::string& username) {
void AboutSigninInternals::OnPrimaryAccountCleared(
const AccountInfo& primary_account_info) {
NotifyObservers();
}
......@@ -589,7 +594,7 @@ void AboutSigninInternals::SigninStatus::AddRefreshTokenEvent(
std::unique_ptr<base::DictionaryValue>
AboutSigninInternals::SigninStatus::ToValue(
AccountTrackerService* account_tracker,
SigninManagerBase* signin_manager,
identity::IdentityManager* identity_manager,
SigninErrorController* signin_error_controller,
ProfileOAuth2TokenService* token_service,
GaiaCookieManagerService* cookie_manager_service,
......@@ -605,15 +610,16 @@ AboutSigninInternals::SigninStatus::ToValue(
signin_client->GetProductVersion());
AddSectionEntry(basic_info, "Account Consistency",
GetAccountConsistencyDescription(account_consistency));
AddSectionEntry(basic_info, "Signin Status",
signin_manager->IsAuthenticated() ? "Signed In" : "Not Signed In");
AddSectionEntry(
basic_info, "Signin Status",
identity_manager->HasPrimaryAccount() ? "Signed In" : "Not Signed In");
OAuth2TokenServiceDelegate::LoadCredentialsState load_tokens_state =
token_service->GetDelegate()->load_credentials_state();
AddSectionEntry(basic_info, "TokenService Load Status",
TokenServiceLoadCredentialsStateToLabel(load_tokens_state));
if (signin_manager->IsAuthenticated()) {
std::string account_id = signin_manager->GetAuthenticatedAccountId();
if (identity_manager->HasPrimaryAccount()) {
std::string account_id = identity_manager->GetPrimaryAccountId();
AddSectionEntry(basic_info,
SigninStatusFieldToLabel(signin_internals_util::ACCOUNT_ID),
account_id);
......@@ -622,7 +628,7 @@ AboutSigninInternals::SigninStatus::ToValue(
account_tracker->GetAccountInfo(account_id).gaia);
AddSectionEntry(basic_info,
SigninStatusFieldToLabel(signin_internals_util::USERNAME),
signin_manager->GetAuthenticatedAccountInfo().email);
identity_manager->GetPrimaryAccountInfo().email);
if (signin_error_controller->HasError()) {
const std::string error_account_id =
signin_error_controller->error_account_id();
......
......@@ -20,6 +20,11 @@
#include "components/signin/core/browser/signin_internals_util.h"
#include "components/signin/core/browser/signin_manager.h"
#include "google_apis/gaia/oauth2_token_service.h"
#include "services/identity/public/cpp/identity_manager.h"
namespace identity {
class IdentityManager;
}
class AccountTrackerService;
class PrefRegistrySimple;
......@@ -38,8 +43,9 @@ class AboutSigninInternals
public OAuth2TokenService::Observer,
public OAuth2TokenService::DiagnosticsObserver,
public GaiaCookieManagerService::Observer,
SigninManagerBase::Observer,
SigninErrorController::Observer {
SigninErrorController::Observer,
identity::IdentityManager::Observer,
identity::IdentityManager::DiagnosticsObserver {
public:
class Observer {
public:
......@@ -53,6 +59,7 @@ class AboutSigninInternals
AboutSigninInternals(ProfileOAuth2TokenService* token_service,
AccountTrackerService* account_tracker,
identity::IdentityManager* identity_manager,
SigninManagerBase* signin_manager,
SigninErrorController* signin_error_controller,
GaiaCookieManagerService* cookie_manager_service,
......@@ -181,7 +188,7 @@ class AboutSigninInternals
// }
std::unique_ptr<base::DictionaryValue> ToValue(
AccountTrackerService* account_tracker,
SigninManagerBase* signin_manager,
identity::IdentityManager* identity_manager,
SigninErrorController* signin_error_controller,
ProfileOAuth2TokenService* token_service,
GaiaCookieManagerService* cookie_manager_service_,
......@@ -194,11 +201,12 @@ class AboutSigninInternals
const signin_internals_util::TimedSigninStatusField& field,
const std::string& value) override;
// IdentityMager::DiagnosticsObserver implementations.
void OnAccessTokenRequested(const std::string& account_id,
const std::string& consumer_id,
const identity::ScopeSet& scopes) override;
// OAuth2TokenService::DiagnosticsObserver implementations.
void OnAccessTokenRequested(
const std::string& account_id,
const std::string& consumer_id,
const OAuth2TokenService::ScopeSet& scopes) override;
void OnFetchAccessTokenComplete(const std::string& account_id,
const std::string& consumer_id,
const OAuth2TokenService::ScopeSet& scopes,
......@@ -217,12 +225,12 @@ class AboutSigninInternals
void OnRefreshTokensLoaded() override;
void OnEndBatchChanges() override;
// SigninManagerBase::Observer implementations.
void GoogleSigninFailed(const GoogleServiceAuthError& error) override;
void GoogleSigninSucceeded(const std::string& account_id,
const std::string& username) override;
void GoogleSignedOut(const std::string& account_id,
const std::string& username) override;
// IdentityManager::Observer implementations.
void OnPrimaryAccountSigninFailed(
const GoogleServiceAuthError& error) override;
void OnPrimaryAccountSet(const AccountInfo& primary_account_info) override;
void OnPrimaryAccountCleared(
const AccountInfo& primary_account_info) override;
void NotifyObservers();
......@@ -235,6 +243,9 @@ class AboutSigninInternals
// Weak pointer to the account tracker.
AccountTrackerService* account_tracker_;
// Weak pointer to the identity manager.
identity::IdentityManager* identity_manager_;
// Weak pointer to the signin manager.
SigninManagerBase* signin_manager_;
......
......@@ -14,6 +14,7 @@
#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/gaia_cookie_manager_service_factory.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/signin/signin_client_factory.h"
#include "ios/chrome/browser/signin/signin_error_controller_factory.h"
......@@ -28,6 +29,7 @@ AboutSigninInternalsFactory::AboutSigninInternalsFactory()
DependsOn(AccountTrackerServiceFactory::GetInstance());
DependsOn(GaiaCookieManagerServiceFactory::GetInstance());
DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
DependsOn(IdentityManagerFactory::GetInstance());
DependsOn(SigninClientFactory::GetInstance());
DependsOn(SigninErrorControllerFactory::GetInstance());
DependsOn(SigninManagerFactory::GetInstance());
......@@ -56,6 +58,7 @@ AboutSigninInternalsFactory::BuildServiceInstanceFor(
ProfileOAuth2TokenServiceFactory::GetForBrowserState(
chrome_browser_state),
AccountTrackerServiceFactory::GetForBrowserState(chrome_browser_state),
IdentityManagerFactory::GetForBrowserState(chrome_browser_state),
SigninManagerFactory::GetForBrowserState(chrome_browser_state),
SigninErrorControllerFactory::GetForBrowserState(chrome_browser_state),
GaiaCookieManagerServiceFactory::GetForBrowserState(chrome_browser_state),
......
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