#ifndef ASH_BIRCH_BIRCH_WEATHER_PROVIDER_H_
#define ASH_BIRCH_BIRCH_WEATHER_PROVIDER_H_
#include <optional>
#include <string>
#include "ash/ash_export.h"
#include "ash/birch/birch_data_provider.h"
#include "ash/public/cpp/ambient/weather_info.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
namespace gfx {
class ImageSkia;
}
namespace ash {
class BirchModel;
class ASH_EXPORT BirchWeatherProvider : public BirchDataProvider {
public:
explicit BirchWeatherProvider(BirchModel* birch_model);
BirchWeatherProvider(const BirchWeatherProvider&) = delete;
BirchWeatherProvider& operator=(const BirchWeatherProvider&) = delete;
~BirchWeatherProvider() override;
void RequestBirchDataFetch() override;
void ResetCacheForTest();
private:
void FetchWeather();
void OnWeatherInfoFetched(const std::optional<WeatherInfo>& weather_info);
void OnWeatherConditionIconDownloaded(
const std::string& condition_icon_url,
const std::u16string& weather_description,
float temp_f,
const gfx::ImageSkia& icon);
void AddItemToBirchModel(const std::u16string& weather_description,
float temp_f,
const std::string& icon_url);
const raw_ptr<BirchModel> birch_model_;
bool is_fetching_ = false;
base::Time last_fetch_time_;
std::optional<WeatherInfo> last_weather_info_;
base::WeakPtrFactory<BirchWeatherProvider> weak_factory_{this};
};
}
#endif