summaryrefslogtreecommitdiffstats
path: root/ppapi/proxy/printing_resource.cc
diff options
context:
space:
mode:
authorraymes@chromium.org <raymes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-04 00:07:44 +0000
committerraymes@chromium.org <raymes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-04 00:07:44 +0000
commite1f5c9beb4952df82815be228e71fa46c219b0b0 (patch)
tree9d09a28bbe3ade14197e243d81c1e040ff1870ed /ppapi/proxy/printing_resource.cc
parente64eef241cdf4b096e0e1976ccb11ab0f070d2ea (diff)
downloadchromium_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/printing_resource.cc')
-rw-r--r--ppapi/proxy/printing_resource.cc36
1 files changed, 11 insertions, 25 deletions
diff --git a/ppapi/proxy/printing_resource.cc b/ppapi/proxy/printing_resource.cc
index 9fd8fde..22950c2 100644
--- a/ppapi/proxy/printing_resource.cc
+++ b/ppapi/proxy/printing_resource.cc
@@ -4,6 +4,7 @@
#include "ppapi/proxy/printing_resource.h"
+#include "base/bind.h"
#include "ipc/ipc_message.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/proxy/dispatch_reply_message.h"
@@ -12,10 +13,8 @@
namespace ppapi {
namespace proxy {
-PrintingResource::PrintingResource(Connection connection,
- PP_Instance instance)
- : PluginResource(connection, instance),
- print_settings_(NULL) {
+PrintingResource::PrintingResource(Connection connection, PP_Instance instance)
+ : PluginResource(connection, instance) {
}
PrintingResource::~PrintingResource() {
@@ -31,39 +30,26 @@ int32_t PrintingResource::GetDefaultPrintSettings(
if (!print_settings)
return PP_ERROR_BADARGUMENT;
- if (TrackedCallback::IsPending(callback_))
- return PP_ERROR_INPROGRESS;
-
if (!sent_create_to_browser())
SendCreateToBrowser(PpapiHostMsg_Printing_Create());
- DCHECK(!print_settings_);
- print_settings_ = print_settings;
- callback_ = callback;
-
- CallBrowser(PpapiHostMsg_Printing_GetDefaultPrintSettings());
+ CallBrowser<PpapiPluginMsg_Printing_GetDefaultPrintSettingsReply>(
+ PpapiHostMsg_Printing_GetDefaultPrintSettings(),
+ base::Bind(&PrintingResource::OnPluginMsgGetDefaultPrintSettingsReply,
+ this, print_settings, callback));
return PP_OK_COMPLETIONPENDING;
}
-void PrintingResource::OnReplyReceived(
- const ResourceMessageReplyParams& params,
- const IPC::Message& msg) {
- IPC_BEGIN_MESSAGE_MAP(PrintingResource, msg)
- PPAPI_DISPATCH_RESOURCE_REPLY(
- PpapiPluginMsg_Printing_GetDefaultPrintSettingsReply,
- OnPluginMsgGetDefaultPrintSettingsReply)
- IPC_END_MESSAGE_MAP()
-}
-
void PrintingResource::OnPluginMsgGetDefaultPrintSettingsReply(
+ PP_PrintSettings_Dev* settings_out,
+ scoped_refptr<TrackedCallback> callback,
const ResourceMessageReplyParams& params,
const PP_PrintSettings_Dev& settings) {
if (params.result() == PP_OK)
- *print_settings_ = settings;
- print_settings_ = NULL;
+ *settings_out = settings;
// Notify the plugin of the new data.
- TrackedCallback::ClearAndRun(&callback_, params.result());
+ TrackedCallback::ClearAndRun(&callback, params.result());
// DANGER: May delete |this|!
}