| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/signin/core/browser/account_fetcher_service.h" | 5 #include "components/signin/core/browser/account_fetcher_service.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 signin_client_(nullptr), | 58 signin_client_(nullptr), |
| 59 invalidation_service_(nullptr), | 59 invalidation_service_(nullptr), |
| 60 network_fetches_enabled_(false), | 60 network_fetches_enabled_(false), |
| 61 profile_loaded_(false), | 61 profile_loaded_(false), |
| 62 refresh_tokens_loaded_(false), | 62 refresh_tokens_loaded_(false), |
| 63 shutdown_called_(false), | 63 shutdown_called_(false), |
| 64 scheduled_refresh_enabled_(true), | 64 scheduled_refresh_enabled_(true), |
| 65 child_info_request_(nullptr) {} | 65 child_info_request_(nullptr) {} |
| 66 | 66 |
| 67 AccountFetcherService::~AccountFetcherService() { | 67 AccountFetcherService::~AccountFetcherService() { |
| 68 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 68 DCHECK(shutdown_called_); | 69 DCHECK(shutdown_called_); |
| 69 } | 70 } |
| 70 | 71 |
| 71 // static | 72 // static |
| 72 void AccountFetcherService::RegisterPrefs( | 73 void AccountFetcherService::RegisterPrefs( |
| 73 user_prefs::PrefRegistrySyncable* user_prefs) { | 74 user_prefs::PrefRegistrySyncable* user_prefs) { |
| 74 user_prefs->RegisterInt64Pref(kLastUpdatePref, 0); | 75 user_prefs->RegisterInt64Pref(kLastUpdatePref, 0); |
| 75 } | 76 } |
| 76 | 77 |
| 77 void AccountFetcherService::Initialize( | 78 void AccountFetcherService::Initialize( |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 RefreshAccountInfo(*it, only_fetch_if_invalid); | 136 RefreshAccountInfo(*it, only_fetch_if_invalid); |
| 136 } | 137 } |
| 137 } | 138 } |
| 138 | 139 |
| 139 // Child account status is refreshed through invalidations which are only | 140 // Child account status is refreshed through invalidations which are only |
| 140 // available for the primary account. Finding the primary account requires a | 141 // available for the primary account. Finding the primary account requires a |
| 141 // dependency on signin_manager which we get around by only allowing a single | 142 // dependency on signin_manager which we get around by only allowing a single |
| 142 // account. This is possible since we only support a single account to be a | 143 // account. This is possible since we only support a single account to be a |
| 143 // child anyway. | 144 // child anyway. |
| 144 void AccountFetcherService::UpdateChildInfo() { | 145 void AccountFetcherService::UpdateChildInfo() { |
| 145 DCHECK(CalledOnValidThread()); | 146 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 146 std::vector<std::string> accounts = token_service_->GetAccounts(); | 147 std::vector<std::string> accounts = token_service_->GetAccounts(); |
| 147 if (accounts.size() == 1) { | 148 if (accounts.size() == 1) { |
| 148 const std::string& candidate = accounts[0]; | 149 const std::string& candidate = accounts[0]; |
| 149 if (candidate == child_request_account_id_) | 150 if (candidate == child_request_account_id_) |
| 150 return; | 151 return; |
| 151 if (!child_request_account_id_.empty()) | 152 if (!child_request_account_id_.empty()) |
| 152 ResetChildInfo(); | 153 ResetChildInfo(); |
| 153 if (!AccountSupportsUserInfo(candidate)) | 154 if (!AccountSupportsUserInfo(candidate)) |
| 154 return; | 155 return; |
| 155 child_request_account_id_ = candidate; | 156 child_request_account_id_ = candidate; |
| 156 StartFetchingChildInfo(candidate); | 157 StartFetchingChildInfo(candidate); |
| 157 } else { | 158 } else { |
| 158 ResetChildInfo(); | 159 ResetChildInfo(); |
| 159 } | 160 } |
| 160 } | 161 } |
| 161 | 162 |
| 162 void AccountFetcherService::MaybeEnableNetworkFetches() { | 163 void AccountFetcherService::MaybeEnableNetworkFetches() { |
| 163 DCHECK(CalledOnValidThread()); | 164 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 164 if (!profile_loaded_ || !refresh_tokens_loaded_) | 165 if (!profile_loaded_ || !refresh_tokens_loaded_) |
| 165 return; | 166 return; |
| 166 if (!network_fetches_enabled_) { | 167 if (!network_fetches_enabled_) { |
| 167 network_fetches_enabled_ = true; | 168 network_fetches_enabled_ = true; |
| 168 ScheduleNextRefresh(); | 169 ScheduleNextRefresh(); |
| 169 } | 170 } |
| 170 RefreshAllAccountInfo(true); | 171 RefreshAllAccountInfo(true); |
| 171 UpdateChildInfo(); | 172 UpdateChildInfo(); |
| 172 } | 173 } |
| 173 | 174 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 192 } else { | 193 } else { |
| 193 timer_.Start(FROM_HERE, kRefreshFromTokenServiceDelay - time_since_update, | 194 timer_.Start(FROM_HERE, kRefreshFromTokenServiceDelay - time_since_update, |
| 194 this, | 195 this, |
| 195 &AccountFetcherService::RefreshAllAccountsAndScheduleNext); | 196 &AccountFetcherService::RefreshAllAccountsAndScheduleNext); |
| 196 } | 197 } |
| 197 } | 198 } |
| 198 | 199 |
| 199 // Starts fetching user information. This is called periodically to refresh. | 200 // Starts fetching user information. This is called periodically to refresh. |
| 200 void AccountFetcherService::StartFetchingUserInfo( | 201 void AccountFetcherService::StartFetchingUserInfo( |
| 201 const std::string& account_id) { | 202 const std::string& account_id) { |
| 202 DCHECK(CalledOnValidThread()); | 203 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 203 DCHECK(network_fetches_enabled_); | 204 DCHECK(network_fetches_enabled_); |
| 204 | 205 |
| 205 std::unique_ptr<AccountInfoFetcher>& request = | 206 std::unique_ptr<AccountInfoFetcher>& request = |
| 206 user_info_requests_[account_id]; | 207 user_info_requests_[account_id]; |
| 207 if (!request) { | 208 if (!request) { |
| 208 DVLOG(1) << "StartFetching " << account_id; | 209 DVLOG(1) << "StartFetching " << account_id; |
| 209 std::unique_ptr<AccountInfoFetcher> fetcher = | 210 std::unique_ptr<AccountInfoFetcher> fetcher = |
| 210 base::MakeUnique<AccountInfoFetcher>( | 211 base::MakeUnique<AccountInfoFetcher>( |
| 211 token_service_, signin_client_->GetURLRequestContext(), this, | 212 token_service_, signin_client_->GetURLRequestContext(), this, |
| 212 account_id); | 213 account_id); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 DVLOG(1) << "REVOKED " << account_id; | 335 DVLOG(1) << "REVOKED " << account_id; |
| 335 | 336 |
| 336 if (!network_fetches_enabled_) | 337 if (!network_fetches_enabled_) |
| 337 return; | 338 return; |
| 338 user_info_requests_.erase(account_id); | 339 user_info_requests_.erase(account_id); |
| 339 UpdateChildInfo(); | 340 UpdateChildInfo(); |
| 340 account_tracker_service_->StopTrackingAccount(account_id); | 341 account_tracker_service_->StopTrackingAccount(account_id); |
| 341 } | 342 } |
| 342 | 343 |
| 343 void AccountFetcherService::OnRefreshTokensLoaded() { | 344 void AccountFetcherService::OnRefreshTokensLoaded() { |
| 344 DCHECK(CalledOnValidThread()); | 345 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 345 refresh_tokens_loaded_ = true; | 346 refresh_tokens_loaded_ = true; |
| 346 MaybeEnableNetworkFetches(); | 347 MaybeEnableNetworkFetches(); |
| 347 } | 348 } |
| OLD | NEW |