Commit f79dc64e authored by Anastasiia N's avatar Anastasiia N Committed by Commit Bot

Remove GetURLLoaderFactory() from AccountManager

Update ProfileOAuth2TokenServiceDelegateChromeOS to return nullptr
and use AccountManager's URLLoaderFactory in CreateAccessTokenFetcher()
instead of using the one which is provided in parameters.


Bug: 1119401
Change-Id: I1a02c1167f808144d83327762b8f3ba7fb5d19ab
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2369092
Commit-Queue: Anastasiia N <anastasiian@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Reviewed-by: default avatarKush Sinha <sinhak@chromium.org>
Cr-Commit-Position: refs/heads/master@{#808817}
parent 00de67b5
......@@ -226,7 +226,7 @@ void EduAccountLoginHandler::FetchFamilyMembers() {
family_fetcher_ = std::make_unique<FamilyInfoFetcher>(
this, IdentityManagerFactory::GetForProfile(profile),
account_manager->GetUrlLoaderFactory());
profile->GetURLLoaderFactory());
family_fetcher_->StartGetFamilyMembers();
}
......@@ -277,7 +277,7 @@ void EduAccountLoginHandler::FetchReAuthProofTokenForParent(
DCHECK(account_manager);
gaia_auth_fetcher_ = std::make_unique<GaiaAuthFetcher>(
this, gaia::GaiaSource::kChrome, account_manager->GetUrlLoaderFactory());
this, gaia::GaiaSource::kChrome, profile->GetURLLoaderFactory());
gaia_auth_fetcher_->StartCreateReAuthProofTokenForParent(
child_oauth_access_token, parent_obfuscated_gaia_id, parent_credential);
}
......
......@@ -95,6 +95,7 @@ class SigninHelper : public GaiaAuthConsumer {
: account_manager_(account_manager),
close_dialog_closure_(close_dialog_closure),
email_(email),
url_loader_factory_(url_loader_factory),
gaia_auth_fetcher_(this,
gaia::GaiaSource::kChrome,
url_loader_factory) {
......@@ -147,6 +148,10 @@ class SigninHelper : public GaiaAuthConsumer {
const std::string GetEmail() { return email_; }
const scoped_refptr<network::SharedURLLoaderFactory> GetUrlLoaderFactory() {
return url_loader_factory_;
}
private:
// A non-owning pointer to Chrome OS AccountManager.
chromeos::AccountManager* const account_manager_;
......@@ -156,6 +161,7 @@ class SigninHelper : public GaiaAuthConsumer {
chromeos::AccountManager::AccountKey account_key_;
// The user's email for which |this| object has been created.
const std::string email_;
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
// Used for exchanging auth code for OAuth tokens.
GaiaAuthFetcher gaia_auth_fetcher_;
......@@ -203,9 +209,8 @@ class ChildSigninHelper : public SigninHelper {
DCHECK(!secondary_account_consent_logger_);
secondary_account_consent_logger_ =
std::make_unique<SecondaryAccountConsentLogger>(
identity_manager_, GetAccountManager()->GetUrlLoaderFactory(),
pref_service_, GetEmail(), parent_obfuscated_gaia_id_,
re_auth_proof_token_,
identity_manager_, GetUrlLoaderFactory(), pref_service_, GetEmail(),
parent_obfuscated_gaia_id_, re_auth_proof_token_,
base::BindOnce(&ChildSigninHelper::OnConsentLogged,
weak_ptr_factory_.GetWeakPtr(),
result.refresh_token));
......@@ -334,8 +339,8 @@ void InlineLoginHandlerChromeOS::CompleteLogin(const std::string& email,
InlineLoginDialogChromeOS::EduCoexistenceFlowResult::kFlowCompleted);
// ChildSigninHelper deletes itself after its work is done.
new ChildSigninHelper(
account_manager, close_dialog_closure_,
account_manager->GetUrlLoaderFactory(), gaia_id, email, auth_code,
account_manager, close_dialog_closure_, profile->GetURLLoaderFactory(),
gaia_id, email, auth_code,
GetAccountDeviceId(GetSigninScopedDeviceIdForProfile(profile), gaia_id),
identity_manager, profile->GetPrefs(), *parentId, *rapt);
return;
......@@ -343,8 +348,8 @@ void InlineLoginHandlerChromeOS::CompleteLogin(const std::string& email,
// SigninHelper deletes itself after its work is done.
new SigninHelper(
account_manager, close_dialog_closure_,
account_manager->GetUrlLoaderFactory(), gaia_id, email, auth_code,
account_manager, close_dialog_closure_, profile->GetURLLoaderFactory(),
gaia_id, email, auth_code,
GetAccountDeviceId(GetSigninScopedDeviceIdForProfile(profile), gaia_id));
}
......
......@@ -600,12 +600,6 @@ void AccountManager::RemoveObserver(AccountManager::Observer* observer) {
observers_.RemoveObserver(observer);
}
scoped_refptr<network::SharedURLLoaderFactory>
AccountManager::GetUrlLoaderFactory() {
DCHECK(url_loader_factory_);
return url_loader_factory_;
}
void AccountManager::SetUrlLoaderFactoryForTests(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) {
url_loader_factory_ = url_loader_factory;
......@@ -614,7 +608,6 @@ void AccountManager::SetUrlLoaderFactoryForTests(
std::unique_ptr<OAuth2AccessTokenFetcher>
AccountManager::CreateAccessTokenFetcher(
const AccountKey& account_key,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
OAuth2AccessTokenConsumer* consumer) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
......@@ -624,7 +617,7 @@ AccountManager::CreateAccessTokenFetcher(
}
return std::make_unique<OAuth2AccessTokenFetcherImpl>(
consumer, url_loader_factory, it->second.token);
consumer, url_loader_factory_, it->second.token);
}
bool AccountManager::IsTokenAvailable(const AccountKey& account_key) const {
......@@ -657,7 +650,7 @@ void AccountManager::RevokeGaiaTokenOnServer(const std::string& refresh_token) {
pending_token_revocation_requests_.emplace_back(
std::make_unique<GaiaTokenRevocationRequest>(
GetUrlLoaderFactory(), delay_network_call_runner_, refresh_token,
url_loader_factory_, delay_network_call_runner_, refresh_token,
weak_factory_.GetWeakPtr()));
}
......
......@@ -216,9 +216,6 @@ class COMPONENT_EXPORT(ACCOUNT_MANAGER) AccountManager {
// not in the list of known observers.
void RemoveObserver(Observer* observer);
// Gets AccountManager's URL Loader Factory.
scoped_refptr<network::SharedURLLoaderFactory> GetUrlLoaderFactory();
// Sets the provided URL Loader Factory. Used only by tests.
void SetUrlLoaderFactoryForTests(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory);
......@@ -228,7 +225,6 @@ class COMPONENT_EXPORT(ACCOUNT_MANAGER) AccountManager {
// |account_key|, otherwise a |nullptr| is returned.
std::unique_ptr<OAuth2AccessTokenFetcher> CreateAccessTokenFetcher(
const AccountKey& account_key,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
OAuth2AccessTokenConsumer* consumer) const;
// Returns |true| if an LST is available for |account_key|. Note that
......
......@@ -124,7 +124,7 @@ ProfileOAuth2TokenServiceDelegateChromeOS::CreateAccessTokenFetcher(
account_tracker_service_->GetAccountInfo(account_id).gaia,
chromeos::account_manager::AccountType::
ACCOUNT_TYPE_GAIA} /* account_key */,
url_loader_factory, consumer);
consumer);
}
// Note: This method should use the same logic for filtering accounts as
......@@ -253,23 +253,7 @@ void ProfileOAuth2TokenServiceDelegateChromeOS::UpdateCredentials(
scoped_refptr<network::SharedURLLoaderFactory>
ProfileOAuth2TokenServiceDelegateChromeOS::GetURLLoaderFactory() const {
if (!is_regular_profile_) {
// Signin and Lock Screen profiles (non-|is_regular_profile_|s) have weird
// expectations around token loading. They do not have an account associated
// with them but expect calls like |LoadCredentials| and
// |GetURLLoaderFactory| to successfully complete.
// We *can* return a |nullptr| here because the return value of
// |GetURLLoaderFactory| is never used by Signin and Lock Screen profiles.
// They get a hard-coded |GoogleServiceAuthError::USER_NOT_SIGNED_UP| error
// returned to them by access token fetchers.
// We *must* return a |nullptr| here because otherwise |AccountManager|
// DCHECKs as it has not been initialized for non-|is_regular_profile_| and
// crashes for this weird case (Non-regular profiles expecting to act on
// accounts).
// See https://crbug.com/996615 for details.
return nullptr;
}
return account_manager_->GetUrlLoaderFactory();
}
void ProfileOAuth2TokenServiceDelegateChromeOS::OnGetAccounts(
......
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