#ifndef BASE_ANDROID_BACKGROUND_THREAD_POOL_FIELD_TRIAL_H_
#define BASE_ANDROID_BACKGROUND_THREAD_POOL_FIELD_TRIAL_H_
#include <optional>
#include <string_view>
#include "base/auto_reset.h"
#include "base/base_export.h"
#include "base/synchronization/synchronization_buildflags.h"
namespace base::android {
class BASE_EXPORT BackgroundThreadPoolFieldTrial {
public:
static void Initialize();
static bool ShouldUsePriorityInheritanceLocks();
static bool ShouldUseBackgroundThreadPool();
struct BASE_EXPORT TrialInfo {
std::string trial_name;
std::string group_name;
};
static std::optional<TrialInfo> GetTrialInfo();
protected:
enum class Configuration : int {
kDisabled = 0,
kPISupportedTrialControl = 1,
kPISupportedTrialEnabledPILocksOnly = 2,
kPISupportedTrialEnabledBGThreadPoolOnly = 3,
kPISupportedTrialEnabledBoth = 4,
kGeneralTrialControl = 5,
kGeneralTrialEnabledBGThreadPool = 6,
kConfigurationMax = kGeneralTrialEnabledBGThreadPool,
};
friend class ScopedUsePriorityInheritanceLocksForTesting;
static std::optional<Configuration> s_configuration_;
private:
static Configuration ReadConfigurationFromCommandLine();
static Configuration GetConfiguration();
static TrialInfo GetGeneralTrialInfo();
#if BUILDFLAG(ENABLE_MUTEX_PRIORITY_INHERITANCE)
static TrialInfo GetPISupportedTrialInfo();
#endif
};
#if BUILDFLAG(ENABLE_MUTEX_PRIORITY_INHERITANCE)
class BASE_EXPORT ScopedUsePriorityInheritanceLocksForTesting {
public:
ScopedUsePriorityInheritanceLocksForTesting();
~ScopedUsePriorityInheritanceLocksForTesting();
private:
base::AutoReset<std::optional<BackgroundThreadPoolFieldTrial::Configuration>>
reset_config_value_;
};
#endif
}
#endif