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 @@
#include "base/base_export.h"
#include "base/memory/singleton.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/field_trial_params.h"
#include "base/synchronization/lock.h"
namespace base {
......@@ -23,9 +24,6 @@ class BASE_EXPORT FieldTrialParamAssociator {
FieldTrialParamAssociator();
~FieldTrialParamAssociator();
// Key-value mapping type for field trial parameters.
typedef std::map<std::string, std::string> FieldTrialParams;
// Retrieve the singleton.
static FieldTrialParamAssociator* GetInstance();
......
......@@ -11,22 +11,21 @@
namespace base {
bool AssociateFieldTrialParams(
const std::string& trial_name,
const std::string& group_name,
const std::map<std::string, std::string>& params) {
bool AssociateFieldTrialParams(const std::string& trial_name,
const std::string& group_name,
const FieldTrialParams& params) {
return base::FieldTrialParamAssociator::GetInstance()
->AssociateFieldTrialParams(trial_name, group_name, params);
}
bool GetFieldTrialParams(const std::string& trial_name,
std::map<std::string, std::string>* params) {
FieldTrialParams* params) {
return base::FieldTrialParamAssociator::GetInstance()->GetFieldTrialParams(
trial_name, params);
}
bool GetFieldTrialParamsByFeature(const base::Feature& feature,
std::map<std::string, std::string>* params) {
FieldTrialParams* params) {
if (!base::FeatureList::IsEnabled(feature))
return false;
......@@ -39,7 +38,7 @@ bool GetFieldTrialParamsByFeature(const base::Feature& feature,
std::string GetFieldTrialParamValue(const std::string& trial_name,
const std::string& param_name) {
std::map<std::string, std::string> params;
FieldTrialParams params;
if (GetFieldTrialParams(trial_name, &params)) {
auto it = params.find(param_name);
if (it != params.end())
......
......@@ -14,14 +14,16 @@ namespace base {
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
// 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
// is already active (group() has been called on it). Thread safe.
BASE_EXPORT bool AssociateFieldTrialParams(
const std::string& trial_name,
const std::string& group_name,
const std::map<std::string, std::string>& params);
BASE_EXPORT bool AssociateFieldTrialParams(const std::string& trial_name,
const std::string& group_name,
const FieldTrialParams& params);
// 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
......@@ -29,9 +31,8 @@ BASE_EXPORT bool AssociateFieldTrialParams(
// 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),
// if it wasn't already. Thread safe.
BASE_EXPORT bool GetFieldTrialParams(
const std::string& trial_name,
std::map<std::string, std::string>* params);
BASE_EXPORT bool GetFieldTrialParams(const std::string& trial_name,
FieldTrialParams* params);
// 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
......@@ -40,9 +41,8 @@ BASE_EXPORT bool GetFieldTrialParams(
// 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.
// group() will be called on it), if it wasn't already. Thread safe.
BASE_EXPORT bool GetFieldTrialParamsByFeature(
const base::Feature& feature,
std::map<std::string, std::string>* params);
BASE_EXPORT bool GetFieldTrialParamsByFeature(const base::Feature& feature,
FieldTrialParams* params);
// Retrieves a specific parameter value corresponding to |param_name| for the
// specified field trial, based on its selected group. If the field trial does
......
......@@ -251,7 +251,7 @@ void InitializeFeatureList(const base::DictionaryValue& dcs_features,
feature_name, base::FeatureList::OVERRIDE_DISABLE_FEATURE)) {
// Build a map of the FieldTrial parameters and associate it to the
// FieldTrial.
base::FieldTrialParamAssociator::FieldTrialParams params;
base::FieldTrialParams params;
for (Iterator p(*params_dict); !p.IsAtEnd(); p.Advance()) {
std::string val;
if (p.value().GetAsString(&val)) {
......
......@@ -80,7 +80,7 @@ base::HistogramBase::Sample ToSample(ReportCircumstance circumstance) {
uint32_t GetFieldTrialUint32Param(const char* trial_name,
const char* parameter_name,
uint32_t default_param) {
std::map<std::string, std::string> trial_params;
base::FieldTrialParams trial_params;
bool result = base::GetFieldTrialParams(trial_name, &trial_params);
if (!result)
return default_param;
......
......@@ -1532,9 +1532,9 @@ class ResourceFetchPriorityExperimentTest : public FrameSchedulerImplTest {
public:
ResourceFetchPriorityExperimentTest()
: FrameSchedulerImplTest({kUseResourceFetchPriority}, {}) {
std::map<std::string, std::string> params{
{"HIGHEST", "HIGH"}, {"MEDIUM", "NORMAL"}, {"LOW", "NORMAL"},
{"LOWEST", "LOW"}, {"IDLE", "LOW"}, {"THROTTLED", "LOW"}};
base::FieldTrialParams params{{"HIGHEST", "HIGH"}, {"MEDIUM", "NORMAL"},
{"LOW", "NORMAL"}, {"LOWEST", "LOW"},
{"IDLE", "LOW"}, {"THROTTLED", "LOW"}};
const char kStudyName[] = "ResourceFetchPriorityExperiment";
const char kGroupName[] = "GroupName1";
......@@ -1567,9 +1567,9 @@ class ResourceFetchPriorityExperimentOnlyWhenLoadingTest
public:
ResourceFetchPriorityExperimentOnlyWhenLoadingTest()
: FrameSchedulerImplTest({kUseResourceFetchPriorityOnlyWhenLoading}, {}) {
std::map<std::string, std::string> params{
{"HIGHEST", "HIGH"}, {"MEDIUM", "NORMAL"}, {"LOW", "NORMAL"},
{"LOWEST", "LOW"}, {"IDLE", "LOW"}, {"THROTTLED", "LOW"}};
base::FieldTrialParams params{{"HIGHEST", "HIGH"}, {"MEDIUM", "NORMAL"},
{"LOW", "NORMAL"}, {"LOWEST", "LOW"},
{"IDLE", "LOW"}, {"THROTTLED", "LOW"}};
const char kStudyName[] = "ResourceFetchPriorityExperiment";
const char kGroupName[] = "GroupName2";
......@@ -1746,9 +1746,8 @@ TEST_F(FrameSchedulerImplTest, TaskTypeToTaskQueueMapping) {
class ThrottleAndFreezeTaskTypesExperimentTest : public FrameSchedulerImplTest {
public:
ThrottleAndFreezeTaskTypesExperimentTest(
std::map<std::string, std::string> params,
const char* group_name) {
ThrottleAndFreezeTaskTypesExperimentTest(const base::FieldTrialParams& params,
const char* group_name) {
const char kStudyName[] = "ThrottleAndFreezeTaskTypes";
field_trial_list_ = std::make_unique<base::FieldTrialList>(nullptr);
......@@ -1772,7 +1771,7 @@ class ThrottleableAndFreezableTaskTypesTest
public:
ThrottleableAndFreezableTaskTypesTest()
: ThrottleAndFreezeTaskTypesExperimentTest(
std::map<std::string, std::string>{
base::FieldTrialParams{
// Leading spaces are allowed.
{kThrottleableTaskTypesListParam, "PostedMessage"},
{kFreezableTaskTypesListParam,
......@@ -1826,7 +1825,7 @@ class FreezableOnlyTaskTypesTest
public:
FreezableOnlyTaskTypesTest()
: ThrottleAndFreezeTaskTypesExperimentTest(
std::map<std::string, std::string>{
base::FieldTrialParams{
{kThrottleableTaskTypesListParam, ""},
{kFreezableTaskTypesListParam,
"PostedMessage,MediaElementEvent,DOMManipulation"}},
......@@ -1880,7 +1879,7 @@ class ThrottleableOnlyTaskTypesTest
public:
ThrottleableOnlyTaskTypesTest()
: ThrottleAndFreezeTaskTypesExperimentTest(
std::map<std::string, std::string>{
base::FieldTrialParams{
{kFreezableTaskTypesListParam, ""},
{kThrottleableTaskTypesListParam, "PostedMessage"}},
"Group3") {}
......
......@@ -565,7 +565,7 @@ MainThreadSchedulerImpl::SchedulingSettings::SchedulingSettings() {
if (use_resource_fetch_priority ||
use_resource_priorities_only_during_loading) {
std::map<std::string, std::string> params;
base::FieldTrialParams params;
base::GetFieldTrialParams(kResourceFetchPriorityExperiment, &params);
for (size_t net_priority = 0;
net_priority < net::RequestPrioritySize::NUM_PRIORITIES;
......
......@@ -68,10 +68,9 @@ struct BackgroundThrottlingSettings {
base::Optional<base::TimeDelta> initial_budget;
};
double GetDoubleParameterFromMap(
const std::map<std::string, std::string>& settings,
const std::string& setting_name,
double default_value) {
double GetDoubleParameterFromMap(const base::FieldTrialParams& settings,
const std::string& setting_name,
double default_value) {
const auto& find_it = settings.find(setting_name);
if (find_it == settings.end())
return default_value;
......@@ -90,7 +89,7 @@ base::Optional<base::TimeDelta> DoubleToOptionalTime(double value) {
}
BackgroundThrottlingSettings GetBackgroundThrottlingSettings() {
std::map<std::string, std::string> background_throttling_settings;
base::FieldTrialParams background_throttling_settings;
base::GetFieldTrialParams("ExpensiveBackgroundTimerThrottling",
&background_throttling_settings);
......
......@@ -1075,16 +1075,16 @@ void ExpensiveTestTask(scoped_refptr<base::TestMockTimeTaskRunner> task_runner,
}
void InitializeTrialParams() {
std::map<std::string, std::string> params = {{"cpu_budget", "0.01"},
{"max_budget", "0.0"},
{"initial_budget", "0.0"},
{"max_delay", "0.0"}};
base::FieldTrialParams params = {{"cpu_budget", "0.01"},
{"max_budget", "0.0"},
{"initial_budget", "0.0"},
{"max_delay", "0.0"}};
const char kParamName[] = "ExpensiveBackgroundTimerThrottling";
const char kGroupName[] = "Enabled";
EXPECT_TRUE(base::AssociateFieldTrialParams(kParamName, kGroupName, params));
EXPECT_TRUE(base::FieldTrialList::CreateFieldTrial(kParamName, kGroupName));
std::map<std::string, std::string> actual_params;
base::FieldTrialParams actual_params;
base::GetFieldTrialParams(kParamName, &actual_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