| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef PPAPI_PROXY_ENTER_PROXY_H_ | 5 #ifndef PPAPI_PROXY_ENTER_PROXY_H_ |
| 6 #define PPAPI_PROXY_ENTER_PROXY_H_ | 6 #define PPAPI_PROXY_ENTER_PROXY_H_ |
| 7 | 7 |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "ppapi/cpp/completion_callback.h" | 9 #include "ppapi/cpp/completion_callback.h" |
| 10 #include "ppapi/proxy/host_dispatcher.h" | 10 #include "ppapi/proxy/host_dispatcher.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 // Where DoFoo's signature looks like this: | 82 // Where DoFoo's signature looks like this: |
| 83 // int32_t DoFoo(PP_CompletionCallback callback); | 83 // int32_t DoFoo(PP_CompletionCallback callback); |
| 84 // And SendResult's implementation looks like this: | 84 // And SendResult's implementation looks like this: |
| 85 // void MyClass::SendResult(int32_t result, const HostResource& res) { | 85 // void MyClass::SendResult(int32_t result, const HostResource& res) { |
| 86 // Send(new FooMsg_FooComplete(..., result, res)); | 86 // Send(new FooMsg_FooComplete(..., result, res)); |
| 87 // } | 87 // } |
| 88 template<typename ResourceT> | 88 template<typename ResourceT> |
| 89 class EnterHostFromHostResourceForceCallback | 89 class EnterHostFromHostResourceForceCallback |
| 90 : public EnterHostFromHostResource<ResourceT> { | 90 : public EnterHostFromHostResource<ResourceT> { |
| 91 public: | 91 public: |
| 92 EnterHostFromHostResourceForceCallback( |
| 93 const HostResource& host_resource, |
| 94 const pp::CompletionCallback& callback) |
| 95 : EnterHostFromHostResource<ResourceT>(host_resource), |
| 96 needs_running_(true), |
| 97 callback_(callback) { |
| 98 } |
| 99 |
| 92 // For callbacks that take no parameters except the "int32_t result". Most | 100 // For callbacks that take no parameters except the "int32_t result". Most |
| 93 // implementations will use the 1-extra-argument constructor below. | 101 // implementations will use the 1-extra-argument constructor below. |
| 94 template<class CallbackFactory, typename Method> | 102 template<class CallbackFactory, typename Method> |
| 95 EnterHostFromHostResourceForceCallback( | 103 EnterHostFromHostResourceForceCallback( |
| 96 const HostResource& host_resource, | 104 const HostResource& host_resource, |
| 97 CallbackFactory& factory, | 105 CallbackFactory& factory, |
| 98 Method method) | 106 Method method) |
| 99 : EnterHostFromHostResource<ResourceT>(host_resource), | 107 : EnterHostFromHostResource<ResourceT>(host_resource), |
| 100 needs_running_(true), | 108 needs_running_(true), |
| 101 callback_(factory.NewOptionalCallback(method)) { | 109 callback_(factory.NewOptionalCallback(method)) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 bool needs_running_; | 169 bool needs_running_; |
| 162 pp::CompletionCallback callback_; | 170 pp::CompletionCallback callback_; |
| 163 }; | 171 }; |
| 164 | 172 |
| 165 // Like EnterHostFromHostResourceForceCallback but for Function APIs. It takes | 173 // Like EnterHostFromHostResourceForceCallback but for Function APIs. It takes |
| 166 // an instance instead of a resource ID. | 174 // an instance instead of a resource ID. |
| 167 template<typename FunctionT> | 175 template<typename FunctionT> |
| 168 class EnterHostFunctionForceCallback | 176 class EnterHostFunctionForceCallback |
| 169 : public thunk::EnterFunctionNoLock<FunctionT> { | 177 : public thunk::EnterFunctionNoLock<FunctionT> { |
| 170 public: | 178 public: |
| 171 // For callbacks that take no parameters except the "int32_t result". Most | 179 EnterHostFunctionForceCallback( |
| 172 // implementations will use the 1-extra-argument constructor below. | 180 PP_Instance instance, |
| 173 template<class CallbackFactory, typename Method> | 181 const pp::CompletionCallback& callback) |
| 174 EnterHostFunctionForceCallback(PP_Instance instance, | |
| 175 CallbackFactory& factory, | |
| 176 Method method) | |
| 177 : thunk::EnterFunctionNoLock<FunctionT>(instance, false), | 182 : thunk::EnterFunctionNoLock<FunctionT>(instance, false), |
| 178 needs_running_(true), | 183 needs_running_(true), |
| 179 callback_(factory.NewOptionalCallback(method)) { | 184 callback_(callback) { |
| 180 if (this->failed()) | 185 if (this->failed()) |
| 181 RunCallback(PP_ERROR_BADARGUMENT); | 186 RunCallback(PP_ERROR_BADARGUMENT); |
| 182 } | 187 } |
| 183 | |
| 184 // For callbacks that take an extra parameter as a closure. | |
| 185 template<class CallbackFactory, typename Method, typename A> | |
| 186 EnterHostFunctionForceCallback(PP_Instance instance, | |
| 187 CallbackFactory& factory, | |
| 188 Method method, | |
| 189 const A& a) | |
| 190 : thunk::EnterFunctionNoLock<FunctionT>(instance, false), | |
| 191 needs_running_(true), | |
| 192 callback_(factory.NewOptionalCallback(method, a)) { | |
| 193 if (this->failed()) | |
| 194 RunCallback(PP_ERROR_BADARGUMENT); | |
| 195 } | |
| 196 | |
| 197 // For callbacks that take two extra parameters as a closure. | |
| 198 template<class CallbackFactory, typename Method, typename A, typename B> | |
| 199 EnterHostFunctionForceCallback(PP_Instance instance, | |
| 200 CallbackFactory& factory, | |
| 201 Method method, | |
| 202 const A& a, | |
| 203 const B& b) | |
| 204 : thunk::EnterFunctionNoLock<FunctionT>(instance), | |
| 205 needs_running_(true), | |
| 206 callback_(factory.NewOptionalCallback(method, a, b)) { | |
| 207 if (this->failed()) | |
| 208 RunCallback(PP_ERROR_BADARGUMENT); | |
| 209 } | |
| 210 | 188 |
| 211 ~EnterHostFunctionForceCallback() { | 189 ~EnterHostFunctionForceCallback() { |
| 212 if (needs_running_) { | 190 if (needs_running_) { |
| 213 NOTREACHED() << "Should always call SetResult except in the " | 191 NOTREACHED() << "Should always call SetResult except in the " |
| 214 "initialization failed case."; | 192 "initialization failed case."; |
| 215 RunCallback(PP_ERROR_FAILED); | 193 RunCallback(PP_ERROR_FAILED); |
| 216 } | 194 } |
| 217 } | 195 } |
| 218 | 196 |
| 219 void SetResult(int32_t result) { | 197 void SetResult(int32_t result) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 235 } | 213 } |
| 236 | 214 |
| 237 bool needs_running_; | 215 bool needs_running_; |
| 238 pp::CompletionCallback callback_; | 216 pp::CompletionCallback callback_; |
| 239 }; | 217 }; |
| 240 | 218 |
| 241 } // namespace proxy | 219 } // namespace proxy |
| 242 } // namespace ppapi | 220 } // namespace ppapi |
| 243 | 221 |
| 244 #endif // PPAPI_PROXY_ENTER_PROXY_H_ | 222 #endif // PPAPI_PROXY_ENTER_PROXY_H_ |
| OLD | NEW |