Commit b5ad87f4 authored by Miyoung Shin's avatar Miyoung Shin Committed by Commit Bot

Use the type alias of base::FieldTrialParams in blink

This CL moves the type alias of FieldTrialParams from
field_trial_param_associator.h to field_trial_params.h and use
base::FieldTrialParams in blink.

Bug: 952716
Change-Id: Ia6587a4799a43591ef19cd88cc0c7292bc22c7f8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1605282Reviewed-by: default avatarLuke Halliwell <halliwell@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Commit-Queue: Miyoung Shin(OOO till May 17) <myid.shin@igalia.com>
Cr-Commit-Position: refs/heads/master@{#659185}
parent dc72ec91
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/base_export.h" #include "base/base_export.h"
#include "base/memory/singleton.h" #include "base/memory/singleton.h"
#include "base/metrics/field_trial.h" #include "base/metrics/field_trial.h"
#include "base/metrics/field_trial_params.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
namespace base { namespace base {
...@@ -23,9 +24,6 @@ class BASE_EXPORT FieldTrialParamAssociator { ...@@ -23,9 +24,6 @@ class BASE_EXPORT FieldTrialParamAssociator {
FieldTrialParamAssociator(); FieldTrialParamAssociator();
~FieldTrialParamAssociator(); ~FieldTrialParamAssociator();
// Key-value mapping type for field trial parameters.
typedef std::map<std::string, std::string> FieldTrialParams;
// Retrieve the singleton. // Retrieve the singleton.
static FieldTrialParamAssociator* GetInstance(); static FieldTrialParamAssociator* GetInstance();
......
...@@ -11,22 +11,21 @@ ...@@ -11,22 +11,21 @@
namespace base { namespace base {
bool AssociateFieldTrialParams( bool AssociateFieldTrialParams(const std::string& trial_name,
const std::string& trial_name,
const std::string& group_name, const std::string& group_name,
const std::map<std::string, std::string>& params) { const FieldTrialParams& params) {
return base::FieldTrialParamAssociator::GetInstance() return base::FieldTrialParamAssociator::GetInstance()
->AssociateFieldTrialParams(trial_name, group_name, params); ->AssociateFieldTrialParams(trial_name, group_name, params);
} }
bool GetFieldTrialParams(const std::string& trial_name, bool GetFieldTrialParams(const std::string& trial_name,
std::map<std::string, std::string>* params) { FieldTrialParams* params) {
return base::FieldTrialParamAssociator::GetInstance()->GetFieldTrialParams( return base::FieldTrialParamAssociator::GetInstance()->GetFieldTrialParams(
trial_name, params); trial_name, params);
} }
bool GetFieldTrialParamsByFeature(const base::Feature& feature, bool GetFieldTrialParamsByFeature(const base::Feature& feature,
std::map<std::string, std::string>* params) { FieldTrialParams* params) {
if (!base::FeatureList::IsEnabled(feature)) if (!base::FeatureList::IsEnabled(feature))
return false; return false;
...@@ -39,7 +38,7 @@ bool GetFieldTrialParamsByFeature(const base::Feature& feature, ...@@ -39,7 +38,7 @@ bool GetFieldTrialParamsByFeature(const base::Feature& feature,
std::string GetFieldTrialParamValue(const std::string& trial_name, std::string GetFieldTrialParamValue(const std::string& trial_name,
const std::string& param_name) { const std::string& param_name) {
std::map<std::string, std::string> params; FieldTrialParams params;
if (GetFieldTrialParams(trial_name, &params)) { if (GetFieldTrialParams(trial_name, &params)) {
auto it = params.find(param_name); auto it = params.find(param_name);
if (it != params.end()) if (it != params.end())
......
...@@ -14,14 +14,16 @@ namespace base { ...@@ -14,14 +14,16 @@ namespace base {
struct Feature; struct Feature;
// Key-value mapping type for field trial parameters.
typedef std::map<std::string, std::string> FieldTrialParams;
// Associates the specified set of key-value |params| with the field trial // Associates the specified set of key-value |params| with the field trial
// specified by |trial_name| and |group_name|. Fails and returns false if the // specified by |trial_name| and |group_name|. Fails and returns false if the
// specified field trial already has params associated with it or the trial // specified field trial already has params associated with it or the trial
// is already active (group() has been called on it). Thread safe. // is already active (group() has been called on it). Thread safe.
BASE_EXPORT bool AssociateFieldTrialParams( BASE_EXPORT bool AssociateFieldTrialParams(const std::string& trial_name,
const std::string& trial_name,
const std::string& group_name, const std::string& group_name,
const std::map<std::string, std::string>& params); const FieldTrialParams& params);
// Retrieves the set of key-value |params| for the specified field trial, based // Retrieves the set of key-value |params| for the specified field trial, based
// on its selected group. If the field trial does not exist or its selected // on its selected group. If the field trial does not exist or its selected
...@@ -29,9 +31,8 @@ BASE_EXPORT bool AssociateFieldTrialParams( ...@@ -29,9 +31,8 @@ BASE_EXPORT bool AssociateFieldTrialParams(
// does not modify |params|. Calling this function will result in the field // does not modify |params|. Calling this function will result in the field
// trial being marked as active if found (i.e. group() will be called on it), // trial being marked as active if found (i.e. group() will be called on it),
// if it wasn't already. Thread safe. // if it wasn't already. Thread safe.
BASE_EXPORT bool GetFieldTrialParams( BASE_EXPORT bool GetFieldTrialParams(const std::string& trial_name,
const std::string& trial_name, FieldTrialParams* params);
std::map<std::string, std::string>* params);
// Retrieves the set of key-value |params| for the field trial associated with // Retrieves the set of key-value |params| for the field trial associated with
// the specified |feature|. A feature is associated with at most one field // the specified |feature|. A feature is associated with at most one field
...@@ -40,9 +41,8 @@ BASE_EXPORT bool GetFieldTrialParams( ...@@ -40,9 +41,8 @@ BASE_EXPORT bool GetFieldTrialParams(
// returns false and does not modify |params|. Calling this function will // returns false and does not modify |params|. Calling this function will
// result in the associated field trial being marked as active if found (i.e. // result in the associated field trial being marked as active if found (i.e.
// group() will be called on it), if it wasn't already. Thread safe. // group() will be called on it), if it wasn't already. Thread safe.
BASE_EXPORT bool GetFieldTrialParamsByFeature( BASE_EXPORT bool GetFieldTrialParamsByFeature(const base::Feature& feature,
const base::Feature& feature, FieldTrialParams* params);
std::map<std::string, std::string>* params);
// Retrieves a specific parameter value corresponding to |param_name| for the // Retrieves a specific parameter value corresponding to |param_name| for the
// specified field trial, based on its selected group. If the field trial does // specified field trial, based on its selected group. If the field trial does
......
...@@ -251,7 +251,7 @@ void InitializeFeatureList(const base::DictionaryValue& dcs_features, ...@@ -251,7 +251,7 @@ void InitializeFeatureList(const base::DictionaryValue& dcs_features,
feature_name, base::FeatureList::OVERRIDE_DISABLE_FEATURE)) { feature_name, base::FeatureList::OVERRIDE_DISABLE_FEATURE)) {
// Build a map of the FieldTrial parameters and associate it to the // Build a map of the FieldTrial parameters and associate it to the
// FieldTrial. // FieldTrial.
base::FieldTrialParamAssociator::FieldTrialParams params; base::FieldTrialParams params;
for (Iterator p(*params_dict); !p.IsAtEnd(); p.Advance()) { for (Iterator p(*params_dict); !p.IsAtEnd(); p.Advance()) {
std::string val; std::string val;
if (p.value().GetAsString(&val)) { if (p.value().GetAsString(&val)) {
......
...@@ -80,7 +80,7 @@ base::HistogramBase::Sample ToSample(ReportCircumstance circumstance) { ...@@ -80,7 +80,7 @@ base::HistogramBase::Sample ToSample(ReportCircumstance circumstance) {
uint32_t GetFieldTrialUint32Param(const char* trial_name, uint32_t GetFieldTrialUint32Param(const char* trial_name,
const char* parameter_name, const char* parameter_name,
uint32_t default_param) { uint32_t default_param) {
std::map<std::string, std::string> trial_params; base::FieldTrialParams trial_params;
bool result = base::GetFieldTrialParams(trial_name, &trial_params); bool result = base::GetFieldTrialParams(trial_name, &trial_params);
if (!result) if (!result)
return default_param; return default_param;
......
...@@ -1532,9 +1532,9 @@ class ResourceFetchPriorityExperimentTest : public FrameSchedulerImplTest { ...@@ -1532,9 +1532,9 @@ class ResourceFetchPriorityExperimentTest : public FrameSchedulerImplTest {
public: public:
ResourceFetchPriorityExperimentTest() ResourceFetchPriorityExperimentTest()
: FrameSchedulerImplTest({kUseResourceFetchPriority}, {}) { : FrameSchedulerImplTest({kUseResourceFetchPriority}, {}) {
std::map<std::string, std::string> params{ base::FieldTrialParams params{{"HIGHEST", "HIGH"}, {"MEDIUM", "NORMAL"},
{"HIGHEST", "HIGH"}, {"MEDIUM", "NORMAL"}, {"LOW", "NORMAL"}, {"LOW", "NORMAL"}, {"LOWEST", "LOW"},
{"LOWEST", "LOW"}, {"IDLE", "LOW"}, {"THROTTLED", "LOW"}}; {"IDLE", "LOW"}, {"THROTTLED", "LOW"}};
const char kStudyName[] = "ResourceFetchPriorityExperiment"; const char kStudyName[] = "ResourceFetchPriorityExperiment";
const char kGroupName[] = "GroupName1"; const char kGroupName[] = "GroupName1";
...@@ -1567,9 +1567,9 @@ class ResourceFetchPriorityExperimentOnlyWhenLoadingTest ...@@ -1567,9 +1567,9 @@ class ResourceFetchPriorityExperimentOnlyWhenLoadingTest
public: public:
ResourceFetchPriorityExperimentOnlyWhenLoadingTest() ResourceFetchPriorityExperimentOnlyWhenLoadingTest()
: FrameSchedulerImplTest({kUseResourceFetchPriorityOnlyWhenLoading}, {}) { : FrameSchedulerImplTest({kUseResourceFetchPriorityOnlyWhenLoading}, {}) {
std::map<std::string, std::string> params{ base::FieldTrialParams params{{"HIGHEST", "HIGH"}, {"MEDIUM", "NORMAL"},
{"HIGHEST", "HIGH"}, {"MEDIUM", "NORMAL"}, {"LOW", "NORMAL"}, {"LOW", "NORMAL"}, {"LOWEST", "LOW"},
{"LOWEST", "LOW"}, {"IDLE", "LOW"}, {"THROTTLED", "LOW"}}; {"IDLE", "LOW"}, {"THROTTLED", "LOW"}};
const char kStudyName[] = "ResourceFetchPriorityExperiment"; const char kStudyName[] = "ResourceFetchPriorityExperiment";
const char kGroupName[] = "GroupName2"; const char kGroupName[] = "GroupName2";
...@@ -1746,8 +1746,7 @@ TEST_F(FrameSchedulerImplTest, TaskTypeToTaskQueueMapping) { ...@@ -1746,8 +1746,7 @@ TEST_F(FrameSchedulerImplTest, TaskTypeToTaskQueueMapping) {
class ThrottleAndFreezeTaskTypesExperimentTest : public FrameSchedulerImplTest { class ThrottleAndFreezeTaskTypesExperimentTest : public FrameSchedulerImplTest {
public: public:
ThrottleAndFreezeTaskTypesExperimentTest( ThrottleAndFreezeTaskTypesExperimentTest(const base::FieldTrialParams& params,
std::map<std::string, std::string> params,
const char* group_name) { const char* group_name) {
const char kStudyName[] = "ThrottleAndFreezeTaskTypes"; const char kStudyName[] = "ThrottleAndFreezeTaskTypes";
...@@ -1772,7 +1771,7 @@ class ThrottleableAndFreezableTaskTypesTest ...@@ -1772,7 +1771,7 @@ class ThrottleableAndFreezableTaskTypesTest
public: public:
ThrottleableAndFreezableTaskTypesTest() ThrottleableAndFreezableTaskTypesTest()
: ThrottleAndFreezeTaskTypesExperimentTest( : ThrottleAndFreezeTaskTypesExperimentTest(
std::map<std::string, std::string>{ base::FieldTrialParams{
// Leading spaces are allowed. // Leading spaces are allowed.
{kThrottleableTaskTypesListParam, "PostedMessage"}, {kThrottleableTaskTypesListParam, "PostedMessage"},
{kFreezableTaskTypesListParam, {kFreezableTaskTypesListParam,
...@@ -1826,7 +1825,7 @@ class FreezableOnlyTaskTypesTest ...@@ -1826,7 +1825,7 @@ class FreezableOnlyTaskTypesTest
public: public:
FreezableOnlyTaskTypesTest() FreezableOnlyTaskTypesTest()
: ThrottleAndFreezeTaskTypesExperimentTest( : ThrottleAndFreezeTaskTypesExperimentTest(
std::map<std::string, std::string>{ base::FieldTrialParams{
{kThrottleableTaskTypesListParam, ""}, {kThrottleableTaskTypesListParam, ""},
{kFreezableTaskTypesListParam, {kFreezableTaskTypesListParam,
"PostedMessage,MediaElementEvent,DOMManipulation"}}, "PostedMessage,MediaElementEvent,DOMManipulation"}},
...@@ -1880,7 +1879,7 @@ class ThrottleableOnlyTaskTypesTest ...@@ -1880,7 +1879,7 @@ class ThrottleableOnlyTaskTypesTest
public: public:
ThrottleableOnlyTaskTypesTest() ThrottleableOnlyTaskTypesTest()
: ThrottleAndFreezeTaskTypesExperimentTest( : ThrottleAndFreezeTaskTypesExperimentTest(
std::map<std::string, std::string>{ base::FieldTrialParams{
{kFreezableTaskTypesListParam, ""}, {kFreezableTaskTypesListParam, ""},
{kThrottleableTaskTypesListParam, "PostedMessage"}}, {kThrottleableTaskTypesListParam, "PostedMessage"}},
"Group3") {} "Group3") {}
......
...@@ -565,7 +565,7 @@ MainThreadSchedulerImpl::SchedulingSettings::SchedulingSettings() { ...@@ -565,7 +565,7 @@ MainThreadSchedulerImpl::SchedulingSettings::SchedulingSettings() {
if (use_resource_fetch_priority || if (use_resource_fetch_priority ||
use_resource_priorities_only_during_loading) { use_resource_priorities_only_during_loading) {
std::map<std::string, std::string> params; base::FieldTrialParams params;
base::GetFieldTrialParams(kResourceFetchPriorityExperiment, &params); base::GetFieldTrialParams(kResourceFetchPriorityExperiment, &params);
for (size_t net_priority = 0; for (size_t net_priority = 0;
net_priority < net::RequestPrioritySize::NUM_PRIORITIES; net_priority < net::RequestPrioritySize::NUM_PRIORITIES;
......
...@@ -68,8 +68,7 @@ struct BackgroundThrottlingSettings { ...@@ -68,8 +68,7 @@ struct BackgroundThrottlingSettings {
base::Optional<base::TimeDelta> initial_budget; base::Optional<base::TimeDelta> initial_budget;
}; };
double GetDoubleParameterFromMap( double GetDoubleParameterFromMap(const base::FieldTrialParams& settings,
const std::map<std::string, std::string>& settings,
const std::string& setting_name, const std::string& setting_name,
double default_value) { double default_value) {
const auto& find_it = settings.find(setting_name); const auto& find_it = settings.find(setting_name);
...@@ -90,7 +89,7 @@ base::Optional<base::TimeDelta> DoubleToOptionalTime(double value) { ...@@ -90,7 +89,7 @@ base::Optional<base::TimeDelta> DoubleToOptionalTime(double value) {
} }
BackgroundThrottlingSettings GetBackgroundThrottlingSettings() { BackgroundThrottlingSettings GetBackgroundThrottlingSettings() {
std::map<std::string, std::string> background_throttling_settings; base::FieldTrialParams background_throttling_settings;
base::GetFieldTrialParams("ExpensiveBackgroundTimerThrottling", base::GetFieldTrialParams("ExpensiveBackgroundTimerThrottling",
&background_throttling_settings); &background_throttling_settings);
......
...@@ -1075,7 +1075,7 @@ void ExpensiveTestTask(scoped_refptr<base::TestMockTimeTaskRunner> task_runner, ...@@ -1075,7 +1075,7 @@ void ExpensiveTestTask(scoped_refptr<base::TestMockTimeTaskRunner> task_runner,
} }
void InitializeTrialParams() { void InitializeTrialParams() {
std::map<std::string, std::string> params = {{"cpu_budget", "0.01"}, base::FieldTrialParams params = {{"cpu_budget", "0.01"},
{"max_budget", "0.0"}, {"max_budget", "0.0"},
{"initial_budget", "0.0"}, {"initial_budget", "0.0"},
{"max_delay", "0.0"}}; {"max_delay", "0.0"}};
...@@ -1084,7 +1084,7 @@ void InitializeTrialParams() { ...@@ -1084,7 +1084,7 @@ void InitializeTrialParams() {
EXPECT_TRUE(base::AssociateFieldTrialParams(kParamName, kGroupName, params)); EXPECT_TRUE(base::AssociateFieldTrialParams(kParamName, kGroupName, params));
EXPECT_TRUE(base::FieldTrialList::CreateFieldTrial(kParamName, kGroupName)); EXPECT_TRUE(base::FieldTrialList::CreateFieldTrial(kParamName, kGroupName));
std::map<std::string, std::string> actual_params; base::FieldTrialParams actual_params;
base::GetFieldTrialParams(kParamName, &actual_params); base::GetFieldTrialParams(kParamName, &actual_params);
EXPECT_EQ(actual_params, params); EXPECT_EQ(actual_params, params);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment