Commit 093c5cfd authored by Alexei Svitkine's avatar Alexei Svitkine Committed by Chromium LUCI CQ

Remove an unnecessary field trial look up when using params.

This should speed up using feature / field trial params APIs.

Bug: 1163921
Change-Id: Ieacd216cba47c259287b3b392bd00fa7077ac084
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2615481
Commit-Queue: Alexei Svitkine <asvitkine@chromium.org>
Auto-Submit: Alexei Svitkine <asvitkine@chromium.org>
Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841559}
parent 9bd54160
...@@ -39,16 +39,13 @@ bool FieldTrialParamAssociator::AssociateFieldTrialParams( ...@@ -39,16 +39,13 @@ bool FieldTrialParamAssociator::AssociateFieldTrialParams(
return true; return true;
} }
bool FieldTrialParamAssociator::GetFieldTrialParams( bool FieldTrialParamAssociator::GetFieldTrialParams(FieldTrial* field_trial,
const std::string& trial_name, FieldTrialParams* params) {
FieldTrialParams* params) {
FieldTrial* field_trial = FieldTrialList::Find(trial_name);
if (!field_trial) if (!field_trial)
return false; return false;
// First try the local map, falling back to getting it from shared memory. // First try the local map, falling back to getting it from shared memory.
if (GetFieldTrialParamsWithoutFallback(trial_name, field_trial->group_name(), if (GetFieldTrialParamsWithoutFallback(field_trial->trial_name(),
params)) { field_trial->group_name(), params)) {
return true; return true;
} }
......
...@@ -33,9 +33,9 @@ class BASE_EXPORT FieldTrialParamAssociator { ...@@ -33,9 +33,9 @@ class BASE_EXPORT FieldTrialParamAssociator {
const FieldTrialParams& params); const FieldTrialParams& params);
// Gets the parameters for a field trial and its chosen group. If not found in // Gets the parameters for a field trial and its chosen group. If not found in
// field_trial_params_, then tries to looks it up in shared memory. // field_trial_params_, then tries to looks it up in shared memory. Returns
bool GetFieldTrialParams(const std::string& trial_name, // false if no params are available or the passed |field_trial| is null.
FieldTrialParams* params); bool GetFieldTrialParams(FieldTrial* field_trial, FieldTrialParams* params);
// Gets the parameters for a field trial and its chosen group. Does not // Gets the parameters for a field trial and its chosen group. Does not
// fallback to looking it up in shared memory. This should only be used if you // fallback to looking it up in shared memory. This should only be used if you
......
...@@ -86,8 +86,9 @@ bool AssociateFieldTrialParamsFromString( ...@@ -86,8 +86,9 @@ bool AssociateFieldTrialParamsFromString(
bool GetFieldTrialParams(const std::string& trial_name, bool GetFieldTrialParams(const std::string& trial_name,
FieldTrialParams* params) { FieldTrialParams* params) {
return FieldTrialParamAssociator::GetInstance()->GetFieldTrialParams( FieldTrial* trial = FieldTrialList::Find(trial_name);
trial_name, params); return FieldTrialParamAssociator::GetInstance()->GetFieldTrialParams(trial,
params);
} }
bool GetFieldTrialParamsByFeature(const Feature& feature, bool GetFieldTrialParamsByFeature(const Feature& feature,
...@@ -96,10 +97,8 @@ bool GetFieldTrialParamsByFeature(const Feature& feature, ...@@ -96,10 +97,8 @@ bool GetFieldTrialParamsByFeature(const Feature& feature,
return false; return false;
FieldTrial* trial = FeatureList::GetFieldTrial(feature); FieldTrial* trial = FeatureList::GetFieldTrial(feature);
if (!trial) return FieldTrialParamAssociator::GetInstance()->GetFieldTrialParams(trial,
return false; params);
return GetFieldTrialParams(trial->trial_name(), params);
} }
std::string GetFieldTrialParamValue(const std::string& trial_name, std::string GetFieldTrialParamValue(const std::string& trial_name,
......
...@@ -1275,8 +1275,7 @@ TEST_F(FieldTrialListTest, AssociateFieldTrialParams) { ...@@ -1275,8 +1275,7 @@ TEST_F(FieldTrialListTest, AssociateFieldTrialParams) {
// Check that we fetch the param from shared memory properly. // Check that we fetch the param from shared memory properly.
std::map<std::string, std::string> new_params; std::map<std::string, std::string> new_params;
FieldTrialParamAssociator::GetInstance()->GetFieldTrialParams(trial_name, GetFieldTrialParams(trial_name, &new_params);
&new_params);
EXPECT_EQ("value1", new_params["key1"]); EXPECT_EQ("value1", new_params["key1"]);
EXPECT_EQ("value2", new_params["key2"]); EXPECT_EQ("value2", new_params["key2"]);
EXPECT_EQ(2U, new_params.size()); EXPECT_EQ(2U, new_params.size());
...@@ -1315,8 +1314,7 @@ TEST_F(FieldTrialListTest, MAYBE_ClearParamsFromSharedMemory) { ...@@ -1315,8 +1314,7 @@ TEST_F(FieldTrialListTest, MAYBE_ClearParamsFromSharedMemory) {
// Check that there are no params associated with the field trial anymore. // Check that there are no params associated with the field trial anymore.
std::map<std::string, std::string> new_params; std::map<std::string, std::string> new_params;
FieldTrialParamAssociator::GetInstance()->GetFieldTrialParams(trial_name, GetFieldTrialParams(trial_name, &new_params);
&new_params);
EXPECT_EQ(0U, new_params.size()); EXPECT_EQ(0U, new_params.size());
// Now duplicate the handle so we can easily check that the trial is still // Now duplicate the handle so we can easily check that the trial is still
......
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