From c8c2d1901aec01e934adf561a9fdf0cc776cdef8 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 29 Jan 2018 16:35:13 +0100 Subject: BASELINE: Update Chromium to 64.0.3282.139 Change-Id: I1cae68fe9c94ff7608b26b8382fc19862cdb293a Reviewed-by: Alexandru Croitor --- chromium/base/values.cc | 90 ++++++++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 46 deletions(-) (limited to 'chromium/base/values.cc') 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::CreateWithCopiedBuffer(const char* buffer, return std::make_unique(BlobStorage(buffer, buffer + size)); } +// static +Value Value::FromUniquePtrValue(std::unique_ptr val) { + return std::move(*val); +} + +// static +std::unique_ptr Value::ToUniquePtrValue(Value val) { + return std::make_unique(std::move(val)); +} + Value::Value(Value&& that) noexcept { InternalMoveConstructFrom(std::move(that)); } @@ -312,6 +323,7 @@ Value* Value::FindPath(span path) { } const Value* Value::FindPath(std::initializer_list 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 path, Type type) { const Value* Value::FindPathOfType(std::initializer_list 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 path, } Value* Value::SetPath(std::initializer_list 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 path, Value value) { } bool Value::RemovePath(std::initializer_list 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 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()); + 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(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 in_value) { - return static_cast( - SetWithoutPathExpansion(path, std::move(in_value))); -} - -ListValue* DictionaryValue::SetListWithoutPathExpansion( - StringPiece path, - std::unique_ptr in_value) { - return static_cast( - 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(*this).GetBinary( - index, const_cast(out_value)); -} - bool ListValue::GetDictionary(size_t index, const DictionaryValue** out_value) const { const Value* value; @@ -1371,11 +1371,9 @@ std::unique_ptr ListValue::CreateDeepCopy() const { return std::make_unique(list_); } -ValueSerializer::~ValueSerializer() { -} +ValueSerializer::~ValueSerializer() = default; -ValueDeserializer::~ValueDeserializer() { -} +ValueDeserializer::~ValueDeserializer() = default; std::ostream& operator<<(std::ostream& out, const Value& value) { std::string json; -- cgit v1.2.3