| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file provides infrastructure for dispatching host resource call | 5 // This file provides infrastructure for dispatching host resource call |
| 6 // messages. Normal IPC message handlers can't take extra parameters or | 6 // messages. Normal IPC message handlers can't take extra parameters or |
| 7 // return values. We want to take a HostMessageContext as a parameter and | 7 // return values. We want to take a HostMessageContext as a parameter and |
| 8 // also return the int32_t return value to the caller. | 8 // also return the int32_t return value to the caller. |
| 9 | 9 |
| 10 #ifndef PPAPI_HOST_DISPATCH_HOST_MESSAGE_H_ | 10 #ifndef PPAPI_HOST_DISPATCH_HOST_MESSAGE_H_ |
| 11 #define PPAPI_HOST_DISPATCH_HOST_MESSAGE_H_ | 11 #define PPAPI_HOST_DISPATCH_HOST_MESSAGE_H_ |
| 12 | 12 |
| 13 #include "base/profiler/scoped_profile.h" | 13 #include "base/profiler/scoped_profile.h" |
| 14 #include "ipc/ipc_message_macros.h" | 14 #include "ipc/ipc_message_macros.h" |
| 15 #include "ppapi/c/pp_errors.h" | 15 #include "ppapi/c/pp_errors.h" |
| 16 | 16 |
| 17 namespace ppapi { | 17 namespace ppapi { |
| 18 namespace host { | 18 namespace host { |
| 19 | 19 |
| 20 struct HostMessageContext; | 20 struct HostMessageContext; |
| 21 | 21 |
| 22 template <class ObjT, class Method> | 22 template <class ObjT, class Method> |
| 23 inline int32_t DispatchResourceCall(ObjT* obj, Method method, | 23 inline int32_t DispatchResourceCall(ObjT* obj, Method method, |
| 24 HostMessageContext* context, | 24 HostMessageContext* context, |
| 25 Tuple<>& arg) { | 25 base::Tuple<>& arg) { |
| 26 return (obj->*method)(context); | 26 return (obj->*method)(context); |
| 27 } | 27 } |
| 28 | 28 |
| 29 template <class ObjT, class Method, class A> | 29 template <class ObjT, class Method, class A> |
| 30 inline int32_t DispatchResourceCall(ObjT* obj, Method method, | 30 inline int32_t DispatchResourceCall(ObjT* obj, Method method, |
| 31 HostMessageContext* context, | 31 HostMessageContext* context, |
| 32 Tuple<A>& arg) { | 32 base::Tuple<A>& arg) { |
| 33 return (obj->*method)(context, get<0>(arg)); | 33 return (obj->*method)(context, base::get<0>(arg)); |
| 34 } | 34 } |
| 35 | 35 |
| 36 template<class ObjT, class Method, class A, class B> | 36 template<class ObjT, class Method, class A, class B> |
| 37 inline int32_t DispatchResourceCall(ObjT* obj, Method method, | 37 inline int32_t DispatchResourceCall(ObjT* obj, Method method, |
| 38 HostMessageContext* context, | 38 HostMessageContext* context, |
| 39 Tuple<A, B>& arg) { | 39 base::Tuple<A, B>& arg) { |
| 40 return (obj->*method)(context, get<0>(arg), get<1>(arg)); | 40 return (obj->*method)(context, base::get<0>(arg), base::get<1>(arg)); |
| 41 } | 41 } |
| 42 | 42 |
| 43 template<class ObjT, class Method, class A, class B, class C> | 43 template<class ObjT, class Method, class A, class B, class C> |
| 44 inline int32_t DispatchResourceCall(ObjT* obj, Method method, | 44 inline int32_t DispatchResourceCall(ObjT* obj, Method method, |
| 45 HostMessageContext* context, | 45 HostMessageContext* context, |
| 46 Tuple<A, B, C>& arg) { | 46 base::Tuple<A, B, C>& arg) { |
| 47 return (obj->*method)(context, get<0>(arg), get<1>(arg), get<2>(arg)); | 47 return (obj->*method)(context, base::get<0>(arg), base::get<1>(arg), |
| 48 base::get<2>(arg)); |
| 48 } | 49 } |
| 49 | 50 |
| 50 template<class ObjT, class Method, class A, class B, class C, class D> | 51 template<class ObjT, class Method, class A, class B, class C, class D> |
| 51 inline int32_t DispatchResourceCall(ObjT* obj, Method method, | 52 inline int32_t DispatchResourceCall(ObjT* obj, Method method, |
| 52 HostMessageContext* context, | 53 HostMessageContext* context, |
| 53 Tuple<A, B, C, D>& arg) { | 54 base::Tuple<A, B, C, D>& arg) { |
| 54 return (obj->*method)(context, get<0>(arg), get<1>(arg), get<2>(arg), | 55 return (obj->*method)(context, base::get<0>(arg), base::get<1>(arg), |
| 55 get<3>(arg)); | 56 base::get<2>(arg), base::get<3>(arg)); |
| 56 } | 57 } |
| 57 | 58 |
| 58 template<class ObjT, class Method, class A, class B, class C, class D, class E> | 59 template<class ObjT, class Method, class A, class B, class C, class D, class E> |
| 59 inline int32_t DispatchResourceCall(ObjT* obj, Method method, | 60 inline int32_t DispatchResourceCall(ObjT* obj, Method method, |
| 60 HostMessageContext* context, | 61 HostMessageContext* context, |
| 61 Tuple<A, B, C, D, E>& arg) { | 62 base::Tuple<A, B, C, D, E>& arg) { |
| 62 return (obj->*method)(context, get<0>(arg), get<1>(arg), get<2>(arg), | 63 return (obj->*method)(context, base::get<0>(arg), base::get<1>(arg), |
| 63 get<3>(arg), get<4>(arg)); | 64 base::get<2>(arg), base::get<3>(arg), |
| 65 base::get<4>(arg)); |
| 64 } | 66 } |
| 65 | 67 |
| 66 // Note that this only works for message with 1 or more parameters. For | 68 // Note that this only works for message with 1 or more parameters. For |
| 67 // 0-parameter messages you need to use the _0 version below (since there are | 69 // 0-parameter messages you need to use the _0 version below (since there are |
| 68 // no params in the message). | 70 // no params in the message). |
| 69 #define PPAPI_DISPATCH_HOST_RESOURCE_CALL(msg_class, member_func) \ | 71 #define PPAPI_DISPATCH_HOST_RESOURCE_CALL(msg_class, member_func) \ |
| 70 case msg_class::ID: { \ | 72 case msg_class::ID: { \ |
| 71 TRACK_RUN_IN_THIS_SCOPED_REGION(member_func); \ | 73 TRACK_RUN_IN_THIS_SCOPED_REGION(member_func); \ |
| 72 msg_class::Schema::Param p; \ | 74 msg_class::Schema::Param p; \ |
| 73 if (msg_class::Read(&ipc_message__, &p)) { \ | 75 if (msg_class::Read(&ipc_message__, &p)) { \ |
| 74 return ppapi::host::DispatchResourceCall( \ | 76 return ppapi::host::DispatchResourceCall( \ |
| 75 this, \ | 77 this, \ |
| 76 &_IpcMessageHandlerClass::member_func, \ | 78 &_IpcMessageHandlerClass::member_func, \ |
| 77 context, p); \ | 79 context, p); \ |
| 78 } \ | 80 } \ |
| 79 return PP_ERROR_FAILED; \ | 81 return PP_ERROR_FAILED; \ |
| 80 } | 82 } |
| 81 | 83 |
| 82 #define PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(msg_class, member_func) \ | 84 #define PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(msg_class, member_func) \ |
| 83 case msg_class::ID: { \ | 85 case msg_class::ID: { \ |
| 84 TRACK_RUN_IN_THIS_SCOPED_REGION(member_func); \ | 86 TRACK_RUN_IN_THIS_SCOPED_REGION(member_func); \ |
| 85 return member_func(context); \ | 87 return member_func(context); \ |
| 86 } | 88 } |
| 87 | 89 |
| 88 } // namespace host | 90 } // namespace host |
| 89 } // namespace ppapi | 91 } // namespace ppapi |
| 90 | 92 |
| 91 #endif // PPAPI_HOST_DISPATCH_HOST_MESSAGE_H_ | 93 #endif // PPAPI_HOST_DISPATCH_HOST_MESSAGE_H_ |
| OLD | NEW |