#ifndef UI_MESSAGE_CENTER_NOTIFICATION_LIST_H_
#define UI_MESSAGE_CENTER_NOTIFICATION_LIST_H_
#include <stddef.h>
#include <list>
#include <map>
#include <set>
#include <string>
#include "base/gtest_prod_util.h"
#include "base/memory/raw_ptr.h"
#include "ui/message_center/message_center_export.h"
#include "ui/message_center/notification_blocker.h"
#include "ui/message_center/public/cpp/notification_types.h"
namespace base {
class TimeDelta;
}
namespace gfx {
class Image;
}
namespace message_center {
namespace test {
class NotificationListTest;
}
class Notification;
class NotificationDelegate;
struct NotifierId;
enum class ExpandState { DEFAULT = 0, USER_EXPANDED = 1, USER_COLLAPSED = 2 };
struct MESSAGE_CENTER_EXPORT ComparePriorityTimestampSerial {
bool operator()(Notification* n1, Notification* n2) const;
};
struct MESSAGE_CENTER_EXPORT CompareTimestampSerial {
bool operator()(Notification* n1, Notification* n2) const;
};
template <typename PlainCompare>
struct UniquePtrCompare {
template <typename T>
bool operator()(const std::unique_ptr<T>& n1,
const std::unique_ptr<T>& n2) const {
return PlainCompare()(n1.get(), n2.get());
}
};
class MESSAGE_CENTER_EXPORT NotificationList {
public:
struct NotificationState {
bool operator!=(const NotificationState& other) const;
bool shown_as_popup = false;
bool is_read = false;
ExpandState expand_state = ExpandState::DEFAULT;
};
using Notifications = std::set<Notification*, ComparePriorityTimestampSerial>;
using OwnedNotifications =
std::map<std::unique_ptr<Notification>,
NotificationState,
UniquePtrCompare<ComparePriorityTimestampSerial>>;
using PopupNotifications = std::set<Notification*, CompareTimestampSerial>;
explicit NotificationList(MessageCenter* message_center);
NotificationList(const NotificationList&) = delete;
NotificationList& operator=(const NotificationList&) = delete;
virtual ~NotificationList();
void SetNotificationsShown(const NotificationBlockers& blockers,
std::set<std::string>* updated_ids);
void AddNotification(std::unique_ptr<Notification> notification);
void UpdateNotificationMessage(
const std::string& old_id,
std::unique_ptr<Notification> new_notification);
void RemoveNotification(const std::string& id);
Notifications GetNotifications() const;
Notifications GetNotificationsByNotifierId(
const NotifierId& notifier_id) const;
Notifications GetNotificationsByAppId(const std::string& app_id) const;
Notifications GetNotificationsByOriginUrl(const GURL& origin_url) const;
bool SetNotificationIcon(const std::string& notification_id,
const ui::ImageModel& image);
bool SetNotificationImage(const std::string& notification_id,
const gfx::Image& image);
bool HasNotificationOfType(const std::string& id,
const NotificationType type) const;
bool HasPopupNotifications(const NotificationBlockers& blockers) const;
PopupNotifications GetPopupNotifications(const NotificationBlockers& blockers,
std::list<std::string>* blocked);
PopupNotifications GetPopupNotificationsWithoutBlocker(
const NotificationBlockers& blockers,
const NotificationBlocker& blocker) const;
void MarkSinglePopupAsShown(const std::string& id,
bool mark_notification_as_read);
void MarkSinglePopupAsDisplayed(const std::string& id);
void ResetSinglePopup(const std::string& id);
ExpandState GetNotificationExpandState(const std::string& id);
void SetNotificationExpandState(const std::string& id,
ExpandState expand_state);
NotificationDelegate* GetNotificationDelegate(const std::string& id);
bool quiet_mode() const { return quiet_mode_; }
void SetQuietMode(bool quiet_mode);
void EnterQuietModeWithExpire(const base::TimeDelta& expires_in);
Notification* GetNotificationById(const std::string& id);
void PopupBlocked(const std::string& id);
Notifications GetVisibleNotifications(
const NotificationBlockers& blockers) const;
Notifications GetVisibleNotificationsWithoutBlocker(
const NotificationBlockers& blockers,
const NotificationBlocker* ignored_blocker) const;
size_t NotificationCount(const NotificationBlockers& blockers) const;
private:
friend class NotificationListTest;
FRIEND_TEST_ALL_PREFIXES(NotificationListTest, TestPushingShownNotification);
OwnedNotifications::iterator GetNotification(const std::string& id);
OwnedNotifications::const_iterator GetNotification(
const std::string& id) const;
void EraseNotification(OwnedNotifications::iterator iter);
void PushNotification(std::unique_ptr<Notification> notification);
raw_ptr<MessageCenter> message_center_;
OwnedNotifications notifications_;
bool quiet_mode_;
};
}
#endif