Chromium Code Reviews| Index: chrome/browser/profiles/profile_info_cache.cc |
| diff --git a/chrome/browser/profiles/profile_info_cache.cc b/chrome/browser/profiles/profile_info_cache.cc |
| index be3618a423e757bb492ec475e42d233959585b99..7a10af3b887a1c2ddfd256f3d14be4d2c2424bb6 100644 |
| --- a/chrome/browser/profiles/profile_info_cache.cc |
| +++ b/chrome/browser/profiles/profile_info_cache.cc |
| @@ -148,6 +148,10 @@ void DeleteBitmap(const base::FilePath& image_path) { |
| base::DeleteFile(image_path, false); |
| } |
| +void DeleteDownloader(ProfileAvatarDownloader* downloader) { |
|
noms (inactive)
2015/01/30 16:05:40
nit: add a comment as to why we would need to post
Marc Treib
2015/01/30 16:12:40
Done.
This would be much nicer as an inline lambda
|
| + delete downloader; |
| +} |
| + |
| } // namespace |
| ProfileInfoCache::ProfileInfoCache(PrefService* prefs, |
| @@ -903,9 +907,14 @@ void ProfileInfoCache::SaveAvatarImageAtPath( |
| // Remove the file from the list of downloads in progress. Note that this list |
| // only contains the high resolution avatars, and not the Gaia profile images. |
| - if (avatar_images_downloads_in_progress_[key]) { |
| - delete avatar_images_downloads_in_progress_[key]; |
| - avatar_images_downloads_in_progress_[key] = NULL; |
| + auto downloader_iter = avatar_images_downloads_in_progress_.find(key); |
|
noms (inactive)
2015/01/30 16:05:40
YAY AUTO!!!
|
| + if (downloader_iter != avatar_images_downloads_in_progress_.end()) { |
| + // We mustn't delete the avatar downloader right here, since we're being |
| + // called by it. |
| + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| + base::Bind(&DeleteDownloader, |
| + downloader_iter->second)); |
| + avatar_images_downloads_in_progress_.erase(downloader_iter); |
| } |
| if (!data->size()) { |
| @@ -1048,7 +1057,7 @@ void ProfileInfoCache::DownloadHighResAvatar( |
| const std::string file_name = |
| profiles::GetDefaultAvatarIconFileNameAtIndex(icon_index); |
| // If the file is already being downloaded, don't start another download. |
| - if (avatar_images_downloads_in_progress_[file_name]) |
| + if (avatar_images_downloads_in_progress_.count(file_name)) |
| return; |
| // Start the download for this file. The cache takes ownership of the |