#ifndef ASH_SYSTEM_TIME_CALENDAR_LIST_MODEL_H_
#define ASH_SYSTEM_TIME_CALENDAR_LIST_MODEL_H_
#include <list>
#include <optional>
#include "ash/ash_export.h"
#include "ash/calendar/calendar_client.h"
#include "ash/public/cpp/session/session_observer.h"
#include "ash/system/time/calendar_event_fetch_types.h"
#include "base/functional/callback.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "google_apis/calendar/calendar_api_response_types.h"
#include "google_apis/common/api_error_codes.h"
namespace ash {
using CalendarList = std::list<google_apis::calendar::SingleCalendar>;
class ASH_EXPORT CalendarListModel : public SessionObserver {
public:
CalendarListModel();
CalendarListModel(const CalendarListModel& other) = delete;
CalendarListModel& operator=(const CalendarListModel& other) = delete;
~CalendarListModel() override;
class Observer : public base::CheckedObserver {
public:
virtual void OnCalendarListFetchComplete() {}
};
void OnSessionStateChanged(session_manager::SessionState state) override;
void OnActiveUserSessionChanged(const AccountId& account_id) override;
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
void FetchCalendars();
void CancelFetch();
bool get_is_cached() { return is_cached_; }
bool get_fetch_in_progress() { return fetch_in_progress_; }
bool list_cached_and_no_fetch_in_progress() {
return (is_cached_ && !fetch_in_progress_);
}
CalendarList GetCachedCalendarList();
private:
friend class CalendarUpNextViewPixelTest;
friend class CalendarViewWithUpNextViewAnimationTest;
friend class CalendarViewWithUpNextViewTest;
friend class PostLoginGlanceablesMetricsRecorderTest;
void OnCalendarListFetched(
google_apis::ApiErrorCode error,
std::unique_ptr<google_apis::calendar::CalendarList> calendars);
void OnCalendarListFetchTimeout();
void ClearCachedCalendarList();
void ClearCacheAndCancelFetch();
CalendarList calendar_list_;
bool fetch_in_progress_ = false;
bool is_cached_ = false;
base::TimeTicks fetch_start_time_;
base::OneShotTimer timeout_;
base::OnceClosure cancel_closure_;
ScopedSessionObserver session_observer_;
base::ObserverList<Observer> observers_;
base::WeakPtrFactory<CalendarListModel> weak_factory_{this};
};
}
#endif