Commit 4efdc010 authored by David Roger's avatar David Roger Committed by Commit Bot

[signin] Cleanup ProfileAvatarDownloader::FetchCompleteCallback

This changes the callback from RepeatingCallback to OnceCallback,
and removes the nested callback which was unnecessary and made the code
hard to understand.

Bug: 1041472
Change-Id: If93482c0cfa9e676a0b35712bf545d33b60ada89
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2094987Reviewed-by: default avatarMonica Basta <msalama@chromium.org>
Commit-Queue: David Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748649}
parent 974b4e4a
...@@ -357,8 +357,9 @@ void ProfileAttributesStorage::DownloadHighResAvatar( ...@@ -357,8 +357,9 @@ void ProfileAttributesStorage::DownloadHighResAvatar(
std::unique_ptr<ProfileAvatarDownloader>& current_downloader = std::unique_ptr<ProfileAvatarDownloader>& current_downloader =
avatar_images_downloads_in_progress_[file_name]; avatar_images_downloads_in_progress_[file_name];
current_downloader.reset(new ProfileAvatarDownloader( current_downloader.reset(new ProfileAvatarDownloader(
icon_index, base::Bind(&ProfileAttributesStorage::SaveAvatarImageAtPath, icon_index,
AsWeakPtr(), profile_path))); base::BindOnce(&ProfileAttributesStorage::SaveAvatarImageAtPathNoCallback,
AsWeakPtr(), profile_path)));
current_downloader->Start(); current_downloader->Start();
} }
...@@ -434,3 +435,12 @@ void ProfileAttributesStorage::OnAvatarPictureSaved( ...@@ -434,3 +435,12 @@ void ProfileAttributesStorage::OnAvatarPictureSaved(
NotifyOnProfileHighResAvatarLoaded(profile_path); NotifyOnProfileHighResAvatarLoaded(profile_path);
} }
void ProfileAttributesStorage::SaveAvatarImageAtPathNoCallback(
const base::FilePath& profile_path,
gfx::Image image,
const std::string& key,
const base::FilePath& image_path) {
SaveAvatarImageAtPath(profile_path, image, key, image_path,
base::OnceClosure());
}
...@@ -192,6 +192,12 @@ class ProfileAttributesStorage ...@@ -192,6 +192,12 @@ class ProfileAttributesStorage
base::OnceClosure callback, base::OnceClosure callback,
bool success) const; bool success) const;
// Helper function that calls SaveAvatarImageAtPath without a callback.
void SaveAvatarImageAtPathNoCallback(const base::FilePath& profile_path,
gfx::Image image,
const std::string& key,
const base::FilePath& image_path);
// Notifies observers. // Notifies observers.
void NotifyOnProfileHighResAvatarLoaded( void NotifyOnProfileHighResAvatarLoaded(
const base::FilePath& profile_path) const; const base::FilePath& profile_path) const;
......
...@@ -725,8 +725,9 @@ TEST_F(ProfileAttributesStorageTest, DownloadHighResAvatarTest) { ...@@ -725,8 +725,9 @@ TEST_F(ProfileAttributesStorageTest, DownloadHighResAvatarTest) {
// Simulate downloading a high-res avatar. // Simulate downloading a high-res avatar.
ProfileAvatarDownloader avatar_downloader( ProfileAvatarDownloader avatar_downloader(
kIconIndex, base::Bind(&ProfileAttributesStorage::SaveAvatarImageAtPath, kIconIndex,
base::Unretained(storage()), entry->GetPath())); base::Bind(&ProfileAttributesStorage::SaveAvatarImageAtPathNoCallback,
base::Unretained(storage()), entry->GetPath()));
// Put a real bitmap into "bitmap": a 2x2 bitmap of green 32 bit pixels. // Put a real bitmap into "bitmap": a 2x2 bitmap of green 32 bit pixels.
SkBitmap bitmap; SkBitmap bitmap;
......
...@@ -21,11 +21,9 @@ const char kHighResAvatarDownloadUrlPrefix[] = ...@@ -21,11 +21,9 @@ const char kHighResAvatarDownloadUrlPrefix[] =
"https://www.gstatic.com/chrome/profile_avatars/"; "https://www.gstatic.com/chrome/profile_avatars/";
} }
ProfileAvatarDownloader::ProfileAvatarDownloader( ProfileAvatarDownloader::ProfileAvatarDownloader(size_t icon_index,
size_t icon_index, FetchCompleteCallback callback)
const FetchCompleteCallback& callback) : icon_index_(icon_index), callback_(std::move(callback)) {
: icon_index_(icon_index),
callback_(callback) {
DCHECK(!callback_.is_null()); DCHECK(!callback_.is_null());
GURL url(std::string(kHighResAvatarDownloadUrlPrefix) + GURL url(std::string(kHighResAvatarDownloadUrlPrefix) +
profiles::GetDefaultAvatarIconFileNameAtIndex(icon_index)); profiles::GetDefaultAvatarIconFileNameAtIndex(icon_index));
...@@ -81,8 +79,8 @@ void ProfileAvatarDownloader::OnFetchComplete(const GURL& url, ...@@ -81,8 +79,8 @@ void ProfileAvatarDownloader::OnFetchComplete(const GURL& url,
return; return;
// Decode the downloaded bitmap. Ownership of the image is taken by |cache_|. // Decode the downloaded bitmap. Ownership of the image is taken by |cache_|.
callback_.Run(gfx::Image::CreateFrom1xBitmap(*bitmap), std::move(callback_).Run(
profiles::GetDefaultAvatarIconFileNameAtIndex(icon_index_), gfx::Image::CreateFrom1xBitmap(*bitmap),
profiles::GetPathOfHighResAvatarAtIndex(icon_index_), profiles::GetDefaultAvatarIconFileNameAtIndex(icon_index_),
base::OnceClosure()); profiles::GetPathOfHighResAvatarAtIndex(icon_index_));
} }
...@@ -16,14 +16,10 @@ class Image; ...@@ -16,14 +16,10 @@ class Image;
class ProfileAvatarDownloader : public BitmapFetcherDelegate { class ProfileAvatarDownloader : public BitmapFetcherDelegate {
public: public:
using FetchCompleteCallback = using FetchCompleteCallback = base::OnceCallback<
base::RepeatingCallback<void(gfx::Image, void(gfx::Image, const std::string&, const base::FilePath&)>;
const std::string&,
const base::FilePath&, ProfileAvatarDownloader(size_t icon_index, FetchCompleteCallback callback);
base::OnceClosure)>;
ProfileAvatarDownloader(size_t icon_index,
const FetchCompleteCallback& callback);
~ProfileAvatarDownloader() override; ~ProfileAvatarDownloader() override;
void Start(); void Start();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment