Skip to content

Commit

Permalink
Cleanup: Remove deprecated base::Value methods from dbus. Use base::V…
Browse files Browse the repository at this point in the history
…alue too.

Review URL: https://chromiumcodereview.appspot.com/12207091

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@181989 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
thestig@chromium.org committed Feb 12, 2013
1 parent 7c2cdd2 commit f40b736
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 71 deletions.
43 changes: 22 additions & 21 deletions dbus/values_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ bool IsExactlyRepresentableByDouble(T value) {
}

// Pops values from |reader| and appends them to |list_value|.
bool PopListElements(MessageReader* reader, ListValue* list_value) {
bool PopListElements(MessageReader* reader, base::ListValue* list_value) {
while (reader->HasMoreData()) {
Value* element_value = PopDataAsValue(reader);
base::Value* element_value = PopDataAsValue(reader);
if (!element_value)
return false;
list_value->Append(element_value);
Expand All @@ -33,7 +33,7 @@ bool PopListElements(MessageReader* reader, ListValue* list_value) {

// Pops dict-entries from |reader| and sets them to |dictionary_value|
bool PopDictionaryEntries(MessageReader* reader,
DictionaryValue* dictionary_value) {
base::DictionaryValue* dictionary_value) {
while (reader->HasMoreData()) {
DCHECK_EQ(Message::DICT_ENTRY, reader->GetDataType());
MessageReader entry_reader(NULL);
Expand All @@ -47,14 +47,14 @@ bool PopDictionaryEntries(MessageReader* reader,
return false;
} else {
// If the type of keys is not STRING, convert it to string.
scoped_ptr<Value> key(PopDataAsValue(&entry_reader));
scoped_ptr<base::Value> key(PopDataAsValue(&entry_reader));
if (!key.get())
return false;
// Use JSONWriter to convert an arbitrary value to a string.
base::JSONWriter::Write(key.get(), &key_string);
}
// Get the value and set the key-value pair.
Value* value = PopDataAsValue(&entry_reader);
base::Value* value = PopDataAsValue(&entry_reader);
if (!value)
return false;
dictionary_value->SetWithoutPathExpansion(key_string, value);
Expand Down Expand Up @@ -85,54 +85,54 @@ std::string GetTypeSignature(const base::Value& value) {

} // namespace

Value* PopDataAsValue(MessageReader* reader) {
Value* result = NULL;
base::Value* PopDataAsValue(MessageReader* reader) {
base::Value* result = NULL;
switch (reader->GetDataType()) {
case Message::INVALID_DATA:
// Do nothing.
break;
case Message::BYTE: {
uint8 value = 0;
if (reader->PopByte(&value))
result = Value::CreateIntegerValue(value);
result = new base::FundamentalValue(value);
break;
}
case Message::BOOL: {
bool value = false;
if (reader->PopBool(&value))
result = Value::CreateBooleanValue(value);
result = new base::FundamentalValue(value);
break;
}
case Message::INT16: {
int16 value = 0;
if (reader->PopInt16(&value))
result = Value::CreateIntegerValue(value);
result = new base::FundamentalValue(value);
break;
}
case Message::UINT16: {
uint16 value = 0;
if (reader->PopUint16(&value))
result = Value::CreateIntegerValue(value);
result = new base::FundamentalValue(value);
break;
}
case Message::INT32: {
int32 value = 0;
if (reader->PopInt32(&value))
result = Value::CreateIntegerValue(value);
result = new base::FundamentalValue(value);
break;
}
case Message::UINT32: {
uint32 value = 0;
if (reader->PopUint32(&value))
result = Value::CreateDoubleValue(value);
result = new base::FundamentalValue(static_cast<double>(value));
break;
}
case Message::INT64: {
int64 value = 0;
if (reader->PopInt64(&value)) {
DLOG_IF(WARNING, !IsExactlyRepresentableByDouble(value)) <<
value << " is not exactly representable by double";
result = Value::CreateDoubleValue(value);
result = new base::FundamentalValue(static_cast<double>(value));
}
break;
}
Expand All @@ -141,26 +141,26 @@ Value* PopDataAsValue(MessageReader* reader) {
if (reader->PopUint64(&value)) {
DLOG_IF(WARNING, !IsExactlyRepresentableByDouble(value)) <<
value << " is not exactly representable by double";
result = Value::CreateDoubleValue(value);
result = new base::FundamentalValue(static_cast<double>(value));
}
break;
}
case Message::DOUBLE: {
double value = 0;
if (reader->PopDouble(&value))
result = Value::CreateDoubleValue(value);
result = new base::FundamentalValue(value);
break;
}
case Message::STRING: {
std::string value;
if (reader->PopString(&value))
result = Value::CreateStringValue(value);
result = new base::StringValue(value);
break;
}
case Message::OBJECT_PATH: {
ObjectPath value;
if (reader->PopObjectPath(&value))
result = Value::CreateStringValue(value.value());
result = new base::StringValue(value.value());
break;
}
case Message::UNIX_FD: {
Expand All @@ -174,11 +174,12 @@ Value* PopDataAsValue(MessageReader* reader) {
// If the type of the array's element is DICT_ENTRY, create a
// DictionaryValue, otherwise create a ListValue.
if (sub_reader.GetDataType() == Message::DICT_ENTRY) {
scoped_ptr<DictionaryValue> dictionary_value(new DictionaryValue);
scoped_ptr<base::DictionaryValue> dictionary_value(
new base::DictionaryValue);
if (PopDictionaryEntries(&sub_reader, dictionary_value.get()))
result = dictionary_value.release();
} else {
scoped_ptr<ListValue> list_value(new ListValue);
scoped_ptr<base::ListValue> list_value(new base::ListValue);
if (PopListElements(&sub_reader, list_value.get()))
result = list_value.release();
}
Expand All @@ -188,7 +189,7 @@ Value* PopDataAsValue(MessageReader* reader) {
case Message::STRUCT: {
MessageReader sub_reader(NULL);
if (reader->PopStruct(&sub_reader)) {
scoped_ptr<ListValue> list_value(new ListValue);
scoped_ptr<base::ListValue> list_value(new base::ListValue);
if (PopListElements(&sub_reader, list_value.get()))
result = list_value.release();
}
Expand Down
Loading

0 comments on commit f40b736

Please sign in to comment.