Commit 5207e8de authored by Jan Wilken Dörrie's avatar Jan Wilken Dörrie Committed by Commit Bot

[Chrome Cleaner] Simplify wstring_embedded_nulls.mojom

This change simplifies wstring_embedded_nulls.mojom by removing the
union and making it a simple struct wrapping an uint16 array.

Bug: 911896
Change-Id: Idd4042f6a7bee8f066f6ce6477d6e5967b4d12be
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2320571
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Auto-Submit: Jan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: default avatarJoe Mason <joenotcharles@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792172}
parent 4c1882e8
......@@ -9,53 +9,21 @@
namespace mojo {
using chrome_cleaner::WStringEmbeddedNulls;
using chrome_cleaner::mojom::NullValueDataView;
using chrome_cleaner::mojom::WStringEmbeddedNullsDataView;
// static
bool StructTraits<NullValueDataView, nullptr_t>::Read(NullValueDataView data,
nullptr_t* value) {
*value = nullptr;
return true;
}
// static
base::span<const uint16_t>
UnionTraits<WStringEmbeddedNullsDataView, WStringEmbeddedNulls>::value(
StructTraits<WStringEmbeddedNullsDataView, WStringEmbeddedNulls>::value(
const WStringEmbeddedNulls& str) {
DCHECK_EQ(WStringEmbeddedNullsDataView::Tag::VALUE, GetTag(str));
// This should only be called by Mojo to get the data to be send through the
// pipe. When called by Mojo in this case, str will outlive the returned span.
return base::make_span(str.CastAsUInt16Array(), str.size());
}
// static
nullptr_t
UnionTraits<WStringEmbeddedNullsDataView, WStringEmbeddedNulls>::null_value(
const chrome_cleaner::WStringEmbeddedNulls& str) {
DCHECK_EQ(WStringEmbeddedNullsDataView::Tag::NULL_VALUE, GetTag(str));
return nullptr;
}
// static
chrome_cleaner::mojom::WStringEmbeddedNullsDataView::Tag
UnionTraits<WStringEmbeddedNullsDataView, WStringEmbeddedNulls>::GetTag(
const chrome_cleaner::WStringEmbeddedNulls& str) {
return str.size() == 0 ? WStringEmbeddedNullsDataView::Tag::NULL_VALUE
: WStringEmbeddedNullsDataView::Tag::VALUE;
}
// static
bool UnionTraits<WStringEmbeddedNullsDataView, WStringEmbeddedNulls>::Read(
bool StructTraits<WStringEmbeddedNullsDataView, WStringEmbeddedNulls>::Read(
WStringEmbeddedNullsDataView str_view,
WStringEmbeddedNulls* out) {
if (str_view.is_null_value()) {
*out = WStringEmbeddedNulls();
return true;
}
ArrayDataView<uint16_t> view;
str_view.GetValueDataView(&view);
// Note: Casting is intentional, since the data view represents the string as
......
......@@ -15,24 +15,13 @@
namespace mojo {
// Defines NullValue as mapped to nullptr_t.
template <>
struct StructTraits<chrome_cleaner::mojom::NullValueDataView, nullptr_t> {
static bool Read(chrome_cleaner::mojom::NullValueDataView data,
nullptr_t* value);
};
template <>
struct UnionTraits<chrome_cleaner::mojom::WStringEmbeddedNullsDataView,
chrome_cleaner::WStringEmbeddedNulls> {
struct StructTraits<chrome_cleaner::mojom::WStringEmbeddedNullsDataView,
chrome_cleaner::WStringEmbeddedNulls> {
// This should only be called by Mojo to marshal the object before sending it
// through the pipe.
static base::span<const uint16_t> value(
const chrome_cleaner::WStringEmbeddedNulls& str);
static nullptr_t null_value(const chrome_cleaner::WStringEmbeddedNulls& str);
static chrome_cleaner::mojom::WStringEmbeddedNullsDataView::Tag GetTag(
const chrome_cleaner::WStringEmbeddedNulls& str);
static bool Read(chrome_cleaner::mojom::WStringEmbeddedNullsDataView str_view,
chrome_cleaner::WStringEmbeddedNulls* out);
......
......@@ -5,20 +5,6 @@
module chrome_cleaner.mojom;
// Typemapped to chrome_cleaner::WStringEmbeddedNulls.
//
// Note: Mojo doesn't allow sending null arrays over the wire, and the strings
// represented by this type can be empty (without a null at the end).
// Because of that, represented as a union of either something that is
// always empty (NullValue) or a non-empty array of uint16.
union WStringEmbeddedNulls {
// The underlying string is a null array (not the same as an empty string,
// which has at least one character '\0').
NullValue? null_value;
// The underlying string is either a null-terminated empty string (size is 1),
// or a non-empty string that can be either null-terminated or not.
struct WStringEmbeddedNulls {
array<uint16> value;
};
struct NullValue {
};
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