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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/profiler/scoped_tracker.h" | 10 #include "base/profiler/scoped_tracker.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 | 63 |
64 // static | 64 // static |
65 void AccountFetcherService::RegisterPrefs( | 65 void AccountFetcherService::RegisterPrefs( |
66 user_prefs::PrefRegistrySyncable* user_prefs) { | 66 user_prefs::PrefRegistrySyncable* user_prefs) { |
67 user_prefs->RegisterInt64Pref(kLastUpdatePref, 0); | 67 user_prefs->RegisterInt64Pref(kLastUpdatePref, 0); |
68 } | 68 } |
69 | 69 |
70 void AccountFetcherService::Initialize( | 70 void AccountFetcherService::Initialize( |
71 SigninClient* signin_client, | 71 SigninClient* signin_client, |
72 OAuth2TokenService* token_service, | 72 OAuth2TokenService* token_service, |
73 AccountTrackerService* account_tracker_service, | 73 AccountTrackerService* account_tracker_service) { |
74 invalidation::InvalidationService* invalidation_service) { | |
75 DCHECK(signin_client); | 74 DCHECK(signin_client); |
76 DCHECK(!signin_client_); | 75 DCHECK(!signin_client_); |
77 signin_client_ = signin_client; | 76 signin_client_ = signin_client; |
78 invalidation_service_ = invalidation_service; | |
79 DCHECK(account_tracker_service); | 77 DCHECK(account_tracker_service); |
80 DCHECK(!account_tracker_service_); | 78 DCHECK(!account_tracker_service_); |
81 account_tracker_service_ = account_tracker_service; | 79 account_tracker_service_ = account_tracker_service; |
82 DCHECK(token_service); | 80 DCHECK(token_service); |
83 DCHECK(!token_service_); | 81 DCHECK(!token_service_); |
84 token_service_ = token_service; | 82 token_service_ = token_service; |
85 token_service_->AddObserver(this); | 83 token_service_->AddObserver(this); |
86 | 84 |
87 last_updated_ = base::Time::FromInternalValue( | 85 last_updated_ = base::Time::FromInternalValue( |
88 signin_client_->GetPrefs()->GetInt64(kLastUpdatePref)); | 86 signin_client_->GetPrefs()->GetInt64(kLastUpdatePref)); |
89 | 87 |
90 RefreshAllAccountInfo(true); | 88 RefreshAllAccountInfo(true); |
Roger Tawa OOO till Jul 10th
2015/10/23 12:42:12
We no longer need this call here. It is a noop wi
knn
2015/10/23 13:32:53
Done.
| |
91 } | 89 } |
92 | 90 |
93 void AccountFetcherService::Shutdown() { | 91 void AccountFetcherService::Shutdown() { |
94 token_service_->RemoveObserver(this); | 92 token_service_->RemoveObserver(this); |
95 // child_info_request_ is an invalidation handler and needs to be | 93 // child_info_request_ is an invalidation handler and needs to be |
96 // unregistered during the lifetime of the invalidation service. | 94 // unregistered during the lifetime of the invalidation service. |
97 child_info_request_.reset(); | 95 child_info_request_.reset(); |
98 shutdown_called_ = true; | 96 shutdown_called_ = true; |
99 } | 97 } |
100 | 98 |
101 void AccountFetcherService::EnableNetworkFetches() { | |
102 DCHECK(CalledOnValidThread()); | |
103 DCHECK(!network_fetches_enabled_); | |
104 network_fetches_enabled_ = true; | |
105 // If there are accounts in |pending_user_info_fetches_|, they were deemed | |
106 // invalid after being loaded from prefs and need to be fetched now instead of | |
107 // waiting after the timer. | |
108 for (const std::string& account_id : pending_user_info_fetches_) | |
109 StartFetchingUserInfo(account_id); | |
110 pending_user_info_fetches_.clear(); | |
111 | |
112 // Now that network fetches are enabled, schedule the next refresh. | |
113 ScheduleNextRefresh(); | |
114 } | |
115 | |
116 bool AccountFetcherService::IsAllUserInfoFetched() const { | 99 bool AccountFetcherService::IsAllUserInfoFetched() const { |
117 return user_info_requests_.empty(); | 100 return user_info_requests_.empty(); |
118 } | 101 } |
119 | 102 |
120 void AccountFetcherService::FetchUserInfoBeforeSignin( | 103 void AccountFetcherService::FetchUserInfoBeforeSignin( |
121 const std::string& account_id) { | 104 const std::string& account_id) { |
122 RefreshAccountInfo(account_id, false); | 105 RefreshAccountInfo(account_id, false); |
123 } | 106 } |
124 | 107 |
108 void AccountFetcherService::SetupInvalidations( | |
109 invalidation::InvalidationService* invalidation_service) { | |
110 DCHECK(!invalidation_service_); | |
111 DCHECK(!child_info_request_); | |
112 invalidation_service_ = invalidation_service; | |
113 } | |
114 | |
125 void AccountFetcherService::RefreshAllAccountInfo(bool only_fetch_if_invalid) { | 115 void AccountFetcherService::RefreshAllAccountInfo(bool only_fetch_if_invalid) { |
126 std::vector<std::string> accounts = token_service_->GetAccounts(); | 116 std::vector<std::string> accounts = token_service_->GetAccounts(); |
127 for (std::vector<std::string>::const_iterator it = accounts.begin(); | 117 for (std::vector<std::string>::const_iterator it = accounts.begin(); |
128 it != accounts.end(); ++it) { | 118 it != accounts.end(); ++it) { |
129 RefreshAccountInfo(*it, only_fetch_if_invalid); | 119 RefreshAccountInfo(*it, only_fetch_if_invalid); |
130 } | 120 } |
131 } | 121 } |
132 | 122 |
133 // Child account status is refreshed through invalidations which are only | 123 // Child account status is refreshed through invalidations which are only |
134 // available for the primary account. Finding the primary account requires a | 124 // available for the primary account. Finding the primary account requires a |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 timer_.Start(FROM_HERE, kRefreshFromTokenServiceDelay - time_since_update, | 163 timer_.Start(FROM_HERE, kRefreshFromTokenServiceDelay - time_since_update, |
174 this, | 164 this, |
175 &AccountFetcherService::RefreshAllAccountsAndScheduleNext); | 165 &AccountFetcherService::RefreshAllAccountsAndScheduleNext); |
176 } | 166 } |
177 } | 167 } |
178 | 168 |
179 // Starts fetching user information. This is called periodically to refresh. | 169 // Starts fetching user information. This is called periodically to refresh. |
180 void AccountFetcherService::StartFetchingUserInfo( | 170 void AccountFetcherService::StartFetchingUserInfo( |
181 const std::string& account_id) { | 171 const std::string& account_id) { |
182 DCHECK(CalledOnValidThread()); | 172 DCHECK(CalledOnValidThread()); |
183 if (!network_fetches_enabled_) { | 173 if (!network_fetches_enabled_) |
184 pending_user_info_fetches_.push_back(account_id); | |
185 return; | 174 return; |
Roger Tawa OOO till Jul 10th
2015/10/23 12:42:12
Let's change this silent drop to:
DCHECK(networ
knn
2015/10/23 13:32:52
Done. Silently dropping in OnRefreshToken{Availabl
| |
186 } | |
187 | 175 |
188 if (!ContainsKey(user_info_requests_, account_id)) { | 176 if (!ContainsKey(user_info_requests_, account_id)) { |
189 DVLOG(1) << "StartFetching " << account_id; | 177 DVLOG(1) << "StartFetching " << account_id; |
190 scoped_ptr<AccountInfoFetcher> fetcher(new AccountInfoFetcher( | 178 scoped_ptr<AccountInfoFetcher> fetcher(new AccountInfoFetcher( |
191 token_service_, signin_client_->GetURLRequestContext(), this, | 179 token_service_, signin_client_->GetURLRequestContext(), this, |
192 account_id)); | 180 account_id)); |
193 user_info_requests_.set(account_id, fetcher.Pass()); | 181 user_info_requests_.set(account_id, fetcher.Pass()); |
194 user_info_requests_.get(account_id)->Start(); | 182 user_info_requests_.get(account_id)->Start(); |
195 } | 183 } |
196 } | 184 } |
(...skipping 12 matching lines...) Expand all Loading... | |
209 child_request_account_id_.clear(); | 197 child_request_account_id_.clear(); |
210 child_info_request_.reset(); | 198 child_info_request_.reset(); |
211 } | 199 } |
212 | 200 |
213 void AccountFetcherService::RefreshAccountInfo(const std::string& account_id, | 201 void AccountFetcherService::RefreshAccountInfo(const std::string& account_id, |
214 bool only_fetch_if_invalid) { | 202 bool only_fetch_if_invalid) { |
215 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is | 203 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is |
216 // fixed. | 204 // fixed. |
217 tracked_objects::ScopedTracker tracking_profile( | 205 tracked_objects::ScopedTracker tracking_profile( |
218 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 206 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
219 "422460 AccountFetcherService::OnRefreshTokenAvailable")); | 207 "422460 AccountFetcherService::OnRefreshTokenAvailable")); |
Roger Tawa OOO till Jul 10th
2015/10/23 12:42:12
Nit: change to match function name.
knn
2015/10/23 13:32:52
Done.
| |
220 | 208 |
221 TRACE_EVENT1("AccountFetcherService", | 209 TRACE_EVENT1("AccountFetcherService", |
222 "AccountFetcherService::RefreshAccountInfo", | 210 "AccountFetcherService::RefreshAccountInfo", |
223 "account_id", | 211 "account_id", |
224 account_id); | 212 account_id); |
225 DVLOG(1) << "AVAILABLE " << account_id; | 213 DVLOG(1) << "AVAILABLE " << account_id; |
226 | 214 |
227 account_tracker_service_->StartTrackingAccount(account_id); | 215 account_tracker_service_->StartTrackingAccount(account_id); |
228 const AccountInfo& info = | 216 const AccountInfo& info = |
229 account_tracker_service_->GetAccountInfo(account_id); | 217 account_tracker_service_->GetAccountInfo(account_id); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
308 "account_id", | 296 "account_id", |
309 account_id); | 297 account_id); |
310 | 298 |
311 DVLOG(1) << "REVOKED " << account_id; | 299 DVLOG(1) << "REVOKED " << account_id; |
312 user_info_requests_.erase(account_id); | 300 user_info_requests_.erase(account_id); |
313 UpdateChildInfo(); | 301 UpdateChildInfo(); |
314 account_tracker_service_->StopTrackingAccount(account_id); | 302 account_tracker_service_->StopTrackingAccount(account_id); |
315 } | 303 } |
316 | 304 |
317 void AccountFetcherService::OnRefreshTokensLoaded() { | 305 void AccountFetcherService::OnRefreshTokensLoaded() { |
318 // OnRefreshTokenAvailable has been called for all accounts by this point. | 306 DCHECK(CalledOnValidThread()); |
319 // Maybe remove this after further investigation. | 307 if (!network_fetches_enabled_) { |
308 network_fetches_enabled_ = true; | |
309 ScheduleNextRefresh(); | |
310 } | |
320 RefreshAllAccountInfo(true); | 311 RefreshAllAccountInfo(true); |
321 UpdateChildInfo(); | 312 UpdateChildInfo(); |
322 } | 313 } |
OLD | NEW |