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 #ifndef IPC_IPC_MESSAGE_H_ | 5 #ifndef IPC_IPC_MESSAGE_H_ |
6 #define IPC_IPC_MESSAGE_H_ | 6 #define IPC_IPC_MESSAGE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/pickle.h" | 12 #include "base/pickle.h" |
13 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
| 14 #include "ipc/attachment_broker.h" |
| 15 #include "ipc/brokerable_attachment.h" |
14 #include "ipc/ipc_export.h" | 16 #include "ipc/ipc_export.h" |
15 | 17 |
16 #if !defined(NDEBUG) | 18 #if !defined(NDEBUG) |
17 #define IPC_MESSAGE_LOG_ENABLED | 19 #define IPC_MESSAGE_LOG_ENABLED |
18 #endif | 20 #endif |
19 | 21 |
20 namespace IPC { | 22 namespace IPC { |
21 | 23 |
22 namespace internal { | 24 namespace internal { |
23 class ChannelReader; | 25 class ChannelReader; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, | 159 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, |
158 void (T::*func)(P*)) { | 160 void (T::*func)(P*)) { |
159 (obj->*func)(parameter); | 161 (obj->*func)(parameter); |
160 return true; | 162 return true; |
161 } | 163 } |
162 | 164 |
163 // Used for async messages with no parameters. | 165 // Used for async messages with no parameters. |
164 static void Log(std::string* name, const Message* msg, std::string* l) { | 166 static void Log(std::string* name, const Message* msg, std::string* l) { |
165 } | 167 } |
166 | 168 |
167 // Find the end of the message data that starts at range_start. Returns NULL | 169 // The static method FindNext() returns several pieces of information, which |
168 // if the entire message is not found in the given data range. | 170 // are aggregated into an instance of this struct. |
169 static const char* FindNext(const char* range_start, const char* range_end) { | 171 struct NextMessageInfo { |
170 return base::Pickle::FindNext(sizeof(Header), range_start, range_end); | 172 NextMessageInfo(); |
171 } | 173 ~NextMessageInfo(); |
| 174 // Whether an entire message was found in the given memory range. If this is |
| 175 // false, the other fields are left uninitialized. |
| 176 bool message_found; |
| 177 // The start address is passed into FindNext() by the caller, so isn't |
| 178 // repeated in this struct. The end address of the pickle should be used to |
| 179 // construct a base::Pickle. |
| 180 const char* pickle_end; |
| 181 // The end address of the message should be used to determine the start |
| 182 // address of the next message. |
| 183 const char* message_end; |
| 184 // If the message has brokerable attachments, this vector will contain the |
| 185 // ids of the brokerable attachments. The caller of FindNext() is |
| 186 // responsible for adding the attachments to the message. |
| 187 std::vector<BrokerableAttachment::AttachmentId> attachment_ids; |
| 188 }; |
| 189 |
| 190 static NextMessageInfo FindNext(const char* range_start, |
| 191 const char* range_end); |
| 192 |
| 193 struct SerializedAttachmentIds { |
| 194 void* buffer; |
| 195 size_t size; |
| 196 }; |
| 197 // Creates a buffer that contains a serialization of the ids of the brokerable |
| 198 // attachments of the message. This buffer is intended to be sent over the IPC |
| 199 // channel immediately after the pickled message. The caller takes ownership |
| 200 // of the buffer. |
| 201 // This method should only be called if the message has brokerable |
| 202 // attachments. |
| 203 SerializedAttachmentIds SerializedIdsOfBrokerableAttachments(); |
| 204 |
| 205 // Adds a placeholder brokerable attachment that must be replaced before the |
| 206 // message can be dispatched. |
| 207 bool AddPlaceholderBrokerableAttachmentWithId( |
| 208 BrokerableAttachment::AttachmentId id); |
172 | 209 |
173 // WriteAttachment appends |attachment| to the end of the set. It returns | 210 // WriteAttachment appends |attachment| to the end of the set. It returns |
174 // false iff the set is full. | 211 // false iff the set is full. |
175 bool WriteAttachment(scoped_refptr<MessageAttachment> attachment); | 212 bool WriteAttachment(scoped_refptr<MessageAttachment> attachment); |
176 // ReadAttachment parses an attachment given the parsing state |iter| and | 213 // ReadAttachment parses an attachment given the parsing state |iter| and |
177 // writes it to |*attachment|. It returns true on success. | 214 // writes it to |*attachment|. It returns true on success. |
178 bool ReadAttachment(base::PickleIterator* iter, | 215 bool ReadAttachment(base::PickleIterator* iter, |
179 scoped_refptr<MessageAttachment>* attachment) const; | 216 scoped_refptr<MessageAttachment>* attachment) const; |
180 // Returns true if there are any attachment in this message. | 217 // Returns true if there are any attachment in this message. |
181 bool HasAttachments() const; | 218 bool HasAttachments() const; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 friend class ChannelWin; | 252 friend class ChannelWin; |
216 friend class internal::ChannelReader; | 253 friend class internal::ChannelReader; |
217 friend class MessageReplyDeserializer; | 254 friend class MessageReplyDeserializer; |
218 friend class SyncMessage; | 255 friend class SyncMessage; |
219 | 256 |
220 #pragma pack(push, 4) | 257 #pragma pack(push, 4) |
221 struct Header : base::Pickle::Header { | 258 struct Header : base::Pickle::Header { |
222 int32 routing; // ID of the view that this message is destined for | 259 int32 routing; // ID of the view that this message is destined for |
223 uint32 type; // specifies the user-defined message type | 260 uint32 type; // specifies the user-defined message type |
224 uint32 flags; // specifies control flags for the message | 261 uint32 flags; // specifies control flags for the message |
| 262 #if USE_ATTACHMENT_BROKER |
| 263 // The number of brokered attachments included with this message. The |
| 264 // ids of the brokered attachment ids are sent immediately after the pickled |
| 265 // message, before the next pickled message is sent. |
| 266 uint32 num_brokered_attachments; |
| 267 #endif |
225 #if defined(OS_POSIX) | 268 #if defined(OS_POSIX) |
226 uint16 num_fds; // the number of descriptors included with this message | 269 uint16 num_fds; // the number of descriptors included with this message |
227 uint16 pad; // explicitly initialize this to appease valgrind | 270 uint16 pad; // explicitly initialize this to appease valgrind |
228 #endif | 271 #endif |
229 }; | 272 }; |
230 #pragma pack(pop) | 273 #pragma pack(pop) |
231 | 274 |
232 Header* header() { | 275 Header* header() { |
233 return headerT<Header>(); | 276 return headerT<Header>(); |
234 } | 277 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 MSG_ROUTING_NONE = -2, | 320 MSG_ROUTING_NONE = -2, |
278 | 321 |
279 // indicates a general message not sent to a particular tab. | 322 // indicates a general message not sent to a particular tab. |
280 MSG_ROUTING_CONTROL = kint32max, | 323 MSG_ROUTING_CONTROL = kint32max, |
281 }; | 324 }; |
282 | 325 |
283 #define IPC_REPLY_ID 0xFFFFFFF0 // Special message id for replies | 326 #define IPC_REPLY_ID 0xFFFFFFF0 // Special message id for replies |
284 #define IPC_LOGGING_ID 0xFFFFFFF1 // Special message id for logging | 327 #define IPC_LOGGING_ID 0xFFFFFFF1 // Special message id for logging |
285 | 328 |
286 #endif // IPC_IPC_MESSAGE_H_ | 329 #endif // IPC_IPC_MESSAGE_H_ |
OLD | NEW |