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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
142 if (!base::PathExists(file_path)) | 142 if (!base::PathExists(file_path)) |
143 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); | 143 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); |
144 } | 144 } |
145 | 145 |
146 void DeleteBitmap(const base::FilePath& image_path) { | 146 void DeleteBitmap(const base::FilePath& image_path) { |
147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
148 base::DeleteFile(image_path, false); | 148 base::DeleteFile(image_path, false); |
149 } | 149 } |
150 | 150 |
151 // Used by SaveAvatarImageAtPath to post a task to delete the |downloader| | |
152 // "soon". We can't just delete it directly there because | |
153 // SaveAvatarImageAtPath is called from this very downloader. | |
154 void DeleteDownloader(ProfileAvatarDownloader* downloader) { | |
155 delete downloader; | |
156 } | |
157 | |
158 } // namespace | 151 } // namespace |
159 | 152 |
160 ProfileInfoCache::ProfileInfoCache(PrefService* prefs, | 153 ProfileInfoCache::ProfileInfoCache(PrefService* prefs, |
161 const base::FilePath& user_data_dir) | 154 const base::FilePath& user_data_dir) |
162 : prefs_(prefs), | 155 : prefs_(prefs), |
163 user_data_dir_(user_data_dir) { | 156 user_data_dir_(user_data_dir) { |
164 // Populate the cache | 157 // Populate the cache |
165 DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache); | 158 DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache); |
166 base::DictionaryValue* cache = update.Get(); | 159 base::DictionaryValue* cache = update.Get(); |
167 for (base::DictionaryValue::Iterator it(*cache); | 160 for (base::DictionaryValue::Iterator it(*cache); |
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
907 scoped_ptr<ImageData> data(new ImageData); | 900 scoped_ptr<ImageData> data(new ImageData); |
908 scoped_refptr<base::RefCountedMemory> png_data = image->As1xPNGBytes(); | 901 scoped_refptr<base::RefCountedMemory> png_data = image->As1xPNGBytes(); |
909 data->assign(png_data->front(), png_data->front() + png_data->size()); | 902 data->assign(png_data->front(), png_data->front() + png_data->size()); |
910 | 903 |
911 // Remove the file from the list of downloads in progress. Note that this list | 904 // Remove the file from the list of downloads in progress. Note that this list |
912 // only contains the high resolution avatars, and not the Gaia profile images. | 905 // only contains the high resolution avatars, and not the Gaia profile images. |
913 auto downloader_iter = avatar_images_downloads_in_progress_.find(key); | 906 auto downloader_iter = avatar_images_downloads_in_progress_.find(key); |
914 if (downloader_iter != avatar_images_downloads_in_progress_.end()) { | 907 if (downloader_iter != avatar_images_downloads_in_progress_.end()) { |
915 // We mustn't delete the avatar downloader right here, since we're being | 908 // We mustn't delete the avatar downloader right here, since we're being |
916 // called by it. | 909 // called by it. |
917 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 910 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, |
918 base::Bind(&DeleteDownloader, | 911 downloader_iter->second); |
919 downloader_iter->second)); | |
920 avatar_images_downloads_in_progress_.erase(downloader_iter); | 912 avatar_images_downloads_in_progress_.erase(downloader_iter); |
921 } | 913 } |
922 | 914 |
923 if (!data->size()) { | 915 if (!data->size()) { |
924 LOG(ERROR) << "Failed to PNG encode the image."; | 916 LOG(ERROR) << "Failed to PNG encode the image."; |
925 } else { | 917 } else { |
926 base::Closure callback = base::Bind(&ProfileInfoCache::OnAvatarPictureSaved, | 918 base::Closure callback = base::Bind(&ProfileInfoCache::OnAvatarPictureSaved, |
927 AsWeakPtr(), key, profile_path); | 919 AsWeakPtr(), key, profile_path); |
928 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 920 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
929 base::Bind(&SaveBitmap, base::Passed(&data), image_path, callback)); | 921 base::Bind(&SaveBitmap, base::Passed(&data), image_path, callback)); |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1173 std::vector<base::FilePath>::const_iterator it; | 1165 std::vector<base::FilePath>::const_iterator it; |
1174 for (it = profiles_to_rename.begin(); it != profiles_to_rename.end(); ++it) { | 1166 for (it = profiles_to_rename.begin(); it != profiles_to_rename.end(); ++it) { |
1175 size_t profile_index = GetIndexOfProfileWithPath(*it); | 1167 size_t profile_index = GetIndexOfProfileWithPath(*it); |
1176 SetProfileIsUsingDefaultNameAtIndex(profile_index, true); | 1168 SetProfileIsUsingDefaultNameAtIndex(profile_index, true); |
1177 // This will assign a new "Person %d" type name and re-sort the cache. | 1169 // This will assign a new "Person %d" type name and re-sort the cache. |
1178 SetNameOfProfileAtIndex(profile_index, ChooseNameForNewProfile( | 1170 SetNameOfProfileAtIndex(profile_index, ChooseNameForNewProfile( |
1179 GetAvatarIconIndexOfProfileAtIndex(profile_index))); | 1171 GetAvatarIconIndexOfProfileAtIndex(profile_index))); |
1180 } | 1172 } |
1181 #endif | 1173 #endif |
1182 } | 1174 } |
OLD | NEW |