| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/format_macros.h" | 7 #include "base/format_macros.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 IDR_PROFILE_AVATAR_10, | 42 IDR_PROFILE_AVATAR_10, |
| 43 IDR_PROFILE_AVATAR_11, | 43 IDR_PROFILE_AVATAR_11, |
| 44 IDR_PROFILE_AVATAR_12, | 44 IDR_PROFILE_AVATAR_12, |
| 45 IDR_PROFILE_AVATAR_13, | 45 IDR_PROFILE_AVATAR_13, |
| 46 IDR_PROFILE_AVATAR_14, | 46 IDR_PROFILE_AVATAR_14, |
| 47 IDR_PROFILE_AVATAR_15, | 47 IDR_PROFILE_AVATAR_15, |
| 48 IDR_PROFILE_AVATAR_16, | 48 IDR_PROFILE_AVATAR_16, |
| 49 IDR_PROFILE_AVATAR_17, | 49 IDR_PROFILE_AVATAR_17, |
| 50 IDR_PROFILE_AVATAR_18, | 50 IDR_PROFILE_AVATAR_18, |
| 51 IDR_PROFILE_AVATAR_19, | 51 IDR_PROFILE_AVATAR_19, |
| 52 IDR_PROFILE_AVATAR_20, |
| 53 IDR_PROFILE_AVATAR_21, |
| 54 IDR_PROFILE_AVATAR_22, |
| 55 IDR_PROFILE_AVATAR_23, |
| 56 IDR_PROFILE_AVATAR_24, |
| 57 IDR_PROFILE_AVATAR_25, |
| 52 }; | 58 }; |
| 53 | 59 |
| 54 const size_t kDefaultAvatarIconsCount = arraysize(kDefaultAvatarIconResources); | 60 const size_t kDefaultAvatarIconsCount = arraysize(kDefaultAvatarIconResources); |
| 55 | 61 |
| 62 // Returns true if the resource ID belongs to a generic avatar icon. |
| 63 bool IsAvatarIconGeneric(int icon_id) { |
| 64 return icon_id == IDR_PROFILE_AVATAR_0 || |
| 65 icon_id == IDR_PROFILE_AVATAR_1 || |
| 66 icon_id == IDR_PROFILE_AVATAR_2 || |
| 67 icon_id == IDR_PROFILE_AVATAR_3 || |
| 68 icon_id == IDR_PROFILE_AVATAR_4 || |
| 69 icon_id == IDR_PROFILE_AVATAR_5 || |
| 70 icon_id == IDR_PROFILE_AVATAR_6 || |
| 71 icon_id == IDR_PROFILE_AVATAR_7; |
| 72 } |
| 73 |
| 56 } // namespace | 74 } // namespace |
| 57 | 75 |
| 58 ProfileInfoCache::ProfileInfoCache(PrefService* prefs, | 76 ProfileInfoCache::ProfileInfoCache(PrefService* prefs, |
| 59 const FilePath& user_data_dir) | 77 const FilePath& user_data_dir) |
| 60 : prefs_(prefs), | 78 : prefs_(prefs), |
| 61 user_data_dir_(user_data_dir) { | 79 user_data_dir_(user_data_dir) { |
| 62 // Populate the cache | 80 // Populate the cache |
| 63 const DictionaryValue* cache = | 81 const DictionaryValue* cache = |
| 64 prefs_->GetDictionary(prefs::kProfileInfoCache); | 82 prefs_->GetDictionary(prefs::kProfileInfoCache); |
| 65 for (DictionaryValue::key_iterator it = cache->begin_keys(); | 83 for (DictionaryValue::key_iterator it = cache->begin_keys(); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 } | 206 } |
| 189 } | 207 } |
| 190 | 208 |
| 191 int ProfileInfoCache::ChooseAvatarIconIndexForNewProfile() { | 209 int ProfileInfoCache::ChooseAvatarIconIndexForNewProfile() { |
| 192 // Start with a random icon to introduce variety. | 210 // Start with a random icon to introduce variety. |
| 193 size_t rand_start_index = base::RandInt(0, GetDefaultAvatarIconCount() - 1); | 211 size_t rand_start_index = base::RandInt(0, GetDefaultAvatarIconCount() - 1); |
| 194 for (size_t icon_index = 0; icon_index < GetDefaultAvatarIconCount(); | 212 for (size_t icon_index = 0; icon_index < GetDefaultAvatarIconCount(); |
| 195 ++icon_index) { | 213 ++icon_index) { |
| 196 size_t rand_icon_index = | 214 size_t rand_icon_index = |
| 197 (icon_index + rand_start_index) % GetDefaultAvatarIconCount(); | 215 (icon_index + rand_start_index) % GetDefaultAvatarIconCount(); |
| 216 if (IsAvatarIconGeneric(GetDefaultAvatarIconResourceIDAtIndex( |
| 217 rand_icon_index))) |
| 218 continue; |
| 219 |
| 198 bool icon_found = false; | 220 bool icon_found = false; |
| 199 for (size_t i = 0; i < GetNumberOfProfiles(); ++i) { | 221 for (size_t i = 0; i < GetNumberOfProfiles(); ++i) { |
| 200 if (GetAvatarIconIndexOfProfileAtIndex(i) == rand_icon_index) { | 222 if (GetAvatarIconIndexOfProfileAtIndex(i) == rand_icon_index) { |
| 201 icon_found = true; | 223 icon_found = true; |
| 202 break; | 224 break; |
| 203 } | 225 } |
| 204 } | 226 } |
| 205 if (!icon_found) | 227 if (!icon_found) |
| 206 return rand_icon_index; | 228 return rand_icon_index; |
| 207 } | 229 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 if (key_compare < 0) | 315 if (key_compare < 0) |
| 294 return sorted_keys_.begin() + i; | 316 return sorted_keys_.begin() + i; |
| 295 } | 317 } |
| 296 } | 318 } |
| 297 return sorted_keys_.end(); | 319 return sorted_keys_.end(); |
| 298 } | 320 } |
| 299 | 321 |
| 300 void ProfileInfoCache::RegisterPrefs(PrefService* prefs) { | 322 void ProfileInfoCache::RegisterPrefs(PrefService* prefs) { |
| 301 prefs->RegisterDictionaryPref(prefs::kProfileInfoCache); | 323 prefs->RegisterDictionaryPref(prefs::kProfileInfoCache); |
| 302 } | 324 } |
| OLD | NEW |