[media] Convert JSONStringValueSerializer to base::WriteJson
Modified to slightly more concise equivalent. Bug: 40912727 Change-Id: Icd4b7a6672f9ba8a6b14734ecc8914243d488d54 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6345874 Reviewed-by: Colin Blundell <blundell@chromium.org> Reviewed-by: Andrew Paseltiner <apaseltiner@chromium.org> Commit-Queue: Ho Cheung <hocheung@chromium.org> Cr-Commit-Position: refs/heads/main@{#1432043}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
83cc7ce7bf
commit
caee6f7b67
media
@ -7,13 +7,15 @@
|
||||
#include <stddef.h>
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
|
||||
#include "base/base64url.h"
|
||||
#include "base/containers/span.h"
|
||||
#include "base/json/json_reader.h"
|
||||
#include "base/json/json_string_value_serializer.h"
|
||||
#include "base/json/json_writer.h"
|
||||
#include "base/json/string_escape.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
@ -73,10 +75,7 @@ std::string GenerateJWKSet(base::span<const uint8_t> key,
|
||||
jwk_set.Set(kKeysTag, std::move(list));
|
||||
|
||||
// Finally serialize |jwk_set| into a string and return it.
|
||||
std::string serialized_jwk;
|
||||
JSONStringValueSerializer serializer(&serialized_jwk);
|
||||
serializer.Serialize(base::Value(std::move(jwk_set)));
|
||||
return serialized_jwk;
|
||||
return base::WriteJson(jwk_set).value_or(std::string());
|
||||
}
|
||||
|
||||
std::string GenerateJWKSet(const KeyIdAndKeyPairs& keys,
|
||||
@ -100,10 +99,7 @@ std::string GenerateJWKSet(const KeyIdAndKeyPairs& keys,
|
||||
}
|
||||
|
||||
// Finally serialize |jwk_set| into a string and return it.
|
||||
std::string serialized_jwk;
|
||||
JSONStringValueSerializer serializer(&serialized_jwk);
|
||||
serializer.Serialize(base::Value(std::move(jwk_set)));
|
||||
return serialized_jwk;
|
||||
return base::WriteJson(jwk_set).value_or(std::string());
|
||||
}
|
||||
|
||||
// Processes a JSON Web Key to extract the key id and key value. Sets |jwk_key|
|
||||
@ -312,12 +308,11 @@ void CreateLicenseRequest(const KeyIdList& key_ids,
|
||||
}
|
||||
|
||||
// Serialize the license request as a string.
|
||||
std::string json;
|
||||
JSONStringValueSerializer serializer(&json);
|
||||
serializer.Serialize(request);
|
||||
std::optional<std::string> json =
|
||||
base::WriteJson(request).value_or(std::string());
|
||||
|
||||
// Convert the serialized license request into std::vector and return it.
|
||||
std::vector<uint8_t> result(json.begin(), json.end());
|
||||
std::vector<uint8_t> result(json->begin(), json->end());
|
||||
license->swap(result);
|
||||
}
|
||||
|
||||
@ -340,12 +335,11 @@ base::Value::Dict MakeKeyIdsDictionary(const KeyIdList& key_ids) {
|
||||
std::vector<uint8_t> SerializeDictionaryToVector(
|
||||
const base::Value::Dict& dictionary) {
|
||||
// Serialize the dictionary as a string.
|
||||
std::string json;
|
||||
JSONStringValueSerializer serializer(&json);
|
||||
serializer.Serialize(dictionary);
|
||||
std::optional<std::string> json =
|
||||
base::WriteJson(dictionary).value_or(std::string());
|
||||
|
||||
// Convert the serialized data into std::vector and return it.
|
||||
return std::vector<uint8_t>(json.begin(), json.end());
|
||||
return std::vector<uint8_t>(json->begin(), json->end());
|
||||
}
|
||||
|
||||
void CreateKeyIdsInitData(const KeyIdList& key_ids,
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include <utility>
|
||||
|
||||
#include "base/functional/bind.h"
|
||||
#include "base/json/json_string_value_serializer.h"
|
||||
#include "base/json/json_writer.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/posix/eintr_wrapper.h"
|
||||
#include "base/posix/safe_strerror.h"
|
||||
@ -387,10 +387,7 @@ std::unique_ptr<base::Value::Dict> MidiManagerAlsa::MidiPort::Value() const {
|
||||
}
|
||||
|
||||
std::string MidiManagerAlsa::MidiPort::JSONValue() const {
|
||||
std::string json;
|
||||
JSONStringValueSerializer serializer(&json);
|
||||
serializer.Serialize(*Value().get());
|
||||
return json;
|
||||
return base::WriteJson(*Value()).value_or(std::string());
|
||||
}
|
||||
|
||||
// TODO(agoode): Do not use SHA256 here. Instead store a persistent
|
||||
|
Reference in New Issue
Block a user