#ifndef CONTENT_BROWSER_MEMORY_PRESSURE_USER_LEVEL_MEMORY_PRESSURE_SIGNAL_GENERATOR_H_
#define CONTENT_BROWSER_MEMORY_PRESSURE_USER_LEVEL_MEMORY_PRESSURE_SIGNAL_GENERATOR_H_
#include "build/build_config.h"
#if BUILDFLAG(IS_ANDROID)
#include <optional>
#include <utility>
#include "base/no_destructor.h"
#include "base/timer/timer.h"
namespace base {
class Process;
class TimeDelta;
}
namespace memory_pressure {
class UserLevelMemoryPressureSignalGenerator {
public:
static void Initialize();
private:
friend class base::NoDestructor<UserLevelMemoryPressureSignalGenerator>;
static UserLevelMemoryPressureSignalGenerator& Get();
UserLevelMemoryPressureSignalGenerator();
~UserLevelMemoryPressureSignalGenerator();
void Start(uint64_t memory_threshold,
base::TimeDelta measure_interval,
base::TimeDelta minimum_interval);
void OnTimerFired();
void OnReportingTimerFired();
void StartPeriodicTimer(base::TimeDelta interval);
void StartReportingTimer();
static std::pair<uint64_t, uint64_t>
GetTotalPrivateFootprintVisibleOrHigherPriorityRenderers();
static void NotifyMemoryPressure();
static void ReportBeforeAfterMetrics(
uint64_t total_pmf_visible_or_higher_priority_renderers,
uint64_t total_pmf,
const char* suffix_name);
static std::optional<uint64_t> GetPrivateFootprint(
const base::Process& process);
uint64_t memory_threshold_;
base::TimeDelta measure_interval_;
base::TimeDelta minimum_interval_;
base::OneShotTimer periodic_measuring_timer_;
base::OneShotTimer delayed_report_timer_;
};
}
#endif
#endif