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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 const char kAvatarIconKey[] = "avatar_icon"; | 51 const char kAvatarIconKey[] = "avatar_icon"; |
52 const char kAuthCredentialsKey[] = "local_auth_credentials"; | 52 const char kAuthCredentialsKey[] = "local_auth_credentials"; |
53 const char kUseGAIAPictureKey[] = "use_gaia_picture"; | 53 const char kUseGAIAPictureKey[] = "use_gaia_picture"; |
54 const char kBackgroundAppsKey[] = "background_apps"; | 54 const char kBackgroundAppsKey[] = "background_apps"; |
55 const char kGAIAPictureFileNameKey[] = "gaia_picture_file_name"; | 55 const char kGAIAPictureFileNameKey[] = "gaia_picture_file_name"; |
56 const char kIsOmittedFromProfileListKey[] = "is_omitted_from_profile_list"; | 56 const char kIsOmittedFromProfileListKey[] = "is_omitted_from_profile_list"; |
57 const char kSigninRequiredKey[] = "signin_required"; | 57 const char kSigninRequiredKey[] = "signin_required"; |
58 const char kSupervisedUserId[] = "managed_user_id"; | 58 const char kSupervisedUserId[] = "managed_user_id"; |
59 const char kProfileIsEphemeral[] = "is_ephemeral"; | 59 const char kProfileIsEphemeral[] = "is_ephemeral"; |
60 const char kActiveTimeKey[] = "active_time"; | 60 const char kActiveTimeKey[] = "active_time"; |
| 61 const char kAuthErrorKey[] = "auth_error"; |
61 | 62 |
62 // First eight are generic icons, which use IDS_NUMBERED_PROFILE_NAME. | 63 // First eight are generic icons, which use IDS_NUMBERED_PROFILE_NAME. |
63 const int kDefaultNames[] = { | 64 const int kDefaultNames[] = { |
64 IDS_DEFAULT_AVATAR_NAME_8, | 65 IDS_DEFAULT_AVATAR_NAME_8, |
65 IDS_DEFAULT_AVATAR_NAME_9, | 66 IDS_DEFAULT_AVATAR_NAME_9, |
66 IDS_DEFAULT_AVATAR_NAME_10, | 67 IDS_DEFAULT_AVATAR_NAME_10, |
67 IDS_DEFAULT_AVATAR_NAME_11, | 68 IDS_DEFAULT_AVATAR_NAME_11, |
68 IDS_DEFAULT_AVATAR_NAME_12, | 69 IDS_DEFAULT_AVATAR_NAME_12, |
69 IDS_DEFAULT_AVATAR_NAME_13, | 70 IDS_DEFAULT_AVATAR_NAME_13, |
70 IDS_DEFAULT_AVATAR_NAME_14, | 71 IDS_DEFAULT_AVATAR_NAME_14, |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 GetInfoForProfileAtIndex(index)->GetBoolean(kIsUsingDefaultNameKey, &value); | 449 GetInfoForProfileAtIndex(index)->GetBoolean(kIsUsingDefaultNameKey, &value); |
449 return value; | 450 return value; |
450 } | 451 } |
451 | 452 |
452 bool ProfileInfoCache::ProfileIsUsingDefaultAvatarAtIndex(size_t index) const { | 453 bool ProfileInfoCache::ProfileIsUsingDefaultAvatarAtIndex(size_t index) const { |
453 bool value = false; | 454 bool value = false; |
454 GetInfoForProfileAtIndex(index)->GetBoolean(kIsUsingDefaultAvatarKey, &value); | 455 GetInfoForProfileAtIndex(index)->GetBoolean(kIsUsingDefaultAvatarKey, &value); |
455 return value; | 456 return value; |
456 } | 457 } |
457 | 458 |
| 459 GoogleServiceAuthError::State ProfileInfoCache::ProfileAuthErrorAtIndex( |
| 460 size_t index) const { |
| 461 int value; |
| 462 GetInfoForProfileAtIndex(index)->GetInteger(kAuthErrorKey, &value); |
| 463 if (value < GoogleServiceAuthError::State::NUM_STATES) |
| 464 return static_cast<GoogleServiceAuthError::State>(value); |
| 465 else |
| 466 return GoogleServiceAuthError::State::NONE; |
| 467 } |
| 468 |
458 size_t ProfileInfoCache::GetAvatarIconIndexOfProfileAtIndex(size_t index) | 469 size_t ProfileInfoCache::GetAvatarIconIndexOfProfileAtIndex(size_t index) |
459 const { | 470 const { |
460 std::string icon_url; | 471 std::string icon_url; |
461 GetInfoForProfileAtIndex(index)->GetString(kAvatarIconKey, &icon_url); | 472 GetInfoForProfileAtIndex(index)->GetString(kAvatarIconKey, &icon_url); |
462 size_t icon_index = 0; | 473 size_t icon_index = 0; |
463 if (!profiles::IsDefaultAvatarIconUrl(icon_url, &icon_index)) | 474 if (!profiles::IsDefaultAvatarIconUrl(icon_url, &icon_index)) |
464 DLOG(WARNING) << "Unknown avatar icon: " << icon_url; | 475 DLOG(WARNING) << "Unknown avatar icon: " << icon_url; |
465 | 476 |
466 return icon_index; | 477 return icon_index; |
467 } | 478 } |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 SetInfoForProfileAtIndex(index, info.release()); | 751 SetInfoForProfileAtIndex(index, info.release()); |
741 } | 752 } |
742 | 753 |
743 void ProfileInfoCache::SetProfileIsUsingDefaultAvatarAtIndex( | 754 void ProfileInfoCache::SetProfileIsUsingDefaultAvatarAtIndex( |
744 size_t index, bool value) { | 755 size_t index, bool value) { |
745 if (value == ProfileIsUsingDefaultAvatarAtIndex(index)) | 756 if (value == ProfileIsUsingDefaultAvatarAtIndex(index)) |
746 return; | 757 return; |
747 | 758 |
748 scoped_ptr<base::DictionaryValue> info( | 759 scoped_ptr<base::DictionaryValue> info( |
749 GetInfoForProfileAtIndex(index)->DeepCopy()); | 760 GetInfoForProfileAtIndex(index)->DeepCopy()); |
750 info->SetBoolean(kIsUsingDefaultAvatarKey, value); | 761 info->SetBoolean(kIsUsingDefaultAvatarKey, (int)value); |
751 // This takes ownership of |info|. | 762 // This takes ownership of |info|. |
752 SetInfoForProfileAtIndex(index, info.release()); | 763 SetInfoForProfileAtIndex(index, info.release()); |
753 } | 764 } |
| 765 |
| 766 void ProfileInfoCache::SetProfileAuthErrorAtIndex( |
| 767 size_t index, GoogleServiceAuthError::State value) { |
| 768 if (value == ProfileAuthErrorAtIndex(index)) |
| 769 return; |
| 770 |
| 771 scoped_ptr<base::DictionaryValue> info( |
| 772 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 773 info->SetInteger(kAuthErrorKey, value); |
| 774 // This takes ownership of |info|. |
| 775 SetInfoForProfileAtIndex(index, info.release()); |
| 776 } |
754 | 777 |
755 bool ProfileInfoCache::IsDefaultProfileName(const base::string16& name) const { | 778 bool ProfileInfoCache::IsDefaultProfileName(const base::string16& name) const { |
756 // Check if it's a "First user" old-style name. | 779 // Check if it's a "First user" old-style name. |
757 if (name == l10n_util::GetStringUTF16(IDS_DEFAULT_PROFILE_NAME) || | 780 if (name == l10n_util::GetStringUTF16(IDS_DEFAULT_PROFILE_NAME) || |
758 name == l10n_util::GetStringUTF16(IDS_LEGACY_DEFAULT_PROFILE_NAME)) | 781 name == l10n_util::GetStringUTF16(IDS_LEGACY_DEFAULT_PROFILE_NAME)) |
759 return true; | 782 return true; |
760 | 783 |
761 // Check if it's one of the old-style profile names. | 784 // Check if it's one of the old-style profile names. |
762 for (size_t i = 0; i < arraysize(kDefaultNames); ++i) { | 785 for (size_t i = 0; i < arraysize(kDefaultNames); ++i) { |
763 if (name == l10n_util::GetStringUTF16(kDefaultNames[i])) | 786 if (name == l10n_util::GetStringUTF16(kDefaultNames[i])) |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1123 std::vector<base::FilePath>::const_iterator it; | 1146 std::vector<base::FilePath>::const_iterator it; |
1124 for (it = profiles_to_rename.begin(); it != profiles_to_rename.end(); ++it) { | 1147 for (it = profiles_to_rename.begin(); it != profiles_to_rename.end(); ++it) { |
1125 size_t profile_index = GetIndexOfProfileWithPath(*it); | 1148 size_t profile_index = GetIndexOfProfileWithPath(*it); |
1126 SetProfileIsUsingDefaultNameAtIndex(profile_index, true); | 1149 SetProfileIsUsingDefaultNameAtIndex(profile_index, true); |
1127 // This will assign a new "Person %d" type name and re-sort the cache. | 1150 // This will assign a new "Person %d" type name and re-sort the cache. |
1128 SetNameOfProfileAtIndex(profile_index, ChooseNameForNewProfile( | 1151 SetNameOfProfileAtIndex(profile_index, ChooseNameForNewProfile( |
1129 GetAvatarIconIndexOfProfileAtIndex(profile_index))); | 1152 GetAvatarIconIndexOfProfileAtIndex(profile_index))); |
1130 } | 1153 } |
1131 #endif | 1154 #endif |
1132 } | 1155 } |
OLD | NEW |