summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMonica Dinculescu <noms@chromium.org>2015-02-11 17:05:28 -0500
committerMonica Dinculescu <noms@chromium.org>2015-02-11 22:06:50 +0000
commit27efdb3e9efd709ec459f72a871db678216507d8 (patch)
treebae82fc2634139012e898a6e91a2ca7029062c74
parentca72cea15121cc5d3f4a9c3ee0312d27fca66d03 (diff)
downloadchromium_src-27efdb3e9efd709ec459f72a871db678216507d8.zip
chromium_src-27efdb3e9efd709ec459f72a871db678216507d8.tar.gz
chromium_src-27efdb3e9efd709ec459f72a871db678216507d8.tar.bz2
[Merge] ProfileInfoCache: Don't delete ProfileAvatarDownloader while we're being called by it
BUG=453795 TBR=noms@chromium.org Review URL: https://codereview.chromium.org/890873004 Cr-Commit-Position: refs/heads/master@{#313937} (cherry picked from commit af25550b46f4aaf597420638aa895db7ebe2657f) Review URL: https://codereview.chromium.org/914423002 Cr-Commit-Position: refs/branch-heads/2272@{#270} Cr-Branched-From: 827a380cfdb31aa54c8d56e63ce2c3fd8c3ba4d4-refs/heads/master@{#310958}
-rw-r--r--chrome/browser/profiles/profile_info_cache.cc20
-rw-r--r--chrome/browser/profiles/profile_info_cache.h2
-rw-r--r--chrome/browser/profiles/profile_info_cache_unittest.cc4
3 files changed, 20 insertions, 6 deletions
diff --git a/chrome/browser/profiles/profile_info_cache.cc b/chrome/browser/profiles/profile_info_cache.cc
index a81962b..1063c6a 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));
+ avatar_images_downloads_in_progress_.erase(downloader_iter);
}
if (!data->size()) {
@@ -1044,7 +1056,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
diff --git a/chrome/browser/profiles/profile_info_cache.h b/chrome/browser/profiles/profile_info_cache.h
index d460246..95db92c 100644
--- a/chrome/browser/profiles/profile_info_cache.h
+++ b/chrome/browser/profiles/profile_info_cache.h
@@ -231,7 +231,7 @@ class ProfileInfoCache : public ProfileInfoInterface,
// This prevents a picture from being downloaded multiple times. The
// ProfileAvatarDownloader instances are deleted when the download completes
// or when the ProfileInfoCache is destroyed.
- mutable std::map<std::string, ProfileAvatarDownloader*>
+ std::map<std::string, ProfileAvatarDownloader*>
avatar_images_downloads_in_progress_;
DISALLOW_COPY_AND_ASSIGN(ProfileInfoCache);
diff --git a/chrome/browser/profiles/profile_info_cache_unittest.cc b/chrome/browser/profiles/profile_info_cache_unittest.cc
index 03223c6..57c2e33 100644
--- a/chrome/browser/profiles/profile_info_cache_unittest.cc
+++ b/chrome/browser/profiles/profile_info_cache_unittest.cc
@@ -571,11 +571,13 @@ TEST_F(ProfileInfoCacheTest, DownloadHighResAvatarTest) {
avatar_downloader.OnFetchComplete(
GURL("http://www.google.com/avatar.png"), &bitmap);
+ // Now the download should not be in progress anymore.
+ EXPECT_EQ(0U, GetCache()->avatar_images_downloads_in_progress_.size());
+
std::string file_name =
profiles::GetDefaultAvatarIconFileNameAtIndex(kIconIndex);
// The file should have been cached and saved.
- EXPECT_EQ(1U, GetCache()->avatar_images_downloads_in_progress_.size());
EXPECT_EQ(1U, GetCache()->cached_avatar_images_.size());
EXPECT_TRUE(GetCache()->GetHighResAvatarOfProfileAtIndex(0));
EXPECT_EQ(GetCache()->cached_avatar_images_[file_name],