Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: chrome/browser/profiles/profile_info_cache.cc

Issue 1307093004: Remove references to IsNewAvatarMenu since the flag was removed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert FRAME_AVATAR_BUTTON changes. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 177
178 // For profiles that don't have the "using default avatar" state set yet, 178 // For profiles that don't have the "using default avatar" state set yet,
179 // assume it's the same as the "using default name" state. 179 // assume it's the same as the "using default name" state.
180 if (!info->HasKey(kIsUsingDefaultAvatarKey)) { 180 if (!info->HasKey(kIsUsingDefaultAvatarKey)) {
181 info->SetBoolean(kIsUsingDefaultAvatarKey, using_default_name); 181 info->SetBoolean(kIsUsingDefaultAvatarKey, using_default_name);
182 } 182 }
183 } 183 }
184 184
185 // If needed, start downloading the high-res avatars and migrate any legacy 185 // If needed, start downloading the high-res avatars and migrate any legacy
186 // profile names. 186 // profile names.
187 if (switches::IsNewAvatarMenu() && !disable_avatar_download_for_testing_) 187 if (!disable_avatar_download_for_testing_)
188 MigrateLegacyProfileNamesAndDownloadAvatars(); 188 MigrateLegacyProfileNamesAndDownloadAvatars();
189 } 189 }
190 190
191 ProfileInfoCache::~ProfileInfoCache() { 191 ProfileInfoCache::~ProfileInfoCache() {
192 STLDeleteContainerPairSecondPointers( 192 STLDeleteContainerPairSecondPointers(
193 cached_avatar_images_.begin(), cached_avatar_images_.end()); 193 cached_avatar_images_.begin(), cached_avatar_images_.end());
194 STLDeleteContainerPairSecondPointers( 194 STLDeleteContainerPairSecondPointers(
195 avatar_images_downloads_in_progress_.begin(), 195 avatar_images_downloads_in_progress_.begin(),
196 avatar_images_downloads_in_progress_.end()); 196 avatar_images_downloads_in_progress_.end());
197 } 197 }
(...skipping 20 matching lines...) Expand all
218 info->SetString(kSupervisedUserId, supervised_user_id); 218 info->SetString(kSupervisedUserId, supervised_user_id);
219 info->SetBoolean(kIsOmittedFromProfileListKey, !supervised_user_id.empty()); 219 info->SetBoolean(kIsOmittedFromProfileListKey, !supervised_user_id.empty());
220 info->SetBoolean(kProfileIsEphemeral, false); 220 info->SetBoolean(kProfileIsEphemeral, false);
221 info->SetBoolean(kIsUsingDefaultNameKey, IsDefaultProfileName(name)); 221 info->SetBoolean(kIsUsingDefaultNameKey, IsDefaultProfileName(name));
222 // Assume newly created profiles use a default avatar. 222 // Assume newly created profiles use a default avatar.
223 info->SetBoolean(kIsUsingDefaultAvatarKey, true); 223 info->SetBoolean(kIsUsingDefaultAvatarKey, true);
224 cache->SetWithoutPathExpansion(key, info.release()); 224 cache->SetWithoutPathExpansion(key, info.release());
225 225
226 sorted_keys_.insert(FindPositionForProfile(key, name), key); 226 sorted_keys_.insert(FindPositionForProfile(key, name), key);
227 227
228 if (switches::IsNewAvatarMenu() && !disable_avatar_download_for_testing_) 228 if (!disable_avatar_download_for_testing_)
229 DownloadHighResAvatarIfNeeded(icon_index, profile_path); 229 DownloadHighResAvatarIfNeeded(icon_index, profile_path);
230 230
231 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, 231 FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
232 observer_list_, 232 observer_list_,
233 OnProfileAdded(profile_path)); 233 OnProfileAdded(profile_path));
234 } 234 }
235 235
236 void ProfileInfoCache::AddObserver(ProfileInfoCacheObserver* obs) { 236 void ProfileInfoCache::AddObserver(ProfileInfoCacheObserver* obs) {
237 observer_list_.AddObserver(obs); 237 observer_list_.AddObserver(obs);
238 } 238 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 } 324 }
325 325
326 const gfx::Image& ProfileInfoCache::GetAvatarIconOfProfileAtIndex( 326 const gfx::Image& ProfileInfoCache::GetAvatarIconOfProfileAtIndex(
327 size_t index) { 327 size_t index) {
328 if (IsUsingGAIAPictureOfProfileAtIndex(index)) { 328 if (IsUsingGAIAPictureOfProfileAtIndex(index)) {
329 const gfx::Image* image = GetGAIAPictureOfProfileAtIndex(index); 329 const gfx::Image* image = GetGAIAPictureOfProfileAtIndex(index);
330 if (image) 330 if (image)
331 return *image; 331 return *image;
332 } 332 }
333 333
334 // Use the high resolution version of the avatar if it exists. 334 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) && !defined(OS_IOS)
335 if (switches::IsNewAvatarMenu()) { 335 // Use the high resolution version of the avatar if it exists. Mobile and
336 const gfx::Image* image = GetHighResAvatarOfProfileAtIndex(index); 336 // ChromeOS don't need the high resolution version so no need to fetch it.
337 if (image) 337 const gfx::Image* image = GetHighResAvatarOfProfileAtIndex(index);
338 return *image; 338 if (image)
339 } 339 return *image;
340 #endif
340 341
341 int resource_id = profiles::GetDefaultAvatarIconResourceIDAtIndex( 342 int resource_id = profiles::GetDefaultAvatarIconResourceIDAtIndex(
342 GetAvatarIconIndexOfProfileAtIndex(index)); 343 GetAvatarIconIndexOfProfileAtIndex(index));
343 return ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id); 344 return ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id);
344 } 345 }
345 346
346 std::string ProfileInfoCache::GetLocalAuthCredentialsOfProfileAtIndex( 347 std::string ProfileInfoCache::GetLocalAuthCredentialsOfProfileAtIndex(
347 size_t index) const { 348 size_t index) const {
348 std::string credentials; 349 std::string credentials;
349 GetInfoForProfileAtIndex(index)->GetString(kAuthCredentialsKey, &credentials); 350 GetInfoForProfileAtIndex(index)->GetString(kAuthCredentialsKey, &credentials);
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 size_t icon_index) { 579 size_t icon_index) {
579 scoped_ptr<base::DictionaryValue> info( 580 scoped_ptr<base::DictionaryValue> info(
580 GetInfoForProfileAtIndex(index)->DeepCopy()); 581 GetInfoForProfileAtIndex(index)->DeepCopy());
581 info->SetString(kAvatarIconKey, 582 info->SetString(kAvatarIconKey,
582 profiles::GetDefaultAvatarIconUrl(icon_index)); 583 profiles::GetDefaultAvatarIconUrl(icon_index));
583 // This takes ownership of |info|. 584 // This takes ownership of |info|.
584 SetInfoForProfileAtIndex(index, info.release()); 585 SetInfoForProfileAtIndex(index, info.release());
585 586
586 base::FilePath profile_path = GetPathOfProfileAtIndex(index); 587 base::FilePath profile_path = GetPathOfProfileAtIndex(index);
587 588
588 if (switches::IsNewAvatarMenu() && !disable_avatar_download_for_testing_) 589 if (!disable_avatar_download_for_testing_)
589 DownloadHighResAvatarIfNeeded(icon_index, profile_path); 590 DownloadHighResAvatarIfNeeded(icon_index, profile_path);
590 591
591 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, 592 FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
592 observer_list_, 593 observer_list_,
593 OnProfileAvatarChanged(profile_path)); 594 OnProfileAvatarChanged(profile_path));
594 } 595 }
595 596
596 void ProfileInfoCache::SetIsOmittedProfileAtIndex(size_t index, 597 void ProfileInfoCache::SetIsOmittedProfileAtIndex(size_t index,
597 bool is_omitted) { 598 bool is_omitted) {
598 if (IsOmittedProfileAtIndex(index) == is_omitted) 599 if (IsOmittedProfileAtIndex(index) == is_omitted)
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 default_name_format.c_str(), 858 default_name_format.c_str(),
858 &generic_profile_number); 859 &generic_profile_number);
859 // Unless it matched the format, this is a custom name. 860 // Unless it matched the format, this is a custom name.
860 return assignments == 1; 861 return assignments == 1;
861 } 862 }
862 863
863 base::string16 ProfileInfoCache::ChooseNameForNewProfile( 864 base::string16 ProfileInfoCache::ChooseNameForNewProfile(
864 size_t icon_index) const { 865 size_t icon_index) const {
865 base::string16 name; 866 base::string16 name;
866 for (int name_index = 1; ; ++name_index) { 867 for (int name_index = 1; ; ++name_index) {
867 if (switches::IsNewAvatarMenu()) { 868 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) && !defined(OS_IOS)
868 name = l10n_util::GetStringFUTF16Int(IDS_NEW_NUMBERED_PROFILE_NAME, 869 name = l10n_util::GetStringFUTF16Int(IDS_NEW_NUMBERED_PROFILE_NAME,
869 name_index); 870 name_index);
870 } else if (icon_index < profiles::GetGenericAvatarIconCount()) { 871 #else
872 if (icon_index < profiles::GetGenericAvatarIconCount()) {
871 name = l10n_util::GetStringFUTF16Int(IDS_NUMBERED_PROFILE_NAME, 873 name = l10n_util::GetStringFUTF16Int(IDS_NUMBERED_PROFILE_NAME,
872 name_index); 874 name_index);
873 } else { 875 } else {
874 name = l10n_util::GetStringUTF16( 876 name = l10n_util::GetStringUTF16(
875 kDefaultNames[icon_index - profiles::GetGenericAvatarIconCount()]); 877 kDefaultNames[icon_index - profiles::GetGenericAvatarIconCount()]);
876 if (name_index > 1) 878 if (name_index > 1)
877 name.append(base::UTF8ToUTF16(base::IntToString(name_index))); 879 name.append(base::UTF8ToUTF16(base::IntToString(name_index)));
878 } 880 }
881 #endif
879 882
880 // Loop through previously named profiles to ensure we're not duplicating. 883 // Loop through previously named profiles to ensure we're not duplicating.
881 bool name_found = false; 884 bool name_found = false;
882 for (size_t i = 0; i < GetNumberOfProfiles(); ++i) { 885 for (size_t i = 0; i < GetNumberOfProfiles(); ++i) {
883 if (GetNameOfProfileAtIndex(i) == name) { 886 if (GetNameOfProfileAtIndex(i) == name) {
884 name_found = true; 887 name_found = true;
885 break; 888 break;
886 } 889 }
887 } 890 }
888 if (!name_found) 891 if (!name_found)
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 if (GetAvatarIconIndexOfProfileAtIndex(i) == icon_index) 1023 if (GetAvatarIconIndexOfProfileAtIndex(i) == icon_index)
1021 return false; 1024 return false;
1022 } 1025 }
1023 return true; 1026 return true;
1024 } 1027 }
1025 1028
1026 bool ProfileInfoCache::ChooseAvatarIconIndexForNewProfile( 1029 bool ProfileInfoCache::ChooseAvatarIconIndexForNewProfile(
1027 bool allow_generic_icon, 1030 bool allow_generic_icon,
1028 bool must_be_unique, 1031 bool must_be_unique,
1029 size_t* out_icon_index) const { 1032 size_t* out_icon_index) const {
1030 // Always allow all icons for new profiles if using the 1033 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) && !defined(OS_IOS)
1031 // --new-avatar-menu flag. 1034 // Always allow the generic icon when displaying the new avatar menu.
1032 if (switches::IsNewAvatarMenu()) 1035 allow_generic_icon = true;
1033 allow_generic_icon = true; 1036 #endif
1034 size_t start = allow_generic_icon ? 0 : profiles::GetGenericAvatarIconCount(); 1037 size_t start = allow_generic_icon ? 0 : profiles::GetGenericAvatarIconCount();
1035 size_t end = profiles::GetDefaultAvatarIconCount(); 1038 size_t end = profiles::GetDefaultAvatarIconCount();
1036 size_t count = end - start; 1039 size_t count = end - start;
1037 1040
1038 int rand = base::RandInt(0, count); 1041 int rand = base::RandInt(0, count);
1039 for (size_t i = 0; i < count; ++i) { 1042 for (size_t i = 0; i < count; ++i) {
1040 size_t icon_index = start + (rand + i) % count; 1043 size_t icon_index = start + (rand + i) % count;
1041 if (!must_be_unique || IconIndexIsUnique(icon_index)) { 1044 if (!must_be_unique || IconIndexIsUnique(icon_index)) {
1042 *out_icon_index = icon_index; 1045 *out_icon_index = icon_index;
1043 return true; 1046 return true;
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1193 const std::string& file_name, 1196 const std::string& file_name,
1194 const base::FilePath& profile_path) { 1197 const base::FilePath& profile_path) {
1195 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1198 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1196 1199
1197 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, 1200 FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
1198 observer_list_, 1201 observer_list_,
1199 OnProfileHighResAvatarLoaded(profile_path)); 1202 OnProfileHighResAvatarLoaded(profile_path));
1200 } 1203 }
1201 1204
1202 void ProfileInfoCache::MigrateLegacyProfileNamesAndDownloadAvatars() { 1205 void ProfileInfoCache::MigrateLegacyProfileNamesAndDownloadAvatars() {
1203 DCHECK(switches::IsNewAvatarMenu());
1204
1205 // Only do this on desktop platforms. 1206 // Only do this on desktop platforms.
1206 #if !defined(OS_ANDROID) && !defined(OS_IOS) && !defined(OS_CHROMEOS) 1207 #if !defined(OS_ANDROID) && !defined(OS_IOS) && !defined(OS_CHROMEOS)
1207 // Migrate any legacy profile names ("First user", "Default Profile") to 1208 // Migrate any legacy profile names ("First user", "Default Profile") to
1208 // new style default names ("Person 1"). The problem here is that every 1209 // new style default names ("Person 1"). The problem here is that every
1209 // time you rename a profile, the ProfileInfoCache sorts itself, so 1210 // time you rename a profile, the ProfileInfoCache sorts itself, so
1210 // whatever you were iterating through is no longer valid. We need to 1211 // whatever you were iterating through is no longer valid. We need to
1211 // save a list of the profile paths (which thankfully do not change) that 1212 // save a list of the profile paths (which thankfully do not change) that
1212 // need to be renamed. We also can't pre-compute the new names, as they 1213 // need to be renamed. We also can't pre-compute the new names, as they
1213 // depend on the names of all the other profiles in the info cache, so they 1214 // depend on the names of all the other profiles in the info cache, so they
1214 // need to be re-computed after each rename. 1215 // need to be re-computed after each rename.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 // The profile info is in the cache but its entry isn't created yet, insert 1281 // The profile info is in the cache but its entry isn't created yet, insert
1281 // it in the map. 1282 // it in the map.
1282 scoped_ptr<ProfileAttributesEntry> new_entry(new ProfileAttributesEntry()); 1283 scoped_ptr<ProfileAttributesEntry> new_entry(new ProfileAttributesEntry());
1283 profile_attributes_entries_.add(path, new_entry.Pass()); 1284 profile_attributes_entries_.add(path, new_entry.Pass());
1284 profile_attributes_entries_.get(path)->Initialize(this, path); 1285 profile_attributes_entries_.get(path)->Initialize(this, path);
1285 } 1286 }
1286 1287
1287 *entry = profile_attributes_entries_.get(path); 1288 *entry = profile_attributes_entries_.get(path);
1288 return true; 1289 return true;
1289 } 1290 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698