Index: ppapi/proxy/enter_proxy.h |
diff --git a/ppapi/proxy/enter_proxy.h b/ppapi/proxy/enter_proxy.h |
index d7bf7c2e9a058a6ddd66c0353d8bdd2feb995867..fdd05a3e91c38849d58d165f7003831ac7ba685d 100644 |
--- a/ppapi/proxy/enter_proxy.h |
+++ b/ppapi/proxy/enter_proxy.h |
@@ -165,6 +165,82 @@ class EnterHostFromHostResourceForceCallback |
pp::CompletionCallback callback_; |
}; |
+// Like EnterHostFromHostResourceForceCallback but for Function APIs. It takes |
+// an instance instead of a resource ID. |
+template<typename FunctionT> |
+class EnterHostFunctionForceCallback |
+ : public thunk::EnterFunctionNoLock<FunctionT> { |
+ public: |
+ // For callbacks that take no parameters except the "int32_t result". Most |
+ // implementations will use the 1-extra-argument constructor below. |
+ template<class CallbackFactory, typename Method> |
+ EnterHostFunctionForceCallback(PP_Instance instance, |
+ CallbackFactory& factory, |
+ Method method) |
+ : thunk::EnterFunctionNoLock<FunctionT>(instance, false), |
+ needs_running_(true), |
+ callback_(factory.NewOptionalCallback(method)) { |
+ if (this->failed()) |
+ RunCallback(PP_ERROR_BADARGUMENT); |
+ } |
+ |
+ // For callbacks that take an extra parameter as a closure. |
+ template<class CallbackFactory, typename Method, typename A> |
+ EnterHostFunctionForceCallback(PP_Instance instance, |
+ CallbackFactory& factory, |
+ Method method, |
+ const A& a) |
+ : thunk::EnterFunctionNoLock<FunctionT>(instance, false), |
+ needs_running_(true), |
+ callback_(factory.NewOptionalCallback(method, a)) { |
+ if (this->failed()) |
+ RunCallback(PP_ERROR_BADRESOURCE); |
viettrungluu
2011/10/17 17:11:03
PP_ERROR_BADARGUMENT?
|
+ } |
+ |
+ // For callbacks that take two extra parameters as a closure. |
+ template<class CallbackFactory, typename Method, typename A, typename B> |
+ EnterHostFunctionForceCallback(PP_Instance instance, |
+ CallbackFactory& factory, |
+ Method method, |
+ const A& a, |
+ const B& b) |
+ : thunk::EnterFunctionNoLock<FunctionT>(instance), |
+ needs_running_(true), |
+ callback_(factory.NewOptionalCallback(method, a, b)) { |
+ if (this->failed()) |
+ RunCallback(PP_ERROR_BADRESOURCE); |
viettrungluu
2011/10/17 17:11:03
"
|
+ } |
+ |
+ ~EnterHostFunctionForceCallback() { |
+ if (needs_running_) { |
+ NOTREACHED() << "Should always call SetResult except in the " |
+ "initialization failed case."; |
+ RunCallback(PP_ERROR_FAILED); |
+ } |
+ } |
+ |
+ void SetResult(int32_t result) { |
+ DCHECK(needs_running_) << "Don't call SetResult when there already is one."; |
+ needs_running_ = false; |
+ if (result != PP_OK_COMPLETIONPENDING) |
+ callback_.Run(result); |
+ } |
+ |
+ PP_CompletionCallback callback() { |
+ return callback_.pp_completion_callback(); |
+ } |
+ |
+ private: |
+ void RunCallback(int32_t result) { |
+ DCHECK(needs_running_); |
+ needs_running_ = false; |
+ callback_.Run(result); |
+ } |
+ |
+ bool needs_running_; |
+ pp::CompletionCallback callback_; |
+}; |
+ |
} // namespace proxy |
} // namespace ppapi |