Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: ipc/ipc_message_utils.h

Issue 3118009: Reapplies r55735, fixing some message code that was checked in that I collided with. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ipc/ipc_message_macros.h ('k') | ipc/ipc_message_utils_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_UTILS_H_ 5 #ifndef IPC_IPC_MESSAGE_UTILS_H_
6 #define IPC_IPC_MESSAGE_UTILS_H_ 6 #define IPC_IPC_MESSAGE_UTILS_H_
7 #pragma once 7 #pragma once
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <string> 10 #include <string>
(...skipping 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1157 return false; 1157 return false;
1158 *a = params.a; 1158 *a = params.a;
1159 *b = params.b; 1159 *b = params.b;
1160 *c = params.c; 1160 *c = params.c;
1161 *d = params.d; 1161 *d = params.d;
1162 *e = params.e; 1162 *e = params.e;
1163 return true; 1163 return true;
1164 } 1164 }
1165 }; 1165 };
1166 1166
1167 // defined in ipc_logging.cc
1168 void GenerateLogData(const std::string& channel, const Message& message,
1169 LogData* data);
1170
1171
1172 #if defined(IPC_MESSAGE_LOG_ENABLED)
1173 inline void AddOutputParamsToLog(const Message* msg, std::wstring* l) {
1174 const std::wstring& output_params = msg->output_params();
1175 if (!l->empty() && !output_params.empty())
1176 l->append(L", ");
1177
1178 l->append(output_params);
1179 }
1180
1181 template <class ReplyParamType>
1182 inline void LogReplyParamsToMessage(const ReplyParamType& reply_params,
1183 const Message* msg) {
1184 if (msg->received_time() != 0) {
1185 std::wstring output_params;
1186 LogParam(reply_params, &output_params);
1187 msg->set_output_params(output_params);
1188 }
1189 }
1190
1191 inline void ConnectMessageAndReply(const Message* msg, Message* reply) {
1192 if (msg->sent_time()) {
1193 // Don't log the sync message after dispatch, as we don't have the
1194 // output parameters at that point. Instead, save its data and log it
1195 // with the outgoing reply message when it's sent.
1196 LogData* data = new LogData;
1197 GenerateLogData("", *msg, data);
1198 msg->set_dont_log();
1199 reply->set_sync_log_data(data);
1200 }
1201 }
1202 #else
1203 inline void AddOutputParamsToLog(const Message* msg, std::wstring* l) {}
1204
1205 template <class ReplyParamType>
1206 inline void LogReplyParamsToMessage(const ReplyParamType& reply_params,
1207 const Message* msg) {}
1208
1209 inline void ConnectMessageAndReply(const Message* msg, Message* reply) {}
1210 #endif
1211
1167 // This class assumes that its template argument is a RefTuple (a Tuple with 1212 // This class assumes that its template argument is a RefTuple (a Tuple with
1168 // reference elements). 1213 // reference elements). This would go into ipc_message_utils_impl.h, but it is
1214 // also used by chrome_frame.
1169 template <class RefTuple> 1215 template <class RefTuple>
1170 class ParamDeserializer : public MessageReplyDeserializer { 1216 class ParamDeserializer : public MessageReplyDeserializer {
1171 public: 1217 public:
1172 explicit ParamDeserializer(const RefTuple& out) : out_(out) { } 1218 explicit ParamDeserializer(const RefTuple& out) : out_(out) { }
1173 1219
1174 bool SerializeOutputParameters(const IPC::Message& msg, void* iter) { 1220 bool SerializeOutputParameters(const IPC::Message& msg, void* iter) {
1175 return ReadParam(&msg, &iter, &out_); 1221 return ReadParam(&msg, &iter, &out_);
1176 } 1222 }
1177 1223
1178 RefTuple out_; 1224 RefTuple out_;
1179 }; 1225 };
1180 1226
1181 // defined in ipc_logging.cc
1182 void GenerateLogData(const std::string& channel, const Message& message,
1183 LogData* data);
1184
1185 // Used for synchronous messages. 1227 // Used for synchronous messages.
1186 template <class SendParamType, class ReplyParamType> 1228 template <class SendParamType, class ReplyParamType>
1187 class MessageWithReply : public SyncMessage { 1229 class MessageWithReply : public SyncMessage {
1188 public: 1230 public:
1189 typedef SendParamType SendParam; 1231 typedef SendParamType SendParam;
1190 typedef typename TupleTypes<SendParam>::ParamTuple RefSendParam; 1232 typedef typename TupleTypes<SendParam>::ParamTuple RefSendParam;
1191 typedef ReplyParamType ReplyParam; 1233 typedef ReplyParamType ReplyParam;
1192 1234
1193 MessageWithReply(int32 routing_id, uint32 type, 1235 MessageWithReply(int32 routing_id, uint32 type,
1194 const RefSendParam& send, const ReplyParam& reply) 1236 const RefSendParam& send, const ReplyParam& reply);
1195 : SyncMessage(routing_id, type, PRIORITY_NORMAL, 1237
1196 new ParamDeserializer<ReplyParam>(reply)) { 1238 // TODO(erg): Migrate these ReadSendParam/ReadReplyParam() methods to
1197 WriteParam(this, send); 1239 // ipc_message_utils_impl.h once I figure out how to get the linkage correct
1240 // in the release builds.
1241 static bool ReadSendParam(const Message* msg, SendParam* p) {
1242 void* iter = SyncMessage::GetDataIterator(msg);
1243 return ReadParam(msg, &iter, p);
1198 } 1244 }
1199 1245
1200 static void Log(const Message* msg, std::wstring* l) { 1246 static bool ReadReplyParam(const Message* msg,
1201 if (msg->is_sync()) { 1247 typename TupleTypes<ReplyParam>::ValueTuple* p) {
1202 SendParam p; 1248 void* iter = SyncMessage::GetDataIterator(msg);
1203 void* iter = SyncMessage::GetDataIterator(msg); 1249 return ReadParam(msg, &iter, p);
1204 if (ReadParam(msg, &iter, &p))
1205 LogParam(p, l);
1206
1207 #if defined(IPC_MESSAGE_LOG_ENABLED)
1208 const std::wstring& output_params = msg->output_params();
1209 if (!l->empty() && !output_params.empty())
1210 l->append(L", ");
1211
1212 l->append(output_params);
1213 #endif
1214 } else {
1215 // This is an outgoing reply. Now that we have the output parameters, we
1216 // can finally log the message.
1217 typename TupleTypes<ReplyParam>::ValueTuple p;
1218 void* iter = SyncMessage::GetDataIterator(msg);
1219 if (ReadParam(msg, &iter, &p))
1220 LogParam(p, l);
1221 }
1222 } 1250 }
1223 1251
1224 template<class T, class Method> 1252 template<class T, class Method>
1225 static bool Dispatch(const Message* msg, T* obj, Method func) { 1253 static bool Dispatch(const Message* msg, T* obj, Method func) {
1226 SendParam send_params; 1254 SendParam send_params;
1227 void* iter = GetDataIterator(msg);
1228 Message* reply = GenerateReply(msg); 1255 Message* reply = GenerateReply(msg);
1229 bool error; 1256 bool error;
1230 if (ReadParam(msg, &iter, &send_params)) { 1257 if (ReadSendParam(msg, &send_params)) {
1231 typename TupleTypes<ReplyParam>::ValueTuple reply_params; 1258 typename TupleTypes<ReplyParam>::ValueTuple reply_params;
1232 DispatchToMethod(obj, func, send_params, &reply_params); 1259 DispatchToMethod(obj, func, send_params, &reply_params);
1233 WriteParam(reply, reply_params); 1260 WriteParam(reply, reply_params);
1234 error = false; 1261 error = false;
1235 #ifdef IPC_MESSAGE_LOG_ENABLED 1262 LogReplyParamsToMessage(reply_params, msg);
1236 if (msg->received_time() != 0) {
1237 std::wstring output_params;
1238 LogParam(reply_params, &output_params);
1239 msg->set_output_params(output_params);
1240 }
1241 #endif
1242 } else { 1263 } else {
1243 NOTREACHED() << "Error deserializing message " << msg->type(); 1264 NOTREACHED() << "Error deserializing message " << msg->type();
1244 reply->set_reply_error(); 1265 reply->set_reply_error();
1245 error = true; 1266 error = true;
1246 } 1267 }
1247 1268
1248 obj->Send(reply); 1269 obj->Send(reply);
1249 return !error; 1270 return !error;
1250 } 1271 }
1251 1272
1252 template<class T, class Method> 1273 template<class T, class Method>
1253 static bool DispatchDelayReply(const Message* msg, T* obj, Method func) { 1274 static bool DispatchDelayReply(const Message* msg, T* obj, Method func) {
1254 SendParam send_params; 1275 SendParam send_params;
1255 void* iter = GetDataIterator(msg);
1256 Message* reply = GenerateReply(msg); 1276 Message* reply = GenerateReply(msg);
1257 bool error; 1277 bool error;
1258 if (ReadParam(msg, &iter, &send_params)) { 1278 if (ReadSendParam(msg, &send_params)) {
1259 Tuple1<Message&> t = MakeRefTuple(*reply); 1279 Tuple1<Message&> t = MakeRefTuple(*reply);
1260 1280 ConnectMessageAndReply(msg, reply);
1261 #ifdef IPC_MESSAGE_LOG_ENABLED
1262 if (msg->sent_time()) {
1263 // Don't log the sync message after dispatch, as we don't have the
1264 // output parameters at that point. Instead, save its data and log it
1265 // with the outgoing reply message when it's sent.
1266 LogData* data = new LogData;
1267 GenerateLogData("", *msg, data);
1268 msg->set_dont_log();
1269 reply->set_sync_log_data(data);
1270 }
1271 #endif
1272 DispatchToMethod(obj, func, send_params, &t); 1281 DispatchToMethod(obj, func, send_params, &t);
1273 error = false; 1282 error = false;
1274 } else { 1283 } else {
1275 NOTREACHED() << "Error deserializing message " << msg->type(); 1284 NOTREACHED() << "Error deserializing message " << msg->type();
1276 reply->set_reply_error(); 1285 reply->set_reply_error();
1277 obj->Send(reply); 1286 obj->Send(reply);
1278 error = true; 1287 error = true;
1279 } 1288 }
1280 return !error; 1289 return !error;
1281 } 1290 }
(...skipping 27 matching lines...) Expand all
1309 ReplyParam p(a, b, c, d, e); 1318 ReplyParam p(a, b, c, d, e);
1310 WriteParam(reply, p); 1319 WriteParam(reply, p);
1311 } 1320 }
1312 }; 1321 };
1313 1322
1314 //----------------------------------------------------------------------------- 1323 //-----------------------------------------------------------------------------
1315 1324
1316 } // namespace IPC 1325 } // namespace IPC
1317 1326
1318 #endif // IPC_IPC_MESSAGE_UTILS_H_ 1327 #endif // IPC_IPC_MESSAGE_UTILS_H_
OLDNEW
« no previous file with comments | « ipc/ipc_message_macros.h ('k') | ipc/ipc_message_utils_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698