libchromeos: Move Dictionary class into its own header file Moved chromeos::dbus_utils::Dictionary type alias into its own header file (chromeos/dictionary.h) and promoting it to the top level namespace (chromeos). So now it becomes chromeos::VariantDictionary and it is now independent from D-Bus data serialization. BUG=None TEST=FEATURE=test emerge-link libchromeos buffet Change-Id: Ibad63fd4168d77b9a4b80c7800016510f87ae33d Reviewed-on: https://chromium-review.googlesource.com/219413 Reviewed-by: Alex Vakulenko <avakulenko@chromium.org> Tested-by: Alex Vakulenko <avakulenko@chromium.org> Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/commands/dbus_command_proxy.cc b/buffet/commands/dbus_command_proxy.cc index 4bbf1ab..0b97c06 100644 --- a/buffet/commands/dbus_command_proxy.cc +++ b/buffet/commands/dbus_command_proxy.cc
@@ -61,7 +61,7 @@ progress_.SetValue(command_instance_->GetProgress()); // Convert a string-to-PropValue map into a string-to-Any map which can be // sent over D-Bus. - chromeos::dbus_utils::Dictionary params; + chromeos::VariantDictionary params; for (const auto& param_pair : command_instance_->GetParameters()) { params.insert(std::make_pair(param_pair.first, param_pair.second->GetValueAsAny()));
diff --git a/buffet/commands/dbus_command_proxy.h b/buffet/commands/dbus_command_proxy.h index eb37d32..553470e 100644 --- a/buffet/commands/dbus_command_proxy.h +++ b/buffet/commands/dbus_command_proxy.h
@@ -46,7 +46,7 @@ chromeos::dbus_utils::ExportedProperty<std::string> id_; chromeos::dbus_utils::ExportedProperty<std::string> status_; chromeos::dbus_utils::ExportedProperty<int32_t> progress_; - chromeos::dbus_utils::ExportedProperty<chromeos::dbus_utils::Dictionary> + chromeos::dbus_utils::ExportedProperty<chromeos::VariantDictionary> parameters_; // Handles calls to org.chromium.Buffet.Command.SetProgress(progress).
diff --git a/buffet/commands/dbus_command_proxy_unittest.cc b/buffet/commands/dbus_command_proxy_unittest.cc index d4550a5..34d9f1d 100644 --- a/buffet/commands/dbus_command_proxy_unittest.cc +++ b/buffet/commands/dbus_command_proxy_unittest.cc
@@ -24,8 +24,8 @@ using buffet::unittests::CreateDictionaryValue; using chromeos::dbus_utils::AsyncEventSequencer; -using chromeos::dbus_utils::Dictionary; using chromeos::dbus_utils::ExportedObjectManager; +using chromeos::VariantDictionary; namespace buffet { @@ -118,7 +118,7 @@ return command_proxy_->progress_.value(); } - Dictionary GetParameters() const { + VariantDictionary GetParameters() const { return command_proxy_->parameters_.value(); } @@ -175,7 +175,7 @@ }; TEST_F(DBusCommandProxyTest, Init) { - Dictionary params = { + VariantDictionary params = { {"height", int32_t{53}}, {"_jumpType", std::string{"_withKick"}}, }; @@ -192,7 +192,8 @@ GetPropertyValue<std::string>(dbus_constants::kCommandStatus)); EXPECT_EQ(0, GetPropertyValue<int32_t>(dbus_constants::kCommandProgress)); EXPECT_EQ(params, - GetPropertyValue<Dictionary>(dbus_constants::kCommandParameters)); + GetPropertyValue<VariantDictionary>( + dbus_constants::kCommandParameters)); } TEST_F(DBusCommandProxyTest, SetProgress) {
diff --git a/buffet/commands/schema_utils.cc b/buffet/commands/schema_utils.cc index 4106511..8f64eec 100644 --- a/buffet/commands/schema_utils.cc +++ b/buffet/commands/schema_utils.cc
@@ -9,6 +9,7 @@ #include <string> #include <base/json/json_writer.h> +#include <chromeos/variant_dictionary.h> #include "buffet/commands/object_schema.h" #include "buffet/commands/prop_types.h" @@ -201,8 +202,8 @@ if (value->GetType() != ValueType::Object) return value->GetValueAsAny(); // Special case for object types. - // Convert native_types::Object to chromeos::dbus_utils::Dictionary - chromeos::dbus_utils::Dictionary dict; + // Convert native_types::Object to chromeos::VariantDictionary + chromeos::VariantDictionary dict; for (const auto& pair : value->GetObject()->GetValue()) { // Since we are inserting the elements from native_types::Object which is // a map, the keys are already sorted. So use the "end()" position as a hint @@ -227,13 +228,13 @@ } // Special case for object types. - // We expect the |value| to contain chromeos::dbus_utils::Dictionary, while + // We expect the |value| to contain chromeos::VariantDictionary, while // PropValue must use native_types::Object instead. Do the conversion. - if (!value.IsTypeCompatible<chromeos::dbus_utils::Dictionary>()) { + if (!value.IsTypeCompatible<chromeos::VariantDictionary>()) { type->GenerateErrorValueTypeMismatch(error); return result; } - const auto& dict = value.Get<chromeos::dbus_utils::Dictionary>(); + const auto& dict = value.Get<chromeos::VariantDictionary>(); native_types::Object obj; CHECK(nullptr != type->GetObjectSchemaPtr()) << "An object type must have a schema defined for it";
diff --git a/buffet/commands/schema_utils.h b/buffet/commands/schema_utils.h index a05d080..33261f0 100644 --- a/buffet/commands/schema_utils.h +++ b/buffet/commands/schema_utils.h
@@ -120,10 +120,10 @@ // Converts PropValue to Any in a format understood by D-Bus data serialization. // Has special handling for Object types where native_types::Object are -// converted to chromeos::dbus_utils::Dictionary. +// converted to chromeos::VariantDictionary. chromeos::Any PropValueToDBusVariant(const PropValue* value); // Converts D-Bus variant to PropValue. -// Has special handling for Object types where chromeos::dbus_utils::Dictionary +// Has special handling for Object types where chromeos::VariantDictionary // is converted to native_types::Object. std::shared_ptr<const PropValue> PropValueFromDBusVariant( const PropType* type,
diff --git a/buffet/commands/schema_utils_unittest.cc b/buffet/commands/schema_utils_unittest.cc index c5acbc8..ffa05a6 100644 --- a/buffet/commands/schema_utils_unittest.cc +++ b/buffet/commands/schema_utils_unittest.cc
@@ -7,6 +7,7 @@ #include <vector> #include <base/values.h> +#include <chromeos/variant_dictionary.h> #include <gtest/gtest.h> #include "buffet/commands/object_schema.h" @@ -19,7 +20,7 @@ using buffet::unittests::CreateDictionaryValue; using buffet::unittests::CreateValue; using buffet::unittests::ValueToString; -using chromeos::dbus_utils::Dictionary; +using chromeos::VariantDictionary; TEST(CommandSchemaUtils, TypedValueToJson_Scalar) { EXPECT_EQ("true", @@ -210,7 +211,8 @@ {"height", int_type.CreateValue(20, nullptr)}, }; prop_value = obj_type.CreateValue(obj, nullptr); - Dictionary dict = PropValueToDBusVariant(prop_value.get()).Get<Dictionary>(); + VariantDictionary dict = + PropValueToDBusVariant(prop_value.get()).Get<VariantDictionary>(); EXPECT_EQ(20, dict["height"].Get<int>()); EXPECT_EQ(10, dict["width"].Get<int>()); } @@ -287,7 +289,7 @@ "'enum':[{'width':10,'height':20},{'width':100,'height':200}]}").get(), nullptr, nullptr)); - Dictionary obj{ + VariantDictionary obj{ {"width", 100}, {"height", 200}, };