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
3 // found in the LICENSE file.
5 #ifndef PPAPI_PROXY_PLUGIN_RESOURCE_CALLBACK_H_
6 #define PPAPI_PROXY_PLUGIN_RESOURCE_CALLBACK_H_
8 #include "base/memory/ref_counted.h"
9 #include "ipc/ipc_message.h"
10 #include "ppapi/proxy/dispatch_reply_message.h"
11 #include "ppapi/proxy/resource_message_params.h"
16 // |PluginResourceCallback| wraps a |base::Callback| on the plugin side which
17 // will be triggered in response to a particular message type being received.
18 // |MsgClass| is the reply message type that the callback will be called with
19 // and |CallbackType| is the type of the |base::Callback| that will be called.
20 class PluginResourceCallbackBase
21 : public base::RefCounted
<PluginResourceCallbackBase
> {
23 virtual void Run(const ResourceMessageReplyParams
& params
,
24 const IPC::Message
& msg
) = 0;
26 friend class base::RefCounted
<PluginResourceCallbackBase
>;
27 virtual ~PluginResourceCallbackBase() {}
30 template<typename MsgClass
, typename CallbackType
>
31 class PluginResourceCallback
: public PluginResourceCallbackBase
{
33 explicit PluginResourceCallback(const CallbackType
& callback
)
34 : callback_(callback
) {}
37 const ResourceMessageReplyParams
& reply_params
,
38 const IPC::Message
& msg
) override
{
39 DispatchResourceReplyOrDefaultParams
<MsgClass
>(
40 &callback_
, &CallbackType::Run
, reply_params
, msg
);
44 ~PluginResourceCallback() override
{}
46 CallbackType callback_
;
52 #endif // PPAPI_PROXY_PLUGIN_RESOURCE_CALLBACK_H_