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

Side by Side Diff: ipc/ipc_message_utils.h

Issue 6055002: Create a message filter for message port messages. This allows a nice cleanu... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years 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 | Annotate | Revision Log
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 903 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 914
915 // The constructor and the Read() method's templated implementations are in 915 // The constructor and the Read() method's templated implementations are in
916 // ipc_message_utils_impl.h. The subclass constructor and Log() methods call 916 // ipc_message_utils_impl.h. The subclass constructor and Log() methods call
917 // the templated versions of these and make sure there are instantiations in 917 // the templated versions of these and make sure there are instantiations in
918 // those translation units. 918 // those translation units.
919 MessageWithTuple(int32 routing_id, uint32 type, const RefParam& p); 919 MessageWithTuple(int32 routing_id, uint32 type, const RefParam& p);
920 920
921 static bool Read(const Message* msg, Param* p) IPC_MSG_NOINLINE; 921 static bool Read(const Message* msg, Param* p) IPC_MSG_NOINLINE;
922 922
923 // Generic dispatcher. Should cover most cases. 923 // Generic dispatcher. Should cover most cases.
924 template<class T, class Method> 924 template<class T, class S, class Method>
925 static bool Dispatch(const Message* msg, T* obj, Method func) { 925 static bool Dispatch(const Message* msg, T* obj, S* sender, Method func) {
926 Param p; 926 Param p;
927 if (Read(msg, &p)) { 927 if (Read(msg, &p)) {
928 DispatchToMethod(obj, func, p); 928 DispatchToMethod(obj, func, p);
929 return true; 929 return true;
930 } 930 }
931 return false; 931 return false;
932 } 932 }
933 933
934 // The following dispatchers exist for the case where the callback function 934 // The following dispatchers exist for the case where the callback function
935 // needs the message as well. They assume that "Param" is a type of Tuple 935 // needs the message as well. They assume that "Param" is a type of Tuple
936 // (except the one arg case, as there is no Tuple1). 936 // (except the one arg case, as there is no Tuple1).
937 template<class T, typename TA> 937 template<class T, class S, typename TA>
938 static bool Dispatch(const Message* msg, T* obj, 938 static bool Dispatch(const Message* msg, T* obj, S* sender,
939 void (T::*func)(const Message&, TA)) { 939 void (T::*func)(const Message&, TA)) {
940 Param p; 940 Param p;
941 if (Read(msg, &p)) { 941 if (Read(msg, &p)) {
942 (obj->*func)(*msg, p.a); 942 (obj->*func)(*msg, p.a);
943 return true; 943 return true;
944 } 944 }
945 return false; 945 return false;
946 } 946 }
947 947
948 template<class T, typename TA, typename TB> 948 template<class T, class S, typename TA, typename TB>
949 static bool Dispatch(const Message* msg, T* obj, 949 static bool Dispatch(const Message* msg, T* obj, S* sender,
950 void (T::*func)(const Message&, TA, TB)) { 950 void (T::*func)(const Message&, TA, TB)) {
951 Param p; 951 Param p;
952 if (Read(msg, &p)) { 952 if (Read(msg, &p)) {
953 (obj->*func)(*msg, p.a, p.b); 953 (obj->*func)(*msg, p.a, p.b);
954 return true; 954 return true;
955 } 955 }
956 return false; 956 return false;
957 } 957 }
958 958
959 template<class T, typename TA, typename TB, typename TC> 959 template<class T, class S, typename TA, typename TB, typename TC>
960 static bool Dispatch(const Message* msg, T* obj, 960 static bool Dispatch(const Message* msg, T* obj, S* sender,
961 void (T::*func)(const Message&, TA, TB, TC)) { 961 void (T::*func)(const Message&, TA, TB, TC)) {
962 Param p; 962 Param p;
963 if (Read(msg, &p)) { 963 if (Read(msg, &p)) {
964 (obj->*func)(*msg, p.a, p.b, p.c); 964 (obj->*func)(*msg, p.a, p.b, p.c);
965 return true; 965 return true;
966 } 966 }
967 return false; 967 return false;
968 } 968 }
969 969
970 template<class T, typename TA, typename TB, typename TC, typename TD> 970 template<class T, class S, typename TA, typename TB, typename TC, typename TD>
971 static bool Dispatch(const Message* msg, T* obj, 971 static bool Dispatch(const Message* msg, T* obj, S* sender,
972 void (T::*func)(const Message&, TA, TB, TC, TD)) { 972 void (T::*func)(const Message&, TA, TB, TC, TD)) {
973 Param p; 973 Param p;
974 if (Read(msg, &p)) { 974 if (Read(msg, &p)) {
975 (obj->*func)(*msg, p.a, p.b, p.c, p.d); 975 (obj->*func)(*msg, p.a, p.b, p.c, p.d);
976 return true; 976 return true;
977 } 977 }
978 return false; 978 return false;
979 } 979 }
980 980
981 template<class T, typename TA, typename TB, typename TC, typename TD, 981 template<class T, class S, typename TA, typename TB, typename TC, typename TD,
982 typename TE> 982 typename TE>
983 static bool Dispatch(const Message* msg, T* obj, 983 static bool Dispatch(const Message* msg, T* obj, S* sender,
984 void (T::*func)(const Message&, TA, TB, TC, TD, TE)) { 984 void (T::*func)(const Message&, TA, TB, TC, TD, TE)) {
985 Param p; 985 Param p;
986 if (Read(msg, &p)) { 986 if (Read(msg, &p)) {
987 (obj->*func)(*msg, p.a, p.b, p.c, p.d, p.e); 987 (obj->*func)(*msg, p.a, p.b, p.c, p.d, p.e);
988 return true; 988 return true;
989 } 989 }
990 return false; 990 return false;
991 } 991 }
992 992
993 // Functions used to do manual unpacking. Only used by the automation code, 993 // Functions used to do manual unpacking. Only used by the automation code,
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 typedef typename TupleTypes<SendParam>::ParamTuple RefSendParam; 1107 typedef typename TupleTypes<SendParam>::ParamTuple RefSendParam;
1108 typedef ReplyParamType ReplyParam; 1108 typedef ReplyParamType ReplyParam;
1109 1109
1110 MessageWithReply(int32 routing_id, uint32 type, 1110 MessageWithReply(int32 routing_id, uint32 type,
1111 const RefSendParam& send, const ReplyParam& reply); 1111 const RefSendParam& send, const ReplyParam& reply);
1112 static bool ReadSendParam(const Message* msg, SendParam* p) IPC_MSG_NOINLINE; 1112 static bool ReadSendParam(const Message* msg, SendParam* p) IPC_MSG_NOINLINE;
1113 static bool ReadReplyParam( 1113 static bool ReadReplyParam(
1114 const Message* msg, 1114 const Message* msg,
1115 typename TupleTypes<ReplyParam>::ValueTuple* p) IPC_MSG_NOINLINE; 1115 typename TupleTypes<ReplyParam>::ValueTuple* p) IPC_MSG_NOINLINE;
1116 1116
1117 template<class T, class Method> 1117 template<class T, class S, class Method>
1118 static bool Dispatch(const Message* msg, T* obj, Method func) { 1118 static bool Dispatch(const Message* msg, T* obj, S* sender, Method func) {
1119 SendParam send_params; 1119 SendParam send_params;
1120 Message* reply = GenerateReply(msg); 1120 Message* reply = GenerateReply(msg);
1121 bool error; 1121 bool error;
1122 if (ReadSendParam(msg, &send_params)) { 1122 if (ReadSendParam(msg, &send_params)) {
1123 typename TupleTypes<ReplyParam>::ValueTuple reply_params; 1123 typename TupleTypes<ReplyParam>::ValueTuple reply_params;
1124 DispatchToMethod(obj, func, send_params, &reply_params); 1124 DispatchToMethod(obj, func, send_params, &reply_params);
1125 WriteParam(reply, reply_params); 1125 WriteParam(reply, reply_params);
1126 error = false; 1126 error = false;
1127 LogReplyParamsToMessage(reply_params, msg); 1127 LogReplyParamsToMessage(reply_params, msg);
1128 } else { 1128 } else {
1129 NOTREACHED() << "Error deserializing message " << msg->type(); 1129 NOTREACHED() << "Error deserializing message " << msg->type();
1130 reply->set_reply_error(); 1130 reply->set_reply_error();
1131 error = true; 1131 error = true;
1132 } 1132 }
1133 1133
1134 obj->Send(reply); 1134 sender->Send(reply);
1135 return !error; 1135 return !error;
1136 } 1136 }
1137 1137
1138 template<class T, class Method> 1138 template<class T, class Method>
1139 static bool DispatchDelayReply(const Message* msg, T* obj, Method func) { 1139 static bool DispatchDelayReply(const Message* msg, T* obj, Method func) {
1140 SendParam send_params; 1140 SendParam send_params;
1141 Message* reply = GenerateReply(msg); 1141 Message* reply = GenerateReply(msg);
1142 bool error; 1142 bool error;
1143 if (ReadSendParam(msg, &send_params)) { 1143 if (ReadSendParam(msg, &send_params)) {
1144 Tuple1<Message&> t = MakeRefTuple(*reply); 1144 Tuple1<Message&> t = MakeRefTuple(*reply);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 ReplyParam p(a, b, c, d, e); 1183 ReplyParam p(a, b, c, d, e);
1184 WriteParam(reply, p); 1184 WriteParam(reply, p);
1185 } 1185 }
1186 }; 1186 };
1187 1187
1188 //----------------------------------------------------------------------------- 1188 //-----------------------------------------------------------------------------
1189 1189
1190 } // namespace IPC 1190 } // namespace IPC
1191 1191
1192 #endif // IPC_IPC_MESSAGE_UTILS_H_ 1192 #endif // IPC_IPC_MESSAGE_UTILS_H_
OLDNEW
« chrome/browser/worker_host/message_port_service.cc ('K') | « ipc/ipc_message_macros.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698