Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Defining IPC Messages | 5 // Defining IPC Messages |
| 6 // | 6 // |
| 7 // Your IPC messages will be defined by macros inside of an XXX_messages.h | 7 // Your IPC messages will be defined by macros inside of an XXX_messages.h |
| 8 // header file. Most of the time, the system can automatically generate all | 8 // header file. Most of the time, the system can automatically generate all |
| 9 // of messaging mechanism from these definitions, but sometimes some manual | 9 // of messaging mechanism from these definitions, but sometimes some manual |
| 10 // coding is required. In these cases, you will also have an XXX_messages.cc | 10 // coding is required. In these cases, you will also have an XXX_messages.cc |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 // Externally-defined structs are registered with IPC_STRUCT_TRAITS_BEGIN(), | 135 // Externally-defined structs are registered with IPC_STRUCT_TRAITS_BEGIN(), |
| 136 // IPC_STRUCT_TRAITS_MEMBER(), and IPC_STRUCT_TRAITS_END() macros. These | 136 // IPC_STRUCT_TRAITS_MEMBER(), and IPC_STRUCT_TRAITS_END() macros. These |
| 137 // cause registration of the types with message generation only. | 137 // cause registration of the types with message generation only. |
| 138 // There's also IPC_STRUCT_TRAITS_PARENT, which is used to register a parent | 138 // There's also IPC_STRUCT_TRAITS_PARENT, which is used to register a parent |
| 139 // class (whose own traits are already defined). Note that | 139 // class (whose own traits are already defined). Note that |
| 140 // IPC_STRUCT_TRAITS_MEMBER() and IPC_STRUCT_TRAITS_PARENT are only permitted | 140 // IPC_STRUCT_TRAITS_MEMBER() and IPC_STRUCT_TRAITS_PARENT are only permitted |
| 141 // inside matching calls to IPC_STRUCT_TRAITS_BEGIN() / | 141 // inside matching calls to IPC_STRUCT_TRAITS_BEGIN() / |
| 142 // IPC_STRUCT_TRAITS_END(). | 142 // IPC_STRUCT_TRAITS_END(). |
| 143 // | 143 // |
| 144 // Enum types are registered with a single IPC_ENUM_TRAITS() macro. There | 144 // Enum types are registered with a single IPC_ENUM_TRAITS() macro. There |
| 145 // is no need to enumerate each value to the IPC mechanism. | 145 // is no need to enumerate each value to the IPC mechanism. By default, enums |
| 146 // are not range-checked when they are read from the wire, and callers must | |
| 147 // not trust values received from less privileged processes. In order for | |
| 148 // IPC to perform validaion, enum authors must provide a specialization for | |
|
aedla
2013/05/31 08:35:15
nit: 'validaion' typo
| |
| 149 // the function template declared in base/enum_validator.h. If such a | |
| 150 // specialization exists for the enum type, then IPC will reject messages | |
| 151 // that fail this validation. For example: | |
| 152 // | |
| 153 // #include "base/enum_validator.h" | |
| 154 // enum Color { RED, GREEN, BLUE }; | |
| 155 // template <> inline bool IsIntValidForEnum<Color>(int x) { | |
| 156 // return x >= RED && x <= BLUE; | |
| 157 // } | |
| 146 // | 158 // |
| 147 // Do not place semicolons following these IPC_ macro invocations. There | 159 // Do not place semicolons following these IPC_ macro invocations. There |
| 148 // is no reason to expect that their expansion corresponds one-to-one with | 160 // is no reason to expect that their expansion corresponds one-to-one with |
| 149 // C++ statements. | 161 // C++ statements. |
| 150 // | 162 // |
| 151 // Once the types have been declared / registered, message definitions follow. | 163 // Once the types have been declared / registered, message definitions follow. |
| 152 // "Sync" messages are just synchronous calls, the Send() call doesn't return | 164 // "Sync" messages are just synchronous calls, the Send() call doesn't return |
| 153 // until a reply comes back. To declare a sync message, use the IPC_SYNC_ | 165 // until a reply comes back. To declare a sync message, use the IPC_SYNC_ |
| 154 // macros. The numbers at the end show how many input/output parameters there | 166 // macros. The numbers at the end show how many input/output parameters there |
| 155 // are (i.e. 1_2 is 1 in, 2 out). Input parameters are first, followed by | 167 // are (i.e. 1_2 is 1 in, 2 out). Input parameters are first, followed by |
| (...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 994 // This corresponds to an enum value from IPCMessageStart. | 1006 // This corresponds to an enum value from IPCMessageStart. |
| 995 #define IPC_MESSAGE_CLASS(message) \ | 1007 #define IPC_MESSAGE_CLASS(message) \ |
| 996 IPC_MESSAGE_ID_CLASS(message.type()) | 1008 IPC_MESSAGE_ID_CLASS(message.type()) |
| 997 | 1009 |
| 998 #endif // IPC_IPC_MESSAGE_MACROS_H_ | 1010 #endif // IPC_IPC_MESSAGE_MACROS_H_ |
| 999 | 1011 |
| 1000 // Clean up IPC_MESSAGE_START in this unguarded section so that the | 1012 // Clean up IPC_MESSAGE_START in this unguarded section so that the |
| 1001 // XXX_messages.h files need not do so themselves. This makes the | 1013 // XXX_messages.h files need not do so themselves. This makes the |
| 1002 // XXX_messages.h files easier to write. | 1014 // XXX_messages.h files easier to write. |
| 1003 #undef IPC_MESSAGE_START | 1015 #undef IPC_MESSAGE_START |
| OLD | NEW |