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 kIsAuthErrorKey[] = "is_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 bool ProfileInfoCache::ProfileIsAuthErrorAtIndex(size_t index) const { |
| 460 bool value = false; |
| 461 GetInfoForProfileAtIndex(index)->GetBoolean(kIsAuthErrorKey, &value); |
| 462 return value; |
| 463 } |
| 464 |
458 size_t ProfileInfoCache::GetAvatarIconIndexOfProfileAtIndex(size_t index) | 465 size_t ProfileInfoCache::GetAvatarIconIndexOfProfileAtIndex(size_t index) |
459 const { | 466 const { |
460 std::string icon_url; | 467 std::string icon_url; |
461 GetInfoForProfileAtIndex(index)->GetString(kAvatarIconKey, &icon_url); | 468 GetInfoForProfileAtIndex(index)->GetString(kAvatarIconKey, &icon_url); |
462 size_t icon_index = 0; | 469 size_t icon_index = 0; |
463 if (!profiles::IsDefaultAvatarIconUrl(icon_url, &icon_index)) | 470 if (!profiles::IsDefaultAvatarIconUrl(icon_url, &icon_index)) |
464 DLOG(WARNING) << "Unknown avatar icon: " << icon_url; | 471 DLOG(WARNING) << "Unknown avatar icon: " << icon_url; |
465 | 472 |
466 return icon_index; | 473 return icon_index; |
467 } | 474 } |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 if (value == ProfileIsUsingDefaultAvatarAtIndex(index)) | 752 if (value == ProfileIsUsingDefaultAvatarAtIndex(index)) |
746 return; | 753 return; |
747 | 754 |
748 scoped_ptr<base::DictionaryValue> info( | 755 scoped_ptr<base::DictionaryValue> info( |
749 GetInfoForProfileAtIndex(index)->DeepCopy()); | 756 GetInfoForProfileAtIndex(index)->DeepCopy()); |
750 info->SetBoolean(kIsUsingDefaultAvatarKey, value); | 757 info->SetBoolean(kIsUsingDefaultAvatarKey, value); |
751 // This takes ownership of |info|. | 758 // This takes ownership of |info|. |
752 SetInfoForProfileAtIndex(index, info.release()); | 759 SetInfoForProfileAtIndex(index, info.release()); |
753 } | 760 } |
754 | 761 |
| 762 void ProfileInfoCache::SetProfileIsAuthErrorAtIndex(size_t index, bool value) { |
| 763 if (value == ProfileIsAuthErrorAtIndex(index)) |
| 764 return; |
| 765 |
| 766 scoped_ptr<base::DictionaryValue> info( |
| 767 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 768 info->SetBoolean(kIsAuthErrorKey, value); |
| 769 // This takes ownership of |info|. |
| 770 SetInfoForProfileAtIndex(index, info.release()); |
| 771 } |
| 772 |
755 bool ProfileInfoCache::IsDefaultProfileName(const base::string16& name) const { | 773 bool ProfileInfoCache::IsDefaultProfileName(const base::string16& name) const { |
756 // Check if it's a "First user" old-style name. | 774 // Check if it's a "First user" old-style name. |
757 if (name == l10n_util::GetStringUTF16(IDS_DEFAULT_PROFILE_NAME) || | 775 if (name == l10n_util::GetStringUTF16(IDS_DEFAULT_PROFILE_NAME) || |
758 name == l10n_util::GetStringUTF16(IDS_LEGACY_DEFAULT_PROFILE_NAME)) | 776 name == l10n_util::GetStringUTF16(IDS_LEGACY_DEFAULT_PROFILE_NAME)) |
759 return true; | 777 return true; |
760 | 778 |
761 // Check if it's one of the old-style profile names. | 779 // Check if it's one of the old-style profile names. |
762 for (size_t i = 0; i < arraysize(kDefaultNames); ++i) { | 780 for (size_t i = 0; i < arraysize(kDefaultNames); ++i) { |
763 if (name == l10n_util::GetStringUTF16(kDefaultNames[i])) | 781 if (name == l10n_util::GetStringUTF16(kDefaultNames[i])) |
764 return true; | 782 return true; |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1123 std::vector<base::FilePath>::const_iterator it; | 1141 std::vector<base::FilePath>::const_iterator it; |
1124 for (it = profiles_to_rename.begin(); it != profiles_to_rename.end(); ++it) { | 1142 for (it = profiles_to_rename.begin(); it != profiles_to_rename.end(); ++it) { |
1125 size_t profile_index = GetIndexOfProfileWithPath(*it); | 1143 size_t profile_index = GetIndexOfProfileWithPath(*it); |
1126 SetProfileIsUsingDefaultNameAtIndex(profile_index, true); | 1144 SetProfileIsUsingDefaultNameAtIndex(profile_index, true); |
1127 // This will assign a new "Person %d" type name and re-sort the cache. | 1145 // This will assign a new "Person %d" type name and re-sort the cache. |
1128 SetNameOfProfileAtIndex(profile_index, ChooseNameForNewProfile( | 1146 SetNameOfProfileAtIndex(profile_index, ChooseNameForNewProfile( |
1129 GetAvatarIconIndexOfProfileAtIndex(profile_index))); | 1147 GetAvatarIconIndexOfProfileAtIndex(profile_index))); |
1130 } | 1148 } |
1131 #endif | 1149 #endif |
1132 } | 1150 } |
OLD | NEW |