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 @@ ...@@ -15,6 +15,7 @@
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h" #include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/certificate_viewer.h" #include "chrome/browser/certificate_viewer.h"
...@@ -204,14 +205,7 @@ std::string CertificateViewerDialog::GetDialogArgs() const { ...@@ -204,14 +205,7 @@ std::string CertificateViewerDialog::GetDialogArgs() const {
// Certificate usage. // Certificate usage.
std::vector<std::string> usages; std::vector<std::string> usages;
x509_certificate_model::GetUsageStrings(cert_hnd, &usages); x509_certificate_model::GetUsageStrings(cert_hnd, &usages);
std::string usagestr; cert_info.SetString("general.usages", base::JoinString(usages, "\n"));
for (auto it = usages.begin(); it != usages.end(); ++it) {
if (usagestr.length() > 0) {
usagestr += "\n";
}
usagestr += *it;
}
cert_info.SetString("general.usages", usagestr);
// Standard certificate details. // Standard certificate details.
const std::string alternative_text = const std::string alternative_text =
...@@ -260,25 +254,24 @@ std::string CertificateViewerDialog::GetDialogArgs() const { ...@@ -260,25 +254,24 @@ std::string CertificateViewerDialog::GetDialogArgs() const {
x509_certificate_model::HashCertSHA1(cert_hnd)); x509_certificate_model::HashCertSHA1(cert_hnd));
// Certificate hierarchy is constructed from bottom up. // Certificate hierarchy is constructed from bottom up.
std::unique_ptr<base::ListValue> children; base::Value children;
int index = 0; int index = 0;
for (auto i = nss_certs_.begin(); i != nss_certs_.end(); ++i, ++index) { for (const auto& cert : nss_certs_) {
std::unique_ptr<base::DictionaryValue> cert_node( base::Value cert_node(base::Value::Type::DICTIONARY);
new base::DictionaryValue()); cert_node.SetKey("label",
base::ListValue cert_details; base::Value(x509_certificate_model::GetTitle(cert.get())));
cert_node->SetString("label", cert_node.SetPath({"payload", "index"}, base::Value(index));
x509_certificate_model::GetTitle(i->get()).c_str());
cert_node->SetDouble("payload.index", index);
// Add the child from the previous iteration. // Add the child from the previous iteration.
if (children) if (!children.is_none())
cert_node->Set("children", std::move(children)); cert_node.SetKey("children", std::move(children));
// Add this node to the children list for the next iteration. // Add this node to the children list for the next iteration.
children = std::make_unique<base::ListValue>(); children = base::Value(base::Value::Type::LIST);
children->Append(std::move(cert_node)); children.GetList().push_back(std::move(cert_node));
++index;
} }
// Set the last node as the top of the certificate hierarchy. // 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); 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