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

Side by Side Diff: google_apis/gaia/account_tracker.cc

Issue 2229413002: google_apis: Use stl utilities from the base namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 4 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
« no previous file with comments | « google_apis/drive/request_sender.cc ('k') | google_apis/gaia/oauth2_token_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "google_apis/gaia/account_tracker.h" 5 #include "google_apis/gaia/account_tracker.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/profiler/scoped_tracker.h" 8 #include "base/profiler/scoped_tracker.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
(...skipping 10 matching lines...) Expand all
21 identity_provider_->AddObserver(this); 21 identity_provider_->AddObserver(this);
22 identity_provider_->GetTokenService()->AddObserver(this); 22 identity_provider_->GetTokenService()->AddObserver(this);
23 } 23 }
24 24
25 AccountTracker::~AccountTracker() { 25 AccountTracker::~AccountTracker() {
26 DCHECK(shutdown_called_); 26 DCHECK(shutdown_called_);
27 } 27 }
28 28
29 void AccountTracker::Shutdown() { 29 void AccountTracker::Shutdown() {
30 shutdown_called_ = true; 30 shutdown_called_ = true;
31 STLDeleteValues(&user_info_requests_); 31 base::STLDeleteValues(&user_info_requests_);
32 identity_provider_->GetTokenService()->RemoveObserver(this); 32 identity_provider_->GetTokenService()->RemoveObserver(this);
33 identity_provider_->RemoveObserver(this); 33 identity_provider_->RemoveObserver(this);
34 } 34 }
35 35
36 bool AccountTracker::IsAllUserInfoFetched() const { 36 bool AccountTracker::IsAllUserInfoFetched() const {
37 return user_info_requests_.empty(); 37 return user_info_requests_.empty();
38 } 38 }
39 39
40 void AccountTracker::AddObserver(Observer* observer) { 40 void AccountTracker::AddObserver(Observer* observer) {
41 observer_list_.AddObserver(observer); 41 observer_list_.AddObserver(observer);
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 NotifySignInChanged(account); 198 NotifySignInChanged(account);
199 } 199 }
200 200
201 void AccountTracker::StartTrackingAccount(const std::string& account_key) { 201 void AccountTracker::StartTrackingAccount(const std::string& account_key) {
202 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is 202 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is
203 // fixed. 203 // fixed.
204 tracked_objects::ScopedTracker tracking_profile( 204 tracked_objects::ScopedTracker tracking_profile(
205 FROM_HERE_WITH_EXPLICIT_FUNCTION( 205 FROM_HERE_WITH_EXPLICIT_FUNCTION(
206 "422460 AccountTracker::StartTrackingAccount")); 206 "422460 AccountTracker::StartTrackingAccount"));
207 207
208 if (!ContainsKey(accounts_, account_key)) { 208 if (!base::ContainsKey(accounts_, account_key)) {
209 DVLOG(1) << "StartTracking " << account_key; 209 DVLOG(1) << "StartTracking " << account_key;
210 AccountState account_state; 210 AccountState account_state;
211 account_state.ids.account_key = account_key; 211 account_state.ids.account_key = account_key;
212 account_state.ids.email = account_key; 212 account_state.ids.email = account_key;
213 account_state.is_signed_in = false; 213 account_state.is_signed_in = false;
214 accounts_.insert(make_pair(account_key, account_state)); 214 accounts_.insert(make_pair(account_key, account_state));
215 } 215 }
216 } 216 }
217 217
218 void AccountTracker::StopTrackingAccount(const std::string account_key) { 218 void AccountTracker::StopTrackingAccount(const std::string account_key) {
219 DVLOG(1) << "StopTracking " << account_key; 219 DVLOG(1) << "StopTracking " << account_key;
220 if (ContainsKey(accounts_, account_key)) { 220 if (base::ContainsKey(accounts_, account_key)) {
221 AccountState& account = accounts_[account_key]; 221 AccountState& account = accounts_[account_key];
222 if (!account.ids.gaia.empty()) { 222 if (!account.ids.gaia.empty()) {
223 UpdateSignInState(account_key, false); 223 UpdateSignInState(account_key, false);
224 NotifyAccountRemoved(account); 224 NotifyAccountRemoved(account);
225 } 225 }
226 accounts_.erase(account_key); 226 accounts_.erase(account_key);
227 } 227 }
228 228
229 if (ContainsKey(user_info_requests_, account_key)) 229 if (base::ContainsKey(user_info_requests_, account_key))
230 DeleteFetcher(user_info_requests_[account_key]); 230 DeleteFetcher(user_info_requests_[account_key]);
231 } 231 }
232 232
233 void AccountTracker::StopTrackingAllAccounts() { 233 void AccountTracker::StopTrackingAllAccounts() {
234 while (!accounts_.empty()) 234 while (!accounts_.empty())
235 StopTrackingAccount(accounts_.begin()->first); 235 StopTrackingAccount(accounts_.begin()->first);
236 } 236 }
237 237
238 void AccountTracker::StartFetchingUserInfo(const std::string& account_key) { 238 void AccountTracker::StartFetchingUserInfo(const std::string& account_key) {
239 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is 239 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is
240 // fixed. 240 // fixed.
241 tracked_objects::ScopedTracker tracking_profile( 241 tracked_objects::ScopedTracker tracking_profile(
242 FROM_HERE_WITH_EXPLICIT_FUNCTION( 242 FROM_HERE_WITH_EXPLICIT_FUNCTION(
243 "422460 AccountTracker::StartFetchingUserInfo")); 243 "422460 AccountTracker::StartFetchingUserInfo"));
244 244
245 if (ContainsKey(user_info_requests_, account_key)) { 245 if (base::ContainsKey(user_info_requests_, account_key)) {
246 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 246 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460
247 // is fixed. 247 // is fixed.
248 tracked_objects::ScopedTracker tracking_profile1( 248 tracked_objects::ScopedTracker tracking_profile1(
249 FROM_HERE_WITH_EXPLICIT_FUNCTION( 249 FROM_HERE_WITH_EXPLICIT_FUNCTION(
250 "422460 AccountTracker::StartFetchingUserInfo 1")); 250 "422460 AccountTracker::StartFetchingUserInfo 1"));
251 251
252 DeleteFetcher(user_info_requests_[account_key]); 252 DeleteFetcher(user_info_requests_[account_key]);
253 } 253 }
254 254
255 DVLOG(1) << "StartFetching " << account_key; 255 DVLOG(1) << "StartFetching " << account_key;
(...skipping 15 matching lines...) Expand all
271 tracked_objects::ScopedTracker tracking_profile3( 271 tracked_objects::ScopedTracker tracking_profile3(
272 FROM_HERE_WITH_EXPLICIT_FUNCTION( 272 FROM_HERE_WITH_EXPLICIT_FUNCTION(
273 "422460 AccountTracker::StartFetchingUserInfo 3")); 273 "422460 AccountTracker::StartFetchingUserInfo 3"));
274 274
275 fetcher->Start(); 275 fetcher->Start();
276 } 276 }
277 277
278 void AccountTracker::OnUserInfoFetchSuccess(AccountIdFetcher* fetcher, 278 void AccountTracker::OnUserInfoFetchSuccess(AccountIdFetcher* fetcher,
279 const std::string& gaia_id) { 279 const std::string& gaia_id) {
280 const std::string& account_key = fetcher->account_key(); 280 const std::string& account_key = fetcher->account_key();
281 DCHECK(ContainsKey(accounts_, account_key)); 281 DCHECK(base::ContainsKey(accounts_, account_key));
282 AccountState& account = accounts_[account_key]; 282 AccountState& account = accounts_[account_key];
283 283
284 account.ids.gaia = gaia_id; 284 account.ids.gaia = gaia_id;
285 NotifyAccountAdded(account); 285 NotifyAccountAdded(account);
286 286
287 if (account.is_signed_in) 287 if (account.is_signed_in)
288 NotifySignInChanged(account); 288 NotifySignInChanged(account);
289 289
290 DeleteFetcher(fetcher); 290 DeleteFetcher(fetcher);
291 } 291 }
292 292
293 void AccountTracker::OnUserInfoFetchFailure(AccountIdFetcher* fetcher) { 293 void AccountTracker::OnUserInfoFetchFailure(AccountIdFetcher* fetcher) {
294 LOG(WARNING) << "Failed to get UserInfo for " << fetcher->account_key(); 294 LOG(WARNING) << "Failed to get UserInfo for " << fetcher->account_key();
295 std::string key = fetcher->account_key(); 295 std::string key = fetcher->account_key();
296 DeleteFetcher(fetcher); 296 DeleteFetcher(fetcher);
297 StopTrackingAccount(key); 297 StopTrackingAccount(key);
298 } 298 }
299 299
300 void AccountTracker::DeleteFetcher(AccountIdFetcher* fetcher) { 300 void AccountTracker::DeleteFetcher(AccountIdFetcher* fetcher) {
301 DVLOG(1) << "DeleteFetcher " << fetcher->account_key(); 301 DVLOG(1) << "DeleteFetcher " << fetcher->account_key();
302 const std::string& account_key = fetcher->account_key(); 302 const std::string& account_key = fetcher->account_key();
303 DCHECK(ContainsKey(user_info_requests_, account_key)); 303 DCHECK(base::ContainsKey(user_info_requests_, account_key));
304 DCHECK_EQ(fetcher, user_info_requests_[account_key]); 304 DCHECK_EQ(fetcher, user_info_requests_[account_key]);
305 user_info_requests_.erase(account_key); 305 user_info_requests_.erase(account_key);
306 delete fetcher; 306 delete fetcher;
307 } 307 }
308 308
309 AccountIdFetcher::AccountIdFetcher( 309 AccountIdFetcher::AccountIdFetcher(
310 OAuth2TokenService* token_service, 310 OAuth2TokenService* token_service,
311 net::URLRequestContextGetter* request_context_getter, 311 net::URLRequestContextGetter* request_context_getter,
312 AccountTracker* tracker, 312 AccountTracker* tracker,
313 const std::string& account_key) 313 const std::string& account_key)
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 "AccountIdFetcher", 381 "AccountIdFetcher",
382 this, 382 this,
383 "OnNetworkError", 383 "OnNetworkError",
384 "response_code", 384 "response_code",
385 response_code); 385 response_code);
386 LOG(ERROR) << "OnNetworkError " << response_code; 386 LOG(ERROR) << "OnNetworkError " << response_code;
387 tracker_->OnUserInfoFetchFailure(this); 387 tracker_->OnUserInfoFetchFailure(this);
388 } 388 }
389 389
390 } // namespace gaia 390 } // namespace gaia
OLDNEW
« no previous file with comments | « google_apis/drive/request_sender.cc ('k') | google_apis/gaia/oauth2_token_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698