summaryrefslogtreecommitdiffstats
path: root/ipc/ipc_message_macros.h
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-13 23:19:10 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-13 23:19:10 +0000
commit5636d90f630655abf66427e30d15f615dc939797 (patch)
tree434691134b27d5f98aaff57635b05bcdba98e1b7 /ipc/ipc_message_macros.h
parent07243f95c726fb67abefa8a19fb9c46e2d63d8f8 (diff)
downloadchromium_src-5636d90f630655abf66427e30d15f615dc939797.zip
chromium_src-5636d90f630655abf66427e30d15f615dc939797.tar.gz
chromium_src-5636d90f630655abf66427e30d15f615dc939797.tar.bz2
Add support for passing an arbitrary parameter to an IPC message handler. The motivation is for WebContentsObserver to pass RenderFrameHost* to message handlers easily.
As an example, an observer would look like this: bool FooWebContentsObserver::OnMessageReceived( const IPC::Message& message, RenderFrameHost* render_frame_host) { IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(FooWebContentsObserver, message, RenderFrameHost, render_frame_host) IPC_MESSAGE_HANDLER(FooHostMsg_Bar, OnBar) . . . void FooWebContentsObserver::OnBar(RenderFrameHost* render_frame_host, ... You can of course still have dispatchers without the extra parameter as before. This is generalizing the existing code that allows an IPC message handler to have a "const IPC::Message& message) first parameter to get access to the IPC. Sync IPCs don't support this yet. It's a lot more work because for them we conveniently reuse tuple's DispatchToMethod. This isn't urgent yet, since sync IPCs aren't dispatched on the UI thread for the most part because of NPAPI and Windows, so punting on this for now. BUG=304341 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/283623002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270237 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ipc/ipc_message_macros.h')
-rw-r--r--ipc/ipc_message_macros.h125
1 files changed, 49 insertions, 76 deletions
diff --git a/ipc/ipc_message_macros.h b/ipc/ipc_message_macros.h
index c4e250c..f924e7b 100644
--- a/ipc/ipc_message_macros.h
+++ b/ipc/ipc_message_macros.h
@@ -434,9 +434,12 @@
// The following macros define the common set of methods provided by ASYNC
// message classes.
+// This macro is for all the async IPCs that don't pass an extra parameter using
+// IPC_BEGIN_MESSAGE_MAP_WITH_PARAM.
#define IPC_ASYNC_MESSAGE_METHODS_GENERIC \
- template<class T, class S, class Method> \
- static bool Dispatch(const Message* msg, T* obj, S* sender, Method func) { \
+ template<class T, class S, class P, class Method> \
+ static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \
+ Method func) { \
Schema::Param p; \
if (Read(msg, &p)) { \
DispatchToMethod(obj, func, p); \
@@ -444,124 +447,86 @@
} \
return false; \
}
+
+// The following macros are for for async IPCs which have a dispatcher with an
+// extra parameter specified using IPC_BEGIN_MESSAGE_MAP_WITH_PARAM.
#define IPC_ASYNC_MESSAGE_METHODS_1 \
IPC_ASYNC_MESSAGE_METHODS_GENERIC \
- template<class T, class S, typename TA> \
- static bool Dispatch(const Message* msg, T* obj, S* sender, \
- void (T::*func)(const Message&, TA)) { \
+ template<class T, class S, class P, typename TA> \
+ static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \
+ void (T::*func)(P*, TA)) { \
Schema::Param p; \
if (Read(msg, &p)) { \
- (obj->*func)(*msg, p.a); \
+ (obj->*func)(parameter, p.a); \
return true; \
} \
return false; \
}
#define IPC_ASYNC_MESSAGE_METHODS_2 \
IPC_ASYNC_MESSAGE_METHODS_GENERIC \
- template<class T, class S, typename TA, typename TB> \
- static bool Dispatch(const Message* msg, T* obj, S* sender, \
- void (T::*func)(const Message&, TA, TB)) { \
+ template<class T, class S, class P, typename TA, typename TB> \
+ static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \
+ void (T::*func)(P*, TA, TB)) { \
Schema::Param p; \
if (Read(msg, &p)) { \
- (obj->*func)(*msg, p.a, p.b); \
+ (obj->*func)(parameter, p.a, p.b); \
return true; \
} \
return false; \
- } \
- template<typename TA, typename TB> \
- static bool Read(const IPC::Message* msg, TA* a, TB* b) { \
- Schema::Param p; \
- if (!Read(msg, &p)) \
- return false; \
- *a = p.a; \
- *b = p.b; \
- return true; \
}
#define IPC_ASYNC_MESSAGE_METHODS_3 \
IPC_ASYNC_MESSAGE_METHODS_GENERIC \
- template<class T, class S, typename TA, typename TB, typename TC> \
- static bool Dispatch(const Message* msg, T* obj, S* sender, \
- void (T::*func)(const Message&, TA, TB, TC)) { \
+ template<class T, class S, class P, typename TA, typename TB, typename TC> \
+ static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \
+ void (T::*func)(P*, TA, TB, TC)) { \
Schema::Param p; \
if (Read(msg, &p)) { \
- (obj->*func)(*msg, p.a, p.b, p.c); \
+ (obj->*func)(parameter, p.a, p.b, p.c); \
return true; \
} \
return false; \
- } \
- template<typename TA, typename TB, typename TC> \
- static bool Read(const IPC::Message* msg, TA* a, TB* b, TC* c) { \
- Schema::Param p; \
- if (!Read(msg, &p)) \
- return false; \
- *a = p.a; \
- *b = p.b; \
- *c = p.c; \
- return true; \
}
#define IPC_ASYNC_MESSAGE_METHODS_4 \
IPC_ASYNC_MESSAGE_METHODS_GENERIC \
- template<class T, class S, typename TA, typename TB, typename TC, \
+ template<class T, class S, class P, typename TA, typename TB, typename TC, \
typename TD> \
- static bool Dispatch(const Message* msg, T* obj, S* sender, \
- void (T::*func)(const Message&, TA, TB, TC, TD)) { \
+ static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \
+ void (T::*func)(P*, TA, TB, TC, TD)) { \
Schema::Param p; \
if (Read(msg, &p)) { \
- (obj->*func)(*msg, p.a, p.b, p.c, p.d); \
+ (obj->*func)(parameter, p.a, p.b, p.c, p.d); \
return true; \
} \
return false; \
- } \
- template<typename TA, typename TB, typename TC, typename TD> \
- static bool Read(const IPC::Message* msg, TA* a, TB* b, TC* c, TD* d) { \
- Schema::Param p; \
- if (!Read(msg, &p)) \
- return false; \
- *a = p.a; \
- *b = p.b; \
- *c = p.c; \
- *d = p.d; \
- return true; \
}
#define IPC_ASYNC_MESSAGE_METHODS_5 \
IPC_ASYNC_MESSAGE_METHODS_GENERIC \
- template<class T, class S, typename TA, typename TB, typename TC, \
+ template<class T, class S, class P, typename TA, typename TB, typename TC, \
typename TD, typename TE> \
- static bool Dispatch(const Message* msg, T* obj, S* sender, \
- void (T::*func)(const Message&, TA, TB, TC, TD, TE)) { \
+ static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \
+ void (T::*func)(P*, TA, TB, TC, TD, TE)) { \
Schema::Param p; \
if (Read(msg, &p)) { \
- (obj->*func)(*msg, p.a, p.b, p.c, p.d, p.e); \
+ (obj->*func)(parameter, p.a, p.b, p.c, p.d, p.e); \
return true; \
} \
return false; \
- } \
- template<typename TA, typename TB, typename TC, typename TD, typename TE> \
- static bool Read(const IPC::Message* msg, TA* a, TB* b, TC* c, TD* d, \
- TE* e) { \
- Schema::Param p; \
- if (!Read(msg, &p)) \
- return false; \
- *a = p.a; \
- *b = p.b; \
- *c = p.c; \
- *d = p.d; \
- *e = p.e; \
- return true; \
}
// The following macros define the common set of methods provided by SYNC
// message classes.
#define IPC_SYNC_MESSAGE_METHODS_GENERIC \
- template<class T, class S, class Method> \
- static bool Dispatch(const Message* msg, T* obj, S* sender, Method func) { \
+ template<class T, class S, class P, class Method> \
+ static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \
+ Method func) { \
Schema::SendParam send_params; \
bool ok = ReadSendParam(msg, &send_params); \
return Schema::DispatchWithSendParams(ok, send_params, msg, obj, sender, \
func); \
} \
- template<class T, class Method> \
- static bool DispatchDelayReply(const Message* msg, T* obj, Method func) { \
+ template<class T, class P, class Method> \
+ static bool DispatchDelayReply(const Message* msg, T* obj, P* parameter, \
+ Method func) { \
Schema::SendParam send_params; \
bool ok = ReadSendParam(msg, &send_params); \
return Schema::DispatchDelayReplyWithSendParams(ok, send_params, msg, \
@@ -932,24 +897,32 @@
#define IPC_BEGIN_MESSAGE_MAP_EX(class_name, msg, msg_is_ok) \
- { \
- typedef class_name _IpcMessageHandlerClass; \
- const IPC::Message& ipc_message__ = msg; \
- bool& msg_is_ok__ = msg_is_ok; \
- switch (ipc_message__.type()) { \
+ IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(class_name, msg, msg_is_ok, void, NULL)
#define IPC_BEGIN_MESSAGE_MAP(class_name, msg) \
{ \
typedef class_name _IpcMessageHandlerClass; \
+ typedef void _ParamClass; \
+ _ParamClass* param__ = NULL; \
const IPC::Message& ipc_message__ = msg; \
bool msg_is_ok__ = true; \
switch (ipc_message__.type()) { \
+#define IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(class_name, msg, msg_is_ok, \
+ param_type, param) \
+ { \
+ typedef class_name _IpcMessageHandlerClass; \
+ typedef param_type _ParamClass; \
+ _ParamClass* param__ = param; \
+ const IPC::Message& ipc_message__ = msg; \
+ bool& msg_is_ok__ = msg_is_ok; \
+ switch (ipc_message__.type()) { \
+
#define IPC_MESSAGE_FORWARD(msg_class, obj, member_func) \
case msg_class::ID: { \
TRACK_RUN_IN_IPC_HANDLER(member_func); \
msg_is_ok__ = msg_class::Dispatch(&ipc_message__, obj, this, \
- &member_func); \
+ param__, &member_func); \
} \
break;
@@ -960,7 +933,7 @@
case msg_class::ID: { \
TRACK_RUN_IN_IPC_HANDLER(member_func); \
msg_is_ok__ = msg_class::DispatchDelayReply(&ipc_message__, obj, \
- &member_func); \
+ param__, &member_func); \
} \
break;