Chromium Code Reviews| Index: ppapi/proxy/dispatch_reply_message.h |
| diff --git a/ppapi/proxy/dispatch_reply_message.h b/ppapi/proxy/dispatch_reply_message.h |
| index 609240f711b1f237e6549f84b1d0598913473a26..fe58c2044ede6ba56c73fd13b8e9dd491a280a5b 100644 |
| --- a/ppapi/proxy/dispatch_reply_message.h |
| +++ b/ppapi/proxy/dispatch_reply_message.h |
| @@ -16,7 +16,6 @@ |
| namespace ppapi { |
| namespace proxy { |
| -struct Context; |
| class ResourceMessageReplyParams; |
| template <class ObjT, class Method> |
| @@ -61,25 +60,72 @@ inline void DispatchResourceReply(ObjT* obj, Method method, |
| return (obj->*method)(params, arg.a, arg.b, arg.c, arg.d, arg.e); |
| } |
| -#define PPAPI_DISPATCH_RESOURCE_REPLY(msg_class, member_func) \ |
| - case msg_class::ID: { \ |
| - TRACK_RUN_IN_IPC_HANDLER(member_func); \ |
| - msg_class::Schema::Param p; \ |
| - if (msg_class::Read(&ipc_message__, &p)) { \ |
| - ppapi::proxy::DispatchResourceReply( \ |
| - this, \ |
| - &_IpcMessageHandlerClass::member_func, \ |
| - params, p); \ |
| - } \ |
| - break; \ |
| - } |
| +// Used to dispatch resource replies. In most cases, you should not call this |
| +// function to dispatch a resource reply manually, but instead use |
| +// |PluginResource::CallBrowser|/|PluginResource::CallRenderer| with a |
| +// |base::Callback| which will be called when a reply message is received |
| +// (see plugin_resource.h). |
| +// |
| +// This function will call your callback with the nested reply message's |
| +// parameters on success. On failure, your callback will be called with each |
| +// parameter having its default constructed value. |
| +// |
| +// Resource replies are a bit weird in that the host will automatically |
| +// generate a reply in error cases (when the call handle returns error rather |
|
yzshen1
2012/10/01 23:41:24
handle -> handler?
raymes
2012/10/02 16:13:36
Done.
|
| +// than returning "completion pending"). This makes it more convenient to write |
| +// the call message handlers. But this also means that the reply handler has to |
| +// handle both the success case (when all of the reply message paramaters are |
| +// specified) and the error case (when the nested reply message is empty). |
| +// In both cases the resource will want to issue completion callbacks to the |
| +// plugin. |
| +// |
| +// This function handles the error case by calling your reply handler with the |
| +// default value for each paramater in the error case. In most situations this |
| +// will be the right thing. You should always dispatch completion callbacks |
| +// using the result code present in the ResourceMessageReplyParams. |
| +template<class MsgClass, class ObjT, class Method> |
| +void DispatchResourceReplyOrDefaultParams( |
| + ObjT* obj, |
| + Method method, |
| + const ResourceMessageReplyParams& reply_params, |
| + const IPC::Message& msg) { |
| + typename MsgClass::Schema::Param msg_params; |
| + // We either expect the nested message type to match, or that there is no |
| + // nested message. No nested message indicates a default reply sent from |
| + // the host: when the resource message handler returns an error, a reply |
| + // is implicitly sent with no nested message. |
| + DCHECK(msg.type() == MsgClass::ID || msg.type() == 0) |
| + << "Resource reply message of unexpected type."; |
| + if (msg.type() == MsgClass::ID && MsgClass::Read(&msg, &msg_params)) { |
| + // Message type matches and the parameters were successfully read. |
| + DispatchResourceReply(obj, method, reply_params, msg_params); |
| + } else { |
| + // the nested message is empty because the host handler didn't explicitly |
|
yzshen1
2012/10/01 23:41:24
nit: "// the" -> "// The"
raymes
2012/10/02 16:13:36
Done.
|
| + // send a reply (likely), or you screwed up and didn't use the correct |
| + // message type when calling this function (you should have hit the |
| + // assertion above, Einstein). |
| + // |
| + // Dispatch the reply function with the default parameters. We explicitly |
| + // use a new Params() structure since if the Read failed due to an invalid |
| + // message, the params could have been partially filled in. |
| + DispatchResourceReply(obj, method, reply_params, |
| + typename MsgClass::Schema::Param()); |
| + } |
| +} |
| -#define PPAPI_DISPATCH_RESOURCE_REPLY_0(msg_class, member_func) \ |
| - case msg_class::ID: { \ |
| - TRACK_RUN_IN_IPC_HANDLER(member_func); \ |
| - member_func(params); \ |
| - break; \ |
| - } |
| +// Template specialization for |Callback|s that only accept a |
| +// |ResourceMessageReplyParams|. In this case |msg| shouldn't contain any |
| +// arguments, so just call the |method| with the |reply_params|. |
| +template<class MsgClass, class Method> |
| +void DispatchResourceReplyOrDefaultParams( |
| + base::Callback<void(const ResourceMessageReplyParams&)>* obj, |
| + Method method, |
| + const ResourceMessageReplyParams& reply_params, |
| + const IPC::Message& msg) { |
| + DCHECK(msg.type() == MsgClass::ID || msg.type() == 0) |
| + << "Resource reply message of unexpected type."; |
| + return (obj->*method)(reply_params); |
| +} |
| } // namespace proxy |
| } // namespace ppapi |