#ifndef CHROME_BROWSER_ANDROID_OOM_INTERVENTION_OOM_INTERVENTION_DECIDER_H_
#define CHROME_BROWSER_ANDROID_OOM_INTERVENTION_OOM_INTERVENTION_DECIDER_H_
#include "base/gtest_prod_util.h"
#include "base/memory/raw_ptr.h"
#include "base/supports_user_data.h"
namespace content {
class BrowserContext;
}
namespace user_prefs {
class PrefRegistrySyncable;
}
class OomInterventionDeciderTest;
class PrefService;
class OomInterventionDecider : public base::SupportsUserData::Data {
public:
class Delegate {
public:
virtual ~Delegate() = default;
virtual bool WasLastShutdownClean() = 0;
};
static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
static OomInterventionDecider* GetForBrowserContext(
content::BrowserContext* context);
OomInterventionDecider(const OomInterventionDecider&) = delete;
OomInterventionDecider& operator=(const OomInterventionDecider&) = delete;
~OomInterventionDecider() override;
bool CanTriggerIntervention(const std::string& host) const;
void OnInterventionDeclined(const std::string& host);
void OnOomDetected(const std::string& host);
void ClearData();
private:
OomInterventionDecider(std::unique_ptr<Delegate> delegate,
PrefService* prefs);
friend class OomInterventionDeciderTest;
FRIEND_TEST_ALL_PREFIXES(OomInterventionDeciderTest, OptOutSingleHost);
FRIEND_TEST_ALL_PREFIXES(OomInterventionDeciderTest, ParmanentlyOptOut);
FRIEND_TEST_ALL_PREFIXES(OomInterventionDeciderTest, WasLastShutdownClean);
static const size_t kMaxListSize;
static const size_t kMaxBlocklistSize;
void OnPrefInitialized(bool success);
bool IsOptedOut(const std::string& host) const;
bool IsInList(const char* list_name, const std::string& host) const;
void AddToList(const char* list_name, const std::string& host);
std::unique_ptr<Delegate> delegate_;
raw_ptr<PrefService> prefs_;
};
#endif