Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2916)

Unified Diff: base/values.cc

Issue 2065793002: Return a unique_ptr from BinaryValue::CreateWithCopiedBuffer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Android and CrOS Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/values.cc
diff --git a/base/values.cc b/base/values.cc
index e55e11af0f3b62b612b4f4ed79118b7d29466728..4772b647748f112260667c75cb570979b034c4b4 100644
--- a/base/values.cc
+++ b/base/values.cc
@@ -304,12 +304,12 @@ BinaryValue::~BinaryValue() {
}
// static
-BinaryValue* BinaryValue::CreateWithCopiedBuffer(const char* buffer,
- size_t size) {
- char* buffer_copy = new char[size];
- memcpy(buffer_copy, buffer, size);
- std::unique_ptr<char[]> scoped_buffer_copy(buffer_copy);
- return new BinaryValue(std::move(scoped_buffer_copy), size);
+std::unique_ptr<BinaryValue> BinaryValue::CreateWithCopiedBuffer(
+ const char* buffer,
+ size_t size) {
+ std::unique_ptr<char[]> buffer_copy(new char[size]);
+ memcpy(buffer_copy.get(), buffer, size);
+ return base::MakeUnique<BinaryValue>(std::move(buffer_copy), size);
}
bool BinaryValue::GetAsBinary(const BinaryValue** out_value) const {
@@ -319,7 +319,7 @@ bool BinaryValue::GetAsBinary(const BinaryValue** out_value) const {
}
BinaryValue* BinaryValue::DeepCopy() const {
- return CreateWithCopiedBuffer(buffer_.get(), size_);
+ return CreateWithCopiedBuffer(buffer_.get(), size_).release();
}
bool BinaryValue::Equals(const Value* other) const {

Powered by Google App Engine
This is Rietveld 408576698