#ifndef ASH_AMBIENT_MODEL_AMBIENT_BACKEND_MODEL_H_
#define ASH_AMBIENT_MODEL_AMBIENT_BACKEND_MODEL_H_
#include <string>
#include <vector>
#include "ash/ambient/ambient_constants.h"
#include "ash/ambient/model/ambient_photo_config.h"
#include "ash/ash_export.h"
#include "ash/public/cpp/ambient/ambient_backend_controller.h"
#include "base/containers/circular_deque.h"
#include "base/observer_list.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "ui/gfx/image/image_skia.h"
namespace ash {
class AmbientBackendModelObserver;
struct ASH_EXPORT PhotoWithDetails {
PhotoWithDetails();
PhotoWithDetails(const PhotoWithDetails&);
PhotoWithDetails& operator=(const PhotoWithDetails&);
PhotoWithDetails(PhotoWithDetails&&);
PhotoWithDetails& operator=(PhotoWithDetails&&);
~PhotoWithDetails();
void Clear();
bool IsNull() const;
gfx::ImageSkia photo;
gfx::ImageSkia related_photo;
std::string details;
std::string related_details;
std::string hash;
bool is_portrait = false;
::ambient::TopicType topic_type = ::ambient::TopicType::kOther;
};
class ASH_EXPORT AmbientBackendModel {
public:
explicit AmbientBackendModel(AmbientPhotoConfig photo_config);
AmbientBackendModel(const AmbientBackendModel&) = delete;
AmbientBackendModel& operator=(AmbientBackendModel&) = delete;
~AmbientBackendModel();
void AddObserver(AmbientBackendModelObserver* observer);
void RemoveObserver(AmbientBackendModelObserver* observer);
bool ImagesReady() const;
void AddNextImage(const PhotoWithDetails& photo);
bool IsHashDuplicate(const std::string& hash) const;
void AddImageFailure();
void ResetImageFailures();
bool ImageLoadingFailed();
void Clear();
void SetPhotoConfig(AmbientPhotoConfig photo_config);
const base::circular_deque<PhotoWithDetails>& all_decoded_topics() const {
return all_decoded_topics_;
}
void GetCurrentAndNextImages(PhotoWithDetails* current_image_out,
PhotoWithDetails* next_image_out) const;
base::TimeDelta GetPhotoRefreshInterval() const;
const AmbientPhotoConfig& photo_config() const { return photo_config_; }
private:
friend class AmbientBackendModelTest;
friend class AmbientAshTestBase;
void NotifyImageAdded();
void NotifyImagesReady();
void OnImagesReadyTimeoutFired();
AmbientPhotoConfig photo_config_;
std::vector<AmbientModeTopic> topics_;
base::circular_deque<PhotoWithDetails> all_decoded_topics_;
base::OneShotTimer images_ready_timeout_timer_;
bool images_ready_timed_out_ = false;
int failures_ = 0;
base::ObserverList<AmbientBackendModelObserver> observers_;
int buffer_length_for_testing_ = -1;
};
}
#endif