OLD | NEW |
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 30 matching lines...) Expand all Loading... |
41 return false; | 41 return false; |
42 // Get key as a string. | 42 // Get key as a string. |
43 std::string key_string; | 43 std::string key_string; |
44 if (entry_reader.GetDataType() == Message::STRING) { | 44 if (entry_reader.GetDataType() == Message::STRING) { |
45 // If the type of keys is STRING, pop it directly. | 45 // If the type of keys is STRING, pop it directly. |
46 if (!entry_reader.PopString(&key_string)) | 46 if (!entry_reader.PopString(&key_string)) |
47 return false; | 47 return false; |
48 } else { | 48 } else { |
49 // If the type of keys is not STRING, convert it to string. | 49 // If the type of keys is not STRING, convert it to string. |
50 scoped_ptr<base::Value> key(PopDataAsValue(&entry_reader)); | 50 scoped_ptr<base::Value> key(PopDataAsValue(&entry_reader)); |
51 if (!key.get()) | 51 if (!key) |
52 return false; | 52 return false; |
53 // Use JSONWriter to convert an arbitrary value to a string. | 53 // Use JSONWriter to convert an arbitrary value to a string. |
54 base::JSONWriter::Write(key.get(), &key_string); | 54 base::JSONWriter::Write(*key, &key_string); |
55 } | 55 } |
56 // Get the value and set the key-value pair. | 56 // Get the value and set the key-value pair. |
57 base::Value* value = PopDataAsValue(&entry_reader); | 57 base::Value* value = PopDataAsValue(&entry_reader); |
58 if (!value) | 58 if (!value) |
59 return false; | 59 return false; |
60 dictionary_value->SetWithoutPathExpansion(key_string, value); | 60 dictionary_value->SetWithoutPathExpansion(key_string, value); |
61 } | 61 } |
62 return true; | 62 return true; |
63 } | 63 } |
64 | 64 |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 } | 298 } |
299 | 299 |
300 void AppendValueDataAsVariant(MessageWriter* writer, const base::Value& value) { | 300 void AppendValueDataAsVariant(MessageWriter* writer, const base::Value& value) { |
301 MessageWriter variant_writer(NULL); | 301 MessageWriter variant_writer(NULL); |
302 writer->OpenVariant(GetTypeSignature(value), &variant_writer); | 302 writer->OpenVariant(GetTypeSignature(value), &variant_writer); |
303 AppendValueData(&variant_writer, value); | 303 AppendValueData(&variant_writer, value); |
304 writer->CloseContainer(&variant_writer); | 304 writer->CloseContainer(&variant_writer); |
305 } | 305 } |
306 | 306 |
307 } // namespace dbus | 307 } // namespace dbus |
OLD | NEW |