[CodeHealth] Migrate from base::Value to base::Value::Dict
Bug: 1303949
Change-Id: Ifb32f7e6fdb0baa52798efacb4a5131eabc89dc5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4349138
Commit-Queue: Victor Tan <[email protected]>
Reviewed-by: Peter Beverloo <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1121248}
diff --git a/chrome/browser/sharing/web_push/json_web_token_util.cc b/chrome/browser/sharing/web_push/json_web_token_util.cc
index f13890c7..a14f844 100644
--- a/chrome/browser/sharing/web_push/json_web_token_util.cc
+++ b/chrome/browser/sharing/web_push/json_web_token_util.cc
@@ -22,17 +22,12 @@
} // namespace
absl::optional<std::string> CreateJSONWebToken(
- const base::Value& claims,
+ const base::Value::Dict& claims,
crypto::ECPrivateKey* private_key) {
- if (!claims.is_dict()) {
- LOG(ERROR) << "claims is not a dictionary";
- return absl::nullopt;
- }
-
// Generate header.
- base::Value header(base::Value::Type::DICT);
- header.SetKey(kKeyAlg, base::Value(kAlgES256));
- header.SetKey(kKeyTyp, base::Value(kTypJwt));
+ base::Value::Dict header;
+ header.Set(kKeyAlg, base::Value(kAlgES256));
+ header.Set(kKeyTyp, base::Value(kTypJwt));
// Serialize header.
std::string header_serialized;
diff --git a/chrome/browser/sharing/web_push/json_web_token_util.h b/chrome/browser/sharing/web_push/json_web_token_util.h
index 5f37fd4..de412fec 100644
--- a/chrome/browser/sharing/web_push/json_web_token_util.h
+++ b/chrome/browser/sharing/web_push/json_web_token_util.h
@@ -23,7 +23,7 @@
//
// https://tools.ietf.org/html/rfc7519
absl::optional<std::string> CreateJSONWebToken(
- const base::Value& claims,
+ const base::Value::Dict& claims,
crypto::ECPrivateKey* private_key);
#endif // CHROME_BROWSER_SHARING_WEB_PUSH_JSON_WEB_TOKEN_UTIL_H_
diff --git a/chrome/browser/sharing/web_push/json_web_token_util_unittest.cc b/chrome/browser/sharing/web_push/json_web_token_util_unittest.cc
index 75175d3..16c304af 100644
--- a/chrome/browser/sharing/web_push/json_web_token_util_unittest.cc
+++ b/chrome/browser/sharing/web_push/json_web_token_util_unittest.cc
@@ -38,7 +38,7 @@
base::Value::Dict claims;
claims.Set("aud", "https://chromium.org");
absl::optional<std::string> jwt =
- CreateJSONWebToken(base::Value(claims.Clone()), private_key.get());
+ CreateJSONWebToken(claims.Clone(), private_key.get());
ASSERT_TRUE(jwt);
// Decompose JWS into data and signautre.
diff --git a/chrome/browser/sharing/web_push/web_push_sender.cc b/chrome/browser/sharing/web_push/web_push_sender.cc
index 550628dd..d8c15ce 100644
--- a/chrome/browser/sharing/web_push/web_push_sender.cc
+++ b/chrome/browser/sharing/web_push/web_push_sender.cc
@@ -47,8 +47,8 @@
const char kContentEncodingOctetStream[] = "application/octet-stream";
absl::optional<std::string> GetAuthHeader(crypto::ECPrivateKey* vapid_key) {
- base::Value claims(base::Value::Type::DICT);
- claims.SetKey(kClaimsKeyAudience, base::Value(kFCMServerAudience));
+ base::Value::Dict claims;
+ claims.Set(kClaimsKeyAudience, base::Value(kFCMServerAudience));
int64_t exp =
(base::Time::Now() + kClaimsValidPeriod - base::Time::UnixEpoch())
@@ -57,8 +57,7 @@
if (exp > INT_MAX)
return absl::nullopt;
- claims.SetKey(kClaimsKeyExpirationTime,
- base::Value(static_cast<int32_t>(exp)));
+ claims.Set(kClaimsKeyExpirationTime, base::Value(static_cast<int32_t>(exp)));
absl::optional<std::string> jwt = CreateJSONWebToken(claims, vapid_key);
if (!jwt)