| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 91 |
| 92 std::unique_ptr<base::Value> PopDataAsValue(MessageReader* reader) { | 92 std::unique_ptr<base::Value> PopDataAsValue(MessageReader* reader) { |
| 93 std::unique_ptr<base::Value> result; | 93 std::unique_ptr<base::Value> result; |
| 94 switch (reader->GetDataType()) { | 94 switch (reader->GetDataType()) { |
| 95 case Message::INVALID_DATA: | 95 case Message::INVALID_DATA: |
| 96 // Do nothing. | 96 // Do nothing. |
| 97 break; | 97 break; |
| 98 case Message::BYTE: { | 98 case Message::BYTE: { |
| 99 uint8_t value = 0; | 99 uint8_t value = 0; |
| 100 if (reader->PopByte(&value)) | 100 if (reader->PopByte(&value)) |
| 101 result = base::MakeUnique<base::FundamentalValue>(value); | 101 result = base::MakeUnique<base::Value>(value); |
| 102 break; | 102 break; |
| 103 } | 103 } |
| 104 case Message::BOOL: { | 104 case Message::BOOL: { |
| 105 bool value = false; | 105 bool value = false; |
| 106 if (reader->PopBool(&value)) | 106 if (reader->PopBool(&value)) |
| 107 result = base::MakeUnique<base::FundamentalValue>(value); | 107 result = base::MakeUnique<base::Value>(value); |
| 108 break; | 108 break; |
| 109 } | 109 } |
| 110 case Message::INT16: { | 110 case Message::INT16: { |
| 111 int16_t value = 0; | 111 int16_t value = 0; |
| 112 if (reader->PopInt16(&value)) | 112 if (reader->PopInt16(&value)) |
| 113 result = base::MakeUnique<base::FundamentalValue>(value); | 113 result = base::MakeUnique<base::Value>(value); |
| 114 break; | 114 break; |
| 115 } | 115 } |
| 116 case Message::UINT16: { | 116 case Message::UINT16: { |
| 117 uint16_t value = 0; | 117 uint16_t value = 0; |
| 118 if (reader->PopUint16(&value)) | 118 if (reader->PopUint16(&value)) |
| 119 result = base::MakeUnique<base::FundamentalValue>(value); | 119 result = base::MakeUnique<base::Value>(value); |
| 120 break; | 120 break; |
| 121 } | 121 } |
| 122 case Message::INT32: { | 122 case Message::INT32: { |
| 123 int32_t value = 0; | 123 int32_t value = 0; |
| 124 if (reader->PopInt32(&value)) | 124 if (reader->PopInt32(&value)) |
| 125 result = base::MakeUnique<base::FundamentalValue>(value); | 125 result = base::MakeUnique<base::Value>(value); |
| 126 break; | 126 break; |
| 127 } | 127 } |
| 128 case Message::UINT32: { | 128 case Message::UINT32: { |
| 129 uint32_t value = 0; | 129 uint32_t value = 0; |
| 130 if (reader->PopUint32(&value)) { | 130 if (reader->PopUint32(&value)) { |
| 131 result = base::MakeUnique<base::FundamentalValue>( | 131 result = base::MakeUnique<base::Value>(static_cast<double>(value)); |
| 132 static_cast<double>(value)); | |
| 133 } | 132 } |
| 134 break; | 133 break; |
| 135 } | 134 } |
| 136 case Message::INT64: { | 135 case Message::INT64: { |
| 137 int64_t value = 0; | 136 int64_t value = 0; |
| 138 if (reader->PopInt64(&value)) { | 137 if (reader->PopInt64(&value)) { |
| 139 DLOG_IF(WARNING, !IsExactlyRepresentableByDouble(value)) << | 138 DLOG_IF(WARNING, !IsExactlyRepresentableByDouble(value)) << |
| 140 value << " is not exactly representable by double"; | 139 value << " is not exactly representable by double"; |
| 141 result = base::MakeUnique<base::FundamentalValue>( | 140 result = base::MakeUnique<base::Value>(static_cast<double>(value)); |
| 142 static_cast<double>(value)); | |
| 143 } | 141 } |
| 144 break; | 142 break; |
| 145 } | 143 } |
| 146 case Message::UINT64: { | 144 case Message::UINT64: { |
| 147 uint64_t value = 0; | 145 uint64_t value = 0; |
| 148 if (reader->PopUint64(&value)) { | 146 if (reader->PopUint64(&value)) { |
| 149 DLOG_IF(WARNING, !IsExactlyRepresentableByDouble(value)) << | 147 DLOG_IF(WARNING, !IsExactlyRepresentableByDouble(value)) << |
| 150 value << " is not exactly representable by double"; | 148 value << " is not exactly representable by double"; |
| 151 result = base::MakeUnique<base::FundamentalValue>( | 149 result = base::MakeUnique<base::Value>(static_cast<double>(value)); |
| 152 static_cast<double>(value)); | |
| 153 } | 150 } |
| 154 break; | 151 break; |
| 155 } | 152 } |
| 156 case Message::DOUBLE: { | 153 case Message::DOUBLE: { |
| 157 double value = 0; | 154 double value = 0; |
| 158 if (reader->PopDouble(&value)) | 155 if (reader->PopDouble(&value)) |
| 159 result = base::MakeUnique<base::FundamentalValue>(value); | 156 result = base::MakeUnique<base::Value>(value); |
| 160 break; | 157 break; |
| 161 } | 158 } |
| 162 case Message::STRING: { | 159 case Message::STRING: { |
| 163 std::string value; | 160 std::string value; |
| 164 if (reader->PopString(&value)) | 161 if (reader->PopString(&value)) |
| 165 result = base::MakeUnique<base::StringValue>(value); | 162 result = base::MakeUnique<base::StringValue>(value); |
| 166 break; | 163 break; |
| 167 } | 164 } |
| 168 case Message::OBJECT_PATH: { | 165 case Message::OBJECT_PATH: { |
| 169 ObjectPath value; | 166 ObjectPath value; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 } | 299 } |
| 303 | 300 |
| 304 void AppendValueDataAsVariant(MessageWriter* writer, const base::Value& value) { | 301 void AppendValueDataAsVariant(MessageWriter* writer, const base::Value& value) { |
| 305 MessageWriter variant_writer(NULL); | 302 MessageWriter variant_writer(NULL); |
| 306 writer->OpenVariant(GetTypeSignature(value), &variant_writer); | 303 writer->OpenVariant(GetTypeSignature(value), &variant_writer); |
| 307 AppendValueData(&variant_writer, value); | 304 AppendValueData(&variant_writer, value); |
| 308 writer->CloseContainer(&variant_writer); | 305 writer->CloseContainer(&variant_writer); |
| 309 } | 306 } |
| 310 | 307 |
| 311 } // namespace dbus | 308 } // namespace dbus |
| OLD | NEW |