Commit 5def9b40 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Stop using deprecated base::Value::CreateWithCopiedBuffer() in chrome/.

Bug: 646113
Change-Id: I2c2077217023325eb49a9a6ff79acadc37c507f6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2473452Reviewed-by: default avatarJan Wilken Dörrie <jdoerrie@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818999}
parent cbcae3bb
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <utility> #include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/containers/span.h"
#include "base/files/file.h" #include "base/files/file.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/macros.h" #include "base/macros.h"
...@@ -175,15 +176,15 @@ TEST_F(FileSystemProviderOperationsReadFileTest, OnSuccess) { ...@@ -175,15 +176,15 @@ TEST_F(FileSystemProviderOperationsReadFileTest, OnSuccess) {
const bool has_more = false; const bool has_more = false;
const int execution_time = 0; const int execution_time = 0;
base::ListValue value_as_list; base::Value values_as_list(base::Value::Type::LIST);
value_as_list.Set(0, std::make_unique<base::Value>(kFileSystemId)); values_as_list.Append(kFileSystemId);
value_as_list.Set(1, std::make_unique<base::Value>(kRequestId)); values_as_list.Append(kRequestId);
value_as_list.Set( values_as_list.Append(base::Value(base::as_bytes(base::make_span(data))));
2, base::Value::CreateWithCopiedBuffer(data.c_str(), data.size())); values_as_list.Append(has_more);
value_as_list.Set(3, std::make_unique<base::Value>(has_more)); values_as_list.Append(execution_time);
value_as_list.Set(4, std::make_unique<base::Value>(execution_time));
std::unique_ptr<Params> params(Params::Create(value_as_list)); std::unique_ptr<Params> params(
Params::Create(base::Value::AsListValue(std::move(values_as_list))));
ASSERT_TRUE(params.get()); ASSERT_TRUE(params.get());
std::unique_ptr<RequestValue> request_value( std::unique_ptr<RequestValue> request_value(
RequestValue::CreateForReadFileSuccess(std::move(params))); RequestValue::CreateForReadFileSuccess(std::move(params)));
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <utility> #include <utility>
#include "base/containers/span.h"
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/common/extensions/api/file_system_provider.h" #include "chrome/common/extensions/api/file_system_provider.h"
...@@ -48,18 +49,22 @@ bool WriteFile::Execute(int request_id) { ...@@ -48,18 +49,22 @@ bool WriteFile::Execute(int request_id) {
// Set the data directly on base::Value() to avoid an extra string copy. // Set the data directly on base::Value() to avoid an extra string copy.
DCHECK(buffer_.get()); DCHECK(buffer_.get());
std::unique_ptr<base::DictionaryValue> options_as_value = options.ToValue();
options_as_value->Set(
"data", base::Value::CreateWithCopiedBuffer(buffer_->data(), length_));
std::unique_ptr<base::ListValue> event_args(new base::ListValue); base::Value options_as_value =
event_args->Append(std::move(options_as_value)); base::Value::FromUniquePtrValue(options.ToValue());
options_as_value.SetKey(
"data",
base::Value(base::as_bytes(base::make_span(buffer_->data(), length_))));
base::Value event_args(base::Value::Type::LIST);
event_args.Append(std::move(options_as_value));
return SendEvent( return SendEvent(
request_id, request_id,
extensions::events::FILE_SYSTEM_PROVIDER_ON_WRITE_FILE_REQUESTED, extensions::events::FILE_SYSTEM_PROVIDER_ON_WRITE_FILE_REQUESTED,
extensions::api::file_system_provider::OnWriteFileRequested::kEventName, extensions::api::file_system_provider::OnWriteFileRequested::kEventName,
std::move(event_args)); base::ListValue::From(
base::Value::ToUniquePtrValue(std::move(event_args))));
} }
void WriteFile::OnSuccess(int /* request_id */, void WriteFile::OnSuccess(int /* request_id */,
......
...@@ -6,7 +6,9 @@ ...@@ -6,7 +6,9 @@
#include <utility> #include <utility>
#include "base/containers/span.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/strings/string_piece.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/chromeos/attestation/mock_tpm_challenge_key.h" #include "chrome/browser/chromeos/attestation/mock_tpm_challenge_key.h"
#include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
...@@ -135,25 +137,26 @@ class EPKChallengeMachineKeyTest : public EPKChallengeKeyTestBase { ...@@ -135,25 +137,26 @@ class EPKChallengeMachineKeyTest : public EPKChallengeKeyTestBase {
} }
std::unique_ptr<base::ListValue> CreateArgs() { std::unique_ptr<base::ListValue> CreateArgs() {
return CreateArgsInternal(nullptr); return CreateArgsInternal(base::Value());
} }
std::unique_ptr<base::ListValue> CreateArgsNoRegister() { std::unique_ptr<base::ListValue> CreateArgsNoRegister() {
return CreateArgsInternal(std::make_unique<bool>(false)); return CreateArgsInternal(base::Value(false));
} }
std::unique_ptr<base::ListValue> CreateArgsRegister() { std::unique_ptr<base::ListValue> CreateArgsRegister() {
return CreateArgsInternal(std::make_unique<bool>(true)); return CreateArgsInternal(base::Value(true));
} }
std::unique_ptr<base::ListValue> CreateArgsInternal( std::unique_ptr<base::ListValue> CreateArgsInternal(
std::unique_ptr<bool> register_key) { base::Value register_key) {
std::unique_ptr<base::ListValue> args(new base::ListValue); static constexpr base::StringPiece kData = "challenge";
args->Append(base::Value::CreateWithCopiedBuffer("challenge", 9)); base::Value args(base::Value::Type::LIST);
if (register_key) { args.Append(base::Value(base::as_bytes(base::make_span(kData))));
args->AppendBoolean(*register_key); if (register_key.is_bool())
} args.Append(std::move(register_key));
return args; return base::ListValue::From(
base::Value::ToUniquePtrValue(std::move(args)));
} }
scoped_refptr<EnterprisePlatformKeysChallengeMachineKeyFunction> func_; scoped_refptr<EnterprisePlatformKeysChallengeMachineKeyFunction> func_;
...@@ -221,10 +224,12 @@ class EPKChallengeUserKeyTest : public EPKChallengeKeyTestBase { ...@@ -221,10 +224,12 @@ class EPKChallengeUserKeyTest : public EPKChallengeKeyTestBase {
} }
std::unique_ptr<base::ListValue> CreateArgsInternal(bool register_key) { std::unique_ptr<base::ListValue> CreateArgsInternal(bool register_key) {
std::unique_ptr<base::ListValue> args(new base::ListValue); static constexpr base::StringPiece kData = "challenge";
args->Append(base::Value::CreateWithCopiedBuffer("challenge", 9)); base::Value args(base::Value::Type::LIST);
args->AppendBoolean(register_key); args.Append(base::Value(base::as_bytes(base::make_span(kData))));
return args; args.Append(register_key);
return base::ListValue::From(
base::Value::ToUniquePtrValue(std::move(args)));
} }
EPKPChallengeKey impl_; EPKPChallengeKey impl_;
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include <memory> #include <memory>
#include <utility> #include <utility>
#include "base/containers/span.h"
#include "base/strings/string_piece.h"
#include "base/values.h" #include "base/values.h"
namespace { namespace {
...@@ -39,7 +41,7 @@ ExtensionFunction::ResponseAction IdltestSendArrayBufferViewFunction::Run() { ...@@ -39,7 +41,7 @@ ExtensionFunction::ResponseAction IdltestSendArrayBufferViewFunction::Run() {
} }
ExtensionFunction::ResponseAction IdltestGetArrayBufferFunction::Run() { ExtensionFunction::ResponseAction IdltestGetArrayBufferFunction::Run() {
static constexpr char kHello[] = "hello world"; static constexpr base::StringPiece kHello = "hello world";
return RespondNow( return RespondNow(OneArgument(base::Value::ToUniquePtrValue(
OneArgument(base::Value::CreateWithCopiedBuffer(kHello, strlen(kHello)))); base::Value(base::as_bytes(base::make_span(kHello))))));
} }
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <vector> #include <vector>
#include "base/bind.h" #include "base/bind.h"
#include "base/containers/span.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/optional.h" #include "base/optional.h"
#include "base/stl_util.h" #include "base/stl_util.h"
...@@ -66,12 +67,9 @@ void BuildWebCryptoRSAAlgorithmDictionary(const PublicKeyInfo& key_info, ...@@ -66,12 +67,9 @@ void BuildWebCryptoRSAAlgorithmDictionary(const PublicKeyInfo& key_info,
base::Value(static_cast<int>(key_info.key_size_bits))); base::Value(static_cast<int>(key_info.key_size_bits)));
// Equals 65537. // Equals 65537.
const unsigned char defaultPublicExponent[] = {0x01, 0x00, 0x01}; static constexpr uint8_t kDefaultPublicExponent[] = {0x01, 0x00, 0x01};
algorithm->SetWithoutPathExpansion( algorithm->SetKey("publicExponent",
"publicExponent", base::Value(base::make_span(kDefaultPublicExponent)));
base::Value::CreateWithCopiedBuffer(
reinterpret_cast<const char*>(defaultPublicExponent),
base::size(defaultPublicExponent)));
} }
void BuildWebCryptoEcdsaAlgorithmDictionary(const PublicKeyInfo& key_info, void BuildWebCryptoEcdsaAlgorithmDictionary(const PublicKeyInfo& key_info,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment