Factorize media/audio into new GN.
[chromium-blink-merge.git] / ppapi / proxy / plugin_resource_callback.h
bloba306c26a1c744eddbcf4dbe333bfb5c538c84b84
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"
13 namespace ppapi {
14 namespace proxy {
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> {
22 public:
23 virtual void Run(const ResourceMessageReplyParams& params,
24 const IPC::Message& msg) = 0;
25 protected:
26 friend class base::RefCounted<PluginResourceCallbackBase>;
27 virtual ~PluginResourceCallbackBase() {}
30 template<typename MsgClass, typename CallbackType>
31 class PluginResourceCallback : public PluginResourceCallbackBase {
32 public:
33 explicit PluginResourceCallback(const CallbackType& callback)
34 : callback_(callback) {}
36 virtual void Run(
37 const ResourceMessageReplyParams& reply_params,
38 const IPC::Message& msg) OVERRIDE {
39 DispatchResourceReplyOrDefaultParams<MsgClass>(
40 &callback_, &CallbackType::Run, reply_params, msg);
43 private:
44 virtual ~PluginResourceCallback() {}
46 CallbackType callback_;
49 } // namespace proxy
50 } // namespace ppapi
52 #endif // PPAPI_PROXY_PLUGIN_RESOURCE_CALLBACK_H_