#ifndef ASH_WALLPAPER_WALLPAPER_PREF_MANAGER_H_
#define ASH_WALLPAPER_WALLPAPER_PREF_MANAGER_H_
#include <optional>
#include <string>
#include <string_view>
#include "ash/ash_export.h"
#include "ash/public/cpp/session/session_observer.h"
#include "ash/public/cpp/style/color_mode_observer.h"
#include "ash/public/cpp/wallpaper/wallpaper_controller.h"
#include "ash/public/cpp/wallpaper/wallpaper_info.h"
#include "ash/wallpaper/wallpaper_utils/wallpaper_calculated_colors.h"
#include "base/containers/flat_map.h"
#include "base/files/file_path.h"
#include "base/observer_list.h"
#include "base/observer_list_types.h"
#include "base/time/time.h"
#include "base/timer/wall_clock_timer.h"
#include "base/values.h"
#include "components/account_id/account_id.h"
class PrefService;
class PrefRegistrySimple;
namespace ash {
class WallpaperControllerClient;
class WallpaperProfileHelper {
public:
virtual ~WallpaperProfileHelper() = default;
virtual void SetClient(WallpaperControllerClient* client) = 0;
virtual PrefService* GetUserPrefServiceSyncable(const AccountId& id) = 0;
virtual AccountId GetActiveAccountId() const = 0;
virtual bool IsWallpaperSyncEnabled(const AccountId& id) const = 0;
virtual bool IsActiveUserSessionStarted() const = 0;
virtual bool IsEphemeral(const AccountId& id) const = 0;
};
class ASH_EXPORT WallpaperPrefManager : public SessionObserver {
public:
class Observer : public base::CheckedObserver {
public:
~Observer() override = default;
virtual void OnDeviceWallpaperImageFilePathUpdated(
const base::FilePath& path) {}
};
static bool ShouldSyncOut(const WallpaperInfo& local_info);
static bool ShouldSyncIn(const WallpaperInfo& synced_info,
const WallpaperInfo& local_info,
const bool is_oobe);
static std::unique_ptr<WallpaperPrefManager> Create(PrefService* local_state);
static std::unique_ptr<WallpaperPrefManager> CreateForTesting(
PrefService* local_state,
std::unique_ptr<WallpaperProfileHelper> profile_helper);
WallpaperPrefManager(const WallpaperPrefManager&) = delete;
~WallpaperPrefManager() override = default;
static void RegisterLocalStatePrefs(PrefRegistrySimple* registry);
static void RegisterProfilePrefs(PrefRegistrySimple* registry);
virtual void SetClient(WallpaperControllerClient* client) = 0;
virtual void AddObserver(Observer* observer) = 0;
virtual void RemoveObserver(Observer* observer) = 0;
virtual bool GetUserWallpaperInfo(const AccountId& account_id,
WallpaperInfo* info) const = 0;
virtual bool SetUserWallpaperInfo(const AccountId& account_id,
const WallpaperInfo& info) = 0;
virtual bool GetUserWallpaperInfo(const AccountId& account_id,
bool is_ephemeral,
WallpaperInfo* info) const = 0;
virtual bool SetUserWallpaperInfo(const AccountId& account_id,
bool is_ephemeral,
const WallpaperInfo& info) = 0;
virtual void RemoveUserWallpaperInfo(const AccountId& account_id) = 0;
virtual std::optional<WallpaperCalculatedColors> GetCachedWallpaperColors(
std::string_view location) const = 0;
virtual void RemoveProminentColors(const AccountId& account_id) = 0;
virtual void CacheKMeanColor(std::string_view location,
SkColor k_mean_color) = 0;
virtual std::optional<SkColor> GetCachedKMeanColor(
std::string_view location) const = 0;
virtual void RemoveKMeanColor(const AccountId& account_id) = 0;
virtual void CacheCelebiColor(std::string_view location,
SkColor celebi_color) = 0;
virtual std::optional<SkColor> GetCelebiColor(
std::string_view location) const = 0;
virtual void RemoveCelebiColor(const AccountId& account_id) = 0;
virtual bool SetDailyGooglePhotosWallpaperIdCache(
const AccountId& account_id,
const WallpaperController::DailyGooglePhotosIdCache& ids) = 0;
virtual bool GetDailyGooglePhotosWallpaperIdCache(
const AccountId& account_id,
WallpaperController::DailyGooglePhotosIdCache& ids_out) const = 0;
virtual bool GetLocalWallpaperInfo(const AccountId& account_id,
WallpaperInfo* info) const = 0;
virtual bool SetLocalWallpaperInfo(const AccountId& account_id,
const WallpaperInfo& info) = 0;
virtual bool GetSyncedWallpaperInfo(const AccountId& account_id,
WallpaperInfo* info) const = 0;
virtual bool SetSyncedWallpaperInfo(const AccountId& account_id,
const WallpaperInfo& info) = 0;
virtual base::TimeDelta GetTimeToNextDailyRefreshUpdate(
const AccountId& account_id) const = 0;
virtual base::FilePath GetDeviceWallpaperImageFilePath() const = 0;
protected:
WallpaperPrefManager() = default;
};
}
#endif