| Index: components/signin/core/browser/account_fetcher_service.cc
|
| diff --git a/components/signin/core/browser/account_fetcher_service.cc b/components/signin/core/browser/account_fetcher_service.cc
|
| index 22c804f6b496723a0a935e75abe82b37765e7d51..2abe3dc297d24f9b56d844044eb4c27abadb6a38 100644
|
| --- a/components/signin/core/browser/account_fetcher_service.cc
|
| +++ b/components/signin/core/browser/account_fetcher_service.cc
|
| @@ -16,6 +16,7 @@
|
| #include "components/signin/core/browser/refresh_token_annotation_request.h"
|
| #include "components/signin/core/browser/signin_client.h"
|
| #include "components/signin/core/common/signin_switches.h"
|
| +#include "google_apis/gaia/oauth2_token_service_delegate.h"
|
| #include "net/url_request/url_request_context_getter.h"
|
|
|
| namespace {
|
| @@ -102,12 +103,7 @@ void AccountFetcherService::EnableNetworkFetches() {
|
| DCHECK(CalledOnValidThread());
|
| DCHECK(!network_fetches_enabled_);
|
| network_fetches_enabled_ = true;
|
| - // If there are accounts in |pending_user_info_fetches_|, they were deemed
|
| - // invalid after being loaded from prefs and need to be fetched now instead of
|
| - // waiting after the timer.
|
| - for (const std::string& account_id : pending_user_info_fetches_)
|
| - StartFetchingUserInfo(account_id);
|
| - pending_user_info_fetches_.clear();
|
| + FetchPendingAccountInfo();
|
|
|
| // Now that network fetches are enabled, schedule the next refresh.
|
| ScheduleNextRefresh();
|
| @@ -122,6 +118,14 @@ void AccountFetcherService::FetchUserInfoBeforeSignin(
|
| RefreshAccountInfo(account_id, false);
|
| }
|
|
|
| +#if defined(OS_ANDROID)
|
| +void AccountFetcherService::OnAccountIdNameMapSeeded() {
|
| + DCHECK(CalledOnValidThread());
|
| + DCHECK(token_service_->GetDelegate()->NeedsAccountIdNameMap());
|
| + FetchPendingAccountInfo();
|
| +}
|
| +#endif
|
| +
|
| void AccountFetcherService::RefreshAllAccountInfo(bool only_fetch_if_invalid) {
|
| std::vector<std::string> accounts = token_service_->GetAccounts();
|
| for (std::vector<std::string>::const_iterator it = accounts.begin();
|
| @@ -146,6 +150,8 @@ void AccountFetcherService::UpdateChildInfo() {
|
| ResetChildInfo();
|
| if (!AccountSupportsUserInfo(candidate))
|
| return;
|
| + if (DeferFetchingAccountInfo(candidate))
|
| + return;
|
| child_request_account_id_ = candidate;
|
| StartFetchingChildInfo(candidate);
|
| } else {
|
| @@ -180,10 +186,8 @@ void AccountFetcherService::ScheduleNextRefresh() {
|
| void AccountFetcherService::StartFetchingUserInfo(
|
| const std::string& account_id) {
|
| DCHECK(CalledOnValidThread());
|
| - if (!network_fetches_enabled_) {
|
| - pending_user_info_fetches_.push_back(account_id);
|
| + if (DeferFetchingAccountInfo(account_id))
|
| return;
|
| - }
|
|
|
| if (!ContainsKey(user_info_requests_, account_id)) {
|
| DVLOG(1) << "StartFetching " << account_id;
|
| @@ -320,3 +324,29 @@ void AccountFetcherService::OnRefreshTokensLoaded() {
|
| RefreshAllAccountInfo(true);
|
| UpdateChildInfo();
|
| }
|
| +
|
| +bool AccountFetcherService::DeferFetchingAccountInfo(
|
| + const std::string& account_id) {
|
| + // There are two reasons for an account to be in |pending_user_info_fetches_|,
|
| + // either they were fetched before network fetch was enabled or the
|
| + // Id <-> Name mapping was required and unavailable for the account.
|
| + bool defer_fetch =
|
| + !network_fetches_enabled_ ||
|
| + (token_service_->GetDelegate()->NeedsAccountIdNameMap() &&
|
| + !account_tracker_service_->HasIdNameMappingForAccount(account_id));
|
| + if (defer_fetch)
|
| + pending_user_info_fetches_.insert(account_id);
|
| + return defer_fetch;
|
| +}
|
| +
|
| +void AccountFetcherService::FetchPendingAccountInfo() {
|
| + // Since further failures will be added back, we create a new copy of the
|
| + // accounts list before processing it.
|
| + std::set<std::string> accounts_to_process;
|
| + pending_user_info_fetches_.swap(accounts_to_process);
|
| + for (const std::string& account : accounts_to_process) {
|
| + if (account_tracker_service_->IsTrackingAccount(account))
|
| + StartFetchingUserInfo(account);
|
| + }
|
| + UpdateChildInfo();
|
| +}
|
|
|