Commit 7db18881 authored by Dominic Battre's avatar Dominic Battre Committed by Commit Bot

Report types as strings

This CL improves the readability of votes uploads:
Before the CL, you would see "autofill_type: [51]".
After the CL, you now see "autofill_type: [51/CREDIT_CARD_NAME_FULL]".

If std::vector<std::string> elements are piped into the LogBuffer,
these are automatically represented as a comma separated list
in the output.

R=kolos@chromium.org

Bug: 928595
Change-Id: I68c917be57c5dbf32a7932235b8c52dc8916cf97
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1724521
Commit-Queue: Dominic Battré <battre@chromium.org>
Reviewed-by: default avatarMaxim Kolosovskiy <kolos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#682537}
parent 5ff15500
...@@ -381,6 +381,12 @@ std::ostream& operator<<(std::ostream& out, ...@@ -381,6 +381,12 @@ std::ostream& operator<<(std::ostream& out,
return out; return out;
} }
std::string FieldTypeToString(int type) {
return base::StrCat(
{base::NumberToString(type), std::string("/"),
AutofillType(static_cast<ServerFieldType>(type)).ToString()});
}
LogBuffer& operator<<(LogBuffer& out, LogBuffer& operator<<(LogBuffer& out,
const autofill::AutofillUploadContents& upload) { const autofill::AutofillUploadContents& upload) {
if (!out.active()) if (!out.active())
...@@ -411,9 +417,11 @@ LogBuffer& operator<<(LogBuffer& out, ...@@ -411,9 +417,11 @@ LogBuffer& operator<<(LogBuffer& out,
out << Tr{} << Attrib{"style", "font-weight: bold"} out << Tr{} << Attrib{"style", "font-weight: bold"}
<< "field_signature:" << field.signature(); << "field_signature:" << field.signature();
LogBuffer autofill_type; std::vector<std::string> types_as_strings;
autofill_type << Tag{"span"} << field.autofill_type(); types_as_strings.reserve(field.autofill_type_size());
out << Tr{} << "autofill_type:" << std::move(autofill_type); for (int type : field.autofill_type())
types_as_strings.emplace_back(FieldTypeToString(type));
out << Tr{} << "autofill_type:" << types_as_strings;
LogBuffer validities; LogBuffer validities;
validities << Tag{"span"} << "["; validities << Tag{"span"} << "[";
......
...@@ -166,6 +166,18 @@ LogBuffer& operator<<(LogBuffer& buf, ...@@ -166,6 +166,18 @@ LogBuffer& operator<<(LogBuffer& buf,
return buf; return buf;
} }
template <typename T>
LogBuffer& operator<<(LogBuffer& buf, const std::vector<T>& values) {
buf << "[";
for (size_t i = 0; i < values.size(); ++i) {
if (i)
buf << ", ";
buf << values.at(i);
}
buf << "]";
return buf;
}
// This is syntactic sugar for creating table rows in a LogBuffer. Each // This is syntactic sugar for creating table rows in a LogBuffer. Each
// value streamed into this LogTableRowBuffer is wrapped by a <td> element. // value streamed into this LogTableRowBuffer is wrapped by a <td> element.
// The entire row is wrapped by a <tr>. // The entire row is wrapped by a <tr>.
......
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