summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorstevenjb@google.com <stevenjb@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-26 01:54:00 +0000
committerstevenjb@google.com <stevenjb@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-26 01:54:00 +0000
commit0de764e26db70294974f67061ab2d991c739e27f (patch)
treec3d7cfa40628e20496f65ce7abd56daebc521077 /base
parent79d0b6726455b644b1a2532cea21a421ce2f9990 (diff)
downloadchromium_src-0de764e26db70294974f67061ab2d991c739e27f.zip
chromium_src-0de764e26db70294974f67061ab2d991c739e27f.tar.gz
chromium_src-0de764e26db70294974f67061ab2d991c739e27f.tar.bz2
Revert recent changes to base::Value
Reverts: 98223: base: Add AsList() function to Value API. 98266: base: Add AsBinary() function to Value API. There are two issues with these commits: 1. libcros uses base::Value to pass data to Chrome. It includes values.h from libchrome which contains its own copy. This is a terrible design flaw in libcros and is being addressed (http://crosbug.com/19576), however we need some time to address this before we can make these changes without breaking Chrome on ChromeOS. 2. AsList() and AsBinary() should be const. The fact that they were not const caused re-factoring that changed const Value& input arguments to Value*, which is against the spec. When we re-introduce this, these members should be made const. BUG=chromium-os:19604 TEST=Check bots + ChromeOS autotests Review URL: http://codereview.chromium.org/7753020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98378 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/json/json_reader_unittest.cc20
-rw-r--r--base/values.cc34
-rw-r--r--base/values.h5
-rw-r--r--base/values_unittest.cc17
4 files changed, 28 insertions, 48 deletions
diff --git a/base/json/json_reader_unittest.cc b/base/json/json_reader_unittest.cc
index 7623a68..a7aeaf0 100644
--- a/base/json/json_reader_unittest.cc
+++ b/base/json/json_reader_unittest.cc
@@ -222,8 +222,8 @@ TEST(JSONReaderTest, Reading) {
// Basic array
root.reset(JSONReader::Read("[true, false, null]", false));
ASSERT_TRUE(root.get());
- ListValue* list = root->AsList();
- ASSERT_TRUE(list);
+ ASSERT_TRUE(root->IsType(Value::TYPE_LIST));
+ ListValue* list = static_cast<ListValue*>(root.get());
ASSERT_EQ(3U, list->GetSize());
// Test with trailing comma. Should be parsed the same as above.
@@ -234,16 +234,16 @@ TEST(JSONReaderTest, Reading) {
// Empty array
root.reset(JSONReader::Read("[]", false));
ASSERT_TRUE(root.get());
- list = root->AsList();
- ASSERT_TRUE(list);
+ ASSERT_TRUE(root->IsType(Value::TYPE_LIST));
+ list = static_cast<ListValue*>(root.get());
ASSERT_EQ(0U, list->GetSize());
// Nested arrays
root.reset(JSONReader::Read("[[true], [], [false, [], [null]], null]",
false));
ASSERT_TRUE(root.get());
- list = root->AsList();
- ASSERT_TRUE(list);
+ ASSERT_TRUE(root->IsType(Value::TYPE_LIST));
+ list = static_cast<ListValue*>(root.get());
ASSERT_EQ(4U, list->GetSize());
// Lots of trailing commas.
@@ -272,8 +272,8 @@ TEST(JSONReaderTest, Reading) {
// Valid if we set |allow_trailing_comma| to true.
root.reset(JSONReader::Read("[true,]", true));
ASSERT_TRUE(root.get());
- list = root->AsList();
- ASSERT_TRUE(list);
+ ASSERT_TRUE(root->IsType(Value::TYPE_LIST));
+ list = static_cast<ListValue*>(root.get());
EXPECT_EQ(1U, list->GetSize());
Value* tmp_value = NULL;
ASSERT_TRUE(list->Get(0, &tmp_value));
@@ -435,8 +435,8 @@ TEST(JSONReaderTest, Reading) {
not_evil.append("[]]");
root.reset(JSONReader::Read(not_evil, false));
ASSERT_TRUE(root.get());
- list = root->AsList();
- ASSERT_TRUE(list);
+ ASSERT_TRUE(root->IsType(Value::TYPE_LIST));
+ list = static_cast<ListValue*>(root.get());
ASSERT_EQ(5001U, list->GetSize());
// Test utf8 encoded input
diff --git a/base/values.cc b/base/values.cc
index ad53469..17aba16 100644
--- a/base/values.cc
+++ b/base/values.cc
@@ -18,7 +18,7 @@ Value* CopyWithoutEmptyChildren(Value* node) {
DCHECK(node);
switch (node->GetType()) {
case Value::TYPE_LIST: {
- ListValue* list = node->AsList();
+ ListValue* list = static_cast<ListValue*>(node);
ListValue* copy = new ListValue;
for (ListValue::const_iterator it = list->begin(); it != list->end();
++it) {
@@ -97,14 +97,6 @@ StringValue* Value::CreateStringValue(const string16& in_value) {
return new StringValue(in_value);
}
-BinaryValue* Value::AsBinary() {
- return NULL;
-}
-
-ListValue* Value::AsList() {
- return NULL;
-}
-
bool Value::GetAsBoolean(bool* out_value) const {
return false;
}
@@ -305,10 +297,6 @@ BinaryValue* BinaryValue::CreateWithCopiedBuffer(const char* buffer,
return new BinaryValue(buffer_copy, size);
}
-BinaryValue* BinaryValue::AsBinary() {
- return this;
-}
-
BinaryValue* BinaryValue::DeepCopy() const {
return CreateWithCopiedBuffer(buffer_, size_);
}
@@ -497,11 +485,11 @@ bool DictionaryValue::GetBinary(const std::string& path,
BinaryValue** out_value) const {
Value* value;
bool result = Get(path, &value);
- if (!result || !value->AsBinary())
+ if (!result || !value->IsType(TYPE_BINARY))
return false;
if (out_value)
- *out_value = value->AsBinary();
+ *out_value = static_cast<BinaryValue*>(value);
return true;
}
@@ -523,11 +511,11 @@ bool DictionaryValue::GetList(const std::string& path,
ListValue** out_value) const {
Value* value;
bool result = Get(path, &value);
- if (!result || !value->AsList())
+ if (!result || !value->IsType(TYPE_LIST))
return false;
if (out_value)
- *out_value = value->AsList();
+ *out_value = static_cast<ListValue*>(value);
return true;
}
@@ -601,11 +589,11 @@ bool DictionaryValue::GetListWithoutPathExpansion(const std::string& key,
ListValue** out_value) const {
Value* value;
bool result = GetWithoutPathExpansion(key, &value);
- if (!result || !value->AsList())
+ if (!result || !value->IsType(TYPE_LIST))
return false;
if (out_value)
- *out_value = value->AsList();
+ *out_value = static_cast<ListValue*>(value);
return true;
}
@@ -814,11 +802,11 @@ bool ListValue::GetDictionary(size_t index, DictionaryValue** out_value) const {
bool ListValue::GetList(size_t index, ListValue** out_value) const {
Value* value;
bool result = Get(index, &value);
- if (!result || !value->AsList())
+ if (!result || !value->IsType(TYPE_LIST))
return false;
if (out_value)
- *out_value = value->AsList();
+ *out_value = static_cast<ListValue*>(value);
return true;
}
@@ -877,10 +865,6 @@ bool ListValue::Insert(size_t index, Value* in_value) {
return true;
}
-ListValue* ListValue::AsList() {
- return this;
-}
-
bool ListValue::GetAsList(ListValue** out_value) {
if (out_value)
*out_value = this;
diff --git a/base/values.h b/base/values.h
index 185729d..a30791b 100644
--- a/base/values.h
+++ b/base/values.h
@@ -87,9 +87,6 @@ class BASE_EXPORT Value {
// Returns true if the current object represents a given type.
bool IsType(Type type) const { return type == type_; }
- virtual BinaryValue* AsBinary();
- virtual ListValue* AsList();
-
// These methods allow the convenient retrieval of settings.
// If the current setting object can be converted into the given type,
// the value is returned through the |out_value| parameter and true is
@@ -196,7 +193,6 @@ class BASE_EXPORT BinaryValue: public Value {
const char* GetBuffer() const { return buffer_; }
// Overridden from Value:
- virtual BinaryValue* AsBinary() OVERRIDE;
virtual BinaryValue* DeepCopy() const OVERRIDE;
virtual bool Equals(const Value* other) const OVERRIDE;
@@ -435,7 +431,6 @@ class BASE_EXPORT ListValue : public Value {
const_iterator end() const { return list_.end(); }
// Overridden from Value:
- virtual ListValue* AsList() OVERRIDE;
virtual bool GetAsList(ListValue** out_value) OVERRIDE;
virtual bool GetAsList(const ListValue** out_value) const OVERRIDE;
virtual ListValue* DeepCopy() const OVERRIDE;
diff --git a/base/values_unittest.cc b/base/values_unittest.cc
index 0ca19d9..553e8e1 100644
--- a/base/values_unittest.cc
+++ b/base/values_unittest.cc
@@ -416,20 +416,21 @@ TEST(ValuesTest, DeepCopy) {
ASSERT_TRUE(copy_dict->Get("binary", &copy_binary));
ASSERT_TRUE(copy_binary);
ASSERT_NE(copy_binary, original_binary);
- BinaryValue* binary_value = copy_binary->AsBinary();
- ASSERT_TRUE(binary_value);
- ASSERT_NE(original_binary->GetBuffer(), binary_value->GetBuffer());
- ASSERT_EQ(original_binary->GetSize(), binary_value->GetSize());
+ ASSERT_TRUE(copy_binary->IsType(Value::TYPE_BINARY));
+ ASSERT_NE(original_binary->GetBuffer(),
+ static_cast<BinaryValue*>(copy_binary)->GetBuffer());
+ ASSERT_EQ(original_binary->GetSize(),
+ static_cast<BinaryValue*>(copy_binary)->GetSize());
ASSERT_EQ(0, memcmp(original_binary->GetBuffer(),
- binary_value->GetBuffer(),
- original_binary->GetSize()));
+ static_cast<BinaryValue*>(copy_binary)->GetBuffer(),
+ original_binary->GetSize()));
Value* copy_value = NULL;
ASSERT_TRUE(copy_dict->Get("list", &copy_value));
ASSERT_TRUE(copy_value);
ASSERT_NE(copy_value, original_list);
- ListValue* copy_list = copy_value->AsList();
- ASSERT_TRUE(copy_list != NULL);
+ ASSERT_TRUE(copy_value->IsType(Value::TYPE_LIST));
+ ListValue* copy_list = static_cast<ListValue*>(copy_value);
ASSERT_EQ(2U, copy_list->GetSize());
Value* copy_list_element_0;