Adds support for empty key fields in field trial parser.

Bug: webrtc:9346
Change-Id: I16e068340d3d48b983270af0c481ed538632e148
Reviewed-on: https://webrtc-review.googlesource.com/c/115241
Reviewed-by: Christoffer Rodbro <crodbro@webrtc.org>
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26070}
This commit is contained in:
Sebastian Jansson 2018-12-20 12:25:19 +01:00 committed by Commit Bot
parent afa07dda42
commit d69998aa5c
3 changed files with 21 additions and 2 deletions

View File

@ -41,9 +41,15 @@ void ParseFieldTrial(
std::initializer_list<FieldTrialParameterInterface*> fields,
std::string trial_string) {
std::map<std::string, FieldTrialParameterInterface*> field_map;
FieldTrialParameterInterface* keyless_field = nullptr;
for (FieldTrialParameterInterface* field : fields) {
field->MarkAsUsed();
field_map[field->Key()] = field;
if (field->Key().empty()) {
RTC_DCHECK(!keyless_field);
keyless_field = field;
} else {
field_map[field->Key()] = field;
}
}
size_t i = 0;
while (i < trial_string.length()) {
@ -62,6 +68,11 @@ void ParseFieldTrial(
RTC_LOG(LS_WARNING) << "Failed to read field with key: '" << key
<< "' in trial: \"" << trial_string << "\"";
}
} else if (!opt_value && keyless_field && !key.empty()) {
if (!keyless_field->Parse(key)) {
RTC_LOG(LS_WARNING) << "Failed to read empty key field with value '"
<< key << "' in trial: \"" << trial_string << "\"";
}
} else {
RTC_LOG(LS_INFO) << "No field with key: '" << key
<< "' (found in trial: \"" << trial_string << "\")";

View File

@ -55,7 +55,7 @@ class FieldTrialParameterInterface {
};
// ParseFieldTrial function parses the given string and fills the given fields
// with extrated values if available.
// with extracted values if available.
void ParseFieldTrial(
std::initializer_list<FieldTrialParameterInterface*> fields,
std::string raw_string);

View File

@ -112,6 +112,14 @@ TEST(FieldTrialParserTest, IgnoresOutOfRange) {
EXPECT_EQ(low.Get(), 20);
EXPECT_EQ(high.Get(), 20);
}
TEST(FieldTrialParserTest, ReadsValuesFromFieldWithoutKey) {
FieldTrialFlag enabled("Enabled");
FieldTrialParameter<int> req("", 10);
ParseFieldTrial({&enabled, &req}, "Enabled,20");
EXPECT_EQ(req.Get(), 20);
ParseFieldTrial({&req}, "30");
EXPECT_EQ(req.Get(), 30);
}
TEST(FieldTrialParserTest, ParsesOptionalParameters) {
FieldTrialOptional<int> max_count("c", absl::nullopt);
ParseFieldTrial({&max_count}, "");