Commit 2b1d90ef authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Modernize CertificateViewerDialog::GetDialogArgs().

- Replace one loop with base::JoinString().
- Use newer base::Value API in another loop.

Change-Id: I73fbd983e3c2306e9a97c9fd46f3fe94a944dcf7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1497855Reviewed-by: default avatarMichael Giuffrida <michaelpg@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#638051}
parent e127d549
......@@ -15,6 +15,7 @@
#include "base/memory/ptr_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/certificate_viewer.h"
......@@ -204,14 +205,7 @@ std::string CertificateViewerDialog::GetDialogArgs() const {
// Certificate usage.
std::vector<std::string> usages;
x509_certificate_model::GetUsageStrings(cert_hnd, &usages);
std::string usagestr;
for (auto it = usages.begin(); it != usages.end(); ++it) {
if (usagestr.length() > 0) {
usagestr += "\n";
}
usagestr += *it;
}
cert_info.SetString("general.usages", usagestr);
cert_info.SetString("general.usages", base::JoinString(usages, "\n"));
// Standard certificate details.
const std::string alternative_text =
......@@ -260,25 +254,24 @@ std::string CertificateViewerDialog::GetDialogArgs() const {
x509_certificate_model::HashCertSHA1(cert_hnd));
// Certificate hierarchy is constructed from bottom up.
std::unique_ptr<base::ListValue> children;
base::Value children;
int index = 0;
for (auto i = nss_certs_.begin(); i != nss_certs_.end(); ++i, ++index) {
std::unique_ptr<base::DictionaryValue> cert_node(
new base::DictionaryValue());
base::ListValue cert_details;
cert_node->SetString("label",
x509_certificate_model::GetTitle(i->get()).c_str());
cert_node->SetDouble("payload.index", index);
for (const auto& cert : nss_certs_) {
base::Value cert_node(base::Value::Type::DICTIONARY);
cert_node.SetKey("label",
base::Value(x509_certificate_model::GetTitle(cert.get())));
cert_node.SetPath({"payload", "index"}, base::Value(index));
// Add the child from the previous iteration.
if (children)
cert_node->Set("children", std::move(children));
if (!children.is_none())
cert_node.SetKey("children", std::move(children));
// Add this node to the children list for the next iteration.
children = std::make_unique<base::ListValue>();
children->Append(std::move(cert_node));
children = base::Value(base::Value::Type::LIST);
children.GetList().push_back(std::move(cert_node));
++index;
}
// Set the last node as the top of the certificate hierarchy.
cert_info.Set("hierarchy", std::move(children));
cert_info.SetKey("hierarchy", std::move(children));
base::JSONWriter::Write(cert_info, &data);
......
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