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

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

Issue 678553002: Badge icons in windows task bar with avatar icon. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes after discussing with Monica Created 6 years, 1 month 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 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 374
375 std::string file_name; 375 std::string file_name;
376 GetInfoForProfileAtIndex(index)->GetString( 376 GetInfoForProfileAtIndex(index)->GetString(
377 kGAIAPictureFileNameKey, &file_name); 377 kGAIAPictureFileNameKey, &file_name);
378 378
379 // If the picture is not on disk then return NULL. 379 // If the picture is not on disk then return NULL.
380 if (file_name.empty()) 380 if (file_name.empty())
381 return NULL; 381 return NULL;
382 382
383 base::FilePath image_path = path.AppendASCII(file_name); 383 base::FilePath image_path = path.AppendASCII(file_name);
384 return LoadAvatarPictureFromPath(key, image_path); 384 return LoadAvatarPictureFromPath(path, key, image_path);
385 } 385 }
386 386
387 bool ProfileInfoCache::IsUsingGAIAPictureOfProfileAtIndex(size_t index) const { 387 bool ProfileInfoCache::IsUsingGAIAPictureOfProfileAtIndex(size_t index) const {
388 bool value = false; 388 bool value = false;
389 GetInfoForProfileAtIndex(index)->GetBoolean(kUseGAIAPictureKey, &value); 389 GetInfoForProfileAtIndex(index)->GetBoolean(kUseGAIAPictureKey, &value);
390 if (!value) { 390 if (!value) {
391 // Prefer the GAIA avatar over a non-customized avatar. 391 // Prefer the GAIA avatar over a non-customized avatar.
392 value = ProfileIsUsingDefaultAvatarAtIndex(index) && 392 value = ProfileIsUsingDefaultAvatarAtIndex(index) &&
393 GetGAIAPictureOfProfileAtIndex(index); 393 GetGAIAPictureOfProfileAtIndex(index);
394 } 394 }
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 const gfx::Image* ProfileInfoCache::GetHighResAvatarOfProfileAtIndex( 987 const gfx::Image* ProfileInfoCache::GetHighResAvatarOfProfileAtIndex(
988 size_t index) const { 988 size_t index) const {
989 int avatar_index = GetAvatarIconIndexOfProfileAtIndex(index); 989 int avatar_index = GetAvatarIconIndexOfProfileAtIndex(index);
990 std::string key = profiles::GetDefaultAvatarIconFileNameAtIndex(avatar_index); 990 std::string key = profiles::GetDefaultAvatarIconFileNameAtIndex(avatar_index);
991 991
992 if (!strcmp(key.c_str(), profiles::GetNoHighResAvatarFileName())) 992 if (!strcmp(key.c_str(), profiles::GetNoHighResAvatarFileName()))
993 return NULL; 993 return NULL;
994 994
995 base::FilePath image_path = 995 base::FilePath image_path =
996 profiles::GetPathOfHighResAvatarAtIndex(avatar_index); 996 profiles::GetPathOfHighResAvatarAtIndex(avatar_index);
997 return LoadAvatarPictureFromPath(key, image_path); 997 return LoadAvatarPictureFromPath(GetPathOfProfileAtIndex(index),
998 key, image_path);
998 } 999 }
999 1000
1000 const gfx::Image* ProfileInfoCache::LoadAvatarPictureFromPath( 1001 const gfx::Image* ProfileInfoCache::LoadAvatarPictureFromPath(
1002 const base::FilePath& profile_path,
1001 const std::string& key, 1003 const std::string& key,
1002 const base::FilePath& image_path) const { 1004 const base::FilePath& image_path) const {
1003 // If the picture is already loaded then use it. 1005 // If the picture is already loaded then use it.
1004 if (cached_avatar_images_.count(key)) { 1006 if (cached_avatar_images_.count(key)) {
1005 if (cached_avatar_images_[key]->IsEmpty()) 1007 if (cached_avatar_images_[key]->IsEmpty())
1006 return NULL; 1008 return NULL;
1007 return cached_avatar_images_[key]; 1009 return cached_avatar_images_[key];
1008 } 1010 }
1009 1011
1010 // If the picture is already being loaded then don't try loading it again. 1012 // If the picture is already being loaded then don't try loading it again.
1011 if (cached_avatar_images_loading_[key]) 1013 if (cached_avatar_images_loading_[key])
1012 return NULL; 1014 return NULL;
1013 cached_avatar_images_loading_[key] = true; 1015 cached_avatar_images_loading_[key] = true;
1014 1016
1015 gfx::Image** image = new gfx::Image*; 1017 gfx::Image** image = new gfx::Image*;
1016 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, 1018 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE,
1017 base::Bind(&ReadBitmap, image_path, image), 1019 base::Bind(&ReadBitmap, image_path, image),
1018 base::Bind(&ProfileInfoCache::OnAvatarPictureLoaded, 1020 base::Bind(&ProfileInfoCache::OnAvatarPictureLoaded,
1019 const_cast<ProfileInfoCache*>(this)->AsWeakPtr(), key, image)); 1021 const_cast<ProfileInfoCache*>(this)->AsWeakPtr(),
1022 profile_path, key, image));
1020 return NULL; 1023 return NULL;
1021 } 1024 }
1022 1025
1023 void ProfileInfoCache::OnAvatarPictureLoaded(const std::string& key, 1026 void ProfileInfoCache::OnAvatarPictureLoaded(const base::FilePath& profile_path,
1027 const std::string& key,
1024 gfx::Image** image) const { 1028 gfx::Image** image) const {
1025 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1029 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1026 1030
1027 cached_avatar_images_loading_[key] = false; 1031 cached_avatar_images_loading_[key] = false;
1028 delete cached_avatar_images_[key]; 1032 delete cached_avatar_images_[key];
1029 1033
1030 if (*image) { 1034 if (*image) {
1031 cached_avatar_images_[key] = *image; 1035 cached_avatar_images_[key] = *image;
1032 } else { 1036 } else {
1033 // Place an empty image in the cache to avoid reloading it again. 1037 // Place an empty image in the cache to avoid reloading it again.
1034 cached_avatar_images_[key] = new gfx::Image(); 1038 cached_avatar_images_[key] = new gfx::Image();
1035 } 1039 }
1036 delete image; 1040 delete image;
1037 1041
1038 content::NotificationService::current()->Notify( 1042 content::NotificationService::current()->Notify(
1039 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, 1043 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
1040 content::NotificationService::AllSources(), 1044 content::NotificationService::AllSources(),
1041 content::NotificationService::NoDetails()); 1045 content::NotificationService::NoDetails());
1046
1047 FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
1048 observer_list_,
1049 OnProfileAvatarChanged(profile_path));
1042 } 1050 }
1043 1051
1044 void ProfileInfoCache::OnAvatarPictureSaved( 1052 void ProfileInfoCache::OnAvatarPictureSaved(
1045 const std::string& file_name, 1053 const std::string& file_name,
1046 const base::FilePath& profile_path) { 1054 const base::FilePath& profile_path) {
1047 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1055 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1048 1056
1049 content::NotificationService::current()->Notify( 1057 content::NotificationService::current()->Notify(
1050 chrome::NOTIFICATION_PROFILE_CACHE_PICTURE_SAVED, 1058 chrome::NOTIFICATION_PROFILE_CACHE_PICTURE_SAVED,
1051 content::NotificationService::AllSources(), 1059 content::NotificationService::AllSources(),
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 std::vector<base::FilePath>::const_iterator it; 1106 std::vector<base::FilePath>::const_iterator it;
1099 for (it = profiles_to_rename.begin(); it != profiles_to_rename.end(); ++it) { 1107 for (it = profiles_to_rename.begin(); it != profiles_to_rename.end(); ++it) {
1100 size_t profile_index = GetIndexOfProfileWithPath(*it); 1108 size_t profile_index = GetIndexOfProfileWithPath(*it);
1101 SetProfileIsUsingDefaultNameAtIndex(profile_index, true); 1109 SetProfileIsUsingDefaultNameAtIndex(profile_index, true);
1102 // This will assign a new "Person %d" type name and re-sort the cache. 1110 // This will assign a new "Person %d" type name and re-sort the cache.
1103 SetNameOfProfileAtIndex(profile_index, ChooseNameForNewProfile( 1111 SetNameOfProfileAtIndex(profile_index, ChooseNameForNewProfile(
1104 GetAvatarIconIndexOfProfileAtIndex(profile_index))); 1112 GetAvatarIconIndexOfProfileAtIndex(profile_index)));
1105 } 1113 }
1106 #endif 1114 #endif
1107 } 1115 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698