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

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

Issue 861053004: [Profiles] Send out less profile avatar related notifications (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
« no previous file with comments | « chrome/browser/profiles/profile_info_cache.h ('k') | chrome/browser/profiles/profile_info_cache_observer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 4e6803e2ceb57727fbdd9386df1918ab01c384ac..4d6cb1d5927d0b8d1e849767e3926eeb611e3533 100644
--- a/chrome/browser/profiles/profile_info_cache.cc
+++ b/chrome/browser/profiles/profile_info_cache.cc
@@ -135,6 +135,12 @@ void ReadBitmap(const base::FilePath& image_path,
*out_image = new gfx::Image(image);
}
+void CheckIfFileExists(const base::FilePath& file_path,
+ const base::Closure& callback) {
+ if (!base::PathExists(file_path))
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback);
+}
+
void DeleteBitmap(const base::FilePath& image_path) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
base::DeleteFile(image_path, false);
@@ -214,7 +220,7 @@ void ProfileInfoCache::AddProfileToCache(
sorted_keys_.insert(FindPositionForProfile(key, name), key);
if (switches::IsNewAvatarMenu())
- DownloadHighResAvatar(icon_index, profile_path);
+ DownloadHighResAvatarIfNeeded(icon_index, profile_path);
FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
observer_list_,
@@ -536,9 +542,8 @@ void ProfileInfoCache::SetAvatarIconOfProfileAtIndex(size_t index,
base::FilePath profile_path = GetPathOfProfileAtIndex(index);
- // If needed, start downloading the high-res avatar.
if (switches::IsNewAvatarMenu())
- DownloadHighResAvatar(icon_index, profile_path);
+ DownloadHighResAvatarIfNeeded(icon_index, profile_path);
FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
observer_list_,
@@ -693,7 +698,6 @@ void ProfileInfoCache::SetIsUsingGAIAPictureOfProfileAtIndex(size_t index,
// This takes ownership of |info|.
SetInfoForProfileAtIndex(index, info.release());
- // Retrieve some info to update observers who care about avatar changes.
base::FilePath profile_path = GetPathOfProfileAtIndex(index);
FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
observer_list_,
@@ -848,7 +852,7 @@ void ProfileInfoCache::RegisterPrefs(PrefRegistrySimple* registry) {
registry->RegisterDictionaryPref(prefs::kProfileInfoCache);
}
-void ProfileInfoCache::DownloadHighResAvatar(
+void ProfileInfoCache::DownloadHighResAvatarIfNeeded(
size_t icon_index,
const base::FilePath& profile_path) {
// Downloading is only supported on desktop.
@@ -856,25 +860,16 @@ void ProfileInfoCache::DownloadHighResAvatar(
return;
#endif
- // TODO(noms): We should check whether the file already exists on disk
- // before trying to re-download it. For now, since this is behind a flag and
- // the resources are still changing, re-download it every time the profile
- // avatar changes, to make sure we have the latest copy.
- 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])
- return;
-
- // Start the download for this file. The cache takes ownership of the
- // |avatar_downloader|, which will be deleted when the download completes, or
- // if that never happens, when the ProfileInfoCache is destroyed.
- ProfileAvatarDownloader* avatar_downloader = new ProfileAvatarDownloader(
- icon_index,
- profile_path,
- this);
- avatar_images_downloads_in_progress_[file_name] = avatar_downloader;
- avatar_downloader->Start();
+ const base::FilePath file_path =
Mike Lerman 2015/01/27 16:39:16 To Simplify the ProfileInfoCache, should all this
noms (inactive) 2015/01/28 02:18:36 Hmm, I don't think so. That would mean we'd create
+ profiles::GetPathOfHighResAvatarAtIndex(icon_index);
+ base::Closure callback =
+ base::Bind(&ProfileInfoCache::DownloadHighResAvatar,
+ AsWeakPtr(),
+ profiles::GetDefaultAvatarIconFileNameAtIndex(icon_index),
+ icon_index,
+ profile_path);
+ BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
+ base::Bind(&CheckIfFileExists, file_path, callback));
}
void ProfileInfoCache::SaveAvatarImageAtPath(
@@ -1015,6 +1010,30 @@ const gfx::Image* ProfileInfoCache::GetHighResAvatarOfProfileAtIndex(
key, image_path);
}
+void ProfileInfoCache::DownloadHighResAvatar(
+ const std::string file_name,
+ size_t icon_index,
+ const base::FilePath& profile_path) {
+ // Downloading is only supported on desktop.
+#if defined(OS_ANDROID) || defined(OS_IOS) || defined(OS_CHROMEOS)
+ return;
+#endif
+
+ // If the file is already being downloaded, don't start another download.
+ if (avatar_images_downloads_in_progress_[file_name])
+ return;
+
+ // Start the download for this file. The cache takes ownership of the
+ // |avatar_downloader|, which will be deleted when the download completes, or
+ // if that never happens, when the ProfileInfoCache is destroyed.
+ ProfileAvatarDownloader* avatar_downloader = new ProfileAvatarDownloader(
+ icon_index,
+ profile_path,
+ this);
+ avatar_images_downloads_in_progress_[file_name] = avatar_downloader;
+ avatar_downloader->Start();
+}
+
const gfx::Image* ProfileInfoCache::LoadAvatarPictureFromPath(
const base::FilePath& profile_path,
const std::string& key,
@@ -1063,7 +1082,7 @@ void ProfileInfoCache::OnAvatarPictureLoaded(const base::FilePath& profile_path,
FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
observer_list_,
- OnProfileAvatarChanged(profile_path));
+ OnProfileHighResAvatarLoaded(profile_path));
}
void ProfileInfoCache::OnAvatarPictureSaved(
@@ -1077,8 +1096,8 @@ void ProfileInfoCache::OnAvatarPictureSaved(
content::NotificationService::NoDetails());
FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
- observer_list_,
- OnProfileAvatarChanged(profile_path));
+ observer_list_,
+ OnProfileHighResAvatarLoaded(profile_path));
// 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.
@@ -1110,9 +1129,8 @@ void ProfileInfoCache::MigrateLegacyProfileNamesAndDownloadAvatars() {
l10n_util::GetStringUTF16(IDS_LEGACY_DEFAULT_PROFILE_NAME));
for (size_t i = 0; i < GetNumberOfProfiles(); i++) {
- // If needed, start downloading the high-res avatar for this profile.
- DownloadHighResAvatar(GetAvatarIconIndexOfProfileAtIndex(i),
- GetPathOfProfileAtIndex(i));
+ DownloadHighResAvatarIfNeeded(GetAvatarIconIndexOfProfileAtIndex(i),
+ GetPathOfProfileAtIndex(i));
base::string16 name = base::i18n::ToLower(GetNameOfProfileAtIndex(i));
if (name == default_profile_name || name == default_legacy_profile_name)
« no previous file with comments | « chrome/browser/profiles/profile_info_cache.h ('k') | chrome/browser/profiles/profile_info_cache_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698