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/profiles/profile_info_cache.h" | 5 #include "chrome/browser/profiles/profile_info_cache.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/i18n/case_conversion.h" | 9 #include "base/i18n/case_conversion.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 #endif | 37 #endif |
38 | 38 |
39 using content::BrowserThread; | 39 using content::BrowserThread; |
40 | 40 |
41 namespace { | 41 namespace { |
42 | 42 |
43 const char kNameKey[] = "name"; | 43 const char kNameKey[] = "name"; |
44 const char kShortcutNameKey[] = "shortcut_name"; | 44 const char kShortcutNameKey[] = "shortcut_name"; |
45 const char kGAIANameKey[] = "gaia_name"; | 45 const char kGAIANameKey[] = "gaia_name"; |
46 const char kGAIAGivenNameKey[] = "gaia_given_name"; | 46 const char kGAIAGivenNameKey[] = "gaia_given_name"; |
| 47 const char kGAIAIdKey[] = "gaia_id"; |
47 const char kUserNameKey[] = "user_name"; | 48 const char kUserNameKey[] = "user_name"; |
48 const char kIsUsingDefaultNameKey[] = "is_using_default_name"; | 49 const char kIsUsingDefaultNameKey[] = "is_using_default_name"; |
49 const char kIsUsingDefaultAvatarKey[] = "is_using_default_avatar"; | 50 const char kIsUsingDefaultAvatarKey[] = "is_using_default_avatar"; |
50 const char kAvatarIconKey[] = "avatar_icon"; | 51 const char kAvatarIconKey[] = "avatar_icon"; |
51 const char kAuthCredentialsKey[] = "local_auth_credentials"; | 52 const char kAuthCredentialsKey[] = "local_auth_credentials"; |
52 const char kUseGAIAPictureKey[] = "use_gaia_picture"; | 53 const char kUseGAIAPictureKey[] = "use_gaia_picture"; |
53 const char kBackgroundAppsKey[] = "background_apps"; | 54 const char kBackgroundAppsKey[] = "background_apps"; |
54 const char kGAIAPictureFileNameKey[] = "gaia_picture_file_name"; | 55 const char kGAIAPictureFileNameKey[] = "gaia_picture_file_name"; |
55 const char kIsOmittedFromProfileListKey[] = "is_omitted_from_profile_list"; | 56 const char kIsOmittedFromProfileListKey[] = "is_omitted_from_profile_list"; |
56 const char kSigninRequiredKey[] = "signin_required"; | 57 const char kSigninRequiredKey[] = "signin_required"; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 STLDeleteContainerPairSecondPointers( | 191 STLDeleteContainerPairSecondPointers( |
191 cached_avatar_images_.begin(), cached_avatar_images_.end()); | 192 cached_avatar_images_.begin(), cached_avatar_images_.end()); |
192 STLDeleteContainerPairSecondPointers( | 193 STLDeleteContainerPairSecondPointers( |
193 avatar_images_downloads_in_progress_.begin(), | 194 avatar_images_downloads_in_progress_.begin(), |
194 avatar_images_downloads_in_progress_.end()); | 195 avatar_images_downloads_in_progress_.end()); |
195 } | 196 } |
196 | 197 |
197 void ProfileInfoCache::AddProfileToCache( | 198 void ProfileInfoCache::AddProfileToCache( |
198 const base::FilePath& profile_path, | 199 const base::FilePath& profile_path, |
199 const base::string16& name, | 200 const base::string16& name, |
200 const base::string16& username, | 201 const std::string& gaia_id, |
| 202 const base::string16& user_name, |
201 size_t icon_index, | 203 size_t icon_index, |
202 const std::string& supervised_user_id) { | 204 const std::string& supervised_user_id) { |
203 std::string key = CacheKeyFromProfilePath(profile_path); | 205 std::string key = CacheKeyFromProfilePath(profile_path); |
204 DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache); | 206 DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache); |
205 base::DictionaryValue* cache = update.Get(); | 207 base::DictionaryValue* cache = update.Get(); |
206 | 208 |
207 scoped_ptr<base::DictionaryValue> info(new base::DictionaryValue); | 209 scoped_ptr<base::DictionaryValue> info(new base::DictionaryValue); |
208 info->SetString(kNameKey, name); | 210 info->SetString(kNameKey, name); |
209 info->SetString(kUserNameKey, username); | 211 info->SetString(kGAIAIdKey, gaia_id); |
| 212 info->SetString(kUserNameKey, user_name); |
210 info->SetString(kAvatarIconKey, | 213 info->SetString(kAvatarIconKey, |
211 profiles::GetDefaultAvatarIconUrl(icon_index)); | 214 profiles::GetDefaultAvatarIconUrl(icon_index)); |
212 // Default value for whether background apps are running is false. | 215 // Default value for whether background apps are running is false. |
213 info->SetBoolean(kBackgroundAppsKey, false); | 216 info->SetBoolean(kBackgroundAppsKey, false); |
214 info->SetString(kSupervisedUserId, supervised_user_id); | 217 info->SetString(kSupervisedUserId, supervised_user_id); |
215 info->SetBoolean(kIsOmittedFromProfileListKey, !supervised_user_id.empty()); | 218 info->SetBoolean(kIsOmittedFromProfileListKey, !supervised_user_id.empty()); |
216 info->SetBoolean(kProfileIsEphemeral, false); | 219 info->SetBoolean(kProfileIsEphemeral, false); |
217 info->SetBoolean(kIsUsingDefaultNameKey, IsDefaultProfileName(name)); | 220 info->SetBoolean(kIsUsingDefaultNameKey, IsDefaultProfileName(name)); |
218 // Assume newly created profiles use a default avatar. | 221 // Assume newly created profiles use a default avatar. |
219 info->SetBoolean(kIsUsingDefaultAvatarKey, true); | 222 info->SetBoolean(kIsUsingDefaultAvatarKey, true); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 return name; | 365 return name; |
363 } | 366 } |
364 | 367 |
365 base::string16 ProfileInfoCache::GetGAIAGivenNameOfProfileAtIndex( | 368 base::string16 ProfileInfoCache::GetGAIAGivenNameOfProfileAtIndex( |
366 size_t index) const { | 369 size_t index) const { |
367 base::string16 name; | 370 base::string16 name; |
368 GetInfoForProfileAtIndex(index)->GetString(kGAIAGivenNameKey, &name); | 371 GetInfoForProfileAtIndex(index)->GetString(kGAIAGivenNameKey, &name); |
369 return name; | 372 return name; |
370 } | 373 } |
371 | 374 |
| 375 std::string ProfileInfoCache::GetGAIAIdOfProfileAtIndex( |
| 376 size_t index) const { |
| 377 std::string gaia_id; |
| 378 GetInfoForProfileAtIndex(index)->GetString(kGAIAIdKey, &gaia_id); |
| 379 return gaia_id; |
| 380 } |
| 381 |
372 const gfx::Image* ProfileInfoCache::GetGAIAPictureOfProfileAtIndex( | 382 const gfx::Image* ProfileInfoCache::GetGAIAPictureOfProfileAtIndex( |
373 size_t index) const { | 383 size_t index) const { |
374 base::FilePath path = GetPathOfProfileAtIndex(index); | 384 base::FilePath path = GetPathOfProfileAtIndex(index); |
375 std::string key = CacheKeyFromProfilePath(path); | 385 std::string key = CacheKeyFromProfilePath(path); |
376 | 386 |
377 std::string file_name; | 387 std::string file_name; |
378 GetInfoForProfileAtIndex(index)->GetString( | 388 GetInfoForProfileAtIndex(index)->GetString( |
379 kGAIAPictureFileNameKey, &file_name); | 389 kGAIAPictureFileNameKey, &file_name); |
380 | 390 |
381 // If the picture is not on disk then return NULL. | 391 // If the picture is not on disk then return NULL. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 GetInfoForProfileAtIndex(index)->GetBoolean(kProfileIsEphemeral, &value); | 450 GetInfoForProfileAtIndex(index)->GetBoolean(kProfileIsEphemeral, &value); |
441 return value; | 451 return value; |
442 } | 452 } |
443 | 453 |
444 bool ProfileInfoCache::ProfileIsUsingDefaultNameAtIndex(size_t index) const { | 454 bool ProfileInfoCache::ProfileIsUsingDefaultNameAtIndex(size_t index) const { |
445 bool value = false; | 455 bool value = false; |
446 GetInfoForProfileAtIndex(index)->GetBoolean(kIsUsingDefaultNameKey, &value); | 456 GetInfoForProfileAtIndex(index)->GetBoolean(kIsUsingDefaultNameKey, &value); |
447 return value; | 457 return value; |
448 } | 458 } |
449 | 459 |
| 460 bool ProfileInfoCache::ProfileIsAuthenticatedAtIndex(size_t index) const { |
| 461 // The profile is authenticated if the gaia_id of the info is not empty. |
| 462 // If it is empty, also check if the user name is not empty. This latter |
| 463 // check is needed in case the profile has not been loaded yet and the |
| 464 // gaia_id property has not yet been written. |
| 465 return !GetGAIAIdOfProfileAtIndex(index).empty() || |
| 466 !GetUserNameOfProfileAtIndex(index).empty(); |
| 467 } |
| 468 |
450 bool ProfileInfoCache::ProfileIsUsingDefaultAvatarAtIndex(size_t index) const { | 469 bool ProfileInfoCache::ProfileIsUsingDefaultAvatarAtIndex(size_t index) const { |
451 bool value = false; | 470 bool value = false; |
452 GetInfoForProfileAtIndex(index)->GetBoolean(kIsUsingDefaultAvatarKey, &value); | 471 GetInfoForProfileAtIndex(index)->GetBoolean(kIsUsingDefaultAvatarKey, &value); |
453 return value; | 472 return value; |
454 } | 473 } |
455 | 474 |
456 bool ProfileInfoCache::ProfileIsAuthErrorAtIndex(size_t index) const { | 475 bool ProfileInfoCache::ProfileIsAuthErrorAtIndex(size_t index) const { |
457 bool value = false; | 476 bool value = false; |
458 GetInfoForProfileAtIndex(index)->GetBoolean(kIsAuthErrorKey, &value); | 477 GetInfoForProfileAtIndex(index)->GetBoolean(kIsAuthErrorKey, &value); |
459 return value; | 478 return value; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 const base::string16& shortcut_name) { | 533 const base::string16& shortcut_name) { |
515 if (shortcut_name == GetShortcutNameOfProfileAtIndex(index)) | 534 if (shortcut_name == GetShortcutNameOfProfileAtIndex(index)) |
516 return; | 535 return; |
517 scoped_ptr<base::DictionaryValue> info( | 536 scoped_ptr<base::DictionaryValue> info( |
518 GetInfoForProfileAtIndex(index)->DeepCopy()); | 537 GetInfoForProfileAtIndex(index)->DeepCopy()); |
519 info->SetString(kShortcutNameKey, shortcut_name); | 538 info->SetString(kShortcutNameKey, shortcut_name); |
520 // This takes ownership of |info|. | 539 // This takes ownership of |info|. |
521 SetInfoForProfileAtIndex(index, info.release()); | 540 SetInfoForProfileAtIndex(index, info.release()); |
522 } | 541 } |
523 | 542 |
524 void ProfileInfoCache::SetUserNameOfProfileAtIndex( | 543 void ProfileInfoCache::SetAuthInfoOfProfileAtIndex( |
525 size_t index, | 544 size_t index, |
| 545 const std::string& gaia_id, |
526 const base::string16& user_name) { | 546 const base::string16& user_name) { |
527 if (user_name == GetUserNameOfProfileAtIndex(index)) | 547 // If both gaia_id and username are unchanged, abort early. |
| 548 if (gaia_id == GetGAIAIdOfProfileAtIndex(index) && |
| 549 user_name == GetUserNameOfProfileAtIndex(index)) { |
528 return; | 550 return; |
| 551 } |
529 | 552 |
530 scoped_ptr<base::DictionaryValue> info( | 553 scoped_ptr<base::DictionaryValue> info( |
531 GetInfoForProfileAtIndex(index)->DeepCopy()); | 554 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 555 |
| 556 info->SetString(kGAIAIdKey, gaia_id); |
532 info->SetString(kUserNameKey, user_name); | 557 info->SetString(kUserNameKey, user_name); |
| 558 |
533 // This takes ownership of |info|. | 559 // This takes ownership of |info|. |
534 SetInfoForProfileAtIndex(index, info.release()); | 560 SetInfoForProfileAtIndex(index, info.release()); |
535 | 561 |
536 base::FilePath profile_path = GetPathOfProfileAtIndex(index); | 562 base::FilePath profile_path = GetPathOfProfileAtIndex(index); |
537 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 563 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, |
538 observer_list_, | 564 observer_list_, |
539 OnProfileUserNameChanged(profile_path)); | 565 OnProfileAuthInfoChanged(profile_path)); |
540 } | 566 } |
541 | 567 |
542 void ProfileInfoCache::SetAvatarIconOfProfileAtIndex(size_t index, | 568 void ProfileInfoCache::SetAvatarIconOfProfileAtIndex(size_t index, |
543 size_t icon_index) { | 569 size_t icon_index) { |
544 scoped_ptr<base::DictionaryValue> info( | 570 scoped_ptr<base::DictionaryValue> info( |
545 GetInfoForProfileAtIndex(index)->DeepCopy()); | 571 GetInfoForProfileAtIndex(index)->DeepCopy()); |
546 info->SetString(kAvatarIconKey, | 572 info->SetString(kAvatarIconKey, |
547 profiles::GetDefaultAvatarIconUrl(icon_index)); | 573 profiles::GetDefaultAvatarIconUrl(icon_index)); |
548 // This takes ownership of |info|. | 574 // This takes ownership of |info|. |
549 SetInfoForProfileAtIndex(index, info.release()); | 575 SetInfoForProfileAtIndex(index, info.release()); |
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1179 std::vector<base::FilePath>::const_iterator it; | 1205 std::vector<base::FilePath>::const_iterator it; |
1180 for (it = profiles_to_rename.begin(); it != profiles_to_rename.end(); ++it) { | 1206 for (it = profiles_to_rename.begin(); it != profiles_to_rename.end(); ++it) { |
1181 size_t profile_index = GetIndexOfProfileWithPath(*it); | 1207 size_t profile_index = GetIndexOfProfileWithPath(*it); |
1182 SetProfileIsUsingDefaultNameAtIndex(profile_index, true); | 1208 SetProfileIsUsingDefaultNameAtIndex(profile_index, true); |
1183 // This will assign a new "Person %d" type name and re-sort the cache. | 1209 // This will assign a new "Person %d" type name and re-sort the cache. |
1184 SetNameOfProfileAtIndex(profile_index, ChooseNameForNewProfile( | 1210 SetNameOfProfileAtIndex(profile_index, ChooseNameForNewProfile( |
1185 GetAvatarIconIndexOfProfileAtIndex(profile_index))); | 1211 GetAvatarIconIndexOfProfileAtIndex(profile_index))); |
1186 } | 1212 } |
1187 #endif | 1213 #endif |
1188 } | 1214 } |
OLD | NEW |