summaryrefslogtreecommitdiffstats
path: root/ipc/ipc_message_utils.h
diff options
context:
space:
mode:
authorerg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-11 17:36:32 +0000
committererg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-11 17:36:32 +0000
commit1c99edc8d48f94702ac085197779ea22b820549b (patch)
treedbcb2aa6714c5769a5a0c134011e90b104603144 /ipc/ipc_message_utils.h
parent4fd3c1a3faa42ee98f95e5f03182a597dea17196 (diff)
downloadchromium_src-1c99edc8d48f94702ac085197779ea22b820549b.zip
chromium_src-1c99edc8d48f94702ac085197779ea22b820549b.tar.gz
chromium_src-1c99edc8d48f94702ac085197779ea22b820549b.tar.bz2
Reapplies r55735, fixing some message code that was checked in that I collided with.
BUG=51411 TEST=none TBR=mpcomplete Review URL: http://codereview.chromium.org/3118009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55749 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ipc/ipc_message_utils.h')
-rw-r--r--ipc/ipc_message_utils.h117
1 files changed, 63 insertions, 54 deletions
diff --git a/ipc/ipc_message_utils.h b/ipc/ipc_message_utils.h
index cdad102..4882688 100644
--- a/ipc/ipc_message_utils.h
+++ b/ipc/ipc_message_utils.h
@@ -1164,8 +1164,54 @@ class MessageWithTuple : public Message {
}
};
+// defined in ipc_logging.cc
+void GenerateLogData(const std::string& channel, const Message& message,
+ LogData* data);
+
+
+#if defined(IPC_MESSAGE_LOG_ENABLED)
+inline void AddOutputParamsToLog(const Message* msg, std::wstring* l) {
+ const std::wstring& output_params = msg->output_params();
+ if (!l->empty() && !output_params.empty())
+ l->append(L", ");
+
+ l->append(output_params);
+}
+
+template <class ReplyParamType>
+inline void LogReplyParamsToMessage(const ReplyParamType& reply_params,
+ const Message* msg) {
+ if (msg->received_time() != 0) {
+ std::wstring output_params;
+ LogParam(reply_params, &output_params);
+ msg->set_output_params(output_params);
+ }
+}
+
+inline void ConnectMessageAndReply(const Message* msg, Message* reply) {
+ if (msg->sent_time()) {
+ // Don't log the sync message after dispatch, as we don't have the
+ // output parameters at that point. Instead, save its data and log it
+ // with the outgoing reply message when it's sent.
+ LogData* data = new LogData;
+ GenerateLogData("", *msg, data);
+ msg->set_dont_log();
+ reply->set_sync_log_data(data);
+ }
+}
+#else
+inline void AddOutputParamsToLog(const Message* msg, std::wstring* l) {}
+
+template <class ReplyParamType>
+inline void LogReplyParamsToMessage(const ReplyParamType& reply_params,
+ const Message* msg) {}
+
+inline void ConnectMessageAndReply(const Message* msg, Message* reply) {}
+#endif
+
// This class assumes that its template argument is a RefTuple (a Tuple with
-// reference elements).
+// reference elements). This would go into ipc_message_utils_impl.h, but it is
+// also used by chrome_frame.
template <class RefTuple>
class ParamDeserializer : public MessageReplyDeserializer {
public:
@@ -1178,10 +1224,6 @@ class ParamDeserializer : public MessageReplyDeserializer {
RefTuple out_;
};
-// defined in ipc_logging.cc
-void GenerateLogData(const std::string& channel, const Message& message,
- LogData* data);
-
// Used for synchronous messages.
template <class SendParamType, class ReplyParamType>
class MessageWithReply : public SyncMessage {
@@ -1191,54 +1233,33 @@ class MessageWithReply : public SyncMessage {
typedef ReplyParamType ReplyParam;
MessageWithReply(int32 routing_id, uint32 type,
- const RefSendParam& send, const ReplyParam& reply)
- : SyncMessage(routing_id, type, PRIORITY_NORMAL,
- new ParamDeserializer<ReplyParam>(reply)) {
- WriteParam(this, send);
- }
-
- static void Log(const Message* msg, std::wstring* l) {
- if (msg->is_sync()) {
- SendParam p;
- void* iter = SyncMessage::GetDataIterator(msg);
- if (ReadParam(msg, &iter, &p))
- LogParam(p, l);
+ const RefSendParam& send, const ReplyParam& reply);
-#if defined(IPC_MESSAGE_LOG_ENABLED)
- const std::wstring& output_params = msg->output_params();
- if (!l->empty() && !output_params.empty())
- l->append(L", ");
+ // TODO(erg): Migrate these ReadSendParam/ReadReplyParam() methods to
+ // ipc_message_utils_impl.h once I figure out how to get the linkage correct
+ // in the release builds.
+ static bool ReadSendParam(const Message* msg, SendParam* p) {
+ void* iter = SyncMessage::GetDataIterator(msg);
+ return ReadParam(msg, &iter, p);
+ }
- l->append(output_params);
-#endif
- } else {
- // This is an outgoing reply. Now that we have the output parameters, we
- // can finally log the message.
- typename TupleTypes<ReplyParam>::ValueTuple p;
- void* iter = SyncMessage::GetDataIterator(msg);
- if (ReadParam(msg, &iter, &p))
- LogParam(p, l);
- }
+ static bool ReadReplyParam(const Message* msg,
+ typename TupleTypes<ReplyParam>::ValueTuple* p) {
+ void* iter = SyncMessage::GetDataIterator(msg);
+ return ReadParam(msg, &iter, p);
}
template<class T, class Method>
static bool Dispatch(const Message* msg, T* obj, Method func) {
SendParam send_params;
- void* iter = GetDataIterator(msg);
Message* reply = GenerateReply(msg);
bool error;
- if (ReadParam(msg, &iter, &send_params)) {
+ if (ReadSendParam(msg, &send_params)) {
typename TupleTypes<ReplyParam>::ValueTuple reply_params;
DispatchToMethod(obj, func, send_params, &reply_params);
WriteParam(reply, reply_params);
error = false;
-#ifdef IPC_MESSAGE_LOG_ENABLED
- if (msg->received_time() != 0) {
- std::wstring output_params;
- LogParam(reply_params, &output_params);
- msg->set_output_params(output_params);
- }
-#endif
+ LogReplyParamsToMessage(reply_params, msg);
} else {
NOTREACHED() << "Error deserializing message " << msg->type();
reply->set_reply_error();
@@ -1252,23 +1273,11 @@ class MessageWithReply : public SyncMessage {
template<class T, class Method>
static bool DispatchDelayReply(const Message* msg, T* obj, Method func) {
SendParam send_params;
- void* iter = GetDataIterator(msg);
Message* reply = GenerateReply(msg);
bool error;
- if (ReadParam(msg, &iter, &send_params)) {
+ if (ReadSendParam(msg, &send_params)) {
Tuple1<Message&> t = MakeRefTuple(*reply);
-
-#ifdef IPC_MESSAGE_LOG_ENABLED
- if (msg->sent_time()) {
- // Don't log the sync message after dispatch, as we don't have the
- // output parameters at that point. Instead, save its data and log it
- // with the outgoing reply message when it's sent.
- LogData* data = new LogData;
- GenerateLogData("", *msg, data);
- msg->set_dont_log();
- reply->set_sync_log_data(data);
- }
-#endif
+ ConnectMessageAndReply(msg, reply);
DispatchToMethod(obj, func, send_params, &t);
error = false;
} else {