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

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

Issue 1127113003: Don't try to download 'NothingToDownload' placeholder avatar. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests. Created 5 years, 7 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
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 887 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 898
899 void ProfileInfoCache::DownloadHighResAvatarIfNeeded( 899 void ProfileInfoCache::DownloadHighResAvatarIfNeeded(
900 size_t icon_index, 900 size_t icon_index,
901 const base::FilePath& profile_path) { 901 const base::FilePath& profile_path) {
902 // Downloading is only supported on desktop. 902 // Downloading is only supported on desktop.
903 #if defined(OS_ANDROID) || defined(OS_IOS) || defined(OS_CHROMEOS) 903 #if defined(OS_ANDROID) || defined(OS_IOS) || defined(OS_CHROMEOS)
904 return; 904 return;
905 #endif 905 #endif
906 DCHECK(!disable_avatar_download_for_testing_); 906 DCHECK(!disable_avatar_download_for_testing_);
907 907
908 // If this is the placeholder avatar, it is already included in the
909 // resources, so it doesn't need to be downloaded.
Mike Lerman 2015/05/13 20:53:59 Can you append: The avatar picture for this index
910 if (icon_index == profiles::GetPlaceholderAvatarIndex())
911 return;
912
908 const base::FilePath& file_path = 913 const base::FilePath& file_path =
909 profiles::GetPathOfHighResAvatarAtIndex(icon_index); 914 profiles::GetPathOfHighResAvatarAtIndex(icon_index);
910 base::Closure callback = 915 base::Closure callback =
911 base::Bind(&ProfileInfoCache::DownloadHighResAvatar, 916 base::Bind(&ProfileInfoCache::DownloadHighResAvatar,
912 AsWeakPtr(), 917 AsWeakPtr(),
913 icon_index, 918 icon_index,
914 profile_path); 919 profile_path);
915 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 920 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
916 base::Bind(&RunCallbackIfFileMissing, file_path, callback)); 921 base::Bind(&RunCallbackIfFileMissing, file_path, callback));
917 } 922 }
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 std::string key = CacheKeyFromProfilePath(GetPathOfProfileAtIndex(index)); 1034 std::string key = CacheKeyFromProfilePath(GetPathOfProfileAtIndex(index));
1030 std::vector<std::string>::iterator key_it = 1035 std::vector<std::string>::iterator key_it =
1031 std::find(sorted_keys_.begin(), sorted_keys_.end(), key); 1036 std::find(sorted_keys_.begin(), sorted_keys_.end(), key);
1032 DCHECK(key_it != sorted_keys_.end()); 1037 DCHECK(key_it != sorted_keys_.end());
1033 sorted_keys_.erase(key_it); 1038 sorted_keys_.erase(key_it);
1034 sorted_keys_.insert(FindPositionForProfile(key, name), key); 1039 sorted_keys_.insert(FindPositionForProfile(key, name), key);
1035 } 1040 }
1036 1041
1037 const gfx::Image* ProfileInfoCache::GetHighResAvatarOfProfileAtIndex( 1042 const gfx::Image* ProfileInfoCache::GetHighResAvatarOfProfileAtIndex(
1038 size_t index) const { 1043 size_t index) const {
1039 int avatar_index = GetAvatarIconIndexOfProfileAtIndex(index); 1044 const size_t avatar_index = GetAvatarIconIndexOfProfileAtIndex(index);
1040 std::string key = profiles::GetDefaultAvatarIconFileNameAtIndex(avatar_index);
1041 1045
1042 // If this is the placeholder avatar, it is already included in the 1046 // If this is the placeholder avatar, it is already included in the
1043 // resources, so it doesn't need to be downloaded. 1047 // resources, so it doesn't need to be downloaded.
1044 if (!strcmp(key.c_str(), profiles::GetNoHighResAvatarFileName())) { 1048 if (avatar_index == profiles::GetPlaceholderAvatarIndex()) {
1045 return &ui::ResourceBundle::GetSharedInstance().GetImageNamed( 1049 return &ui::ResourceBundle::GetSharedInstance().GetImageNamed(
1046 profiles::GetPlaceholderAvatarIconResourceID()); 1050 profiles::GetPlaceholderAvatarIconResourceID());
1047 } 1051 }
1048 1052
1049 base::FilePath image_path = 1053 const std::string file_name =
1054 profiles::GetDefaultAvatarIconFileNameAtIndex(avatar_index);
1055 const base::FilePath image_path =
1050 profiles::GetPathOfHighResAvatarAtIndex(avatar_index); 1056 profiles::GetPathOfHighResAvatarAtIndex(avatar_index);
1051 return LoadAvatarPictureFromPath(GetPathOfProfileAtIndex(index), 1057 return LoadAvatarPictureFromPath(GetPathOfProfileAtIndex(index), file_name,
1052 key, image_path); 1058 image_path);
1053 } 1059 }
1054 1060
1055 void ProfileInfoCache::DownloadHighResAvatar( 1061 void ProfileInfoCache::DownloadHighResAvatar(
1056 size_t icon_index, 1062 size_t icon_index,
1057 const base::FilePath& profile_path) { 1063 const base::FilePath& profile_path) {
1058 // Downloading is only supported on desktop. 1064 // Downloading is only supported on desktop.
1059 #if defined(OS_ANDROID) || defined(OS_IOS) || defined(OS_CHROMEOS) 1065 #if defined(OS_ANDROID) || defined(OS_IOS) || defined(OS_CHROMEOS)
1060 return; 1066 return;
1061 #endif 1067 #endif
1062 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/461175 1068 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/461175
1063 // is fixed. 1069 // is fixed.
1064 tracked_objects::ScopedTracker tracking_profile1( 1070 tracked_objects::ScopedTracker tracking_profile1(
1065 FROM_HERE_WITH_EXPLICIT_FUNCTION( 1071 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1066 "461175 ProfileInfoCache::DownloadHighResAvatar::GetFileName")); 1072 "461175 ProfileInfoCache::DownloadHighResAvatar::GetFileName"));
1067 const std::string file_name = 1073 const std::string file_name =
Mike Lerman 2015/05/12 19:59:12 What happens if icon_index is the non-downloading
emaxx 2015/05/13 12:08:16 It would DCHECK inside GetDefaultAvatarIconFileNam
Mike Lerman 2015/05/13 20:53:59 Let's add a DCHECK(!file_name.empty()), to help pr
1068 profiles::GetDefaultAvatarIconFileNameAtIndex(icon_index); 1074 profiles::GetDefaultAvatarIconFileNameAtIndex(icon_index);
1069 // If the file is already being downloaded, don't start another download. 1075 // If the file is already being downloaded, don't start another download.
1070 if (avatar_images_downloads_in_progress_.count(file_name)) 1076 if (avatar_images_downloads_in_progress_.count(file_name))
1071 return; 1077 return;
1072 1078
1073 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/461175 1079 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/461175
1074 // is fixed. 1080 // is fixed.
1075 tracked_objects::ScopedTracker tracking_profile2( 1081 tracked_objects::ScopedTracker tracking_profile2(
1076 FROM_HERE_WITH_EXPLICIT_FUNCTION( 1082 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1077 "461175 ProfileInfoCache::DownloadHighResAvatar::MakeDownloader")); 1083 "461175 ProfileInfoCache::DownloadHighResAvatar::MakeDownloader"));
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 std::vector<base::FilePath>::const_iterator it; 1211 std::vector<base::FilePath>::const_iterator it;
1206 for (it = profiles_to_rename.begin(); it != profiles_to_rename.end(); ++it) { 1212 for (it = profiles_to_rename.begin(); it != profiles_to_rename.end(); ++it) {
1207 size_t profile_index = GetIndexOfProfileWithPath(*it); 1213 size_t profile_index = GetIndexOfProfileWithPath(*it);
1208 SetProfileIsUsingDefaultNameAtIndex(profile_index, true); 1214 SetProfileIsUsingDefaultNameAtIndex(profile_index, true);
1209 // This will assign a new "Person %d" type name and re-sort the cache. 1215 // This will assign a new "Person %d" type name and re-sort the cache.
1210 SetNameOfProfileAtIndex(profile_index, ChooseNameForNewProfile( 1216 SetNameOfProfileAtIndex(profile_index, ChooseNameForNewProfile(
1211 GetAvatarIconIndexOfProfileAtIndex(profile_index))); 1217 GetAvatarIconIndexOfProfileAtIndex(profile_index)));
1212 } 1218 }
1213 #endif 1219 #endif
1214 } 1220 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698