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" | 14 #include "ipc/attachment_broker.h" |
15 #include "ipc/brokerable_attachment.h" | |
15 #include "ipc/ipc_export.h" | 16 #include "ipc/ipc_export.h" |
16 | 17 |
17 #if !defined(NDEBUG) | 18 #if !defined(NDEBUG) |
18 #define IPC_MESSAGE_LOG_ENABLED | 19 #define IPC_MESSAGE_LOG_ENABLED |
19 #endif | 20 #endif |
20 | 21 |
21 namespace IPC { | 22 namespace IPC { |
22 | 23 |
23 namespace internal { | 24 namespace internal { |
24 class ChannelReader; | 25 class ChannelReader; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 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, |
159 void (T::*func)(P*)) { | 160 void (T::*func)(P*)) { |
160 (obj->*func)(parameter); | 161 (obj->*func)(parameter); |
161 return true; | 162 return true; |
162 } | 163 } |
163 | 164 |
164 // Used for async messages with no parameters. | 165 // Used for async messages with no parameters. |
165 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) { |
166 } | 167 } |
167 | 168 |
168 // 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 |
169 // if the entire message is not found in the given data range. | 170 // are aggregated into an instance of this struct. |
Tom Sepez
2015/09/01 18:01:54
nit: this may be complex enough to warrant being a
erikchen
2015/09/04 02:13:39
This is just a wrapper around several different pi
| |
170 static const char* FindNext(const char* range_start, const char* range_end) { | 171 struct NextMessageInfo { |
171 return base::Pickle::FindNext(sizeof(Header), range_start, range_end); | 172 NextMessageInfo(); |
172 } | 173 ~NextMessageInfo(); |
174 // Whether an entire message was found in the given memory range. | |
175 bool message_found; | |
176 // The parser encountered an unrecoverable error. This will always be false | |
177 // if |message_found| is true. | |
178 bool parsing_error; | |
179 // Only filled in if |message_found| is true. | |
180 // The start address is passed into FindNext() by the caller, so isn't | |
181 // repeated in this struct. The end address of the pickle should be used to | |
182 // construct a base::Pickle. | |
183 const char* pickle_end; | |
184 // Only filled in if |message_found| is true. | |
185 // The end address of the message should be used to determine the start | |
186 // address of the next message. | |
187 const char* message_end; | |
188 // If the message has brokerable attachments, this vector will contain the | |
189 // ids of the brokerable attachments. The caller of FindNext() is | |
190 // responsible for adding the attachments to the message. | |
191 std::vector<BrokerableAttachment::AttachmentId> attachment_ids; | |
192 }; | |
193 | |
194 static NextMessageInfo FindNext(const char* range_start, | |
195 const char* range_end); | |
173 | 196 |
174 // WriteAttachment appends |attachment| to the end of the set. It returns | 197 // WriteAttachment appends |attachment| to the end of the set. It returns |
175 // false iff the set is full. | 198 // false iff the set is full. |
176 bool WriteAttachment(scoped_refptr<MessageAttachment> attachment); | 199 bool WriteAttachment(scoped_refptr<MessageAttachment> attachment); |
177 // ReadAttachment parses an attachment given the parsing state |iter| and | 200 // ReadAttachment parses an attachment given the parsing state |iter| and |
178 // writes it to |*attachment|. It returns true on success. | 201 // writes it to |*attachment|. It returns true on success. |
179 bool ReadAttachment(base::PickleIterator* iter, | 202 bool ReadAttachment(base::PickleIterator* iter, |
180 scoped_refptr<MessageAttachment>* attachment) const; | 203 scoped_refptr<MessageAttachment>* attachment) const; |
181 // Returns true if there are any attachment in this message. | 204 // Returns true if there are any attachment in this message. |
182 bool HasAttachments() const; | 205 bool HasAttachments() const; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
284 MSG_ROUTING_NONE = -2, | 307 MSG_ROUTING_NONE = -2, |
285 | 308 |
286 // indicates a general message not sent to a particular tab. | 309 // indicates a general message not sent to a particular tab. |
287 MSG_ROUTING_CONTROL = kint32max, | 310 MSG_ROUTING_CONTROL = kint32max, |
288 }; | 311 }; |
289 | 312 |
290 #define IPC_REPLY_ID 0xFFFFFFF0 // Special message id for replies | 313 #define IPC_REPLY_ID 0xFFFFFFF0 // Special message id for replies |
291 #define IPC_LOGGING_ID 0xFFFFFFF1 // Special message id for logging | 314 #define IPC_LOGGING_ID 0xFFFFFFF1 // Special message id for logging |
292 | 315 |
293 #endif // IPC_IPC_MESSAGE_H_ | 316 #endif // IPC_IPC_MESSAGE_H_ |
OLD | NEW |