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

Side by Side Diff: ipc/ipc_message_utils.h

Issue 3018045: FBTF: Allow forward declaration of classes passed to sync IPC messages. (Closed)
Patch Set: Fix linkage problems with previous patch. 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 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 class MessageWithTuple : public Message { 1024 class MessageWithTuple : public Message {
1025 public: 1025 public:
1026 typedef ParamType Param; 1026 typedef ParamType Param;
1027 typedef typename TupleTypes<ParamType>::ParamTuple RefParam; 1027 typedef typename TupleTypes<ParamType>::ParamTuple RefParam;
1028 1028
1029 // The constructor and the Read() method's templated implementations are in 1029 // The constructor and the Read() method's templated implementations are in
1030 // ipc_message_utils_impl.h. The subclass constructor and Log() methods call 1030 // ipc_message_utils_impl.h. The subclass constructor and Log() methods call
1031 // the templated versions of these and make sure there are instantiations in 1031 // the templated versions of these and make sure there are instantiations in
1032 // those translation units. 1032 // those translation units.
1033 MessageWithTuple(int32 routing_id, uint32 type, const RefParam& p); 1033 MessageWithTuple(int32 routing_id, uint32 type, const RefParam& p);
1034 static bool Read(const Message* msg, Param* p); 1034
1035 // TODO(erg): Migrate the Read() method to ipc_message_utils_impl.h once I
1036 // figure out how to get the linkage correct in the release builds.
1037 static bool Read(const Message* msg, Param* p) {
1038 void* iter = NULL;
1039 if (ReadParam(msg, &iter, p))
1040 return true;
1041 NOTREACHED() << "Error deserializing message " << msg->type();
1042 return false;
1043 }
1035 1044
1036 // Generic dispatcher. Should cover most cases. 1045 // Generic dispatcher. Should cover most cases.
1037 template<class T, class Method> 1046 template<class T, class Method>
1038 static bool Dispatch(const Message* msg, T* obj, Method func) { 1047 static bool Dispatch(const Message* msg, T* obj, Method func) {
1039 Param p; 1048 Param p;
1040 if (Read(msg, &p)) { 1049 if (Read(msg, &p)) {
1041 DispatchToMethod(obj, func, p); 1050 DispatchToMethod(obj, func, p);
1042 return true; 1051 return true;
1043 } 1052 }
1044 return false; 1053 return false;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 return false; 1154 return false;
1146 *a = params.a; 1155 *a = params.a;
1147 *b = params.b; 1156 *b = params.b;
1148 *c = params.c; 1157 *c = params.c;
1149 *d = params.d; 1158 *d = params.d;
1150 *e = params.e; 1159 *e = params.e;
1151 return true; 1160 return true;
1152 } 1161 }
1153 }; 1162 };
1154 1163
1164 // defined in ipc_logging.cc
1165 void GenerateLogData(const std::string& channel, const Message& message,
1166 LogData* data);
1167
1168
1169 #if defined(IPC_MESSAGE_LOG_ENABLED)
1170 inline void AddOutputParamsToLog(const Message* msg, std::wstring* l) {
1171 const std::wstring& output_params = msg->output_params();
1172 if (!l->empty() && !output_params.empty())
1173 l->append(L", ");
1174
1175 l->append(output_params);
1176 }
1177
1178 template <class ReplyParamType>
1179 inline void LogReplyParamsToMessage(const ReplyParamType& reply_params,
1180 const Message* msg) {
1181 if (msg->received_time() != 0) {
1182 std::wstring output_params;
1183 LogParam(reply_params, &output_params);
1184 msg->set_output_params(output_params);
1185 }
1186 }
1187
1188 inline void ConnectMessageAndReply(const Message* msg, Message* reply) {
1189 if (msg->sent_time()) {
1190 // Don't log the sync message after dispatch, as we don't have the
1191 // output parameters at that point. Instead, save its data and log it
1192 // with the outgoing reply message when it's sent.
1193 LogData* data = new LogData;
1194 GenerateLogData("", *msg, data);
1195 msg->set_dont_log();
1196 reply->set_sync_log_data(data);
1197 }
1198 }
1199 #else
1200 inline void AddOutputParamsToLog(const Message* msg, std::wstring* l) {}
1201
1202 template <class ReplyParamType>
1203 inline void LogReplyParamsToMessage(const ReplyParamType& reply_params,
1204 const Message* msg) {}
1205
1206 inline void ConnectMessageAndReply(const Message* msg, Message* reply) {}
1207 #endif
1208
1155 // This class assumes that its template argument is a RefTuple (a Tuple with 1209 // This class assumes that its template argument is a RefTuple (a Tuple with
1156 // reference elements). 1210 // reference elements). This would go into ipc_message_utils_impl.h, but it is
1211 // also used by chrome_frame.
1157 template <class RefTuple> 1212 template <class RefTuple>
1158 class ParamDeserializer : public MessageReplyDeserializer { 1213 class ParamDeserializer : public MessageReplyDeserializer {
1159 public: 1214 public:
1160 explicit ParamDeserializer(const RefTuple& out) : out_(out) { } 1215 explicit ParamDeserializer(const RefTuple& out) : out_(out) { }
1161 1216
1162 bool SerializeOutputParameters(const IPC::Message& msg, void* iter) { 1217 bool SerializeOutputParameters(const IPC::Message& msg, void* iter) {
1163 return ReadParam(&msg, &iter, &out_); 1218 return ReadParam(&msg, &iter, &out_);
1164 } 1219 }
1165 1220
1166 RefTuple out_; 1221 RefTuple out_;
1167 }; 1222 };
1168 1223
1169 // defined in ipc_logging.cc
1170 void GenerateLogData(const std::string& channel, const Message& message,
1171 LogData* data);
1172
1173 // Used for synchronous messages. 1224 // Used for synchronous messages.
1174 template <class SendParamType, class ReplyParamType> 1225 template <class SendParamType, class ReplyParamType>
1175 class MessageWithReply : public SyncMessage { 1226 class MessageWithReply : public SyncMessage {
1176 public: 1227 public:
1177 typedef SendParamType SendParam; 1228 typedef SendParamType SendParam;
1178 typedef typename TupleTypes<SendParam>::ParamTuple RefSendParam; 1229 typedef typename TupleTypes<SendParam>::ParamTuple RefSendParam;
1179 typedef ReplyParamType ReplyParam; 1230 typedef ReplyParamType ReplyParam;
1180 1231
1181 MessageWithReply(int32 routing_id, uint32 type, 1232 MessageWithReply(int32 routing_id, uint32 type,
1182 const RefSendParam& send, const ReplyParam& reply) 1233 const RefSendParam& send, const ReplyParam& reply);
1183 : SyncMessage(routing_id, type, PRIORITY_NORMAL, 1234
1184 new ParamDeserializer<ReplyParam>(reply)) { 1235 // TODO(erg): Migrate these ReadSendParam/ReadReplyParam() methods to
1185 WriteParam(this, send); 1236 // ipc_message_utils_impl.h once I figure out how to get the linkage correct
1237 // in the release builds.
1238 static bool ReadSendParam(const Message* msg, SendParam* p) {
1239 void* iter = SyncMessage::GetDataIterator(msg);
1240 return ReadParam(msg, &iter, p);
1186 } 1241 }
1187 1242
1188 static void Log(const Message* msg, std::wstring* l) { 1243 static bool ReadReplyParam(const Message* msg,
1189 if (msg->is_sync()) { 1244 typename TupleTypes<ReplyParam>::ValueTuple* p) {
1190 SendParam p; 1245 void* iter = SyncMessage::GetDataIterator(msg);
1191 void* iter = SyncMessage::GetDataIterator(msg); 1246 return ReadParam(msg, &iter, p);
1192 if (ReadParam(msg, &iter, &p))
1193 LogParam(p, l);
1194
1195 #if defined(IPC_MESSAGE_LOG_ENABLED)
1196 const std::wstring& output_params = msg->output_params();
1197 if (!l->empty() && !output_params.empty())
1198 l->append(L", ");
1199
1200 l->append(output_params);
1201 #endif
1202 } else {
1203 // This is an outgoing reply. Now that we have the output parameters, we
1204 // can finally log the message.
1205 typename TupleTypes<ReplyParam>::ValueTuple p;
1206 void* iter = SyncMessage::GetDataIterator(msg);
1207 if (ReadParam(msg, &iter, &p))
1208 LogParam(p, l);
1209 }
1210 } 1247 }
1211 1248
1212 template<class T, class Method> 1249 template<class T, class Method>
1213 static bool Dispatch(const Message* msg, T* obj, Method func) { 1250 static bool Dispatch(const Message* msg, T* obj, Method func) {
1214 SendParam send_params; 1251 SendParam send_params;
1215 void* iter = GetDataIterator(msg);
1216 Message* reply = GenerateReply(msg); 1252 Message* reply = GenerateReply(msg);
1217 bool error; 1253 bool error;
1218 if (ReadParam(msg, &iter, &send_params)) { 1254 if (ReadSendParam(msg, &send_params)) {
1219 typename TupleTypes<ReplyParam>::ValueTuple reply_params; 1255 typename TupleTypes<ReplyParam>::ValueTuple reply_params;
1220 DispatchToMethod(obj, func, send_params, &reply_params); 1256 DispatchToMethod(obj, func, send_params, &reply_params);
1221 WriteParam(reply, reply_params); 1257 WriteParam(reply, reply_params);
1222 error = false; 1258 error = false;
1223 #ifdef IPC_MESSAGE_LOG_ENABLED 1259 LogReplyParamsToMessage(reply_params, msg);
1224 if (msg->received_time() != 0) {
1225 std::wstring output_params;
1226 LogParam(reply_params, &output_params);
1227 msg->set_output_params(output_params);
1228 }
1229 #endif
1230 } else { 1260 } else {
1231 NOTREACHED() << "Error deserializing message " << msg->type(); 1261 NOTREACHED() << "Error deserializing message " << msg->type();
1232 reply->set_reply_error(); 1262 reply->set_reply_error();
1233 error = true; 1263 error = true;
1234 } 1264 }
1235 1265
1236 obj->Send(reply); 1266 obj->Send(reply);
1237 return !error; 1267 return !error;
1238 } 1268 }
1239 1269
1240 template<class T, class Method> 1270 template<class T, class Method>
1241 static bool DispatchDelayReply(const Message* msg, T* obj, Method func) { 1271 static bool DispatchDelayReply(const Message* msg, T* obj, Method func) {
1242 SendParam send_params; 1272 SendParam send_params;
1243 void* iter = GetDataIterator(msg);
1244 Message* reply = GenerateReply(msg); 1273 Message* reply = GenerateReply(msg);
1245 bool error; 1274 bool error;
1246 if (ReadParam(msg, &iter, &send_params)) { 1275 if (ReadSendParam(msg, &send_params)) {
1247 Tuple1<Message&> t = MakeRefTuple(*reply); 1276 Tuple1<Message&> t = MakeRefTuple(*reply);
1248 1277 ConnectMessageAndReply(msg, reply);
1249 #ifdef IPC_MESSAGE_LOG_ENABLED
1250 if (msg->sent_time()) {
1251 // Don't log the sync message after dispatch, as we don't have the
1252 // output parameters at that point. Instead, save its data and log it
1253 // with the outgoing reply message when it's sent.
1254 LogData* data = new LogData;
1255 GenerateLogData("", *msg, data);
1256 msg->set_dont_log();
1257 reply->set_sync_log_data(data);
1258 }
1259 #endif
1260 DispatchToMethod(obj, func, send_params, &t); 1278 DispatchToMethod(obj, func, send_params, &t);
1261 error = false; 1279 error = false;
1262 } else { 1280 } else {
1263 NOTREACHED() << "Error deserializing message " << msg->type(); 1281 NOTREACHED() << "Error deserializing message " << msg->type();
1264 reply->set_reply_error(); 1282 reply->set_reply_error();
1265 obj->Send(reply); 1283 obj->Send(reply);
1266 error = true; 1284 error = true;
1267 } 1285 }
1268 return !error; 1286 return !error;
1269 } 1287 }
(...skipping 27 matching lines...) Expand all
1297 ReplyParam p(a, b, c, d, e); 1315 ReplyParam p(a, b, c, d, e);
1298 WriteParam(reply, p); 1316 WriteParam(reply, p);
1299 } 1317 }
1300 }; 1318 };
1301 1319
1302 //----------------------------------------------------------------------------- 1320 //-----------------------------------------------------------------------------
1303 1321
1304 } // namespace IPC 1322 } // namespace IPC
1305 1323
1306 #endif // IPC_IPC_MESSAGE_UTILS_H_ 1324 #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