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

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

Issue 212603011: Newly created profiles should have the grey silhouette as avatar. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Undo changes to (.png) image resources. Created 6 years, 8 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 | Annotate | Revision Log
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/file_util.h" 8 #include "base/file_util.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/i18n/case_conversion.h" 10 #include "base/i18n/case_conversion.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 IDR_PROFILE_AVATAR_16, 82 IDR_PROFILE_AVATAR_16,
83 IDR_PROFILE_AVATAR_17, 83 IDR_PROFILE_AVATAR_17,
84 IDR_PROFILE_AVATAR_18, 84 IDR_PROFILE_AVATAR_18,
85 IDR_PROFILE_AVATAR_19, 85 IDR_PROFILE_AVATAR_19,
86 IDR_PROFILE_AVATAR_20, 86 IDR_PROFILE_AVATAR_20,
87 IDR_PROFILE_AVATAR_21, 87 IDR_PROFILE_AVATAR_21,
88 IDR_PROFILE_AVATAR_22, 88 IDR_PROFILE_AVATAR_22,
89 IDR_PROFILE_AVATAR_23, 89 IDR_PROFILE_AVATAR_23,
90 IDR_PROFILE_AVATAR_24, 90 IDR_PROFILE_AVATAR_24,
91 IDR_PROFILE_AVATAR_25, 91 IDR_PROFILE_AVATAR_25,
92 IDR_PROFILE_AVATAR_26,
92 }; 93 };
93 94
95 // This avatar does not exist on the server, the high res copy is in the build.
96 const char* kNoHighResAvatar = "NothingToDownload";
97
94 // File names for the high-res avatar icon resources. In the same order as 98 // File names for the high-res avatar icon resources. In the same order as
95 // the avatars in kDefaultAvatarIconResources. 99 // the avatars in kDefaultAvatarIconResources.
96 const char* kDefaultAvatarIconResourceFileNames[] = { 100 const char* kDefaultAvatarIconResourceFileNames[] = {
97 "avatar_generic.png", 101 "avatar_generic.png",
98 "avatar_generic_aqua.png", 102 "avatar_generic_aqua.png",
99 "avatar_generic_blue.png", 103 "avatar_generic_blue.png",
100 "avatar_generic_green.png", 104 "avatar_generic_green.png",
101 "avatar_generic_orange.png", 105 "avatar_generic_orange.png",
102 "avatar_generic_purple.png", 106 "avatar_generic_purple.png",
103 "avatar_generic_red.png", 107 "avatar_generic_red.png",
104 "avatar_generic_yellow.png", 108 "avatar_generic_yellow.png",
105 "avatar_secret_agent.png", 109 "avatar_secret_agent.png",
106 "avatar_superhero.png", 110 "avatar_superhero.png",
107 "avatar_volley_ball.png", 111 "avatar_volley_ball.png",
108 "avatar_businessman.png", 112 "avatar_businessman.png",
109 "avatar_ninja.png", 113 "avatar_ninja.png",
110 "avatar_alien.png", 114 "avatar_alien.png",
111 "avatar_smiley.png", 115 "avatar_smiley.png",
112 "avatar_flower.png", 116 "avatar_flower.png",
113 "avatar_pizza.png", 117 "avatar_pizza.png",
114 "avatar_soccer.png", 118 "avatar_soccer.png",
115 "avatar_burger.png", 119 "avatar_burger.png",
116 "avatar_cat.png", 120 "avatar_cat.png",
117 "avatar_cupcake.png", 121 "avatar_cupcake.png",
118 "avatar_dog.png", 122 "avatar_dog.png",
119 "avatar_horse.png", 123 "avatar_horse.png",
120 "avatar_margarita.png", 124 "avatar_margarita.png",
121 "avatar_note.png", 125 "avatar_note.png",
122 "avatar_sun_cloud.png", 126 "avatar_sun_cloud.png",
127 kNoHighResAvatar,
123 }; 128 };
124 129
125 const size_t kDefaultAvatarIconsCount = arraysize(kDefaultAvatarIconResources); 130 const size_t kDefaultAvatarIconsCount = arraysize(kDefaultAvatarIconResources);
126 131
127 // The first 8 icons are generic. 132 // The first 8 icons are generic.
128 const size_t kGenericIconCount = 8; 133 const size_t kGenericIconCount = 8;
129 134
135 // The avatar used as a placeholder (grey silhouette).
136 const int kPlaceholderAvatarIcon = 26;
137
130 // First eight are generic icons, which use IDS_NUMBERED_PROFILE_NAME. 138 // First eight are generic icons, which use IDS_NUMBERED_PROFILE_NAME.
131 const int kDefaultNames[] = { 139 const int kDefaultNames[] = {
132 IDS_DEFAULT_AVATAR_NAME_8, 140 IDS_DEFAULT_AVATAR_NAME_8,
133 IDS_DEFAULT_AVATAR_NAME_9, 141 IDS_DEFAULT_AVATAR_NAME_9,
134 IDS_DEFAULT_AVATAR_NAME_10, 142 IDS_DEFAULT_AVATAR_NAME_10,
135 IDS_DEFAULT_AVATAR_NAME_11, 143 IDS_DEFAULT_AVATAR_NAME_11,
136 IDS_DEFAULT_AVATAR_NAME_12, 144 IDS_DEFAULT_AVATAR_NAME_12,
137 IDS_DEFAULT_AVATAR_NAME_13, 145 IDS_DEFAULT_AVATAR_NAME_13,
138 IDS_DEFAULT_AVATAR_NAME_14, 146 IDS_DEFAULT_AVATAR_NAME_14,
139 IDS_DEFAULT_AVATAR_NAME_15, 147 IDS_DEFAULT_AVATAR_NAME_15,
140 IDS_DEFAULT_AVATAR_NAME_16, 148 IDS_DEFAULT_AVATAR_NAME_16,
141 IDS_DEFAULT_AVATAR_NAME_17, 149 IDS_DEFAULT_AVATAR_NAME_17,
142 IDS_DEFAULT_AVATAR_NAME_18, 150 IDS_DEFAULT_AVATAR_NAME_18,
143 IDS_DEFAULT_AVATAR_NAME_19, 151 IDS_DEFAULT_AVATAR_NAME_19,
144 IDS_DEFAULT_AVATAR_NAME_20, 152 IDS_DEFAULT_AVATAR_NAME_20,
145 IDS_DEFAULT_AVATAR_NAME_21, 153 IDS_DEFAULT_AVATAR_NAME_21,
146 IDS_DEFAULT_AVATAR_NAME_22, 154 IDS_DEFAULT_AVATAR_NAME_22,
147 IDS_DEFAULT_AVATAR_NAME_23, 155 IDS_DEFAULT_AVATAR_NAME_23,
148 IDS_DEFAULT_AVATAR_NAME_24, 156 IDS_DEFAULT_AVATAR_NAME_24,
149 IDS_DEFAULT_AVATAR_NAME_25 157 IDS_DEFAULT_AVATAR_NAME_25,
158 IDS_DEFAULT_AVATAR_NAME_26
150 }; 159 };
151 160
152 typedef std::vector<unsigned char> ImageData; 161 typedef std::vector<unsigned char> ImageData;
153 162
154 // Writes |data| to disk and takes ownership of the pointer. On completion 163 // Writes |data| to disk and takes ownership of the pointer. On completion
155 // |success| is set to true on success and false on failure. 164 // |success| is set to true on success and false on failure.
156 void SaveBitmap(ImageData* data, 165 void SaveBitmap(ImageData* data,
157 const base::FilePath& image_path, 166 const base::FilePath& image_path,
158 bool* success) { 167 bool* success) {
159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 466
458 base::FilePath image_path = path.AppendASCII(file_name); 467 base::FilePath image_path = path.AppendASCII(file_name);
459 return LoadAvatarPictureFromPath(key, image_path); 468 return LoadAvatarPictureFromPath(key, image_path);
460 } 469 }
461 470
462 const gfx::Image* ProfileInfoCache::GetHighResAvatarOfProfileAtIndex( 471 const gfx::Image* ProfileInfoCache::GetHighResAvatarOfProfileAtIndex(
463 size_t index) const { 472 size_t index) const {
464 int avatar_index = GetAvatarIconIndexOfProfileAtIndex(index); 473 int avatar_index = GetAvatarIconIndexOfProfileAtIndex(index);
465 std::string key = kDefaultAvatarIconResourceFileNames[avatar_index]; 474 std::string key = kDefaultAvatarIconResourceFileNames[avatar_index];
466 475
476 if (!strcmp(key.c_str(), kNoHighResAvatar))
477 return NULL;
478
467 base::FilePath user_data_dir; 479 base::FilePath user_data_dir;
468 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); 480 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
469 base::FilePath image_path = 481 base::FilePath image_path =
470 user_data_dir.AppendASCII(kHighResAvatarFolderName).AppendASCII(key); 482 user_data_dir.AppendASCII(kHighResAvatarFolderName).AppendASCII(key);
471 return LoadAvatarPictureFromPath(key, image_path); 483 return LoadAvatarPictureFromPath(key, image_path);
472 } 484 }
473 485
474 const gfx::Image* ProfileInfoCache::LoadAvatarPictureFromPath( 486 const gfx::Image* ProfileInfoCache::LoadAvatarPictureFromPath(
475 const std::string& key, 487 const std::string& key,
476 const base::FilePath& image_path) const { 488 const base::FilePath& image_path) const {
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 935
924 const base::FilePath& ProfileInfoCache::GetUserDataDir() const { 936 const base::FilePath& ProfileInfoCache::GetUserDataDir() const {
925 return user_data_dir_; 937 return user_data_dir_;
926 } 938 }
927 939
928 // static 940 // static
929 size_t ProfileInfoCache::GetDefaultAvatarIconCount() { 941 size_t ProfileInfoCache::GetDefaultAvatarIconCount() {
930 return kDefaultAvatarIconsCount; 942 return kDefaultAvatarIconsCount;
931 } 943 }
932 944
945
946 int ProfileInfoCache::GetPlaceholderAvatarIndex() {
947 return kPlaceholderAvatarIcon;
948 }
949
950 int ProfileInfoCache::GetPlaceholderAvatarIconResourceID() {
951 return IDR_PROFILE_AVATAR_26;
952 }
953
933 // static 954 // static
934 int ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(size_t index) { 955 int ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(size_t index) {
935 DCHECK(IsDefaultAvatarIconIndex(index)); 956 DCHECK(IsDefaultAvatarIconIndex(index));
936 return kDefaultAvatarIconResources[index]; 957 return kDefaultAvatarIconResources[index];
937 } 958 }
938 959
939 // static 960 // static
940 std::string ProfileInfoCache::GetDefaultAvatarIconUrl(size_t index) { 961 std::string ProfileInfoCache::GetDefaultAvatarIconUrl(size_t index) {
941 DCHECK(IsDefaultAvatarIconIndex(index)); 962 DCHECK(IsDefaultAvatarIconIndex(index));
942 return base::StringPrintf("%s%" PRIuS, kDefaultUrlPrefix, index); 963 return base::StringPrintf("%s%" PRIuS, kDefaultUrlPrefix, index);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1053 info->GetString(kNameKey, &name); 1074 info->GetString(kNameKey, &name);
1054 names.push_back(name); 1075 names.push_back(name);
1055 } 1076 }
1056 return names; 1077 return names;
1057 } 1078 }
1058 1079
1059 // static 1080 // static
1060 void ProfileInfoCache::RegisterPrefs(PrefRegistrySimple* registry) { 1081 void ProfileInfoCache::RegisterPrefs(PrefRegistrySimple* registry) {
1061 registry->RegisterDictionaryPref(prefs::kProfileInfoCache); 1082 registry->RegisterDictionaryPref(prefs::kProfileInfoCache);
1062 } 1083 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698