Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Unified Diff: dbus/values_util.cc

Issue 221393004: dbus/values_util.h: Add functions to append collection type values to message. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed keybuk@'s comment, unmarked old functions as deprecated as they are useful. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dbus/values_util.h ('k') | dbus/values_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dbus/values_util.cc
diff --git a/dbus/values_util.cc b/dbus/values_util.cc
index 7574f39a643d466b94fee5b437fdaf81cdd7d589..c27c2723b84cb9f42820d22ffe6cb8fc96ff1cd6 100644
--- a/dbus/values_util.cc
+++ b/dbus/values_util.cc
@@ -77,6 +77,8 @@ std::string GetTypeSignature(const base::Value& value) {
return "ay";
case base::Value::TYPE_DICTIONARY:
return "a{sv}";
+ case base::Value::TYPE_LIST:
+ return "av";
default:
DLOG(ERROR) << "Unexpected type " << value.GetType();
return std::string();
@@ -253,4 +255,53 @@ void AppendBasicTypeValueDataAsVariant(MessageWriter* writer,
writer->CloseContainer(&sub_writer);
}
+void AppendValueData(MessageWriter* writer, const base::Value& value) {
+ switch (value.GetType()) {
+ case base::Value::TYPE_DICTIONARY: {
+ const base::DictionaryValue* dictionary = NULL;
+ value.GetAsDictionary(&dictionary);
+ dbus::MessageWriter array_writer(NULL);
+ writer->OpenArray("{sv}", &array_writer);
+ for (base::DictionaryValue::Iterator iter(*dictionary);
+ !iter.IsAtEnd(); iter.Advance()) {
+ dbus::MessageWriter dict_entry_writer(NULL);
+ array_writer.OpenDictEntry(&dict_entry_writer);
+ dict_entry_writer.AppendString(iter.key());
+ AppendValueDataAsVariant(&dict_entry_writer, iter.value());
+ array_writer.CloseContainer(&dict_entry_writer);
+ }
+ writer->CloseContainer(&array_writer);
+ break;
+ }
+ case base::Value::TYPE_LIST: {
+ const base::ListValue* list = NULL;
+ value.GetAsList(&list);
+ dbus::MessageWriter array_writer(NULL);
+ writer->OpenArray("v", &array_writer);
+ for (base::ListValue::const_iterator iter = list->begin();
+ iter != list->end(); ++iter) {
+ const base::Value* value = *iter;
+ AppendValueDataAsVariant(&array_writer, *value);
+ }
+ writer->CloseContainer(&array_writer);
+ break;
+ }
+ case base::Value::TYPE_BOOLEAN:
+ case base::Value::TYPE_INTEGER:
+ case base::Value::TYPE_DOUBLE:
+ case base::Value::TYPE_STRING:
+ AppendBasicTypeValueData(writer, value);
+ break;
+ default:
+ DLOG(ERROR) << "Unexpected type: " << value.GetType();
+ }
+}
+
+void AppendValueDataAsVariant(MessageWriter* writer, const base::Value& value) {
+ MessageWriter variant_writer(NULL);
+ writer->OpenVariant(GetTypeSignature(value), &variant_writer);
+ AppendValueData(&variant_writer, value);
+ writer->CloseContainer(&variant_writer);
+}
+
} // namespace dbus
« no previous file with comments | « dbus/values_util.h ('k') | dbus/values_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698