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,11 +162,13 @@ using Iterator = base::DictionaryValue::Iterator; ...@@ -162,11 +162,13 @@ using Iterator = base::DictionaryValue::Iterator;
std::vector<const base::Feature*> GetInternalFeatures(); std::vector<const base::Feature*> GetInternalFeatures();
const std::vector<const base::Feature*>& GetFeatures() { const std::vector<const base::Feature*>& GetFeatures() {
static const base::NoDestructor<std::vector<const base::Feature*>> features([] { static const base::NoDestructor<std::vector<const base::Feature*>> features(
[] {
auto features = std::vector<const base::Feature*>( auto features = std::vector<const base::Feature*>(
kFeatures, kFeatures + sizeof(kFeatures) / sizeof(base::Feature*)); kFeatures, kFeatures + sizeof(kFeatures) / sizeof(base::Feature*));
auto internal_features = GetInternalFeatures(); auto internal_features = GetInternalFeatures();
features.insert(features.end(), internal_features.begin(), internal_features.end()); features.insert(features.end(), internal_features.begin(),
internal_features.end());
return features; return features;
}()); }());
if (GetTestFeatures().size() > 0) if (GetTestFeatures().size() > 0)
...@@ -270,19 +272,18 @@ bool IsFeatureEnabled(const base::Feature& feature) { ...@@ -270,19 +272,18 @@ bool IsFeatureEnabled(const base::Feature& feature) {
} }
base::DictionaryValue GetOverriddenFeaturesForStorage( base::DictionaryValue GetOverriddenFeaturesForStorage(
const base::DictionaryValue& features) { const base::Value& features) {
base::DictionaryValue persistent_dict; base::DictionaryValue persistent_dict;
// |features| maps feature names to either a boolean or a dict of params. // |features| maps feature names to either a boolean or a dict of params.
for (Iterator it(features); !it.IsAtEnd(); it.Advance()) { for (const auto& feature : features.DictItems()) {
bool enabled; if (feature.second.is_bool()) {
if (it.value().GetAsBoolean(&enabled)) { persistent_dict.SetBoolean(feature.first, feature.second.GetBool());
persistent_dict.SetBoolean(it.key(), enabled);
continue; continue;
} }
const base::DictionaryValue* params_dict; const base::DictionaryValue* params_dict;
if (it.value().GetAsDictionary(&params_dict)) { if (feature.second.GetAsDictionary(&params_dict)) {
auto params = std::make_unique<base::DictionaryValue>(); auto params = std::make_unique<base::DictionaryValue>();
bool bval; bool bval;
...@@ -301,18 +302,18 @@ base::DictionaryValue GetOverriddenFeaturesForStorage( ...@@ -301,18 +302,18 @@ base::DictionaryValue GetOverriddenFeaturesForStorage(
} else if (param_val.GetAsString(&sval)) { } else if (param_val.GetAsString(&sval)) {
params->SetString(param_key, sval); params->SetString(param_key, sval);
} else { } else {
LOG(ERROR) << "Entry in params dict for \"" << it.key() << "\"" LOG(ERROR) << "Entry in params dict for \"" << feature.first << "\""
<< " is not of a supported type (key: " << p.key() << " is not of a supported type (key: " << param_key
<< ", type: " << param_val.type(); << ", type: " << param_val.type();
} }
} }
persistent_dict.Set(it.key(), std::move(params)); persistent_dict.Set(feature.first, std::move(params));
continue; continue;
} }
// Other base::Value types are not supported. // Other base::Value types are not supported.
LOG(ERROR) << "A DCS feature mapped to an unsupported value. key: " 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; return persistent_dict;
......
...@@ -17,7 +17,8 @@ ...@@ -17,7 +17,8 @@
namespace base { namespace base {
class DictionaryValue; class DictionaryValue;
class ListValue; class ListValue;
} class Value;
} // namespace base
namespace chromecast { namespace chromecast {
...@@ -57,7 +58,7 @@ bool IsFeatureEnabled(const base::Feature& feature); ...@@ -57,7 +58,7 @@ bool IsFeatureEnabled(const base::Feature& feature);
// to disk. Encodes all values as strings, which is how the FieldTrial // to disk. Encodes all values as strings, which is how the FieldTrial
// classes expect the param data. // classes expect the param data.
base::DictionaryValue GetOverriddenFeaturesForStorage( 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 // 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 // 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