Commit cc32eb56 authored by Matt Swartwout's avatar Matt Swartwout Committed by Commit Bot

Make GetOverridenFeaturesForStorage accept a base::Value

base::DictionaryValue is deprecated, and we are transitioning some
internal code to use base::Value instead of base::DictionaryValue, and
it calls GetOverridenFeaturesForStorage. So here we make
GetOverridenFeaturesForStorage accept a base::Value. We do not change
the return value so that we do not break any existing usages.

Bug: Internal 119219865
Test: None
Change-Id: I61a794456b586f0a0b99dc258d13f02d10ae7646
Reviewed-on: https://chromium-review.googlesource.com/c/1321672Reviewed-by: default avatarSergey Volk <servolk@chromium.org>
Commit-Queue: Matt Swartwout <mwswartwout@google.com>
Cr-Commit-Position: refs/heads/master@{#606550}
parent c7b95288
......@@ -162,13 +162,15 @@ using Iterator = base::DictionaryValue::Iterator;
std::vector<const base::Feature*> GetInternalFeatures();
const std::vector<const base::Feature*>& GetFeatures() {
static const base::NoDestructor<std::vector<const base::Feature*>> features([] {
auto features = std::vector<const base::Feature*>(
kFeatures, kFeatures + sizeof(kFeatures) / sizeof(base::Feature*));
auto internal_features = GetInternalFeatures();
features.insert(features.end(), internal_features.begin(), internal_features.end());
return features;
}());
static const base::NoDestructor<std::vector<const base::Feature*>> features(
[] {
auto features = std::vector<const base::Feature*>(
kFeatures, kFeatures + sizeof(kFeatures) / sizeof(base::Feature*));
auto internal_features = GetInternalFeatures();
features.insert(features.end(), internal_features.begin(),
internal_features.end());
return features;
}());
if (GetTestFeatures().size() > 0)
return GetTestFeatures();
return *features;
......@@ -270,19 +272,18 @@ bool IsFeatureEnabled(const base::Feature& feature) {
}
base::DictionaryValue GetOverriddenFeaturesForStorage(
const base::DictionaryValue& features) {
const base::Value& features) {
base::DictionaryValue persistent_dict;
// |features| maps feature names to either a boolean or a dict of params.
for (Iterator it(features); !it.IsAtEnd(); it.Advance()) {
bool enabled;
if (it.value().GetAsBoolean(&enabled)) {
persistent_dict.SetBoolean(it.key(), enabled);
for (const auto& feature : features.DictItems()) {
if (feature.second.is_bool()) {
persistent_dict.SetBoolean(feature.first, feature.second.GetBool());
continue;
}
const base::DictionaryValue* params_dict;
if (it.value().GetAsDictionary(&params_dict)) {
if (feature.second.GetAsDictionary(&params_dict)) {
auto params = std::make_unique<base::DictionaryValue>();
bool bval;
......@@ -301,18 +302,18 @@ base::DictionaryValue GetOverriddenFeaturesForStorage(
} else if (param_val.GetAsString(&sval)) {
params->SetString(param_key, sval);
} else {
LOG(ERROR) << "Entry in params dict for \"" << it.key() << "\""
<< " is not of a supported type (key: " << p.key()
LOG(ERROR) << "Entry in params dict for \"" << feature.first << "\""
<< " is not of a supported type (key: " << param_key
<< ", type: " << param_val.type();
}
}
persistent_dict.Set(it.key(), std::move(params));
persistent_dict.Set(feature.first, std::move(params));
continue;
}
// Other base::Value types are not supported.
LOG(ERROR) << "A DCS feature mapped to an unsupported value. key: "
<< it.key() << " type: " << it.value().type();
<< feature.first << " type: " << feature.second.type();
}
return persistent_dict;
......
......@@ -17,7 +17,8 @@
namespace base {
class DictionaryValue;
class ListValue;
}
class Value;
} // namespace base
namespace chromecast {
......@@ -57,7 +58,7 @@ bool IsFeatureEnabled(const base::Feature& feature);
// to disk. Encodes all values as strings, which is how the FieldTrial
// classes expect the param data.
base::DictionaryValue GetOverriddenFeaturesForStorage(
const base::DictionaryValue& features);
const base::Value& features);
// Query the set of experiment ids set for this run. Intended only for metrics
// reporting. Must be called after InitializeFeatureList(). May be called on any
......
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