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,7 +357,8 @@ void ProfileAttributesStorage::DownloadHighResAvatar(
std::unique_ptr<ProfileAvatarDownloader>& current_downloader =
avatar_images_downloads_in_progress_[file_name];
current_downloader.reset(new ProfileAvatarDownloader(
icon_index, base::Bind(&ProfileAttributesStorage::SaveAvatarImageAtPath,
icon_index,
base::BindOnce(&ProfileAttributesStorage::SaveAvatarImageAtPathNoCallback,
AsWeakPtr(), profile_path)));
current_downloader->Start();
......@@ -434,3 +435,12 @@ void ProfileAttributesStorage::OnAvatarPictureSaved(
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
base::OnceClosure callback,
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.
void NotifyOnProfileHighResAvatarLoaded(
const base::FilePath& profile_path) const;
......
......@@ -725,7 +725,8 @@ TEST_F(ProfileAttributesStorageTest, DownloadHighResAvatarTest) {
// Simulate downloading a high-res avatar.
ProfileAvatarDownloader avatar_downloader(
kIconIndex, base::Bind(&ProfileAttributesStorage::SaveAvatarImageAtPath,
kIconIndex,
base::Bind(&ProfileAttributesStorage::SaveAvatarImageAtPathNoCallback,
base::Unretained(storage()), entry->GetPath()));
// Put a real bitmap into "bitmap": a 2x2 bitmap of green 32 bit pixels.
......
......@@ -21,11 +21,9 @@ const char kHighResAvatarDownloadUrlPrefix[] =
"https://www.gstatic.com/chrome/profile_avatars/";
}
ProfileAvatarDownloader::ProfileAvatarDownloader(
size_t icon_index,
const FetchCompleteCallback& callback)
: icon_index_(icon_index),
callback_(callback) {
ProfileAvatarDownloader::ProfileAvatarDownloader(size_t icon_index,
FetchCompleteCallback callback)
: icon_index_(icon_index), callback_(std::move(callback)) {
DCHECK(!callback_.is_null());
GURL url(std::string(kHighResAvatarDownloadUrlPrefix) +
profiles::GetDefaultAvatarIconFileNameAtIndex(icon_index));
......@@ -81,8 +79,8 @@ void ProfileAvatarDownloader::OnFetchComplete(const GURL& url,
return;
// Decode the downloaded bitmap. Ownership of the image is taken by |cache_|.
callback_.Run(gfx::Image::CreateFrom1xBitmap(*bitmap),
std::move(callback_).Run(
gfx::Image::CreateFrom1xBitmap(*bitmap),
profiles::GetDefaultAvatarIconFileNameAtIndex(icon_index_),
profiles::GetPathOfHighResAvatarAtIndex(icon_index_),
base::OnceClosure());
profiles::GetPathOfHighResAvatarAtIndex(icon_index_));
}
......@@ -16,14 +16,10 @@ class Image;
class ProfileAvatarDownloader : public BitmapFetcherDelegate {
public:
using FetchCompleteCallback =
base::RepeatingCallback<void(gfx::Image,
const std::string&,
const base::FilePath&,
base::OnceClosure)>;
ProfileAvatarDownloader(size_t icon_index,
const FetchCompleteCallback& callback);
using FetchCompleteCallback = base::OnceCallback<
void(gfx::Image, const std::string&, const base::FilePath&)>;
ProfileAvatarDownloader(size_t icon_index, FetchCompleteCallback callback);
~ProfileAvatarDownloader() override;
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