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/brokerable_attachment.h" |
14 #include "ipc/ipc_export.h" | 15 #include "ipc/ipc_export.h" |
15 | 16 |
16 #if !defined(NDEBUG) | 17 #if !defined(NDEBUG) |
17 #define IPC_MESSAGE_LOG_ENABLED | 18 #define IPC_MESSAGE_LOG_ENABLED |
18 #endif | 19 #endif |
19 | 20 |
20 namespace IPC { | 21 namespace IPC { |
21 | 22 |
22 namespace internal { | 23 namespace internal { |
23 class ChannelReader; | 24 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, | 158 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, |
158 void (T::*func)(P*)) { | 159 void (T::*func)(P*)) { |
159 (obj->*func)(parameter); | 160 (obj->*func)(parameter); |
160 return true; | 161 return true; |
161 } | 162 } |
162 | 163 |
163 // Used for async messages with no parameters. | 164 // Used for async messages with no parameters. |
164 static void Log(std::string* name, const Message* msg, std::string* l) { | 165 static void Log(std::string* name, const Message* msg, std::string* l) { |
165 } | 166 } |
166 | 167 |
167 // Find the end of the message data that starts at range_start. Returns NULL | 168 // The static method FindNext() returns several pieces of information, which |
168 // if the entire message is not found in the given data range. | 169 // are aggregated into an instance of this struct. |
169 static const char* FindNext(const char* range_start, const char* range_end) { | 170 struct NextMessageInfo { |
170 return base::Pickle::FindNext(sizeof(Header), range_start, range_end); | 171 NextMessageInfo(); |
171 } | 172 ~NextMessageInfo(); |
| 173 |
| 174 // Whether an entire message was found in the given memory range. |
| 175 bool message_found; |
| 176 // Only filled in if |message_found| is true. |
| 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 // Only filled in if |message_found| is true. |
| 182 // The end address of the message should be used to determine the start |
| 183 // address of the next message. |
| 184 const char* message_end; |
| 185 // If the message has brokerable attachments, this vector will contain the |
| 186 // ids of the brokerable attachments. The caller of FindNext() is |
| 187 // responsible for adding the attachments to the message. |
| 188 std::vector<BrokerableAttachment::AttachmentId> attachment_ids; |
| 189 }; |
| 190 |
| 191 // |info| is an output parameter and must not be nullptr. |
| 192 static void FindNext(const char* range_start, |
| 193 const char* range_end, |
| 194 NextMessageInfo* info); |
172 | 195 |
173 // WriteAttachment appends |attachment| to the end of the set. It returns | 196 // WriteAttachment appends |attachment| to the end of the set. It returns |
174 // false iff the set is full. | 197 // false iff the set is full. |
175 bool WriteAttachment(scoped_refptr<MessageAttachment> attachment); | 198 bool WriteAttachment(scoped_refptr<MessageAttachment> attachment); |
176 // ReadAttachment parses an attachment given the parsing state |iter| and | 199 // ReadAttachment parses an attachment given the parsing state |iter| and |
177 // writes it to |*attachment|. It returns true on success. | 200 // writes it to |*attachment|. It returns true on success. |
178 bool ReadAttachment(base::PickleIterator* iter, | 201 bool ReadAttachment(base::PickleIterator* iter, |
179 scoped_refptr<MessageAttachment>* attachment) const; | 202 scoped_refptr<MessageAttachment>* attachment) const; |
180 // Returns true if there are any attachment in this message. | 203 // Returns true if there are any attachment in this message. |
181 bool HasAttachments() const; | 204 bool HasAttachments() const; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 MSG_ROUTING_NONE = -2, | 300 MSG_ROUTING_NONE = -2, |
278 | 301 |
279 // indicates a general message not sent to a particular tab. | 302 // indicates a general message not sent to a particular tab. |
280 MSG_ROUTING_CONTROL = kint32max, | 303 MSG_ROUTING_CONTROL = kint32max, |
281 }; | 304 }; |
282 | 305 |
283 #define IPC_REPLY_ID 0xFFFFFFF0 // Special message id for replies | 306 #define IPC_REPLY_ID 0xFFFFFFF0 // Special message id for replies |
284 #define IPC_LOGGING_ID 0xFFFFFFF1 // Special message id for logging | 307 #define IPC_LOGGING_ID 0xFFFFFFF1 // Special message id for logging |
285 | 308 |
286 #endif // IPC_IPC_MESSAGE_H_ | 309 #endif // IPC_IPC_MESSAGE_H_ |
OLD | NEW |