#ifndef ASH_AMBIENT_AMBIENT_BACKUP_PHOTO_DOWNLOADER_H_
#define ASH_AMBIENT_AMBIENT_BACKUP_PHOTO_DOWNLOADER_H_
#include <string>
#include <vector>
#include "ash/ash_export.h"
#include "base/files/file_path.h"
#include "base/functional/callback.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "ui/gfx/geometry/size.h"
namespace base {
class SequencedTaskRunner;
}
namespace gfx {
class ImageSkia;
}
namespace ash {
class AmbientAccessTokenController;
class ASH_EXPORT AmbientBackupPhotoDownloader {
public:
AmbientBackupPhotoDownloader(
AmbientAccessTokenController& access_token_controller,
int cache_idx,
gfx::Size target_size,
const std::string& url,
base::OnceCallback<void(bool success)> completion_cb);
AmbientBackupPhotoDownloader(const AmbientBackupPhotoDownloader&) = delete;
AmbientBackupPhotoDownloader& operator=(const AmbientBackupPhotoDownloader&) =
delete;
~AmbientBackupPhotoDownloader();
private:
void RunCompletionCallback(bool success);
void DecodeImage(base::FilePath temp_image_path);
void ScheduleResizeAndEncode(const gfx::ImageSkia& decoded_image);
void SaveImage(const std::vector<unsigned char>& encoded_image);
const int cache_idx_;
const gfx::Size target_size_;
const scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
base::OnceCallback<void(bool success)> completion_cb_;
base::FilePath temp_image_path_;
base::WeakPtrFactory<AmbientBackupPhotoDownloader> weak_factory_{this};
};
}
#endif