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

Side by Side Diff: ppapi/proxy/dispatch_reply_message.h

Issue 11267034: Provide IPC mechanism for host-to-resource messaging (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: else NOTREACHED Created 8 years, 1 month 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 | « ppapi/host/dispatch_host_message.h ('k') | ppapi/proxy/websocket_resource.cc » ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // This file provides infrastructure for dispatching host resource reply 5 // This file provides infrastructure for dispatching messasges from host
6 // messages. Normal IPC Reply handlers can't take extra parameters. 6 // resource, inlcuding reply messages or unsolicited replies. Normal IPC Reply
7 // We want to take a ResourceMessageReplyParams as a parameter. 7 // handlers can't take extra parameters. We want to take a
8 // ResourceMessageReplyParams as a parameter.
8 9
9 #ifndef PPAPI_PROXY_DISPATCH_REPLY_MESSAGE_H_ 10 #ifndef PPAPI_PROXY_DISPATCH_REPLY_MESSAGE_H_
10 #define PPAPI_PROXY_DISPATCH_REPLY_MESSAGE_H_ 11 #define PPAPI_PROXY_DISPATCH_REPLY_MESSAGE_H_
11 12
12 #include "base/profiler/scoped_profile.h" // For TRACK_RUN_IN_IPC_HANDLER. 13 #include "base/profiler/scoped_profile.h" // For TRACK_RUN_IN_IPC_HANDLER.
13 #include "ipc/ipc_message_macros.h" 14 #include "ipc/ipc_message_macros.h"
14 #include "ppapi/c/pp_errors.h" 15 #include "ppapi/c/pp_errors.h"
15 16
16 namespace ppapi { 17 namespace ppapi {
17 namespace proxy { 18 namespace proxy {
18 19
19 class ResourceMessageReplyParams; 20 class ResourceMessageReplyParams;
20 21
21 template <class ObjT, class Method> 22 template <class ObjT, class Method>
22 inline void DispatchResourceReply(ObjT* obj, Method method, 23 inline void DispatchResourceReply(ObjT* obj, Method method,
23 const ResourceMessageReplyParams& params, 24 const ResourceMessageReplyParams& params,
24 const Tuple0& arg) { 25 const Tuple0& arg) {
25 (obj->*method)(params); 26 (obj->*method)(params);
26 } 27 }
27 28
28 template <class ObjT, class Method, class A> 29 template <class ObjT, class Method, class A>
29 inline void DispatchResourceReply(ObjT* obj, Method method, 30 inline void DispatchResourceReply(ObjT* obj, Method method,
30 const ResourceMessageReplyParams& params, 31 const ResourceMessageReplyParams& params,
31 const Tuple1<A>& arg) { 32 const Tuple1<A>& arg) {
32 return (obj->*method)(params, arg.a); 33 (obj->*method)(params, arg.a);
33 } 34 }
34 35
35 template<class ObjT, class Method, class A, class B> 36 template<class ObjT, class Method, class A, class B>
36 inline void DispatchResourceReply(ObjT* obj, Method method, 37 inline void DispatchResourceReply(ObjT* obj, Method method,
37 const ResourceMessageReplyParams& params, 38 const ResourceMessageReplyParams& params,
38 const Tuple2<A, B>& arg) { 39 const Tuple2<A, B>& arg) {
39 return (obj->*method)(params, arg.a, arg.b); 40 (obj->*method)(params, arg.a, arg.b);
40 } 41 }
41 42
42 template<class ObjT, class Method, class A, class B, class C> 43 template<class ObjT, class Method, class A, class B, class C>
43 inline void DispatchResourceReply(ObjT* obj, Method method, 44 inline void DispatchResourceReply(ObjT* obj, Method method,
44 const ResourceMessageReplyParams& params, 45 const ResourceMessageReplyParams& params,
45 const Tuple3<A, B, C>& arg) { 46 const Tuple3<A, B, C>& arg) {
46 return (obj->*method)(params, arg.a, arg.b, arg.c); 47 (obj->*method)(params, arg.a, arg.b, arg.c);
47 } 48 }
48 49
49 template<class ObjT, class Method, class A, class B, class C, class D> 50 template<class ObjT, class Method, class A, class B, class C, class D>
50 inline void DispatchResourceReply(ObjT* obj, Method method, 51 inline void DispatchResourceReply(ObjT* obj, Method method,
51 const ResourceMessageReplyParams& params, 52 const ResourceMessageReplyParams& params,
52 const Tuple4<A, B, C, D>& arg) { 53 const Tuple4<A, B, C, D>& arg) {
53 return (obj->*method)(params, arg.a, arg.b, arg.c, arg.d); 54 (obj->*method)(params, arg.a, arg.b, arg.c, arg.d);
54 } 55 }
55 56
56 template<class ObjT, class Method, class A, class B, class C, class D, class E> 57 template<class ObjT, class Method, class A, class B, class C, class D, class E>
57 inline void DispatchResourceReply(ObjT* obj, Method method, 58 inline void DispatchResourceReply(ObjT* obj, Method method,
58 const ResourceMessageReplyParams& params, 59 const ResourceMessageReplyParams& params,
59 const Tuple5<A, B, C, D, E>& arg) { 60 const Tuple5<A, B, C, D, E>& arg) {
60 return (obj->*method)(params, arg.a, arg.b, arg.c, arg.d, arg.e); 61 (obj->*method)(params, arg.a, arg.b, arg.c, arg.d, arg.e);
61 } 62 }
62 63
63 // Used to dispatch resource replies. In most cases, you should not call this 64 // Used to dispatch resource replies. In most cases, you should not call this
64 // function to dispatch a resource reply manually, but instead use 65 // function to dispatch a resource reply manually, but instead use
65 // |PluginResource::CallBrowser|/|PluginResource::CallRenderer| with a 66 // |PluginResource::CallBrowser|/|PluginResource::CallRenderer| with a
66 // |base::Callback| which will be called when a reply message is received 67 // |base::Callback| which will be called when a reply message is received
67 // (see plugin_resource.h). 68 // (see plugin_resource.h).
68 // 69 //
69 // This function will call your callback with the nested reply message's 70 // This function will call your callback with the nested reply message's
70 // parameters on success. On failure, your callback will be called with each 71 // parameters on success. On failure, your callback will be called with each
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 // |ResourceMessageReplyParams|. In this case |msg| shouldn't contain any 118 // |ResourceMessageReplyParams|. In this case |msg| shouldn't contain any
118 // arguments, so just call the |method| with the |reply_params|. 119 // arguments, so just call the |method| with the |reply_params|.
119 template<class MsgClass, class Method> 120 template<class MsgClass, class Method>
120 void DispatchResourceReplyOrDefaultParams( 121 void DispatchResourceReplyOrDefaultParams(
121 base::Callback<void(const ResourceMessageReplyParams&)>* obj, 122 base::Callback<void(const ResourceMessageReplyParams&)>* obj,
122 Method method, 123 Method method,
123 const ResourceMessageReplyParams& reply_params, 124 const ResourceMessageReplyParams& reply_params,
124 const IPC::Message& msg) { 125 const IPC::Message& msg) {
125 DCHECK(msg.type() == MsgClass::ID || msg.type() == 0) 126 DCHECK(msg.type() == MsgClass::ID || msg.type() == 0)
126 << "Resource reply message of unexpected type."; 127 << "Resource reply message of unexpected type.";
127 return (obj->*method)(reply_params); 128 (obj->*method)(reply_params);
128 } 129 }
129 130
131 // Note that this only works for message with 1 or more parameters. For
132 // 0-parameter messages you need to use the _0 version below (since there are
133 // no params in the message).
134 #define PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL(msg_class, member_func) \
135 case msg_class::ID: { \
136 msg_class::Schema::Param p; \
137 if (msg_class::Read(&ipc_message__, &p)) { \
138 ppapi::proxy::DispatchResourceReply( \
139 this, \
140 &_IpcMessageHandlerClass::member_func, \
141 params, p); \
142 } else { \
143 NOTREACHED(); \
144 } \
145 break; \
146 }
147
148 #define PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_0(msg_class, member_func) \
149 case msg_class::ID: { \
150 member_func(params); \
151 break; \
152 }
153
154 #define PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_UNHANDLED(code) \
155 default: { \
156 code; \
157 } \
158 break;
159
130 } // namespace proxy 160 } // namespace proxy
131 } // namespace ppapi 161 } // namespace ppapi
132 162
133 #endif // PPAPI_PROXY_DISPATCH_REPLY_MESSAGE_H_ 163 #endif // PPAPI_PROXY_DISPATCH_REPLY_MESSAGE_H_
OLDNEW
« no previous file with comments | « ppapi/host/dispatch_host_message.h ('k') | ppapi/proxy/websocket_resource.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698