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 <stdint.h> | |
8 #include <string> | 9 #include <string> |
Tom Sepez
2015/09/03 19:53:09
nit: ditto
tfarina
2015/09/04 14:01:14
Done.
| |
9 | 10 |
10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
11 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
12 #include "base/pickle.h" | 13 #include "base/pickle.h" |
13 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.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 |
(...skipping 30 matching lines...) Expand all Loading... | |
49 PUMPING_MSGS_BIT = 0x40, | 50 PUMPING_MSGS_BIT = 0x40, |
50 HAS_SENT_TIME_BIT = 0x80, | 51 HAS_SENT_TIME_BIT = 0x80, |
51 }; | 52 }; |
52 | 53 |
53 ~Message() override; | 54 ~Message() override; |
54 | 55 |
55 Message(); | 56 Message(); |
56 | 57 |
57 // Initialize a message with a user-defined type, priority value, and | 58 // Initialize a message with a user-defined type, priority value, and |
58 // destination WebView ID. | 59 // destination WebView ID. |
59 Message(int32 routing_id, uint32 type, PriorityValue priority); | 60 Message(int32_t routing_id, uint32_t type, PriorityValue priority); |
60 | 61 |
61 // Initializes a message from a const block of data. The data is not copied; | 62 // Initializes a message from a const block of data. The data is not copied; |
62 // instead the data is merely referenced by this message. Only const methods | 63 // instead the data is merely referenced by this message. Only const methods |
63 // should be used on the message when initialized this way. | 64 // should be used on the message when initialized this way. |
64 Message(const char* data, int data_len); | 65 Message(const char* data, int data_len); |
65 | 66 |
66 Message(const Message& other); | 67 Message(const Message& other); |
67 Message& operator=(const Message& other); | 68 Message& operator=(const Message& other); |
68 | 69 |
69 PriorityValue priority() const { | 70 PriorityValue priority() const { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 } | 120 } |
120 | 121 |
121 void set_dispatch_error() const { | 122 void set_dispatch_error() const { |
122 dispatch_error_ = true; | 123 dispatch_error_ = true; |
123 } | 124 } |
124 | 125 |
125 bool dispatch_error() const { | 126 bool dispatch_error() const { |
126 return dispatch_error_; | 127 return dispatch_error_; |
127 } | 128 } |
128 | 129 |
129 uint32 type() const { | 130 uint32_t type() const { |
130 return header()->type; | 131 return header()->type; |
131 } | 132 } |
132 | 133 |
133 int32 routing_id() const { | 134 int32_t routing_id() const { |
134 return header()->routing; | 135 return header()->routing; |
135 } | 136 } |
136 | 137 |
137 void set_routing_id(int32 new_id) { | 138 void set_routing_id(int32_t new_id) { |
138 header()->routing = new_id; | 139 header()->routing = new_id; |
139 } | 140 } |
140 | 141 |
141 uint32 flags() const { | 142 uint32_t flags() const { |
142 return header()->flags; | 143 return header()->flags; |
143 } | 144 } |
144 | 145 |
145 // Sets all the given header values. The message should be empty at this | 146 // Sets all the given header values. The message should be empty at this |
146 // call. | 147 // call. |
147 void SetHeaderValues(int32 routing, uint32 type, uint32 flags); | 148 void SetHeaderValues(int32_t routing, uint32_t type, uint32_t flags); |
148 | 149 |
149 template<class T, class S, class P> | 150 template<class T, class S, class P> |
150 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, | 151 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, |
151 void (T::*func)()) { | 152 void (T::*func)()) { |
152 (obj->*func)(); | 153 (obj->*func)(); |
153 return true; | 154 return true; |
154 } | 155 } |
155 | 156 |
156 template<class T, class S, class P> | 157 template<class T, class S, class P> |
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, |
(...skipping 25 matching lines...) Expand all Loading... | |
183 bool HasMojoHandles() const; | 184 bool HasMojoHandles() const; |
184 // Whether the message has any brokerable attachments. | 185 // Whether the message has any brokerable attachments. |
185 bool HasBrokerableAttachments() const; | 186 bool HasBrokerableAttachments() const; |
186 | 187 |
187 void set_sender_pid(base::ProcessId id) { sender_pid_ = id; } | 188 void set_sender_pid(base::ProcessId id) { sender_pid_ = id; } |
188 base::ProcessId get_sender_pid() const { return sender_pid_; } | 189 base::ProcessId get_sender_pid() const { return sender_pid_; } |
189 | 190 |
190 #ifdef IPC_MESSAGE_LOG_ENABLED | 191 #ifdef IPC_MESSAGE_LOG_ENABLED |
191 // Adds the outgoing time from Time::Now() at the end of the message and sets | 192 // Adds the outgoing time from Time::Now() at the end of the message and sets |
192 // a bit to indicate that it's been added. | 193 // a bit to indicate that it's been added. |
193 void set_sent_time(int64 time); | 194 void set_sent_time(int64_t time); |
194 int64 sent_time() const; | 195 int64_t sent_time() const; |
195 | 196 |
196 void set_received_time(int64 time) const; | 197 void set_received_time(int64_t time) const; |
197 int64 received_time() const { return received_time_; } | 198 int64_t received_time() const { return received_time_; } |
198 void set_output_params(const std::string& op) const { output_params_ = op; } | 199 void set_output_params(const std::string& op) const { output_params_ = op; } |
199 const std::string& output_params() const { return output_params_; } | 200 const std::string& output_params() const { return output_params_; } |
200 // The following four functions are needed so we can log sync messages with | 201 // The following four functions are needed so we can log sync messages with |
201 // delayed replies. We stick the log data from the sent message into the | 202 // delayed replies. We stick the log data from the sent message into the |
202 // reply message, so that when it's sent and we have the output parameters | 203 // reply message, so that when it's sent and we have the output parameters |
203 // we can log it. As such, we set a flag on the sent message to not log it. | 204 // we can log it. As such, we set a flag on the sent message to not log it. |
204 void set_sync_log_data(LogData* data) const { log_data_ = data; } | 205 void set_sync_log_data(LogData* data) const { log_data_ = data; } |
205 LogData* sync_log_data() const { return log_data_; } | 206 LogData* sync_log_data() const { return log_data_; } |
206 void set_dont_log() const { dont_log_ = true; } | 207 void set_dont_log() const { dont_log_ = true; } |
207 bool dont_log() const { return dont_log_; } | 208 bool dont_log() const { return dont_log_; } |
208 #endif | 209 #endif |
209 | 210 |
210 protected: | 211 protected: |
211 friend class Channel; | 212 friend class Channel; |
212 friend class ChannelMojo; | 213 friend class ChannelMojo; |
213 friend class ChannelNacl; | 214 friend class ChannelNacl; |
214 friend class ChannelPosix; | 215 friend class ChannelPosix; |
215 friend class ChannelWin; | 216 friend class ChannelWin; |
216 friend class internal::ChannelReader; | 217 friend class internal::ChannelReader; |
217 friend class MessageReplyDeserializer; | 218 friend class MessageReplyDeserializer; |
218 friend class SyncMessage; | 219 friend class SyncMessage; |
219 | 220 |
220 #pragma pack(push, 4) | 221 #pragma pack(push, 4) |
221 struct Header : base::Pickle::Header { | 222 struct Header : base::Pickle::Header { |
222 int32 routing; // ID of the view that this message is destined for | 223 int32_t routing; // ID of the view that this message is destined for |
223 uint32 type; // specifies the user-defined message type | 224 uint32_t type; // specifies the user-defined message type |
224 uint32 flags; // specifies control flags for the message | 225 uint32_t flags; // specifies control flags for the message |
225 #if defined(OS_POSIX) | 226 #if defined(OS_POSIX) |
226 uint16 num_fds; // the number of descriptors included with this message | 227 uint16_t num_fds; // the number of descriptors included with this message |
227 uint16 pad; // explicitly initialize this to appease valgrind | 228 uint16_t pad; // explicitly initialize this to appease valgrind |
228 #endif | 229 #endif |
229 }; | 230 }; |
230 #pragma pack(pop) | 231 #pragma pack(pop) |
231 | 232 |
232 Header* header() { | 233 Header* header() { |
233 return headerT<Header>(); | 234 return headerT<Header>(); |
234 } | 235 } |
235 const Header* header() const { | 236 const Header* header() const { |
236 return headerT<Header>(); | 237 return headerT<Header>(); |
237 } | 238 } |
(...skipping 16 matching lines...) Expand all Loading... | |
254 const MessageAttachmentSet* attachment_set() const { | 255 const MessageAttachmentSet* attachment_set() const { |
255 return attachment_set_.get(); | 256 return attachment_set_.get(); |
256 } | 257 } |
257 | 258 |
258 // The process id of the sender of the message. This member is populated with | 259 // The process id of the sender of the message. This member is populated with |
259 // a valid value for every message dispatched to listeners. | 260 // a valid value for every message dispatched to listeners. |
260 base::ProcessId sender_pid_; | 261 base::ProcessId sender_pid_; |
261 | 262 |
262 #ifdef IPC_MESSAGE_LOG_ENABLED | 263 #ifdef IPC_MESSAGE_LOG_ENABLED |
263 // Used for logging. | 264 // Used for logging. |
264 mutable int64 received_time_; | 265 mutable int64_t received_time_; |
265 mutable std::string output_params_; | 266 mutable std::string output_params_; |
266 mutable LogData* log_data_; | 267 mutable LogData* log_data_; |
267 mutable bool dont_log_; | 268 mutable bool dont_log_; |
268 #endif | 269 #endif |
269 }; | 270 }; |
270 | 271 |
271 //------------------------------------------------------------------------------ | 272 //------------------------------------------------------------------------------ |
272 | 273 |
273 } // namespace IPC | 274 } // namespace IPC |
274 | 275 |
275 enum SpecialRoutingIDs { | 276 enum SpecialRoutingIDs { |
276 // indicates that we don't have a routing ID yet. | 277 // indicates that we don't have a routing ID yet. |
277 MSG_ROUTING_NONE = -2, | 278 MSG_ROUTING_NONE = -2, |
278 | 279 |
279 // indicates a general message not sent to a particular tab. | 280 // indicates a general message not sent to a particular tab. |
280 MSG_ROUTING_CONTROL = kint32max, | 281 MSG_ROUTING_CONTROL = kint32max, |
281 }; | 282 }; |
282 | 283 |
283 #define IPC_REPLY_ID 0xFFFFFFF0 // Special message id for replies | 284 #define IPC_REPLY_ID 0xFFFFFFF0 // Special message id for replies |
284 #define IPC_LOGGING_ID 0xFFFFFFF1 // Special message id for logging | 285 #define IPC_LOGGING_ID 0xFFFFFFF1 // Special message id for logging |
285 | 286 |
286 #endif // IPC_IPC_MESSAGE_H_ | 287 #endif // IPC_IPC_MESSAGE_H_ |
OLD | NEW |