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