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/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/i18n/case_conversion.h" | 10 #include "base/i18n/case_conversion.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/path_service.h" | |
13 #include "base/prefs/pref_registry_simple.h" | 14 #include "base/prefs/pref_registry_simple.h" |
14 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
15 #include "base/prefs/scoped_user_pref_update.h" | 16 #include "base/prefs/scoped_user_pref_update.h" |
16 #include "base/rand_util.h" | 17 #include "base/rand_util.h" |
17 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
18 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
19 #include "base/strings/string_piece.h" | 20 #include "base/strings/string_piece.h" |
20 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
21 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
22 #include "base/values.h" | 23 #include "base/values.h" |
23 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
24 #include "chrome/browser/chrome_notification_types.h" | 25 #include "chrome/browser/chrome_notification_types.h" |
26 #include "chrome/common/chrome_paths.h" | |
25 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
26 #include "chrome/common/profile_management_switches.h" | 28 #include "chrome/common/profile_management_switches.h" |
27 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
28 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
29 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
30 #include "grit/theme_resources.h" | 32 #include "grit/theme_resources.h" |
31 #include "third_party/skia/include/core/SkBitmap.h" | 33 #include "third_party/skia/include/core/SkBitmap.h" |
32 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
33 #include "ui/base/resource/resource_bundle.h" | 35 #include "ui/base/resource/resource_bundle.h" |
34 #include "ui/gfx/image/image.h" | 36 #include "ui/gfx/image/image.h" |
(...skipping 18 matching lines...) Expand all Loading... | |
53 const char kGAIAPictureFileNameKey[] = "gaia_picture_file_name"; | 55 const char kGAIAPictureFileNameKey[] = "gaia_picture_file_name"; |
54 const char kIsManagedKey[] = "is_managed"; | 56 const char kIsManagedKey[] = "is_managed"; |
55 const char kIsOmittedFromProfileListKey[] = "is_omitted_from_profile_list"; | 57 const char kIsOmittedFromProfileListKey[] = "is_omitted_from_profile_list"; |
56 const char kSigninRequiredKey[] = "signin_required"; | 58 const char kSigninRequiredKey[] = "signin_required"; |
57 const char kManagedUserId[] = "managed_user_id"; | 59 const char kManagedUserId[] = "managed_user_id"; |
58 const char kProfileIsEphemeral[] = "is_ephemeral"; | 60 const char kProfileIsEphemeral[] = "is_ephemeral"; |
59 const char kActiveTimeKey[] = "active_time"; | 61 const char kActiveTimeKey[] = "active_time"; |
60 | 62 |
61 const char kDefaultUrlPrefix[] = "chrome://theme/IDR_PROFILE_AVATAR_"; | 63 const char kDefaultUrlPrefix[] = "chrome://theme/IDR_PROFILE_AVATAR_"; |
62 const char kGAIAPictureFileName[] = "Google Profile Picture.png"; | 64 const char kGAIAPictureFileName[] = "Google Profile Picture.png"; |
65 const char kHighResAvatarFolderName[] = "Avatars"; | |
63 | 66 |
64 const int kDefaultAvatarIconResources[] = { | 67 const int kDefaultAvatarIconResources[] = { |
65 IDR_PROFILE_AVATAR_0, | 68 IDR_PROFILE_AVATAR_0, |
66 IDR_PROFILE_AVATAR_1, | 69 IDR_PROFILE_AVATAR_1, |
67 IDR_PROFILE_AVATAR_2, | 70 IDR_PROFILE_AVATAR_2, |
68 IDR_PROFILE_AVATAR_3, | 71 IDR_PROFILE_AVATAR_3, |
69 IDR_PROFILE_AVATAR_4, | 72 IDR_PROFILE_AVATAR_4, |
70 IDR_PROFILE_AVATAR_5, | 73 IDR_PROFILE_AVATAR_5, |
71 IDR_PROFILE_AVATAR_6, | 74 IDR_PROFILE_AVATAR_6, |
72 IDR_PROFILE_AVATAR_7, | 75 IDR_PROFILE_AVATAR_7, |
(...skipping 10 matching lines...) Expand all Loading... | |
83 IDR_PROFILE_AVATAR_18, | 86 IDR_PROFILE_AVATAR_18, |
84 IDR_PROFILE_AVATAR_19, | 87 IDR_PROFILE_AVATAR_19, |
85 IDR_PROFILE_AVATAR_20, | 88 IDR_PROFILE_AVATAR_20, |
86 IDR_PROFILE_AVATAR_21, | 89 IDR_PROFILE_AVATAR_21, |
87 IDR_PROFILE_AVATAR_22, | 90 IDR_PROFILE_AVATAR_22, |
88 IDR_PROFILE_AVATAR_23, | 91 IDR_PROFILE_AVATAR_23, |
89 IDR_PROFILE_AVATAR_24, | 92 IDR_PROFILE_AVATAR_24, |
90 IDR_PROFILE_AVATAR_25, | 93 IDR_PROFILE_AVATAR_25, |
91 }; | 94 }; |
92 | 95 |
96 // File names for the high-res avatar icon resources. In the same order as | |
97 // the avatars in kDefaultAvatarIconResources. | |
98 const char* kDefaultAvatarIconResourceFileNames[] = { | |
99 "chrome_avatar_generic.png", | |
100 "chrome_avatar_generic_aqua.png", | |
101 "chrome_avatar_generic_blue.png", | |
102 "chrome_avatar_generic_green.png", | |
103 "chrome_avatar_generic_orange.png", | |
104 "chrome_avatar_generic_purple.png", | |
105 "chrome_avatar_generic_red.png", | |
106 "chrome_avatar_generic_yellow.png", | |
107 "chrome_avatar_secret_agent.png", | |
108 "chrome_avatar_superhero.png", | |
109 "chrome_avatar_volley_ball.png", | |
110 "chrome_avatar_businessman.png", | |
111 "chrome_avatar_ninja.png", | |
112 "chrome_avatar_alien.png", | |
113 "chrome_avatar_smiley.png", | |
114 "chrome_avatar_flower.png", | |
115 "chrome_avatar_pizza.png", | |
116 "chrome_avatar_soccer.png", | |
117 "chrome_avatar_burger.png", | |
118 "chrome_avatar_cat.png", | |
119 "chrome_avatar_cupcake.png", | |
120 "chrome_avatar_dog.png", | |
121 "chrome_avatar_horse.png", | |
122 "chrome_avatar_margarita.png", | |
123 "chrome_avatar_note.png", | |
124 "chrome_avatar_sun_cloud.png", | |
Roger Tawa OOO till Jul 10th
2014/03/25 14:39:49
Do we really need chrome_ prefix ?
noms (inactive)
2014/03/25 19:24:22
Nope! On 2014/03/25 14:39:49, Roger Tawa wrote:
| |
125 }; | |
126 | |
93 const size_t kDefaultAvatarIconsCount = arraysize(kDefaultAvatarIconResources); | 127 const size_t kDefaultAvatarIconsCount = arraysize(kDefaultAvatarIconResources); |
94 | 128 |
95 // The first 8 icons are generic. | 129 // The first 8 icons are generic. |
96 const size_t kGenericIconCount = 8; | 130 const size_t kGenericIconCount = 8; |
97 | 131 |
98 // First eight are generic icons, which use IDS_NUMBERED_PROFILE_NAME. | 132 // First eight are generic icons, which use IDS_NUMBERED_PROFILE_NAME. |
99 const int kDefaultNames[] = { | 133 const int kDefaultNames[] = { |
100 IDS_DEFAULT_AVATAR_NAME_8, | 134 IDS_DEFAULT_AVATAR_NAME_8, |
101 IDS_DEFAULT_AVATAR_NAME_9, | 135 IDS_DEFAULT_AVATAR_NAME_9, |
102 IDS_DEFAULT_AVATAR_NAME_10, | 136 IDS_DEFAULT_AVATAR_NAME_10, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 } | 179 } |
146 | 180 |
147 // Reads a PNG from disk and decodes it. If the bitmap was successfully read | 181 // Reads a PNG from disk and decodes it. If the bitmap was successfully read |
148 // from disk the then |out_image| will contain the bitmap image, otherwise it | 182 // from disk the then |out_image| will contain the bitmap image, otherwise it |
149 // will be NULL. | 183 // will be NULL. |
150 void ReadBitmap(const base::FilePath& image_path, | 184 void ReadBitmap(const base::FilePath& image_path, |
151 gfx::Image** out_image) { | 185 gfx::Image** out_image) { |
152 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 186 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
153 *out_image = NULL; | 187 *out_image = NULL; |
154 | 188 |
189 // If the path doesn't exist, don't even try reading it. | |
190 if (!base::PathExists(image_path)) | |
191 return; | |
192 | |
155 std::string image_data; | 193 std::string image_data; |
156 if (!base::ReadFileToString(image_path, &image_data)) { | 194 if (!base::ReadFileToString(image_path, &image_data)) { |
157 LOG(ERROR) << "Failed to read PNG file from disk."; | 195 LOG(ERROR) << "Failed to read PNG file from disk."; |
158 return; | 196 return; |
159 } | 197 } |
160 | 198 |
161 gfx::Image image = gfx::Image::CreateFrom1xPNGBytes( | 199 gfx::Image image = gfx::Image::CreateFrom1xPNGBytes( |
162 base::RefCountedString::TakeString(&image_data)); | 200 base::RefCountedString::TakeString(&image_data)); |
163 if (image.IsEmpty()) { | 201 if (image.IsEmpty()) { |
164 LOG(ERROR) << "Failed to decode PNG file."; | 202 LOG(ERROR) << "Failed to decode PNG file."; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
218 if (info->GetBoolean(kIsManagedKey, &is_managed)) { | 256 if (info->GetBoolean(kIsManagedKey, &is_managed)) { |
219 info->Remove(kIsManagedKey, NULL); | 257 info->Remove(kIsManagedKey, NULL); |
220 info->SetString(kManagedUserId, is_managed ? "DUMMY_ID" : std::string()); | 258 info->SetString(kManagedUserId, is_managed ? "DUMMY_ID" : std::string()); |
221 } | 259 } |
222 info->SetBoolean(kIsUsingDefaultName, IsDefaultName(name)); | 260 info->SetBoolean(kIsUsingDefaultName, IsDefaultName(name)); |
223 } | 261 } |
224 } | 262 } |
225 | 263 |
226 ProfileInfoCache::~ProfileInfoCache() { | 264 ProfileInfoCache::~ProfileInfoCache() { |
227 STLDeleteContainerPairSecondPointers( | 265 STLDeleteContainerPairSecondPointers( |
228 gaia_pictures_.begin(), gaia_pictures_.end()); | 266 cached_avatar_images_.begin(), cached_avatar_images_.end()); |
229 } | 267 } |
230 | 268 |
231 void ProfileInfoCache::AddProfileToCache(const base::FilePath& profile_path, | 269 void ProfileInfoCache::AddProfileToCache(const base::FilePath& profile_path, |
232 const base::string16& name, | 270 const base::string16& name, |
233 const base::string16& username, | 271 const base::string16& username, |
234 size_t icon_index, | 272 size_t icon_index, |
235 const std::string& managed_user_id) { | 273 const std::string& managed_user_id) { |
236 std::string key = CacheKeyFromProfilePath(profile_path); | 274 std::string key = CacheKeyFromProfilePath(profile_path); |
237 DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache); | 275 DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache); |
238 base::DictionaryValue* cache = update.Get(); | 276 base::DictionaryValue* cache = update.Get(); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
357 } | 395 } |
358 | 396 |
359 const gfx::Image& ProfileInfoCache::GetAvatarIconOfProfileAtIndex( | 397 const gfx::Image& ProfileInfoCache::GetAvatarIconOfProfileAtIndex( |
360 size_t index) const { | 398 size_t index) const { |
361 if (IsUsingGAIAPictureOfProfileAtIndex(index)) { | 399 if (IsUsingGAIAPictureOfProfileAtIndex(index)) { |
362 const gfx::Image* image = GetGAIAPictureOfProfileAtIndex(index); | 400 const gfx::Image* image = GetGAIAPictureOfProfileAtIndex(index); |
363 if (image) | 401 if (image) |
364 return *image; | 402 return *image; |
365 } | 403 } |
366 | 404 |
405 // Use the high resolution version of the avatar if it exists. | |
406 if (switches::IsNewProfileManagement()) { | |
407 const gfx::Image* image = GetHighResAvatarOfProfileAtIndex(index); | |
408 if (image) | |
409 return *image; | |
410 } | |
411 | |
367 int resource_id = GetDefaultAvatarIconResourceIDAtIndex( | 412 int resource_id = GetDefaultAvatarIconResourceIDAtIndex( |
368 GetAvatarIconIndexOfProfileAtIndex(index)); | 413 GetAvatarIconIndexOfProfileAtIndex(index)); |
369 return ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id); | 414 return ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id); |
370 } | 415 } |
371 | 416 |
372 std::string ProfileInfoCache::GetLocalAuthCredentialsOfProfileAtIndex( | 417 std::string ProfileInfoCache::GetLocalAuthCredentialsOfProfileAtIndex( |
373 size_t index) const { | 418 size_t index) const { |
374 std::string credentials; | 419 std::string credentials; |
375 GetInfoForProfileAtIndex(index)->GetString(kAuthCredentialsKey, &credentials); | 420 GetInfoForProfileAtIndex(index)->GetString(kAuthCredentialsKey, &credentials); |
376 return credentials; | 421 return credentials; |
(...skipping 28 matching lines...) Expand all Loading... | |
405 GetInfoForProfileAtIndex(index)->GetBoolean(kUseGAIANameKey, &value); | 450 GetInfoForProfileAtIndex(index)->GetBoolean(kUseGAIANameKey, &value); |
406 return value; | 451 return value; |
407 } | 452 } |
408 | 453 |
409 const gfx::Image* ProfileInfoCache::GetGAIAPictureOfProfileAtIndex( | 454 const gfx::Image* ProfileInfoCache::GetGAIAPictureOfProfileAtIndex( |
410 size_t index) const { | 455 size_t index) const { |
411 base::FilePath path = GetPathOfProfileAtIndex(index); | 456 base::FilePath path = GetPathOfProfileAtIndex(index); |
412 std::string key = CacheKeyFromProfilePath(path); | 457 std::string key = CacheKeyFromProfilePath(path); |
413 | 458 |
414 // If the picture is already loaded then use it. | 459 // If the picture is already loaded then use it. |
415 if (gaia_pictures_.count(key)) { | 460 if (cached_avatar_images_.count(key)) { |
416 if (gaia_pictures_[key]->IsEmpty()) | 461 if (cached_avatar_images_[key]->IsEmpty()) |
417 return NULL; | 462 return NULL; |
418 return gaia_pictures_[key]; | 463 return cached_avatar_images_[key]; |
419 } | 464 } |
420 | 465 |
421 std::string file_name; | 466 std::string file_name; |
422 GetInfoForProfileAtIndex(index)->GetString( | 467 GetInfoForProfileAtIndex(index)->GetString( |
423 kGAIAPictureFileNameKey, &file_name); | 468 kGAIAPictureFileNameKey, &file_name); |
424 | 469 |
425 // If the picture is not on disk or it is already being loaded then return | 470 // If the picture is not on disk then return NULL. |
426 // NULL. | 471 if (file_name.empty()) |
427 if (file_name.empty() || gaia_pictures_loading_[key]) | |
428 return NULL; | 472 return NULL; |
429 | 473 |
430 gaia_pictures_loading_[key] = true; | |
431 base::FilePath image_path = path.AppendASCII(file_name); | 474 base::FilePath image_path = path.AppendASCII(file_name); |
475 LoadAvatarPictureFromPath(key, image_path); | |
476 return NULL; | |
477 } | |
478 | |
479 const gfx::Image* ProfileInfoCache::GetHighResAvatarOfProfileAtIndex( | |
480 size_t index) const { | |
481 int avatar_index = GetAvatarIconIndexOfProfileAtIndex(index); | |
482 std::string key = kDefaultAvatarIconResourceFileNames[avatar_index]; | |
483 | |
484 // If the picture is already loaded then use it. | |
485 if (cached_avatar_images_.count(key)) { | |
486 if (cached_avatar_images_[key]->IsEmpty()) | |
487 return NULL; | |
488 return cached_avatar_images_[key]; | |
489 } | |
490 | |
491 base::FilePath user_data_dir; | |
492 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | |
493 base::FilePath image_path = | |
494 user_data_dir.AppendASCII(kHighResAvatarFolderName).AppendASCII(key); | |
495 LoadAvatarPictureFromPath(key, image_path); | |
496 return NULL; | |
497 } | |
Roger Tawa OOO till Jul 10th
2014/03/25 14:39:49
GetGAIAPictureOfProfileAtIndex() and GetHighResAva
noms (inactive)
2014/03/25 19:24:22
Unfortunately GetGAIAPictureOfProfileAtIndex() is
| |
498 | |
499 void ProfileInfoCache::LoadAvatarPictureFromPath( | |
500 const std::string& key, | |
501 const base::FilePath& image_path) const { | |
502 // If the picture is already being loaded then don't try loading it again. | |
503 if (cached_avatar_images_loading_[key]) | |
504 return; | |
505 cached_avatar_images_loading_[key] = true; | |
506 | |
432 gfx::Image** image = new gfx::Image*; | 507 gfx::Image** image = new gfx::Image*; |
433 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, | 508 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, |
434 base::Bind(&ReadBitmap, image_path, image), | 509 base::Bind(&ReadBitmap, image_path, image), |
435 base::Bind(&ProfileInfoCache::OnGAIAPictureLoaded, | 510 base::Bind(&ProfileInfoCache::OnAvatarPictureLoaded, |
436 const_cast<ProfileInfoCache*>(this)->AsWeakPtr(), path, image)); | 511 const_cast<ProfileInfoCache*>(this)->AsWeakPtr(), key, image)); |
437 | |
438 return NULL; | |
439 } | 512 } |
440 | 513 |
441 bool ProfileInfoCache::ProfileIsManagedAtIndex(size_t index) const { | 514 bool ProfileInfoCache::ProfileIsManagedAtIndex(size_t index) const { |
442 return !GetManagedUserIdOfProfileAtIndex(index).empty(); | 515 return !GetManagedUserIdOfProfileAtIndex(index).empty(); |
443 } | 516 } |
444 | 517 |
445 bool ProfileInfoCache::IsOmittedProfileAtIndex(size_t index) const { | 518 bool ProfileInfoCache::IsOmittedProfileAtIndex(size_t index) const { |
446 bool value = false; | 519 bool value = false; |
447 GetInfoForProfileAtIndex(index)->GetBoolean(kIsOmittedFromProfileListKey, | 520 GetInfoForProfileAtIndex(index)->GetBoolean(kIsOmittedFromProfileListKey, |
448 &value); | 521 &value); |
(...skipping 18 matching lines...) Expand all Loading... | |
467 GetInfoForProfileAtIndex(index)->GetBoolean(kProfileIsEphemeral, &value); | 540 GetInfoForProfileAtIndex(index)->GetBoolean(kProfileIsEphemeral, &value); |
468 return value; | 541 return value; |
469 } | 542 } |
470 | 543 |
471 bool ProfileInfoCache::ProfileIsUsingDefaultNameAtIndex(size_t index) const { | 544 bool ProfileInfoCache::ProfileIsUsingDefaultNameAtIndex(size_t index) const { |
472 bool value = false; | 545 bool value = false; |
473 GetInfoForProfileAtIndex(index)->GetBoolean(kIsUsingDefaultName, &value); | 546 GetInfoForProfileAtIndex(index)->GetBoolean(kIsUsingDefaultName, &value); |
474 return value; | 547 return value; |
475 } | 548 } |
476 | 549 |
477 void ProfileInfoCache::OnGAIAPictureLoaded(const base::FilePath& path, | 550 void ProfileInfoCache::OnAvatarPictureLoaded(const std::string& key, |
478 gfx::Image** image) const { | 551 gfx::Image** image) const { |
479 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 552 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
480 | 553 |
481 std::string key = CacheKeyFromProfilePath(path); | 554 cached_avatar_images_loading_[key] = false; |
482 gaia_pictures_loading_[key] = false; | |
483 | 555 |
484 if (*image) { | 556 if (*image) { |
485 delete gaia_pictures_[key]; | 557 delete cached_avatar_images_[key]; |
486 gaia_pictures_[key] = *image; | 558 cached_avatar_images_[key] = *image; |
487 } else { | 559 } else { |
488 // Place an empty image in the cache to avoid reloading it again. | 560 // Place an empty image in the cache to avoid reloading it again. |
489 gaia_pictures_[key] = new gfx::Image(); | 561 cached_avatar_images_[key] = new gfx::Image(); |
Roger Tawa OOO till Jul 10th
2014/03/25 14:39:49
I still think there is a potential memory leak her
noms (inactive)
2014/03/25 19:24:22
I've just deleted |cached_avatar_images_[key]| in
| |
490 } | 562 } |
491 delete image; | 563 delete image; |
492 | 564 |
493 content::NotificationService::current()->Notify( | 565 content::NotificationService::current()->Notify( |
494 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, | 566 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, |
495 content::NotificationService::AllSources(), | 567 content::NotificationService::AllSources(), |
496 content::NotificationService::NoDetails()); | 568 content::NotificationService::NoDetails()); |
497 } | 569 } |
498 | 570 |
499 void ProfileInfoCache::OnGAIAPictureSaved(const base::FilePath& path, | 571 void ProfileInfoCache::OnGAIAPictureSaved(const base::FilePath& path, |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
698 OnProfileNameChanged(profile_path, old_display_name)); | 770 OnProfileNameChanged(profile_path, old_display_name)); |
699 } | 771 } |
700 } | 772 } |
701 | 773 |
702 void ProfileInfoCache::SetGAIAPictureOfProfileAtIndex(size_t index, | 774 void ProfileInfoCache::SetGAIAPictureOfProfileAtIndex(size_t index, |
703 const gfx::Image* image) { | 775 const gfx::Image* image) { |
704 base::FilePath path = GetPathOfProfileAtIndex(index); | 776 base::FilePath path = GetPathOfProfileAtIndex(index); |
705 std::string key = CacheKeyFromProfilePath(path); | 777 std::string key = CacheKeyFromProfilePath(path); |
706 | 778 |
707 // Delete the old bitmap from cache. | 779 // Delete the old bitmap from cache. |
708 std::map<std::string, gfx::Image*>::iterator it = gaia_pictures_.find(key); | 780 std::map<std::string, gfx::Image*>::iterator it = |
709 if (it != gaia_pictures_.end()) { | 781 cached_avatar_images_.find(key); |
782 if (it != cached_avatar_images_.end()) { | |
710 delete it->second; | 783 delete it->second; |
711 gaia_pictures_.erase(it); | 784 cached_avatar_images_.erase(it); |
712 } | 785 } |
713 | 786 |
714 std::string old_file_name; | 787 std::string old_file_name; |
715 GetInfoForProfileAtIndex(index)->GetString( | 788 GetInfoForProfileAtIndex(index)->GetString( |
716 kGAIAPictureFileNameKey, &old_file_name); | 789 kGAIAPictureFileNameKey, &old_file_name); |
717 std::string new_file_name; | 790 std::string new_file_name; |
718 | 791 |
719 if (!image) { | 792 if (!image) { |
720 // Delete the old bitmap from disk. | 793 // Delete the old bitmap from disk. |
721 if (!old_file_name.empty()) { | 794 if (!old_file_name.empty()) { |
722 base::FilePath image_path = path.AppendASCII(old_file_name); | 795 base::FilePath image_path = path.AppendASCII(old_file_name); |
723 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 796 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
724 base::Bind(&DeleteBitmap, image_path)); | 797 base::Bind(&DeleteBitmap, image_path)); |
725 } | 798 } |
726 } else { | 799 } else { |
727 // Save the new bitmap to disk. | 800 // Save the new bitmap to disk. |
728 gaia_pictures_[key] = new gfx::Image(*image); | 801 cached_avatar_images_[key] = new gfx::Image(*image); |
729 scoped_ptr<ImageData> data(new ImageData); | 802 scoped_ptr<ImageData> data(new ImageData); |
730 scoped_refptr<base::RefCountedMemory> png_data = image->As1xPNGBytes(); | 803 scoped_refptr<base::RefCountedMemory> png_data = image->As1xPNGBytes(); |
731 data->assign(png_data->front(), png_data->front() + png_data->size()); | 804 data->assign(png_data->front(), png_data->front() + png_data->size()); |
732 if (!data->size()) { | 805 if (!data->size()) { |
733 LOG(ERROR) << "Failed to PNG encode the image."; | 806 LOG(ERROR) << "Failed to PNG encode the image."; |
734 } else { | 807 } else { |
735 new_file_name = | 808 new_file_name = |
736 old_file_name.empty() ? kGAIAPictureFileName : old_file_name; | 809 old_file_name.empty() ? kGAIAPictureFileName : old_file_name; |
737 base::FilePath image_path = path.AppendASCII(new_file_name); | 810 base::FilePath image_path = path.AppendASCII(new_file_name); |
738 bool* success = new bool; | 811 bool* success = new bool; |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1036 info->GetString(kNameKey, &name); | 1109 info->GetString(kNameKey, &name); |
1037 names.push_back(name); | 1110 names.push_back(name); |
1038 } | 1111 } |
1039 return names; | 1112 return names; |
1040 } | 1113 } |
1041 | 1114 |
1042 // static | 1115 // static |
1043 void ProfileInfoCache::RegisterPrefs(PrefRegistrySimple* registry) { | 1116 void ProfileInfoCache::RegisterPrefs(PrefRegistrySimple* registry) { |
1044 registry->RegisterDictionaryPref(prefs::kProfileInfoCache); | 1117 registry->RegisterDictionaryPref(prefs::kProfileInfoCache); |
1045 } | 1118 } |
OLD | NEW |