Chromium Code Reviews| Index: chrome/browser/profiles/profile_info_cache.cc |
| diff --git a/chrome/browser/profiles/profile_info_cache.cc b/chrome/browser/profiles/profile_info_cache.cc |
| index 4a71e0241bcbee7aa1392ac1a059a5ccc6f984b9..daf63a0196c197ec165cbbc0262829dd3c1fe995 100644 |
| --- a/chrome/browser/profiles/profile_info_cache.cc |
| +++ b/chrome/browser/profiles/profile_info_cache.cc |
| @@ -51,12 +51,6 @@ bool IsDefaultAvatarIconUrl(const std::string& url, size_t* icon_index) { |
| return false; |
| } |
| -// Returns a URL for the default avatar icon with specified index. |
| -std::string GetDefaultAvatarIconUrl(int icon_index) { |
| - DCHECK_LT(icon_index, kDefaultAvatarIconsCount); |
| - return StringPrintf("%s%d", kDefaultUrlPrefix, icon_index); |
| -} |
| - |
| } // namespace |
| ProfileInfoCache::ProfileInfoCache(PrefService* prefs, |
| @@ -108,6 +102,18 @@ size_t ProfileInfoCache::GetNumberOfProfiles() const { |
| return sorted_keys_.size(); |
| } |
| +size_t ProfileInfoCache::GetIndexOfProfileWithPath( |
| + const FilePath& profile_path) const { |
| + if (profile_path.DirName() != user_data_dir_) |
| + return std::string::npos; |
| + std::string search_key = profile_path.BaseName().MaybeAsASCII(); |
| + for (size_t i = 0; i < sorted_keys_.size(); ++i) { |
| + if (sorted_keys_[i] == search_key) |
| + return i; |
| + } |
| + return std::string::npos; |
| +} |
| + |
| string16 ProfileInfoCache::GetNameOfProfileAtIndex(size_t index) const { |
| string16 name; |
| GetInfoForProfileAtIndex(index)->GetString(kNameKey, &name); |
| @@ -126,17 +132,21 @@ FilePath ProfileInfoCache::GetPathOfProfileAtIndex(size_t index) const { |
| const gfx::Image& ProfileInfoCache::GetAvatarIconOfProfileAtIndex( |
| size_t index) const { |
| + int resource_id = GetDefaultAvatarIconResourceIDAtIndex( |
| + GetAvatarIconIndexOfProfileAtIndex(index)); |
| + return ResourceBundle::GetSharedInstance().GetImageNamed(resource_id); |
| +} |
| + |
| +size_t ProfileInfoCache::GetAvatarIconIndexOfProfileAtIndex(size_t index) |
| + const { |
| std::string icon_url; |
| GetInfoForProfileAtIndex(index)->GetString(kAvatarIconKey, &icon_url); |
| size_t icon_index = 0; |
| - if (IsDefaultAvatarIconUrl(icon_url, &icon_index)) { |
| - int resource_id = GetDefaultAvatarIconResourceIDAtIndex(icon_index); |
| - return ResourceBundle::GetSharedInstance().GetImageNamed(resource_id); |
| - } |
| + if (IsDefaultAvatarIconUrl(icon_url, &icon_index)) |
| + return icon_index; |
| DLOG(WARNING) << "Unknown avatar icon: " << icon_url; |
| - return ResourceBundle::GetSharedInstance().GetImageNamed( |
| - GetDefaultAvatarIconResourceIDAtIndex(0)); |
| + return GetDefaultAvatarIconResourceIDAtIndex(0); |
| } |
| void ProfileInfoCache::SetNameOfProfileAtIndex(size_t index, |
| @@ -164,6 +174,12 @@ int ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(size_t index) { |
| return kDefaultAvatarIconResources[index]; |
| } |
| +std::string ProfileInfoCache::GetDefaultAvatarIconUrl(size_t index) { |
| + int icon_index = index; |
|
James Hawkins
2011/06/30 23:02:58
Why are you using a temp int?
sail
2011/07/01 01:16:18
Removed.
|
| + DCHECK_LT(icon_index, kDefaultAvatarIconsCount); |
| + return StringPrintf("%s%d", kDefaultUrlPrefix, icon_index); |
| +} |
| + |
| const DictionaryValue* ProfileInfoCache::GetInfoForProfileAtIndex( |
| size_t index) const { |
| DCHECK_LT(index, GetNumberOfProfiles()); |