Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(361)

Unified Diff: mojo/public/cpp/bindings/struct_traits.h

Issue 2253293002: Mojo C++ bindings: change the first template parameter of StructTraits and UnionTraits. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@91_extra
Patch Set: rebase Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/public/cpp/bindings/struct_traits.h
diff --git a/mojo/public/cpp/bindings/struct_traits.h b/mojo/public/cpp/bindings/struct_traits.h
index b2a60c7887b9280d2772266bca0c3c25822e4497..c3ea5ad3dce5cd045dadadfb01caff28574170bb 100644
--- a/mojo/public/cpp/bindings/struct_traits.h
+++ b/mojo/public/cpp/bindings/struct_traits.h
@@ -8,7 +8,11 @@
namespace mojo {
// This must be specialized for any type |T| to be serialized/deserialized as
-// a mojom struct of type |MojomType|.
+// a mojom struct. |DataViewType| is the corresponding data view type of the
+// mojom struct. For example, if the mojom struct is example.Foo,
+// |DataViewType| will be example::FooDataView, which can also be referred to by
+// example::Foo::DataView (in chromium) and example::blink::Foo::DataView (in
+// blink).
//
// Each specialization needs to implement a few things:
// 1. Static getters for each field in the Mojom type. These should be
@@ -20,19 +24,22 @@ namespace mojo {
// from |input|.
//
// Serializable form of a field:
-// Value or reference of the same type used in |MojomType|, or the
-// following alternatives:
+// Value or reference of the same type used in the generated stuct
+// wrapper type, or the following alternatives:
// - string:
// Value or reference of any type that has a StringTraits defined.
-// Supported by default: base::StringPiece, std::string.
+// Supported by default: base::StringPiece, std::string, mojo::String,
+// WTF::String (in blink).
//
// - array:
// Value or reference of any type that has an ArrayTraits defined.
-// Supported by default: std::vector, WTF::Vector (in blink), CArray.
+// Supported by default: std::vector, CArray, mojo::Array, WTF::Vector
+// (in blink), mojo::WTFArray (in blink).
//
// - map:
// Value or reference of any type that has a MapTraits defined.
-// Supported by default: std::map.
+// Supported by default: std::map, std::unordered_map, mojo::Map,
+// WTF::HashMap (in blink), mojo::WTFMap (in blink).
//
// - struct:
// Value or reference of any type that has a StructTraits defined.
@@ -40,6 +47,10 @@ namespace mojo {
// - enum:
// Value of any type that has an EnumTraits defined.
//
+// For any nullable string/struct/array/map/union field you could also
+// return value or reference of base::Optional<T>/WTF::Optional<T>, if T
+// has the right *Traits defined.
+//
// During serialization, getters for string/struct/array/map/union fields
// are called twice (one for size calculation and one for actual
// serialization). If you want to return a value (as opposed to a
@@ -49,14 +60,13 @@ namespace mojo {
// Getters for fields of other types are called once.
//
// 2. A static Read() method to set the contents of a |T| instance from a
-// |MojomType|DataView (e.g., if |MojomType| is test::Example, the data
-// view will be test::ExampleDataView).
+// DataViewType.
//
-// static bool Read(|MojomType|DataView data, T* output);
+// static bool Read(DataViewType data, T* output);
//
-// The generated |MojomType|DataView type provides a convenient,
-// inexpensive view of a serialized struct's field data. The caller
-// guarantees that |!data.is_null()|.
+// The generated DataViewType provides a convenient, inexpensive view of a
+// serialized struct's field data. The caller guarantees that
+// |!data.is_null()|.
//
// Returning false indicates invalid incoming data and causes the message
// pipe receiving it to be disconnected. Therefore, you can do custom
@@ -112,9 +122,12 @@ namespace mojo {
// reference/value to the Mojo bindings for serialization:
// - if T is used in the "type_mappings" section of a typemap config file,
// you need to declare it as pass-by-value:
-// type_mappings = [ "MojomType=T(pass_by_value)" ]
-// - if another type U's StructTraits has a getter for T, it needs to return
-// non-const reference/value.
+// type_mappings = [ "MojomType=T(move_only)" ]
+// or
+// type_mappings = [ "MojomType=T(copyable_pass_by_value)" ]
+//
+// - if another type U's StructTraits/UnionTraits has a getter for T, it
+// needs to return non-const reference/value.
//
// EXAMPLE:
//
@@ -129,7 +142,7 @@ namespace mojo {
//
// StructTraits for Foo:
// template <>
-// struct StructTraits<Foo, CustomFoo> {
+// struct StructTraits<FooDataView, CustomFoo> {
// // Optional methods dealing with null:
// static bool IsNull(const CustomFoo& input);
// static void SetToNull(CustomFoo* output);
@@ -145,7 +158,7 @@ namespace mojo {
// static bool Read(FooDataView data, CustomFoo* output);
// };
//
-template <typename MojomType, typename T>
+template <typename DataViewType, typename T>
struct StructTraits;
} // namespace mojo
« no previous file with comments | « mojo/common/common_custom_types_struct_traits.cc ('k') | mojo/public/cpp/bindings/tests/rect_blink_traits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698