Pull the new r369476 of base library from Chromium
The merge was done against r369476 which corresponds to git commit
0471d0e2e2ef4a544a63481a389e1df33ea7c00a of Jan 14, 2016
Change-Id: Ie6894cf65424cc5ad115110faccd51602b2d1234
Reviewed-on: https://weave-review.googlesource.com/2225
Reviewed-by: Alex Vakulenko <avakulenko@google.com>
diff --git a/third_party/chromium/base/values.cc b/third_party/chromium/base/values.cc
index 689fdd7..55719da 100644
--- a/third_party/chromium/base/values.cc
+++ b/third_party/chromium/base/values.cc
@@ -9,6 +9,7 @@
#include <algorithm>
#include <cmath>
#include <ostream>
+#include <utility>
#include "base/json/json_writer.h"
#include "base/logging.h"
@@ -32,7 +33,7 @@
if (child_copy) {
if (!copy)
copy.reset(new ListValue);
- copy->Append(child_copy.Pass());
+ copy->Append(std::move(child_copy));
}
}
return copy;
@@ -46,7 +47,7 @@
if (child_copy) {
if (!copy)
copy.reset(new DictionaryValue);
- copy->SetWithoutPathExpansion(it.key(), child_copy.Pass());
+ copy->SetWithoutPathExpansion(it.key(), std::move(child_copy));
}
}
return copy;
@@ -92,23 +93,23 @@
return make_scoped_ptr(new Value(TYPE_NULL));
}
-bool Value::GetAsBinary(const BinaryValue** out_value) const {
+bool Value::GetAsBinary(const BinaryValue** /* out_value */) const {
return false;
}
-bool Value::GetAsBoolean(bool* out_value) const {
+bool Value::GetAsBoolean(bool* /* out_value */) const {
return false;
}
-bool Value::GetAsInteger(int* out_value) const {
+bool Value::GetAsInteger(int* /* out_value */) const {
return false;
}
-bool Value::GetAsDouble(double* out_value) const {
+bool Value::GetAsDouble(double* /* out_value */) const {
return false;
}
-bool Value::GetAsString(std::string* out_value) const {
+bool Value::GetAsString(std::string* /* out_value */) const {
return false;
}
@@ -116,19 +117,19 @@
return false;
}
-bool Value::GetAsList(ListValue** out_value) {
+bool Value::GetAsList(ListValue** /* out_value */) {
return false;
}
-bool Value::GetAsList(const ListValue** out_value) const {
+bool Value::GetAsList(const ListValue** /* out_value */) const {
return false;
}
-bool Value::GetAsDictionary(DictionaryValue** out_value) {
+bool Value::GetAsDictionary(DictionaryValue** /* out_value */) {
return false;
}
-bool Value::GetAsDictionary(const DictionaryValue** out_value) const {
+bool Value::GetAsDictionary(const DictionaryValue** /* out_value */) const {
return false;
}
@@ -298,10 +299,7 @@
}
BinaryValue::BinaryValue(scoped_ptr<char[]> buffer, size_t size)
- : Value(TYPE_BINARY),
- buffer_(buffer.Pass()),
- size_(size) {
-}
+ : Value(TYPE_BINARY), buffer_(std::move(buffer)), size_(size) {}
BinaryValue::~BinaryValue() {
}
@@ -312,7 +310,7 @@
char* buffer_copy = new char[size];
memcpy(buffer_copy, buffer, size);
scoped_ptr<char[]> scoped_buffer_copy(buffer_copy);
- return new BinaryValue(scoped_buffer_copy.Pass(), size);
+ return new BinaryValue(std::move(scoped_buffer_copy), size);
}
bool BinaryValue::GetAsBinary(const BinaryValue** out_value) const {
@@ -336,6 +334,16 @@
///////////////////// DictionaryValue ////////////////////
+// static
+scoped_ptr<DictionaryValue> DictionaryValue::From(scoped_ptr<Value> value) {
+ DictionaryValue* out;
+ if (value && value->GetAsDictionary(&out)) {
+ ignore_result(value.release());
+ return make_scoped_ptr(out);
+ }
+ return nullptr;
+}
+
DictionaryValue::DictionaryValue()
: Value(TYPE_DICTIONARY) {
}
@@ -394,7 +402,8 @@
current_path.erase(0, delimiter_position + 1);
}
- current_dictionary->SetWithoutPathExpansion(current_path, in_value.Pass());
+ current_dictionary->SetWithoutPathExpansion(current_path,
+ std::move(in_value));
}
void DictionaryValue::Set(const std::string& path, Value* in_value) {
@@ -457,27 +466,30 @@
SetWithoutPathExpansion(path, new StringValue(in_value));
}
-bool DictionaryValue::Get(const std::string& path,
+bool DictionaryValue::Get(StringPiece path,
const Value** out_value) const {
DCHECK(IsStringUTF8(path));
- std::string current_path(path);
+ StringPiece current_path(path);
const DictionaryValue* current_dictionary = this;
for (size_t delimiter_position = current_path.find('.');
delimiter_position != std::string::npos;
delimiter_position = current_path.find('.')) {
const DictionaryValue* child_dictionary = NULL;
- if (!current_dictionary->GetDictionary(
- current_path.substr(0, delimiter_position), &child_dictionary))
+ if (!current_dictionary->GetDictionaryWithoutPathExpansion(
+ current_path.substr(0, delimiter_position).as_string(),
+ &child_dictionary)) {
return false;
+ }
current_dictionary = child_dictionary;
- current_path.erase(0, delimiter_position + 1);
+ current_path = current_path.substr(delimiter_position + 1);
}
- return current_dictionary->GetWithoutPathExpansion(current_path, out_value);
+ return current_dictionary->GetWithoutPathExpansion(current_path.as_string(),
+ out_value);
}
-bool DictionaryValue::Get(const std::string& path, Value** out_value) {
+bool DictionaryValue::Get(StringPiece path, Value** out_value) {
return static_cast<const DictionaryValue&>(*this).Get(
path,
const_cast<const Value**>(out_value));
@@ -554,7 +566,7 @@
const_cast<const BinaryValue**>(out_value));
}
-bool DictionaryValue::GetDictionary(const std::string& path,
+bool DictionaryValue::GetDictionary(StringPiece path,
const DictionaryValue** out_value) const {
const Value* value;
bool result = Get(path, &value);
@@ -567,7 +579,7 @@
return true;
}
-bool DictionaryValue::GetDictionary(const std::string& path,
+bool DictionaryValue::GetDictionary(StringPiece path,
DictionaryValue** out_value) {
return static_cast<const DictionaryValue&>(*this).GetDictionary(
path,
@@ -824,6 +836,16 @@
///////////////////// ListValue ////////////////////
+// static
+scoped_ptr<ListValue> ListValue::From(scoped_ptr<Value> value) {
+ ListValue* out;
+ if (value && value->GetAsList(&out)) {
+ ignore_result(value.release());
+ return make_scoped_ptr(out);
+ }
+ return nullptr;
+}
+
ListValue::ListValue() : Value(TYPE_LIST) {
}