| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 friend class ChannelWin; | 263 friend class ChannelWin; |
| 227 friend class internal::ChannelReader; | 264 friend class internal::ChannelReader; |
| 228 friend class MessageReplyDeserializer; | 265 friend class MessageReplyDeserializer; |
| 229 friend class SyncMessage; | 266 friend class SyncMessage; |
| 230 | 267 |
| 231 #pragma pack(push, 4) | 268 #pragma pack(push, 4) |
| 232 struct Header : base::Pickle::Header { | 269 struct Header : base::Pickle::Header { |
| 233 int32 routing; // ID of the view that this message is destined for | 270 int32 routing; // ID of the view that this message is destined for |
| 234 uint32 type; // specifies the user-defined message type | 271 uint32 type; // specifies the user-defined message type |
| 235 uint32 flags; // specifies control flags for the message | 272 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 |
| 236 #if defined(OS_POSIX) | 279 #if defined(OS_POSIX) |
| 237 uint16 num_fds; // the number of descriptors included with this message | 280 uint16 num_fds; // the number of descriptors included with this message |
| 238 uint16 pad; // explicitly initialize this to appease valgrind | 281 uint16 pad; // explicitly initialize this to appease valgrind |
| 239 #endif | 282 #endif |
| 240 }; | 283 }; |
| 241 #pragma pack(pop) | 284 #pragma pack(pop) |
| 242 | 285 |
| 243 Header* header() { | 286 Header* header() { |
| 244 return headerT<Header>(); | 287 return headerT<Header>(); |
| 245 } | 288 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 MSG_ROUTING_NONE = -2, | 331 MSG_ROUTING_NONE = -2, |
| 289 | 332 |
| 290 // indicates a general message not sent to a particular tab. | 333 // indicates a general message not sent to a particular tab. |
| 291 MSG_ROUTING_CONTROL = kint32max, | 334 MSG_ROUTING_CONTROL = kint32max, |
| 292 }; | 335 }; |
| 293 | 336 |
| 294 #define IPC_REPLY_ID 0xFFFFFFF0 // Special message id for replies | 337 #define IPC_REPLY_ID 0xFFFFFFF0 // Special message id for replies |
| 295 #define IPC_LOGGING_ID 0xFFFFFFF1 // Special message id for logging | 338 #define IPC_LOGGING_ID 0xFFFFFFF1 // Special message id for logging |
| 296 | 339 |
| 297 #endif // IPC_IPC_MESSAGE_H_ | 340 #endif // IPC_IPC_MESSAGE_H_ |
| OLD | NEW |