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

Unified Diff: chrome/browser/profiles/profile_info_cache.cc

Issue 890873004: ProfileInfoCache: Don't delete ProfileAvatarDownloader while we're being called by it (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix test Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
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..bcb7ee27f25cbe72bb0b9ea2ecbdff596f4debf1 100644
--- a/chrome/browser/profiles/profile_info_cache.cc
+++ b/chrome/browser/profiles/profile_info_cache.cc
@@ -148,6 +148,13 @@ void DeleteBitmap(const base::FilePath& image_path) {
base::DeleteFile(image_path, false);
}
+// Used by SaveAvatarImageAtPath to post a task to delete the |downloader|
+// "soon". We can't just delete it directly there because
+// SaveAvatarImageAtPath is called from this very downloader.
+void DeleteDownloader(ProfileAvatarDownloader* downloader) {
+ delete downloader;
+}
+
} // namespace
ProfileInfoCache::ProfileInfoCache(PrefService* prefs,
@@ -903,9 +910,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);
+ 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));
gab 2015/02/03 18:20:16 FYI, BrowserThread::DeleteSoon(BrowserThread::UI,
+ avatar_images_downloads_in_progress_.erase(downloader_iter);
}
if (!data->size()) {
@@ -1048,7 +1060,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
« no previous file with comments | « chrome/browser/profiles/profile_info_cache.h ('k') | chrome/browser/profiles/profile_info_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698