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/file_util.h" | 8 #include "base/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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 info->SetBoolean(kIsUsingDefaultNameKey, using_default_name); | 162 info->SetBoolean(kIsUsingDefaultNameKey, using_default_name); |
163 } | 163 } |
164 | 164 |
165 // For profiles that don't have the "using default avatar" state set yet, | 165 // For profiles that don't have the "using default avatar" state set yet, |
166 // assume it's the same as the "using default name" state. | 166 // assume it's the same as the "using default name" state. |
167 if (!info->HasKey(kIsUsingDefaultAvatarKey)) { | 167 if (!info->HasKey(kIsUsingDefaultAvatarKey)) { |
168 info->SetBoolean(kIsUsingDefaultAvatarKey, using_default_name); | 168 info->SetBoolean(kIsUsingDefaultAvatarKey, using_default_name); |
169 } | 169 } |
170 } | 170 } |
171 | 171 |
172 // If needed, start downloading the high-res avatars. | 172 // If needed, start downloading the high-res avatars and migrate any legacy |
173 if (switches::IsNewAvatarMenu()) { | 173 // profile names. |
174 for (size_t i = 0; i < GetNumberOfProfiles(); i++) { | 174 if (switches::IsNewAvatarMenu()) |
175 DownloadHighResAvatar(GetAvatarIconIndexOfProfileAtIndex(i), | 175 MigrateLegacyProfileNamesAndDownloadAvatars(); |
176 GetPathOfProfileAtIndex(i)); | |
177 } | |
178 } | |
179 } | 176 } |
180 | 177 |
181 ProfileInfoCache::~ProfileInfoCache() { | 178 ProfileInfoCache::~ProfileInfoCache() { |
182 STLDeleteContainerPairSecondPointers( | 179 STLDeleteContainerPairSecondPointers( |
183 cached_avatar_images_.begin(), cached_avatar_images_.end()); | 180 cached_avatar_images_.begin(), cached_avatar_images_.end()); |
184 STLDeleteContainerPairSecondPointers( | 181 STLDeleteContainerPairSecondPointers( |
185 avatar_images_downloads_in_progress_.begin(), | 182 avatar_images_downloads_in_progress_.begin(), |
186 avatar_images_downloads_in_progress_.end()); | 183 avatar_images_downloads_in_progress_.end()); |
187 } | 184 } |
188 | 185 |
(...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1060 OnProfileAvatarChanged(profile_path)); | 1057 OnProfileAvatarChanged(profile_path)); |
1061 | 1058 |
1062 // Remove the file from the list of downloads in progress. Note that this list | 1059 // Remove the file from the list of downloads in progress. Note that this list |
1063 // only contains the high resolution avatars, and not the Gaia profile images. | 1060 // only contains the high resolution avatars, and not the Gaia profile images. |
1064 if (!avatar_images_downloads_in_progress_[file_name]) | 1061 if (!avatar_images_downloads_in_progress_[file_name]) |
1065 return; | 1062 return; |
1066 | 1063 |
1067 delete avatar_images_downloads_in_progress_[file_name]; | 1064 delete avatar_images_downloads_in_progress_[file_name]; |
1068 avatar_images_downloads_in_progress_[file_name] = NULL; | 1065 avatar_images_downloads_in_progress_[file_name] = NULL; |
1069 } | 1066 } |
1067 | |
1068 void ProfileInfoCache::MigrateLegacyProfileNamesAndDownloadAvatars() { | |
1069 DCHECK(switches::IsNewAvatarMenu()); | |
1070 | |
1071 // Only do this on desktop platforms. | |
1072 #if defined(OS_ANDROID) || defined(OS_IOS) || defined(OS_CHROMEOS) | |
1073 return; | |
1074 #endif | |
Roger Tawa OOO till Jul 10th
2014/08/22 15:28:04
reverse condition and put #ifdef around all the co
noms (inactive)
2014/08/22 20:44:35
Done.
| |
1075 | |
1076 // Migrate any legacy profile names ("First user", "Default Profile") to | |
1077 // new style default names ("Person 1"). The problem here is that every | |
1078 // time you rename a profile, the ProfileInfoCache sorts itself, so | |
1079 // whatever you were iterating through is no longer valid. We need to | |
1080 // save a list of the profile paths (which thankfully do not change) that | |
1081 // need to be renamed. We also can't pre-compute the new names, as they | |
1082 // depend on the names of all the other profiles in the info cache, so they | |
1083 // need to be re-computed after each rename. | |
1084 std::vector<base::FilePath> profiles_to_rename; | |
1085 | |
1086 const base::string16 default_profile_name = base::i18n::ToLower( | |
1087 l10n_util::GetStringUTF16(IDS_DEFAULT_PROFILE_NAME)); | |
1088 const base::string16 default_legacy_profile_name = base::i18n::ToLower( | |
1089 l10n_util::GetStringUTF16(IDS_LEGACY_DEFAULT_PROFILE_NAME)); | |
1090 | |
1091 for (size_t i = 0; i < GetNumberOfProfiles(); i++) { | |
1092 // If needed, start downloading the high-res avatar for this profile. | |
1093 DownloadHighResAvatar(GetAvatarIconIndexOfProfileAtIndex(i), | |
1094 GetPathOfProfileAtIndex(i)); | |
1095 | |
1096 base::string16 name = base::i18n::ToLower(GetNameOfProfileAtIndex(i)); | |
1097 if (name == default_profile_name || name == default_legacy_profile_name) | |
1098 profiles_to_rename.push_back(GetPathOfProfileAtIndex(i)); | |
1099 } | |
1100 | |
1101 // Rename the necessary profiles. | |
1102 std::vector<base::FilePath>::const_iterator it; | |
1103 for (it = profiles_to_rename.begin(); it != profiles_to_rename.end(); ++it) { | |
1104 size_t profile_index = GetIndexOfProfileWithPath(*it); | |
1105 SetProfileIsUsingDefaultNameAtIndex(profile_index, true); | |
1106 // This will assign a new "Person %d" type name and re-sort the cache. | |
1107 SetNameOfProfileAtIndex(profile_index, ChooseNameForNewProfile( | |
1108 GetAvatarIconIndexOfProfileAtIndex(profile_index))); | |
1109 } | |
1110 } | |
OLD | NEW |