summaryrefslogtreecommitdiffstats
path: root/chromium/base/values.cc
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2018-01-29 16:35:13 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2018-02-01 15:33:35 +0000
commitc8c2d1901aec01e934adf561a9fdf0cc776cdef8 (patch)
tree9157c3d9815e5870799e070b113813bec53e0535 /chromium/base/values.cc
parentabefd5095b41dac94ca451d784ab6e27372e981a (diff)
BASELINE: Update Chromium to 64.0.3282.139
Change-Id: I1cae68fe9c94ff7608b26b8382fc19862cdb293a Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/base/values.cc')
-rw-r--r--chromium/base/values.cc90
1 files changed, 44 insertions, 46 deletions
diff --git a/chromium/base/values.cc b/chromium/base/values.cc
index 8d321619e12..76e973221b1 100644
--- a/chromium/base/values.cc
+++ b/chromium/base/values.cc
@@ -17,6 +17,7 @@
#include "base/memory/ptr_util.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/trace_event/memory_usage_estimator.h"
namespace base {
@@ -80,6 +81,16 @@ std::unique_ptr<Value> Value::CreateWithCopiedBuffer(const char* buffer,
return std::make_unique<Value>(BlobStorage(buffer, buffer + size));
}
+// static
+Value Value::FromUniquePtrValue(std::unique_ptr<Value> val) {
+ return std::move(*val);
+}
+
+// static
+std::unique_ptr<Value> Value::ToUniquePtrValue(Value val) {
+ return std::make_unique<Value>(std::move(val));
+}
+
Value::Value(Value&& that) noexcept {
InternalMoveConstructFrom(std::move(that));
}
@@ -312,6 +323,7 @@ Value* Value::FindPath(span<const StringPiece> path) {
}
const Value* Value::FindPath(std::initializer_list<StringPiece> path) const {
+ DCHECK_GE(path.size(), 2u) << "Use FindKey() for a path of length 1.";
return FindPath(make_span(path.begin(), path.size()));
}
@@ -337,6 +349,7 @@ Value* Value::FindPathOfType(span<const StringPiece> path, Type type) {
const Value* Value::FindPathOfType(std::initializer_list<StringPiece> path,
Type type) const {
+ DCHECK_GE(path.size(), 2u) << "Use FindKeyOfType() for a path of length 1.";
return FindPathOfType(make_span(path.begin(), path.size()), type);
}
@@ -349,6 +362,7 @@ const Value* Value::FindPathOfType(span<const StringPiece> path,
}
Value* Value::SetPath(std::initializer_list<StringPiece> path, Value value) {
+ DCHECK_GE(path.size(), 2u) << "Use SetKey() for a path of length 1.";
return SetPath(make_span(path.begin(), path.size()), std::move(value));
}
@@ -383,6 +397,7 @@ Value* Value::SetPath(span<const StringPiece> path, Value value) {
}
bool Value::RemovePath(std::initializer_list<StringPiece> path) {
+ DCHECK_GE(path.size(), 2u) << "Use RemoveKey() for a path of length 1.";
return RemovePath(make_span(path.begin(), path.size()));
}
@@ -607,6 +622,21 @@ bool Value::Equals(const Value* other) const {
return *this == *other;
}
+size_t Value::EstimateMemoryUsage() const {
+ switch (type_) {
+ case Type::STRING:
+ return base::trace_event::EstimateMemoryUsage(string_value_);
+ case Type::BINARY:
+ return base::trace_event::EstimateMemoryUsage(binary_value_);
+ case Type::DICTIONARY:
+ return base::trace_event::EstimateMemoryUsage(dict_);
+ case Type::LIST:
+ return base::trace_event::EstimateMemoryUsage(list_);
+ default:
+ return 0;
+ }
+}
+
void Value::InternalMoveConstructFrom(Value&& that) {
type_ = that.type_;
@@ -695,24 +725,25 @@ Value* DictionaryValue::Set(StringPiece path, std::unique_ptr<Value> in_value) {
DCHECK(in_value);
StringPiece current_path(path);
- DictionaryValue* current_dictionary = this;
+ Value* current_dictionary = this;
for (size_t delimiter_position = current_path.find('.');
delimiter_position != StringPiece::npos;
delimiter_position = current_path.find('.')) {
// Assume that we're indexing into a dictionary.
StringPiece key = current_path.substr(0, delimiter_position);
- DictionaryValue* child_dictionary = nullptr;
- if (!current_dictionary->GetDictionary(key, &child_dictionary)) {
- child_dictionary = current_dictionary->SetDictionaryWithoutPathExpansion(
- key, std::make_unique<DictionaryValue>());
+ Value* child_dictionary =
+ current_dictionary->FindKeyOfType(key, Type::DICTIONARY);
+ if (!child_dictionary) {
+ child_dictionary =
+ current_dictionary->SetKey(key, Value(Type::DICTIONARY));
}
current_dictionary = child_dictionary;
current_path = current_path.substr(delimiter_position + 1);
}
- return current_dictionary->SetWithoutPathExpansion(current_path,
- std::move(in_value));
+ return static_cast<DictionaryValue*>(current_dictionary)
+ ->SetWithoutPathExpansion(current_path, std::move(in_value));
}
Value* DictionaryValue::SetBoolean(StringPiece path, bool in_value) {
@@ -759,20 +790,6 @@ Value* DictionaryValue::SetWithoutPathExpansion(
return result.first->second.get();
}
-DictionaryValue* DictionaryValue::SetDictionaryWithoutPathExpansion(
- StringPiece path,
- std::unique_ptr<DictionaryValue> in_value) {
- return static_cast<DictionaryValue*>(
- SetWithoutPathExpansion(path, std::move(in_value)));
-}
-
-ListValue* DictionaryValue::SetListWithoutPathExpansion(
- StringPiece path,
- std::unique_ptr<ListValue> in_value) {
- return static_cast<ListValue*>(
- SetWithoutPathExpansion(path, std::move(in_value)));
-}
-
bool DictionaryValue::Get(StringPiece path,
const Value** out_value) const {
DCHECK(IsStringUTF8(path));
@@ -781,7 +798,7 @@ bool DictionaryValue::Get(StringPiece path,
for (size_t delimiter_position = current_path.find('.');
delimiter_position != std::string::npos;
delimiter_position = current_path.find('.')) {
- const DictionaryValue* child_dictionary = NULL;
+ const DictionaryValue* child_dictionary = nullptr;
if (!current_dictionary->GetDictionaryWithoutPathExpansion(
current_path.substr(0, delimiter_position), &child_dictionary)) {
return false;
@@ -1064,13 +1081,13 @@ bool DictionaryValue::RemovePath(StringPiece path,
return RemoveWithoutPathExpansion(path, out_value);
StringPiece subdict_path = path.substr(0, delimiter_position);
- DictionaryValue* subdict = NULL;
+ DictionaryValue* subdict = nullptr;
if (!GetDictionary(subdict_path, &subdict))
return false;
result = subdict->RemovePath(path.substr(delimiter_position + 1),
out_value);
if (result && subdict->empty())
- RemoveWithoutPathExpansion(subdict_path, NULL);
+ RemoveWithoutPathExpansion(subdict_path, nullptr);
return result;
}
@@ -1112,7 +1129,7 @@ DictionaryValue::Iterator::Iterator(const DictionaryValue& target)
DictionaryValue::Iterator::Iterator(const Iterator& other) = default;
-DictionaryValue::Iterator::~Iterator() {}
+DictionaryValue::Iterator::~Iterator() = default;
DictionaryValue* DictionaryValue::DeepCopy() const {
return new DictionaryValue(dict_);
@@ -1214,23 +1231,6 @@ bool ListValue::GetString(size_t index, string16* out_value) const {
return value->GetAsString(out_value);
}
-bool ListValue::GetBinary(size_t index, const Value** out_value) const {
- const Value* value;
- bool result = Get(index, &value);
- if (!result || !value->IsType(Type::BINARY))
- return false;
-
- if (out_value)
- *out_value = value;
-
- return true;
-}
-
-bool ListValue::GetBinary(size_t index, Value** out_value) {
- return static_cast<const ListValue&>(*this).GetBinary(
- index, const_cast<const Value**>(out_value));
-}
-
bool ListValue::GetDictionary(size_t index,
const DictionaryValue** out_value) const {
const Value* value;
@@ -1371,11 +1371,9 @@ std::unique_ptr<ListValue> ListValue::CreateDeepCopy() const {
return std::make_unique<ListValue>(list_);
}
-ValueSerializer::~ValueSerializer() {
-}
+ValueSerializer::~ValueSerializer() = default;
-ValueDeserializer::~ValueDeserializer() {
-}
+ValueDeserializer::~ValueDeserializer() = default;
std::ostream& operator<<(std::ostream& out, const Value& value) {
std::string json;