diff options
author | raymes@chromium.org <raymes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-04 00:07:44 +0000 |
---|---|---|
committer | raymes@chromium.org <raymes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-04 00:07:44 +0000 |
commit | e1f5c9beb4952df82815be228e71fa46c219b0b0 (patch) | |
tree | 9d09a28bbe3ade14197e243d81c1e040ff1870ed /ppapi/proxy/gamepad_resource.cc | |
parent | e64eef241cdf4b096e0e1976ccb11ab0f070d2ea (diff) | |
download | chromium_src-e1f5c9beb4952df82815be228e71fa46c219b0b0.zip chromium_src-e1f5c9beb4952df82815be228e71fa46c219b0b0.tar.gz chromium_src-e1f5c9beb4952df82815be228e71fa46c219b0b0.tar.bz2 |
Converted PluginResource reply message handling to use base::Callback
Previously each PluginResource had to write a reply handler (|OnReplyReceived|) for any replies to resource messages. This approach had several problems including the fact that the PluginResource had to track the state of any outstanding calls.
This change allows you to register a base::Callback when calling CallToBrowser/CallToRenderer. The callback will be run when a reply message is received with a sequence number matching the call. The parameters of the reply will be passed to the callback. An example of usage:
CallBrowser<PpapiPluginMsg_MyResourceType_MyReplyMessage>(
PpapiHostMsg_MyResourceType_MyRequestMessage(),
base::Bind(&MyPluginResource::ReplyHandler, this));
If a reply message to this call is received whose type does not match the expected reply message (for example, in the case of an error), the callback will still be invoked but with the default values of the message parameters.
BUG=
Review URL: https://chromiumcodereview.appspot.com/11022005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@160015 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/proxy/gamepad_resource.cc')
-rw-r--r-- | ppapi/proxy/gamepad_resource.cc | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/ppapi/proxy/gamepad_resource.cc b/ppapi/proxy/gamepad_resource.cc index 446c11c..fa028e4 100644 --- a/ppapi/proxy/gamepad_resource.cc +++ b/ppapi/proxy/gamepad_resource.cc @@ -6,6 +6,7 @@ #include <string.h> +#include "base/bind.h" #include "base/threading/platform_thread.h" #include "ppapi/proxy/dispatch_reply_message.h" #include "ppapi/proxy/ppapi_messages.h" @@ -48,7 +49,9 @@ GamepadResource::GamepadResource(Connection connection, PP_Instance instance) memset(&last_read_, 0, sizeof(last_read_)); SendCreateToBrowser(PpapiHostMsg_Gamepad_Create()); - CallBrowser(PpapiHostMsg_Gamepad_RequestMemory()); + CallBrowser<PpapiPluginMsg_Gamepad_SendMemory>( + PpapiHostMsg_Gamepad_RequestMemory(), + base::Bind(&GamepadResource::OnPluginMsgSendMemory, this)); } GamepadResource::~GamepadResource() { @@ -91,14 +94,6 @@ void GamepadResource::Sample(PP_GamepadsSampleData* data) { memcpy(data, &last_read_, sizeof(PP_GamepadsSampleData)); } -void GamepadResource::OnReplyReceived(const ResourceMessageReplyParams& params, - const IPC::Message& msg) { - IPC_BEGIN_MESSAGE_MAP(GamepadResource, msg) - PPAPI_DISPATCH_RESOURCE_REPLY_0(PpapiPluginMsg_Gamepad_SendMemory, - OnPluginMsgSendMemory) - IPC_END_MESSAGE_MAP() -} - void GamepadResource::OnPluginMsgSendMemory( const ResourceMessageReplyParams& params) { // On failure, the handle will be null and the CHECK below will be tripped. |