#ifndef CHROME_BROWSER_APPS_APP_DISCOVERY_SERVICE_ALMANAC_FETCHER_H_
#define CHROME_BROWSER_APPS_APP_DISCOVERY_SERVICE_ALMANAC_FETCHER_H_
#include "base/memory/raw_ptr.h"
#include "chrome/browser/apps/almanac_api_client/proto_file_manager.h"
#include "chrome/browser/apps/app_discovery_service/almanac_api/launcher_app.pb.h"
#include "chrome/browser/apps/app_discovery_service/app_discovery_util.h"
#include "chrome/browser/apps/app_discovery_service/app_fetcher_manager.h"
class Profile;
namespace user_prefs {
class PrefRegistrySyncable;
}
namespace apps {
class AlmanacIconCache;
class AlmanacFetcher : public AppFetcher {
public:
AlmanacFetcher(Profile* profile,
std::unique_ptr<AlmanacIconCache> icon_cache);
AlmanacFetcher(const AlmanacFetcher&) = delete;
AlmanacFetcher& operator=(const AlmanacFetcher&) = delete;
~AlmanacFetcher() override;
void GetApps(ResultCallback callback) override;
base::CallbackListSubscription RegisterForAppUpdates(
RepeatingResultCallback callback) override;
void GetIcon(const std::string& icon_id,
int32_t size_hint_in_dip,
GetIconCallback callback) override;
static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
static void SetSkipApiKeyCheckForTesting(bool skip_api_key_check);
base::Time GetLastAppsUpdateTime() const;
void SetLastAppsUpdateTime(base::Time value);
private:
void DownloadApps();
void OnServerResponse(std::optional<proto::LauncherAppResponse> response);
void OnFileWritten(proto::LauncherAppResponse response, bool write_complete);
void OnAppsUpdate(std::optional<proto::LauncherAppResponse> response);
raw_ptr<Profile> profile_;
std::vector<Result> apps_;
ResultCallbackList subscribers_;
std::unique_ptr<ProtoFileManager<proto::LauncherAppResponse>>
proto_file_manager_;
std::unique_ptr<AlmanacIconCache> icon_cache_;
base::WeakPtrFactory<AlmanacFetcher> weak_factory_{this};
};
}
#endif