#include "extensions/browser/api/alarms/alarm_manager.h"
#include <stddef.h>
#include <algorithm>
#include <memory>
#include <utility>
#include <vector>
#include "base/functional/bind.h"
#include "base/json/json_writer.h"
#include "base/json/values_util.h"
#include "base/lazy_instance.h"
#include "base/memory/raw_ptr.h"
#include "base/numerics/safe_conversions.h"
#include "base/time/clock.h"
#include "base/time/default_clock.h"
#include "base/time/time.h"
#include "base/values.h"
#include "extensions/browser/api/alarms/alarms_api_constants.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_registry_factory.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/state_store.h"
#include "extensions/common/api/alarms.h"
#include "extensions/common/extension_id.h"
namespace extensions {
alarms;
namespace {
const char kRegisteredAlarms[] = …;
const char kAlarmGranularity[] = …;
const base::TimeDelta kDefaultMinPollPeriod() { … }
class DefaultAlarmDelegate : public AlarmManager::Delegate { … };
base::TimeDelta TimeDeltaFromDelay(double delay_in_minutes) { … }
AlarmManager::AlarmList AlarmsFromValue(const ExtensionId extension_id,
base::TimeDelta min_delay,
const base::Value::List& list) { … }
base::Value::List AlarmsToValue(const AlarmManager::AlarmList& alarms) { … }
}
AlarmManager::AlarmManager(content::BrowserContext* context)
: … { … }
AlarmManager::~AlarmManager() = default;
int AlarmManager::GetCountForExtension(const ExtensionId& extension_id) const { … }
void AlarmManager::AddAlarm(const ExtensionId& extension_id,
Alarm alarm,
AddAlarmCallback callback) { … }
void AlarmManager::GetAlarm(const ExtensionId& extension_id,
const std::string& name,
GetAlarmCallback callback) { … }
void AlarmManager::GetAllAlarms(const ExtensionId& extension_id,
GetAllAlarmsCallback callback) { … }
void AlarmManager::RemoveAlarm(const ExtensionId& extension_id,
const std::string& name,
RemoveAlarmCallback callback) { … }
void AlarmManager::RemoveAllAlarms(const ExtensionId& extension_id,
RemoveAllAlarmsCallback callback) { … }
void AlarmManager::AddAlarmWhenReady(Alarm alarm,
AddAlarmCallback callback,
const ExtensionId& extension_id) { … }
void AlarmManager::GetAlarmWhenReady(const std::string& name,
GetAlarmCallback callback,
const ExtensionId& extension_id) { … }
void AlarmManager::GetAllAlarmsWhenReady(GetAllAlarmsCallback callback,
const ExtensionId& extension_id) { … }
void AlarmManager::RemoveAlarmWhenReady(const std::string& name,
RemoveAlarmCallback callback,
const ExtensionId& extension_id) { … }
void AlarmManager::RemoveAllAlarmsWhenReady(RemoveAllAlarmsCallback callback,
const ExtensionId& extension_id) { … }
AlarmManager::AlarmIterator AlarmManager::GetAlarmIterator(
const ExtensionId& extension_id,
const std::string& name) { … }
void AlarmManager::SetClockForTesting(base::Clock* clock) { … }
static base::LazyInstance<
BrowserContextKeyedAPIFactory<AlarmManager>>::DestructorAtExit g_factory = …;
template <>
void BrowserContextKeyedAPIFactory<AlarmManager>::DeclareFactoryDependencies() { … }
BrowserContextKeyedAPIFactory<AlarmManager>*
AlarmManager::GetFactoryInstance() { … }
AlarmManager* AlarmManager::Get(content::BrowserContext* browser_context) { … }
void AlarmManager::RemoveAlarmIterator(const AlarmIterator& iter) { … }
void AlarmManager::OnAlarm(AlarmIterator it) { … }
void AlarmManager::AddAlarmImpl(const ExtensionId& extension_id, Alarm alarm) { … }
void AlarmManager::WriteToStorage(const ExtensionId& extension_id) { … }
void AlarmManager::ReadFromStorage(const ExtensionId& extension_id,
base::TimeDelta min_delay,
std::optional<base::Value> value) { … }
void AlarmManager::SetNextPollTime(const base::Time& time) { … }
void AlarmManager::ScheduleNextPoll() { … }
void AlarmManager::PollAlarms() { … }
static void RemoveAllOnUninstallCallback() { … }
void AlarmManager::RunWhenReady(const ExtensionId& extension_id,
ReadyAction action) { … }
void AlarmManager::OnExtensionLoaded(content::BrowserContext* browser_context,
const Extension* extension) { … }
void AlarmManager::OnExtensionUninstalled(
content::BrowserContext* browser_context,
const Extension* extension,
extensions::UninstallReason reason) { … }
Alarm::Alarm() : … { … }
Alarm::Alarm(const std::string& name,
const alarms::AlarmCreateInfo& create_info,
base::TimeDelta min_granularity,
base::Time now)
: … { … }
Alarm::~Alarm() = default;
Alarm::Alarm(Alarm&&) noexcept = default;
Alarm& Alarm::operator=(Alarm&&) noexcept = default;
}