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" | |
16 #include "ipc/ipc_export.h" | 14 #include "ipc/ipc_export.h" |
17 | 15 |
18 #if !defined(NDEBUG) | 16 #if !defined(NDEBUG) |
19 #define IPC_MESSAGE_LOG_ENABLED | 17 #define IPC_MESSAGE_LOG_ENABLED |
20 #endif | 18 #endif |
21 | 19 |
22 namespace IPC { | 20 namespace IPC { |
23 | 21 |
24 namespace internal { | 22 namespace internal { |
25 class ChannelReader; | 23 class ChannelReader; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, | 157 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, |
160 void (T::*func)(P*)) { | 158 void (T::*func)(P*)) { |
161 (obj->*func)(parameter); | 159 (obj->*func)(parameter); |
162 return true; | 160 return true; |
163 } | 161 } |
164 | 162 |
165 // Used for async messages with no parameters. | 163 // Used for async messages with no parameters. |
166 static void Log(std::string* name, const Message* msg, std::string* l) { | 164 static void Log(std::string* name, const Message* msg, std::string* l) { |
167 } | 165 } |
168 | 166 |
169 // The static method FindNext() returns several pieces of information, which | 167 // Find the end of the message data that starts at range_start. Returns NULL |
170 // are aggregated into an instance of this struct. | 168 // if the entire message is not found in the given data range. |
171 struct NextMessageInfo { | 169 static const char* FindNext(const char* range_start, const char* range_end) { |
172 NextMessageInfo(); | 170 return base::Pickle::FindNext(sizeof(Header), range_start, range_end); |
173 ~NextMessageInfo(); | 171 } |
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); | |
209 | 172 |
210 // WriteAttachment appends |attachment| to the end of the set. It returns | 173 // WriteAttachment appends |attachment| to the end of the set. It returns |
211 // false iff the set is full. | 174 // false iff the set is full. |
212 bool WriteAttachment(scoped_refptr<MessageAttachment> attachment); | 175 bool WriteAttachment(scoped_refptr<MessageAttachment> attachment); |
213 // ReadAttachment parses an attachment given the parsing state |iter| and | 176 // ReadAttachment parses an attachment given the parsing state |iter| and |
214 // writes it to |*attachment|. It returns true on success. | 177 // writes it to |*attachment|. It returns true on success. |
215 bool ReadAttachment(base::PickleIterator* iter, | 178 bool ReadAttachment(base::PickleIterator* iter, |
216 scoped_refptr<MessageAttachment>* attachment) const; | 179 scoped_refptr<MessageAttachment>* attachment) const; |
217 // Returns true if there are any attachment in this message. | 180 // Returns true if there are any attachment in this message. |
218 bool HasAttachments() const; | 181 bool HasAttachments() const; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 friend class ChannelWin; | 226 friend class ChannelWin; |
264 friend class internal::ChannelReader; | 227 friend class internal::ChannelReader; |
265 friend class MessageReplyDeserializer; | 228 friend class MessageReplyDeserializer; |
266 friend class SyncMessage; | 229 friend class SyncMessage; |
267 | 230 |
268 #pragma pack(push, 4) | 231 #pragma pack(push, 4) |
269 struct Header : base::Pickle::Header { | 232 struct Header : base::Pickle::Header { |
270 int32 routing; // ID of the view that this message is destined for | 233 int32 routing; // ID of the view that this message is destined for |
271 uint32 type; // specifies the user-defined message type | 234 uint32 type; // specifies the user-defined message type |
272 uint32 flags; // specifies control flags for the message | 235 uint32 flags; // specifies control flags for the message |
273 #if USE_ATTACHMENT_BROKER | |
274 // The number of brokered attachments included with this message. The | |
275 // ids of the brokered attachment ids are sent immediately after the pickled | |
276 // message, before the next pickled message is sent. | |
277 uint32 num_brokered_attachments; | |
278 #endif | |
279 #if defined(OS_POSIX) | 236 #if defined(OS_POSIX) |
280 uint16 num_fds; // the number of descriptors included with this message | 237 uint16 num_fds; // the number of descriptors included with this message |
281 uint16 pad; // explicitly initialize this to appease valgrind | 238 uint16 pad; // explicitly initialize this to appease valgrind |
282 #endif | 239 #endif |
283 }; | 240 }; |
284 #pragma pack(pop) | 241 #pragma pack(pop) |
285 | 242 |
286 Header* header() { | 243 Header* header() { |
287 return headerT<Header>(); | 244 return headerT<Header>(); |
288 } | 245 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 MSG_ROUTING_NONE = -2, | 288 MSG_ROUTING_NONE = -2, |
332 | 289 |
333 // indicates a general message not sent to a particular tab. | 290 // indicates a general message not sent to a particular tab. |
334 MSG_ROUTING_CONTROL = kint32max, | 291 MSG_ROUTING_CONTROL = kint32max, |
335 }; | 292 }; |
336 | 293 |
337 #define IPC_REPLY_ID 0xFFFFFFF0 // Special message id for replies | 294 #define IPC_REPLY_ID 0xFFFFFFF0 // Special message id for replies |
338 #define IPC_LOGGING_ID 0xFFFFFFF1 // Special message id for logging | 295 #define IPC_LOGGING_ID 0xFFFFFFF1 // Special message id for logging |
339 | 296 |
340 #endif // IPC_IPC_MESSAGE_H_ | 297 #endif // IPC_IPC_MESSAGE_H_ |
OLD | NEW |