#ifndef CHROME_BROWSER_UI_SAFETY_HUB_MENU_NOTIFICATION_SERVICE_H_
#define CHROME_BROWSER_UI_SAFETY_HUB_MENU_NOTIFICATION_SERVICE_H_
#include <list>
#include <map>
#include <memory>
#include <optional>
#include "base/memory/raw_ptr.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/browser/ui/safety_hub/menu_notification.h"
#include "chrome/browser/ui/safety_hub/notification_permission_review_service.h"
#include "chrome/browser/ui/safety_hub/revoked_permissions_service.h"
#include "chrome/browser/ui/safety_hub/safety_hub_constants.h"
#include "chrome/browser/ui/safety_hub/safety_hub_result.h"
#include "components/keyed_service/core/keyed_service.h"
#if !BUILDFLAG(IS_ANDROID)
#include "chrome/browser/extensions/cws_info_service.h"
#include "chrome/browser/ui/safety_hub/password_status_check_service.h"
#endif
struct MenuNotificationEntry {
int command = 0;
std::u16string label;
safety_hub::SafetyHubModuleType module;
};
namespace {
enum MenuNotificationPriority {
LOW = 0,
MEDIUM,
HIGH,
};
struct SafetyHubModuleInfoElement {
SafetyHubModuleInfoElement();
~SafetyHubModuleInfoElement();
SafetyHubModuleInfoElement(
MenuNotificationPriority priority,
base::TimeDelta interval,
base::RepeatingCallback<std::optional<std::unique_ptr<SafetyHubResult>>()>
result_getter,
std::unique_ptr<SafetyHubMenuNotification> notification);
MenuNotificationPriority priority;
base::TimeDelta interval;
base::RepeatingCallback<std::optional<std::unique_ptr<SafetyHubResult>>()>
result_getter;
std::unique_ptr<SafetyHubMenuNotification> notification;
};
using ResultMap =
std::map<safety_hub::SafetyHubModuleType, std::unique_ptr<SafetyHubResult>>;
}
class SafetyHubMenuNotificationService : public KeyedService {
public:
explicit SafetyHubMenuNotificationService(
PrefService* pref_service,
RevokedPermissionsService* revoked_permissions_service,
NotificationPermissionsReviewService* notification_permissions_service,
#if !BUILDFLAG(IS_ANDROID)
PasswordStatusCheckService* password_check_service,
#endif
Profile* profile);
SafetyHubMenuNotificationService(const SafetyHubMenuNotificationService&) =
delete;
SafetyHubMenuNotificationService& operator=(
const SafetyHubMenuNotificationService&) = delete;
~SafetyHubMenuNotificationService() override;
std::optional<MenuNotificationEntry> GetNotificationToShow();
void DismissActiveNotification();
void DismissActiveNotificationOfModule(
safety_hub::SafetyHubModuleType module);
void UpdateResultGetterForTesting(
safety_hub::SafetyHubModuleType type,
base::RepeatingCallback<std::optional<std::unique_ptr<SafetyHubResult>>()>
result_getter);
private:
std::optional<ResultMap> GetResultsFromAllModules();
void SaveNotificationsToPrefs() const;
std::unique_ptr<SafetyHubMenuNotification> GetNotificationFromDict(
const base::Value::Dict& dict,
safety_hub::SafetyHubModuleType& type) const;
void SetInfoElement(
safety_hub::SafetyHubModuleType type,
MenuNotificationPriority priority,
base::TimeDelta interval,
base::RepeatingCallback<std::optional<std::unique_ptr<SafetyHubResult>>()>
result_getter,
const base::Value::Dict& stored_notifications);
void OnSafeBrowsingPrefUpdate();
bool HasAnyNotificationBeenShown() const;
std::map<safety_hub::SafetyHubModuleType, const char*> pref_dict_key_map_;
raw_ptr<PrefService> pref_service_;
std::map<safety_hub::SafetyHubModuleType,
std::unique_ptr<SafetyHubModuleInfoElement>>
module_info_map_;
PrefChangeRegistrar registrar_;
};
#endif