Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / common / safe_browsing / ipc_protobuf_message_macros.h
blob4f14c79bdf6144e83cb4614f3d2a1b8d700bd159
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Protobuf Messages over IPC
6 //
7 // Protobuf messages are registered with IPC_PROTOBUF_MESSAGE_TRAITS_BEGIN() and
8 // friends in much the same way as other externally-defined structs (see
9 // ipc/ipc_message_macros.h). These macros also cause only registration of the
10 // protobuf message type IPC with message generation. Within matching calls to
11 // _BEGIN() and _END(), one may use:
12 // - IPC_PROTOBUF_MESSAGE_TRAITS_OPTIONAL_FUNDAMENTAL_MEMBER() to register an
13 // optional field of fundamental type (any scalar message field type save
14 // "string" and "bytes").
15 // - IPC_PROTOBUF_MESSAGE_TRAITS_OPTIONAL_COMPLEX_MEMBER() to register an
16 // optional field of complex type (scalar message field type "string" or
17 // "bytes", or another message type).
18 // - IPC_PROTOBUF_MESSAGE_TRAITS_REPEATED_COMPLEX_MEMBER() to register a
19 // repeated field of complex type (scalar message field type "string" or
20 // "bytes", or another message type).
22 // Enum types in protobuf messages are registered with
23 // IPC_ENUM_TRAITS_VALIDATE() as with any other enum. In this case, the
24 // validation expression should be the _IsValid() function provided by the
25 // generated protobuf code. For example:
27 // IPC_ENUM_TRAITS_VALIDATE(MyEnumType, MyEnumType_IsValid(value))
29 #ifndef CHROME_COMMON_SAFE_BROWSING_IPC_PROTOBUF_MESSAGE_MACROS_H_
30 #define CHROME_COMMON_SAFE_BROWSING_IPC_PROTOBUF_MESSAGE_MACROS_H_
32 #include <string>
34 #define IPC_PROTOBUF_MESSAGE_TRAITS_BEGIN(message_name) \
35 namespace IPC { \
36 template <> \
37 struct IPC_MESSAGE_EXPORT ParamTraits<message_name> { \
38 typedef message_name param_type; \
39 static void Write(Message* m, const param_type& p); \
40 static bool Read(const Message* m, base::PickleIterator* iter, \
41 param_type* p); \
42 static void Log(const param_type& p, std::string* l); \
44 private: \
45 template <class P> \
46 static bool ReadParamF(const Message* m, \
47 base::PickleIterator* iter, \
48 param_type* p, \
49 void (param_type::*setter_function)(P)); \
50 }; \
51 } // namespace IPC
53 #define IPC_PROTOBUF_MESSAGE_TRAITS_OPTIONAL_FUNDAMENTAL_MEMBER(name)
54 #define IPC_PROTOBUF_MESSAGE_TRAITS_OPTIONAL_COMPLEX_MEMBER(name)
55 #define IPC_PROTOBUF_MESSAGE_TRAITS_REPEATED_COMPLEX_MEMBER(name)
56 #define IPC_PROTOBUF_MESSAGE_TRAITS_END()
58 #endif // CHROME_COMMON_SAFE_BROWSING_IPC_PROTOBUF_MESSAGE_MACROS_H_