From b3e01220cb8511790d45ec3759faae1289ad197d Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 15 Jan 2024 04:01:35 -0600 Subject: [PATCH] refactor: fix deprecated base::Base64Encode() API calls (#40962) * refactor: replace deprecated Base64Encode() usage in IWC::NetworkResourceLoader::OnDataReceived() * refactor: replace deprecated Base64Encode() usage EncodeToken(const base::UnguessableToken& token) --- .../browser/serial/serial_chooser_context.cc | 7 ++----- shell/browser/ui/inspectable_web_contents.cc | 19 ++++--------------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/shell/browser/serial/serial_chooser_context.cc b/shell/browser/serial/serial_chooser_context.cc index 521fe7c53ad..6b77330cb16 100644 --- a/shell/browser/serial/serial_chooser_context.cc +++ b/shell/browser/serial/serial_chooser_context.cc @@ -38,11 +38,8 @@ const char kUsbDriverKey[] = "usb_driver"; std::string EncodeToken(const base::UnguessableToken& token) { const uint64_t data[2] = {token.GetHighForSerialization(), token.GetLowForSerialization()}; - std::string buffer; - base::Base64Encode( - base::StringPiece(reinterpret_cast(&data[0]), sizeof(data)), - &buffer); - return buffer; + return base::Base64Encode( + base::StringPiece(reinterpret_cast(&data[0]), sizeof(data))); } base::Value PortInfoToValue(const device::mojom::SerialPortInfo& port) { diff --git a/shell/browser/ui/inspectable_web_contents.cc b/shell/browser/ui/inspectable_web_contents.cc index 50ea5917b50..45c428ffd6f 100644 --- a/shell/browser/ui/inspectable_web_contents.cc +++ b/shell/browser/ui/inspectable_web_contents.cc @@ -258,22 +258,11 @@ class InspectableWebContents::NetworkResourceLoader void OnDataReceived(base::StringPiece chunk, base::OnceClosure resume) override { - base::Value chunkValue; - bool encoded = !base::IsStringUTF8(chunk); - if (encoded) { - std::string encoded_string; - base::Base64Encode(chunk, &encoded_string); - chunkValue = base::Value(std::move(encoded_string)); - } else { - chunkValue = base::Value(chunk); - } - base::Value id(stream_id_); - base::Value encodedValue(encoded); - - bindings_->CallClientFunction("DevToolsAPI", "streamWrite", std::move(id), - std::move(chunkValue), - std::move(encodedValue)); + bindings_->CallClientFunction( + "DevToolsAPI", "streamWrite", base::Value{stream_id_}, + base::Value{encoded ? base::Base64Encode(chunk) : chunk}, + base::Value{encoded}); std::move(resume).Run(); }