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/buffet_client.cc b/buffet/buffet_client.cc index 63ba2cc..635c037 100644 --- a/buffet/buffet_client.cc +++ b/buffet/buffet_client.cc
@@ -16,6 +16,7 @@ #include <chromeos/dbus/data_serialization.h> #include <chromeos/dbus/dbus_method_invoker.h> #include <chromeos/errors/error.h> +#include <chromeos/variant_dictionary.h> #include <dbus/bus.h> #include <dbus/message.h> #include <dbus/object_proxy.h> @@ -28,8 +29,8 @@ using chromeos::dbus_utils::CallMethodAndBlock; using chromeos::dbus_utils::CallMethodAndBlockWithTimeout; -using chromeos::dbus_utils::Dictionary; using chromeos::dbus_utils::ExtractMethodCallResults; +using chromeos::VariantDictionary; using chromeos::ErrorPtr; namespace { @@ -147,7 +148,7 @@ return EX_USAGE; } - Dictionary params; + VariantDictionary params; if (!args.empty()) { auto key_values = chromeos::data_encoding::WebParamsDecode(args.front()); for (const auto& pair : key_values) { @@ -214,7 +215,7 @@ } ErrorPtr error; - Dictionary property_set{{args.front(), args.back()}}; + VariantDictionary property_set{{args.front(), args.back()}}; auto response = CallMethodAndBlock( manager_proxy_, kManagerInterface, kManagerUpdateStateMethod, &error,
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}, };
diff --git a/buffet/libbuffet/command.cc b/buffet/libbuffet/command.cc index 67db6a5..dfa5581 100644 --- a/buffet/libbuffet/command.cc +++ b/buffet/libbuffet/command.cc
@@ -28,7 +28,7 @@ return GetProperties()->category.value(); } -const chromeos::dbus_utils::Dictionary& Command::GetParameters() const { +const chromeos::VariantDictionary& Command::GetParameters() const { return GetProperties()->parameters.value(); }
diff --git a/buffet/libbuffet/command.h b/buffet/libbuffet/command.h index 3404898..15fbb7b 100644 --- a/buffet/libbuffet/command.h +++ b/buffet/libbuffet/command.h
@@ -9,8 +9,7 @@ #include <base/macros.h> #include <base/memory/weak_ptr.h> -#include <chromeos/any.h> -#include <chromeos/dbus/data_serialization.h> +#include <chromeos/variant_dictionary.h> #include "libbuffet/export.h" @@ -37,7 +36,7 @@ // Returns the command category. const std::string& GetCategory() const; // Returns the command parameters and their values. - const chromeos::dbus_utils::Dictionary& GetParameters() const; + const chromeos::VariantDictionary& GetParameters() const; // Updates the command execution progress. The |progress| must be between // 0 and 100. Returns false if the progress value is incorrect.
diff --git a/buffet/libbuffet/command_listener.h b/buffet/libbuffet/command_listener.h index e36a1d3..452edc6 100644 --- a/buffet/libbuffet/command_listener.h +++ b/buffet/libbuffet/command_listener.h
@@ -12,8 +12,6 @@ #include <base/macros.h> #include <base/memory/scoped_ptr.h> #include <base/memory/weak_ptr.h> -#include <chromeos/any.h> -#include <chromeos/dbus/data_serialization.h> #include <dbus/object_manager.h> #include "libbuffet/export.h"
diff --git a/buffet/libbuffet/private/command_property_set.h b/buffet/libbuffet/private/command_property_set.h index 217458c..4a6aa1a 100644 --- a/buffet/libbuffet/private/command_property_set.h +++ b/buffet/libbuffet/private/command_property_set.h
@@ -8,24 +8,24 @@ #include <string> #include <base/macros.h> -#include <chromeos/any.h> #include <chromeos/dbus/data_serialization.h> +#include <chromeos/variant_dictionary.h> #include <dbus/object_manager.h> #include "buffet/libbuffet/export.h" namespace dbus { -// Specialize dbus::Property for chromeos::dbus_utils::Dictionary type. -template class Property<chromeos::dbus_utils::Dictionary>; +// Specialize dbus::Property for chromeos::VariantDictionary type. +template class Property<chromeos::VariantDictionary>; template <> -inline bool Property<chromeos::dbus_utils::Dictionary>::PopValueFromReader( +inline bool Property<chromeos::VariantDictionary>::PopValueFromReader( MessageReader* reader) { return chromeos::dbus_utils::PopVariantValueFromReader(reader, &value_); } template <> -inline void Property<chromeos::dbus_utils::Dictionary>::AppendSetValueToWriter( +inline void Property<chromeos::VariantDictionary>::AppendSetValueToWriter( MessageWriter* writer) { chromeos::dbus_utils::AppendValueToWriterAsVariant(writer, set_value_); } @@ -44,7 +44,7 @@ dbus::Property<std::string> category; dbus::Property<std::string> status; dbus::Property<int32_t> progress; - dbus::Property<chromeos::dbus_utils::Dictionary> parameters; + dbus::Property<chromeos::VariantDictionary> parameters; private: DISALLOW_COPY_AND_ASSIGN(CommandPropertySet);
diff --git a/buffet/manager.cc b/buffet/manager.cc index 03a5443..c39ec52 100644 --- a/buffet/manager.cc +++ b/buffet/manager.cc
@@ -118,7 +118,7 @@ void Manager::HandleUpdateState( chromeos::ErrorPtr* error, - const chromeos::dbus_utils::Dictionary& property_set) { + const chromeos::VariantDictionary& property_set) { state_manager_->UpdateProperties(property_set, error); }
diff --git a/buffet/manager.h b/buffet/manager.h index 66be522..a56b6c3 100644 --- a/buffet/manager.h +++ b/buffet/manager.h
@@ -56,7 +56,7 @@ const std::string& user_auth_code); // Handles calls to org.chromium.Buffet.Manager.UpdateState(). void HandleUpdateState(chromeos::ErrorPtr* error, - const chromeos::dbus_utils::Dictionary& property_set); + const chromeos::VariantDictionary& property_set); // Handles calls to org.chromium.Buffet.Manager.AddCommand(). void HandleAddCommand(chromeos::ErrorPtr* error, const std::string& json_command);
diff --git a/buffet/states/state_manager.cc b/buffet/states/state_manager.cc index afda934..1171ea0 100644 --- a/buffet/states/state_manager.cc +++ b/buffet/states/state_manager.cc
@@ -104,7 +104,7 @@ } bool StateManager::UpdateProperties( - const chromeos::dbus_utils::Dictionary& property_set, + const chromeos::VariantDictionary& property_set, chromeos::ErrorPtr* error) { for (const auto& pair : property_set) { if (!SetPropertyValue(pair.first, pair.second, error))
diff --git a/buffet/states/state_manager.h b/buffet/states/state_manager.h index 19212f0..2555ab5 100644 --- a/buffet/states/state_manager.h +++ b/buffet/states/state_manager.h
@@ -11,8 +11,8 @@ #include <string> #include <base/macros.h> -#include <chromeos/dbus/data_serialization.h> #include <chromeos/errors/error.h> +#include <chromeos/variant_dictionary.h> #include "buffet/states/state_package.h" @@ -47,7 +47,7 @@ // Updates a number of state properties in one shot. // |property_set| is a (full_property_name)-to-(property_value) map. - bool UpdateProperties(const chromeos::dbus_utils::Dictionary& property_set, + bool UpdateProperties(const chromeos::VariantDictionary& property_set, chromeos::ErrorPtr* error); // Returns all the categories the state properties are registered from.
diff --git a/buffet/states/state_package_unittest.cc b/buffet/states/state_package_unittest.cc index a9caf09..d8dc907 100644 --- a/buffet/states/state_package_unittest.cc +++ b/buffet/states/state_package_unittest.cc
@@ -6,7 +6,7 @@ #include <string> #include <base/values.h> -#include <chromeos/dbus/data_serialization.h> +#include <chromeos/variant_dictionary.h> #include <gtest/gtest.h> #include "buffet/commands/schema_constants.h" @@ -176,7 +176,7 @@ EXPECT_EQ(200, value.TryGet<int>()); value = package_->GetPropertyValue("direction", nullptr); - auto direction = value.TryGet<chromeos::dbus_utils::Dictionary>(); + auto direction = value.TryGet<chromeos::VariantDictionary>(); ASSERT_FALSE(direction.empty()); EXPECT_DOUBLE_EQ(89.9, direction["altitude"].TryGet<double>()); EXPECT_DOUBLE_EQ(57.2957795, direction["azimuth"].TryGet<double>()); @@ -208,7 +208,7 @@ } TEST_F(StatePackageTest, SetPropertyValue_Object) { - chromeos::dbus_utils::Dictionary direction{ + chromeos::VariantDictionary direction{ {"altitude", double{45.0}}, {"azimuth", double{15.0}}, }; @@ -245,7 +245,7 @@ TEST_F(StatePackageTest, SetPropertyValue_Error_Object_TypeMismatch) { chromeos::ErrorPtr error; - chromeos::dbus_utils::Dictionary direction{ + chromeos::VariantDictionary direction{ {"altitude", double{45.0}}, {"azimuth", int{15}}, }; @@ -261,7 +261,7 @@ TEST_F(StatePackageTest, SetPropertyValue_Error_Object_OutOfRange) { chromeos::ErrorPtr error; - chromeos::dbus_utils::Dictionary direction{ + chromeos::VariantDictionary direction{ {"altitude", double{100.0}}, {"azimuth", double{290.0}}, }; @@ -278,7 +278,7 @@ TEST_F(StatePackageTest, SetPropertyValue_Error_Object_UnknownProperty) { chromeos::ErrorPtr error; - chromeos::dbus_utils::Dictionary direction{ + chromeos::VariantDictionary direction{ {"altitude", double{10.0}}, {"azimuth", double{20.0}}, {"spin", double{30.0}}, @@ -291,7 +291,7 @@ TEST_F(StatePackageTest, SetPropertyValue_Error_Object_MissingProperty) { chromeos::ErrorPtr error; - chromeos::dbus_utils::Dictionary direction{ + chromeos::VariantDictionary direction{ {"altitude", double{10.0}}, }; ASSERT_FALSE(package_->SetPropertyValue("direction", direction, &error));