blob: 9f071dbfcd0a066ef22506bb4003a71da89cd39d [file] [log] [blame]
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_CALENDAR_CALENDAR_CONTROLLER_H_
#define ASH_CALENDAR_CALENDAR_CONTROLLER_H_
#include <map>
#include <memory>
#include "ash/ash_export.h"
#include "ash/public/cpp/session/session_observer.h"
#include "components/account_id/account_id.h"
namespace ash {
class CalendarClient;
// Keeps track of all calendar clients per user account and makes
// sure the current active client belongs to the current active user.
// There is expected to exist at most one instance of this class at a time. In
// production the instance is owned by ash::Shell. The instance can be retrieved
// using `Shell::Get()->highlighter_controller()`.
class ASH_EXPORT CalendarController : public SessionObserver {
public:
CalendarController();
CalendarController(const CalendarController& other) = delete;
CalendarController& operator=(const CalendarController& other) = delete;
~CalendarController() override;
// Adds a client to it's corresponding user account id in a map.
void RegisterClientForUser(const AccountId& account_id,
CalendarClient* client);
// Gets the currently active calendar client. Returns `nullptr` if the user
// profile is not registered with the ProfileManager, e.g. before logging in,
// guest user, etc.
CalendarClient* GetClient();
private:
// SessionObserver:
void OnActiveUserSessionChanged(const AccountId& account_id) override;
// The currently active user account id.
AccountId active_user_account_id_;
std::map<const AccountId, CalendarClient*> clients_by_account_id_;
};
} // namespace ash
#endif // ASH_CALENDAR_CALENDAR_CONTROLLER_H_