Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Side by Side Diff: components/signin/core/browser/account_fetcher_service.cc

Issue 1380103004: Delay fetching account info until OnRefreshTokensLoaded(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: delay AFS fetch properly Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 } 91 }
92 92
93 void AccountFetcherService::Shutdown() { 93 void AccountFetcherService::Shutdown() {
94 token_service_->RemoveObserver(this); 94 token_service_->RemoveObserver(this);
95 // child_info_request_ is an invalidation handler and needs to be 95 // child_info_request_ is an invalidation handler and needs to be
96 // unregistered during the lifetime of the invalidation service. 96 // unregistered during the lifetime of the invalidation service.
97 child_info_request_.reset(); 97 child_info_request_.reset();
98 shutdown_called_ = true; 98 shutdown_called_ = true;
99 } 99 }
100 100
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 { 101 bool AccountFetcherService::IsAllUserInfoFetched() const {
117 return user_info_requests_.empty(); 102 return user_info_requests_.empty();
118 } 103 }
119 104
120 void AccountFetcherService::FetchUserInfoBeforeSignin( 105 void AccountFetcherService::FetchUserInfoBeforeSignin(
121 const std::string& account_id) { 106 const std::string& account_id) {
122 RefreshAccountInfo(account_id, false); 107 RefreshAccountInfo(account_id, false);
123 } 108 }
124 109
125 void AccountFetcherService::RefreshAllAccountInfo(bool only_fetch_if_invalid) { 110 void AccountFetcherService::RefreshAllAccountInfo(bool only_fetch_if_invalid) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 timer_.Start(FROM_HERE, kRefreshFromTokenServiceDelay - time_since_update, 158 timer_.Start(FROM_HERE, kRefreshFromTokenServiceDelay - time_since_update,
174 this, 159 this,
175 &AccountFetcherService::RefreshAllAccountsAndScheduleNext); 160 &AccountFetcherService::RefreshAllAccountsAndScheduleNext);
176 } 161 }
177 } 162 }
178 163
179 // Starts fetching user information. This is called periodically to refresh. 164 // Starts fetching user information. This is called periodically to refresh.
180 void AccountFetcherService::StartFetchingUserInfo( 165 void AccountFetcherService::StartFetchingUserInfo(
181 const std::string& account_id) { 166 const std::string& account_id) {
182 DCHECK(CalledOnValidThread()); 167 DCHECK(CalledOnValidThread());
183 if (!network_fetches_enabled_) { 168 if (!network_fetches_enabled_)
184 pending_user_info_fetches_.push_back(account_id);
185 return; 169 return;
186 }
187 170
188 if (!ContainsKey(user_info_requests_, account_id)) { 171 if (!ContainsKey(user_info_requests_, account_id)) {
189 DVLOG(1) << "StartFetching " << account_id; 172 DVLOG(1) << "StartFetching " << account_id;
190 scoped_ptr<AccountInfoFetcher> fetcher(new AccountInfoFetcher( 173 scoped_ptr<AccountInfoFetcher> fetcher(new AccountInfoFetcher(
191 token_service_, signin_client_->GetURLRequestContext(), this, 174 token_service_, signin_client_->GetURLRequestContext(), this,
192 account_id)); 175 account_id));
193 user_info_requests_.set(account_id, fetcher.Pass()); 176 user_info_requests_.set(account_id, fetcher.Pass());
194 user_info_requests_.get(account_id)->Start(); 177 user_info_requests_.get(account_id)->Start();
195 } 178 }
196 } 179 }
(...skipping 12 matching lines...) Expand all
209 child_request_account_id_.clear(); 192 child_request_account_id_.clear();
210 child_info_request_.reset(); 193 child_info_request_.reset();
211 } 194 }
212 195
213 void AccountFetcherService::RefreshAccountInfo(const std::string& account_id, 196 void AccountFetcherService::RefreshAccountInfo(const std::string& account_id,
214 bool only_fetch_if_invalid) { 197 bool only_fetch_if_invalid) {
215 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is 198 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is
216 // fixed. 199 // fixed.
217 tracked_objects::ScopedTracker tracking_profile( 200 tracked_objects::ScopedTracker tracking_profile(
218 FROM_HERE_WITH_EXPLICIT_FUNCTION( 201 FROM_HERE_WITH_EXPLICIT_FUNCTION(
219 "422460 AccountFetcherService::OnRefreshTokenAvailable")); 202 "422460 AccountFetcherService::OnRefreshTokenAvailable"));
Roger Tawa OOO till Jul 10th 2015/10/21 19:09:00 Nit: fix method name in string.
220 203
221 TRACE_EVENT1("AccountFetcherService", 204 TRACE_EVENT1("AccountFetcherService",
222 "AccountFetcherService::RefreshAccountInfo", 205 "AccountFetcherService::RefreshAccountInfo",
223 "account_id", 206 "account_id",
224 account_id); 207 account_id);
225 DVLOG(1) << "AVAILABLE " << account_id; 208 DVLOG(1) << "AVAILABLE " << account_id;
226 209
227 account_tracker_service_->StartTrackingAccount(account_id); 210 account_tracker_service_->StartTrackingAccount(account_id);
228 const AccountInfo& info = 211 const AccountInfo& info =
229 account_tracker_service_->GetAccountInfo(account_id); 212 account_tracker_service_->GetAccountInfo(account_id);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 "account_id", 291 "account_id",
309 account_id); 292 account_id);
310 293
311 DVLOG(1) << "REVOKED " << account_id; 294 DVLOG(1) << "REVOKED " << account_id;
312 user_info_requests_.erase(account_id); 295 user_info_requests_.erase(account_id);
313 UpdateChildInfo(); 296 UpdateChildInfo();
314 account_tracker_service_->StopTrackingAccount(account_id); 297 account_tracker_service_->StopTrackingAccount(account_id);
315 } 298 }
316 299
317 void AccountFetcherService::OnRefreshTokensLoaded() { 300 void AccountFetcherService::OnRefreshTokensLoaded() {
318 // OnRefreshTokenAvailable has been called for all accounts by this point. 301 DCHECK(CalledOnValidThread());
319 // Maybe remove this after further investigation. 302 if (!network_fetches_enabled_) {
303 network_fetches_enabled_ = true;
304 ScheduleNextRefresh();
305 }
320 RefreshAllAccountInfo(true); 306 RefreshAllAccountInfo(true);
321 UpdateChildInfo(); 307 UpdateChildInfo();
322 } 308 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698