OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/signin/token_service.h" | 5 #include "chrome/browser/signin/token_service.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 content::NotificationService::current()->Notify( | 340 content::NotificationService::current()->Notify( |
341 chrome::NOTIFICATION_TOKEN_LOADING_FINISHED, | 341 chrome::NOTIFICATION_TOKEN_LOADING_FINISHED, |
342 content::Source<TokenService>(this), | 342 content::Source<TokenService>(this), |
343 content::NotificationService::NoDetails()); | 343 content::NotificationService::NoDetails()); |
344 } | 344 } |
345 | 345 |
346 // Load tokens from the db_token map into the in memory token map. | 346 // Load tokens from the db_token map into the in memory token map. |
347 void TokenService::LoadTokensIntoMemory( | 347 void TokenService::LoadTokensIntoMemory( |
348 const std::map<std::string, std::string>& db_tokens, | 348 const std::map<std::string, std::string>& db_tokens, |
349 std::map<std::string, std::string>* in_memory_tokens) { | 349 std::map<std::string, std::string>* in_memory_tokens) { |
| 350 // Ensure that there are no active fetchers at the time we first load |
| 351 // tokens from the DB into memory. |
| 352 for (size_t i = 0; i < arraysize(kServices); ++i) { |
| 353 DCHECK(NULL == fetchers_[i].get()); |
| 354 } |
350 | 355 |
351 for (size_t i = 0; i < arraysize(kServices); i++) { | 356 for (size_t i = 0; i < arraysize(kServices); i++) { |
352 LoadSingleTokenIntoMemory(db_tokens, in_memory_tokens, kServices[i]); | 357 LoadSingleTokenIntoMemory(db_tokens, in_memory_tokens, kServices[i]); |
353 } | 358 } |
354 LoadSingleTokenIntoMemory(db_tokens, in_memory_tokens, | 359 LoadSingleTokenIntoMemory(db_tokens, in_memory_tokens, |
355 GaiaConstants::kGaiaOAuth2LoginRefreshToken); | 360 GaiaConstants::kGaiaOAuth2LoginRefreshToken); |
356 LoadSingleTokenIntoMemory(db_tokens, in_memory_tokens, | 361 LoadSingleTokenIntoMemory(db_tokens, in_memory_tokens, |
357 GaiaConstants::kGaiaOAuth2LoginAccessToken); | 362 GaiaConstants::kGaiaOAuth2LoginAccessToken); |
358 | 363 |
359 if (credentials_.lsid.empty() && credentials_.sid.empty()) { | 364 if (credentials_.lsid.empty() && credentials_.sid.empty()) { |
360 // Look for GAIA SID and LSID tokens. If we have both, and the current | 365 // Look for GAIA SID and LSID tokens. If we have both, and the current |
361 // crendentials are empty, update the credentials. | 366 // crendentials are empty, update the credentials. |
362 std::string lsid; | 367 std::string lsid; |
363 std::string sid; | 368 std::string sid; |
364 | 369 |
365 if (db_tokens.count(GaiaConstants::kGaiaLsid) > 0) | 370 if (db_tokens.count(GaiaConstants::kGaiaLsid) > 0) |
366 lsid = db_tokens.find(GaiaConstants::kGaiaLsid)->second; | 371 lsid = db_tokens.find(GaiaConstants::kGaiaLsid)->second; |
367 | 372 |
368 if (db_tokens.count(GaiaConstants::kGaiaSid) > 0) | 373 if (db_tokens.count(GaiaConstants::kGaiaSid) > 0) |
369 sid = db_tokens.find(GaiaConstants::kGaiaSid)->second; | 374 sid = db_tokens.find(GaiaConstants::kGaiaSid)->second; |
370 | 375 |
371 if (!lsid.empty() && !sid.empty()) { | 376 if (!lsid.empty() && !sid.empty()) { |
372 UpdateCredentials(GaiaAuthConsumer::ClientLoginResult(sid, | 377 credentials_ = GaiaAuthConsumer::ClientLoginResult(sid, |
373 lsid, | 378 lsid, |
374 std::string(), | 379 std::string(), |
375 std::string())); | 380 std::string()); |
376 } | 381 } |
377 } | 382 } |
378 } | 383 } |
379 | 384 |
380 void TokenService::LoadSingleTokenIntoMemory( | 385 void TokenService::LoadSingleTokenIntoMemory( |
381 const std::map<std::string, std::string>& db_tokens, | 386 const std::map<std::string, std::string>& db_tokens, |
382 std::map<std::string, std::string>* in_memory_tokens, | 387 std::map<std::string, std::string>* in_memory_tokens, |
383 const std::string& service) { | 388 const std::string& service) { |
384 // OnIssueAuthTokenSuccess should come from the same thread. | 389 // OnIssueAuthTokenSuccess should come from the same thread. |
385 // If a token is already present in the map, it could only have | 390 // If a token is already present in the map, it could only have |
(...skipping 15 matching lines...) Expand all Loading... |
401 } | 406 } |
402 | 407 |
403 void TokenService::Observe(int type, | 408 void TokenService::Observe(int type, |
404 const content::NotificationSource& source, | 409 const content::NotificationSource& source, |
405 const content::NotificationDetails& details) { | 410 const content::NotificationDetails& details) { |
406 DCHECK_EQ(type, chrome::NOTIFICATION_TOKEN_UPDATED); | 411 DCHECK_EQ(type, chrome::NOTIFICATION_TOKEN_UPDATED); |
407 TokenAvailableDetails* tok_details = | 412 TokenAvailableDetails* tok_details = |
408 content::Details<TokenAvailableDetails>(details).ptr(); | 413 content::Details<TokenAvailableDetails>(details).ptr(); |
409 OnIssueAuthTokenSuccess(tok_details->service(), tok_details->token()); | 414 OnIssueAuthTokenSuccess(tok_details->service(), tok_details->token()); |
410 } | 415 } |
OLD | NEW |