chromium/ui/message_center/notification_list.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/message_center/notification_list.h"

#include <string>
#include <utility>

#include "base/check.h"
#include "base/containers/adapters.h"
#include "base/functional/bind.h"
#include "base/not_fatal_until.h"
#include "base/time/time.h"
#include "base/values.h"
#include "build/chromeos_buildflags.h"
#include "ui/gfx/image/image.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/notification_blocker.h"
#include "ui/message_center/public/cpp/message_center_constants.h"
#include "ui/message_center/public/cpp/notification.h"
#include "ui/message_center/public/cpp/notification_types.h"

#if BUILDFLAG(IS_CHROMEOS_ASH)
#include <vector>

#include "ash/constants/ash_features.h"
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

namespace message_center {

namespace {

// Constants -------------------------------------------------------------------

#if BUILDFLAG(IS_CHROMEOS_ASH)

// A notification created within this time period is exempted from over-limit
// removal. NOTE: Used only if the notification limit feature is enabled.
constexpr base::TimeDelta kRemovalExemptionPeriod = base::Seconds(1);

#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

// Helpers ---------------------------------------------------------------------

bool ShouldShowNotificationAsPopup(const Notification& notification,
                                   const NotificationBlockers& blockers,
                                   const NotificationBlocker* except) {}

}  // namespace

bool ComparePriorityTimestampSerial::operator()(Notification* n1,
                                                Notification* n2) const {}

bool CompareTimestampSerial::operator()(Notification* n1,
                                        Notification* n2) const {}

bool NotificationList::NotificationState::operator!=(
    const NotificationState& other) const {}

NotificationList::NotificationList(MessageCenter* message_center)
    :{}

NotificationList::~NotificationList() = default;

#if BUILDFLAG(IS_CHROMEOS_ASH)
std::vector<std::string> NotificationList::GetTopKRemovableNotificationIds(
    size_t count) const {
  CHECK(ash::features::IsNotificationLimitEnabled());

  std::vector<std::string> found_ids;
  const base::Time current_time = base::Time::NowFromSystemTime();
  for (const auto& state_by_notification : base::Reversed(notifications_)) {
    const Notification& notification = *state_by_notification.first;

    // Skip the following notifications:
    // 1. Parent notifications with grouped children because this kind
    //    of notification is a container of child notifications.
    // 2. Pinned notifications.
    // 3. Notifications created within a defined time threshold.
    if (notification.pinned() || notification.group_parent() ||
        current_time - notification.timestamp() <= kRemovalExemptionPeriod) {
      continue;
    }

    found_ids.push_back(notification.id());
    if (found_ids.size() == count) {
      break;
    }
  }

  return found_ids;
}
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

void NotificationList::SetNotificationsShown(
    const NotificationBlockers& blockers,
    std::set<std::string>* updated_ids) {}

void NotificationList::AddNotification(
    std::unique_ptr<Notification> notification) {}

void NotificationList::UpdateNotificationMessage(
    const std::string& old_id,
    std::unique_ptr<Notification> new_notification) {}

void NotificationList::RemoveNotification(const std::string& id) {}

NotificationList::Notifications NotificationList::GetNotifications() const {}

NotificationList::Notifications NotificationList::GetNotificationsByNotifierId(
    const NotifierId& notifier_id) const {}

NotificationList::Notifications NotificationList::GetNotificationsByAppId(
    const std::string& app_id) const {}

NotificationList::Notifications NotificationList::GetNotificationsByOriginUrl(
    const GURL& source_url) const {}

bool NotificationList::SetNotificationIcon(const std::string& notification_id,
                                           const ui::ImageModel& image) {}

bool NotificationList::SetNotificationImage(const std::string& notification_id,
                                            const gfx::Image& image) {}

bool NotificationList::HasNotificationOfType(
    const std::string& id,
    const NotificationType type) const {}

bool NotificationList::HasPopupNotifications(
    const NotificationBlockers& blockers) const {}

NotificationList::PopupNotifications NotificationList::GetPopupNotifications(
    const NotificationBlockers& blockers,
    std::list<std::string>* blocked) {}

NotificationList::PopupNotifications
NotificationList::GetPopupNotificationsWithoutBlocker(
    const NotificationBlockers& blockers,
    const NotificationBlocker& blocker) const {}

void NotificationList::MarkSinglePopupAsShown(const std::string& id,
                                              bool mark_notification_as_read) {}

void NotificationList::MarkSinglePopupAsDisplayed(const std::string& id) {}

void NotificationList::ResetSinglePopup(const std::string& id) {}

ExpandState NotificationList::GetNotificationExpandState(
    const std::string& id) {}

void NotificationList::SetNotificationExpandState(
    const std::string& id,
    const ExpandState expand_state) {}

NotificationDelegate* NotificationList::GetNotificationDelegate(
    const std::string& id) {}

void NotificationList::SetQuietMode(bool quiet_mode) {}

Notification* NotificationList::GetNotificationById(const std::string& id) {}

NotificationList::Notifications NotificationList::GetVisibleNotifications(
    const NotificationBlockers& blockers) const {}

NotificationList::Notifications
NotificationList::GetVisibleNotificationsWithoutBlocker(
    const NotificationBlockers& blockers,
    const NotificationBlocker* ignored_blocker) const {}

size_t NotificationList::NotificationCount(
    const NotificationBlockers& blockers) const {}

NotificationList::OwnedNotifications::iterator
NotificationList::GetNotification(const std::string& id) {}

NotificationList::OwnedNotifications::const_iterator
NotificationList::GetNotification(const std::string& id) const {}

void NotificationList::EraseNotification(OwnedNotifications::iterator iter) {}

void NotificationList::PushNotification(
    std::unique_ptr<Notification> notification) {}

}  // namespace message_center