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

Side by Side 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, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « dbus/values_util.h ('k') | dbus/values_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "dbus/values_util.h" 5 #include "dbus/values_util.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 case base::Value::TYPE_INTEGER: 70 case base::Value::TYPE_INTEGER:
71 return "i"; 71 return "i";
72 case base::Value::TYPE_DOUBLE: 72 case base::Value::TYPE_DOUBLE:
73 return "d"; 73 return "d";
74 case base::Value::TYPE_STRING: 74 case base::Value::TYPE_STRING:
75 return "s"; 75 return "s";
76 case base::Value::TYPE_BINARY: 76 case base::Value::TYPE_BINARY:
77 return "ay"; 77 return "ay";
78 case base::Value::TYPE_DICTIONARY: 78 case base::Value::TYPE_DICTIONARY:
79 return "a{sv}"; 79 return "a{sv}";
80 case base::Value::TYPE_LIST:
81 return "av";
80 default: 82 default:
81 DLOG(ERROR) << "Unexpected type " << value.GetType(); 83 DLOG(ERROR) << "Unexpected type " << value.GetType();
82 return std::string(); 84 return std::string();
83 } 85 }
84 } 86 }
85 87
86 } // namespace 88 } // namespace
87 89
88 base::Value* PopDataAsValue(MessageReader* reader) { 90 base::Value* PopDataAsValue(MessageReader* reader) {
89 base::Value* result = NULL; 91 base::Value* result = NULL;
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 } 248 }
247 249
248 void AppendBasicTypeValueDataAsVariant(MessageWriter* writer, 250 void AppendBasicTypeValueDataAsVariant(MessageWriter* writer,
249 const base::Value& value) { 251 const base::Value& value) {
250 MessageWriter sub_writer(NULL); 252 MessageWriter sub_writer(NULL);
251 writer->OpenVariant(GetTypeSignature(value), &sub_writer); 253 writer->OpenVariant(GetTypeSignature(value), &sub_writer);
252 AppendBasicTypeValueData(&sub_writer, value); 254 AppendBasicTypeValueData(&sub_writer, value);
253 writer->CloseContainer(&sub_writer); 255 writer->CloseContainer(&sub_writer);
254 } 256 }
255 257
258 void AppendValueData(MessageWriter* writer, const base::Value& value) {
259 switch (value.GetType()) {
260 case base::Value::TYPE_DICTIONARY: {
261 const base::DictionaryValue* dictionary = NULL;
262 value.GetAsDictionary(&dictionary);
263 dbus::MessageWriter array_writer(NULL);
264 writer->OpenArray("{sv}", &array_writer);
265 for (base::DictionaryValue::Iterator iter(*dictionary);
266 !iter.IsAtEnd(); iter.Advance()) {
267 dbus::MessageWriter dict_entry_writer(NULL);
268 array_writer.OpenDictEntry(&dict_entry_writer);
269 dict_entry_writer.AppendString(iter.key());
270 AppendValueDataAsVariant(&dict_entry_writer, iter.value());
271 array_writer.CloseContainer(&dict_entry_writer);
272 }
273 writer->CloseContainer(&array_writer);
274 break;
275 }
276 case base::Value::TYPE_LIST: {
277 const base::ListValue* list = NULL;
278 value.GetAsList(&list);
279 dbus::MessageWriter array_writer(NULL);
280 writer->OpenArray("v", &array_writer);
281 for (base::ListValue::const_iterator iter = list->begin();
282 iter != list->end(); ++iter) {
283 const base::Value* value = *iter;
284 AppendValueDataAsVariant(&array_writer, *value);
285 }
286 writer->CloseContainer(&array_writer);
287 break;
288 }
289 case base::Value::TYPE_BOOLEAN:
290 case base::Value::TYPE_INTEGER:
291 case base::Value::TYPE_DOUBLE:
292 case base::Value::TYPE_STRING:
293 AppendBasicTypeValueData(writer, value);
294 break;
295 default:
296 DLOG(ERROR) << "Unexpected type: " << value.GetType();
297 }
298 }
299
300 void AppendValueDataAsVariant(MessageWriter* writer, const base::Value& value) {
301 MessageWriter variant_writer(NULL);
302 writer->OpenVariant(GetTypeSignature(value), &variant_writer);
303 AppendValueData(&variant_writer, value);
304 writer->CloseContainer(&variant_writer);
305 }
306
256 } // namespace dbus 307 } // namespace dbus
OLDNEW
« 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