| 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/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 Loading... |
| 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 (and it will never be |
| 910 // requested from disk by GetHighResAvatarOfProfileAtIndex). |
| 911 if (icon_index == profiles::GetPlaceholderAvatarIndex()) |
| 912 return; |
| 913 |
| 908 const base::FilePath& file_path = | 914 const base::FilePath& file_path = |
| 909 profiles::GetPathOfHighResAvatarAtIndex(icon_index); | 915 profiles::GetPathOfHighResAvatarAtIndex(icon_index); |
| 910 base::Closure callback = | 916 base::Closure callback = |
| 911 base::Bind(&ProfileInfoCache::DownloadHighResAvatar, | 917 base::Bind(&ProfileInfoCache::DownloadHighResAvatar, |
| 912 AsWeakPtr(), | 918 AsWeakPtr(), |
| 913 icon_index, | 919 icon_index, |
| 914 profile_path); | 920 profile_path); |
| 915 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 921 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 916 base::Bind(&RunCallbackIfFileMissing, file_path, callback)); | 922 base::Bind(&RunCallbackIfFileMissing, file_path, callback)); |
| 917 } | 923 } |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1029 std::string key = CacheKeyFromProfilePath(GetPathOfProfileAtIndex(index)); | 1035 std::string key = CacheKeyFromProfilePath(GetPathOfProfileAtIndex(index)); |
| 1030 std::vector<std::string>::iterator key_it = | 1036 std::vector<std::string>::iterator key_it = |
| 1031 std::find(sorted_keys_.begin(), sorted_keys_.end(), key); | 1037 std::find(sorted_keys_.begin(), sorted_keys_.end(), key); |
| 1032 DCHECK(key_it != sorted_keys_.end()); | 1038 DCHECK(key_it != sorted_keys_.end()); |
| 1033 sorted_keys_.erase(key_it); | 1039 sorted_keys_.erase(key_it); |
| 1034 sorted_keys_.insert(FindPositionForProfile(key, name), key); | 1040 sorted_keys_.insert(FindPositionForProfile(key, name), key); |
| 1035 } | 1041 } |
| 1036 | 1042 |
| 1037 const gfx::Image* ProfileInfoCache::GetHighResAvatarOfProfileAtIndex( | 1043 const gfx::Image* ProfileInfoCache::GetHighResAvatarOfProfileAtIndex( |
| 1038 size_t index) const { | 1044 size_t index) const { |
| 1039 int avatar_index = GetAvatarIconIndexOfProfileAtIndex(index); | 1045 const size_t avatar_index = GetAvatarIconIndexOfProfileAtIndex(index); |
| 1040 std::string key = profiles::GetDefaultAvatarIconFileNameAtIndex(avatar_index); | |
| 1041 | 1046 |
| 1042 // If this is the placeholder avatar, it is already included in the | 1047 // If this is the placeholder avatar, it is already included in the |
| 1043 // resources, so it doesn't need to be downloaded. | 1048 // resources, so it doesn't need to be downloaded. |
| 1044 if (!strcmp(key.c_str(), profiles::GetNoHighResAvatarFileName())) { | 1049 if (avatar_index == profiles::GetPlaceholderAvatarIndex()) { |
| 1045 return &ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 1050 return &ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 1046 profiles::GetPlaceholderAvatarIconResourceID()); | 1051 profiles::GetPlaceholderAvatarIconResourceID()); |
| 1047 } | 1052 } |
| 1048 | 1053 |
| 1049 base::FilePath image_path = | 1054 const std::string file_name = |
| 1055 profiles::GetDefaultAvatarIconFileNameAtIndex(avatar_index); |
| 1056 const base::FilePath image_path = |
| 1050 profiles::GetPathOfHighResAvatarAtIndex(avatar_index); | 1057 profiles::GetPathOfHighResAvatarAtIndex(avatar_index); |
| 1051 return LoadAvatarPictureFromPath(GetPathOfProfileAtIndex(index), | 1058 return LoadAvatarPictureFromPath(GetPathOfProfileAtIndex(index), file_name, |
| 1052 key, image_path); | 1059 image_path); |
| 1053 } | 1060 } |
| 1054 | 1061 |
| 1055 void ProfileInfoCache::DownloadHighResAvatar( | 1062 void ProfileInfoCache::DownloadHighResAvatar( |
| 1056 size_t icon_index, | 1063 size_t icon_index, |
| 1057 const base::FilePath& profile_path) { | 1064 const base::FilePath& profile_path) { |
| 1058 // Downloading is only supported on desktop. | 1065 // Downloading is only supported on desktop. |
| 1059 #if defined(OS_ANDROID) || defined(OS_IOS) || defined(OS_CHROMEOS) | 1066 #if defined(OS_ANDROID) || defined(OS_IOS) || defined(OS_CHROMEOS) |
| 1060 return; | 1067 return; |
| 1061 #endif | 1068 #endif |
| 1062 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/461175 | 1069 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/461175 |
| 1063 // is fixed. | 1070 // is fixed. |
| 1064 tracked_objects::ScopedTracker tracking_profile1( | 1071 tracked_objects::ScopedTracker tracking_profile1( |
| 1065 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1072 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1066 "461175 ProfileInfoCache::DownloadHighResAvatar::GetFileName")); | 1073 "461175 ProfileInfoCache::DownloadHighResAvatar::GetFileName")); |
| 1067 const std::string file_name = | 1074 const char* file_name = |
| 1068 profiles::GetDefaultAvatarIconFileNameAtIndex(icon_index); | 1075 profiles::GetDefaultAvatarIconFileNameAtIndex(icon_index); |
| 1076 DCHECK(file_name); |
| 1069 // If the file is already being downloaded, don't start another download. | 1077 // If the file is already being downloaded, don't start another download. |
| 1070 if (avatar_images_downloads_in_progress_.count(file_name)) | 1078 if (avatar_images_downloads_in_progress_.count(file_name)) |
| 1071 return; | 1079 return; |
| 1072 | 1080 |
| 1073 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/461175 | 1081 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/461175 |
| 1074 // is fixed. | 1082 // is fixed. |
| 1075 tracked_objects::ScopedTracker tracking_profile2( | 1083 tracked_objects::ScopedTracker tracking_profile2( |
| 1076 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1084 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1077 "461175 ProfileInfoCache::DownloadHighResAvatar::MakeDownloader")); | 1085 "461175 ProfileInfoCache::DownloadHighResAvatar::MakeDownloader")); |
| 1078 // Start the download for this file. The cache takes ownership of the | 1086 // Start the download for this file. The cache takes ownership of the |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1205 std::vector<base::FilePath>::const_iterator it; | 1213 std::vector<base::FilePath>::const_iterator it; |
| 1206 for (it = profiles_to_rename.begin(); it != profiles_to_rename.end(); ++it) { | 1214 for (it = profiles_to_rename.begin(); it != profiles_to_rename.end(); ++it) { |
| 1207 size_t profile_index = GetIndexOfProfileWithPath(*it); | 1215 size_t profile_index = GetIndexOfProfileWithPath(*it); |
| 1208 SetProfileIsUsingDefaultNameAtIndex(profile_index, true); | 1216 SetProfileIsUsingDefaultNameAtIndex(profile_index, true); |
| 1209 // This will assign a new "Person %d" type name and re-sort the cache. | 1217 // This will assign a new "Person %d" type name and re-sort the cache. |
| 1210 SetNameOfProfileAtIndex(profile_index, ChooseNameForNewProfile( | 1218 SetNameOfProfileAtIndex(profile_index, ChooseNameForNewProfile( |
| 1211 GetAvatarIconIndexOfProfileAtIndex(profile_index))); | 1219 GetAvatarIconIndexOfProfileAtIndex(profile_index))); |
| 1212 } | 1220 } |
| 1213 #endif | 1221 #endif |
| 1214 } | 1222 } |
| OLD | NEW |