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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 void RunCallback(int32_t result) { | 163 void RunCallback(int32_t result) { |
164 DCHECK(needs_running_); | 164 DCHECK(needs_running_); |
165 needs_running_ = false; | 165 needs_running_ = false; |
166 callback_.Run(result); | 166 callback_.Run(result); |
167 } | 167 } |
168 | 168 |
169 bool needs_running_; | 169 bool needs_running_; |
170 pp::CompletionCallback callback_; | 170 pp::CompletionCallback callback_; |
171 }; | 171 }; |
172 | 172 |
173 // Like EnterHostFromHostResourceForceCallback but for Function APIs. It takes | |
174 // an instance instead of a resource ID. | |
175 template<typename FunctionT> | |
176 class EnterHostFunctionForceCallback | |
177 : public thunk::EnterFunctionNoLock<FunctionT> { | |
178 public: | |
179 EnterHostFunctionForceCallback( | |
180 PP_Instance instance, | |
181 const pp::CompletionCallback& callback) | |
182 : thunk::EnterFunctionNoLock<FunctionT>(instance, false), | |
183 needs_running_(true), | |
184 callback_(callback) { | |
185 if (this->failed()) | |
186 RunCallback(PP_ERROR_BADARGUMENT); | |
187 } | |
188 | |
189 ~EnterHostFunctionForceCallback() { | |
190 if (needs_running_) { | |
191 NOTREACHED() << "Should always call SetResult except in the " | |
192 "initialization failed case."; | |
193 RunCallback(PP_ERROR_FAILED); | |
194 } | |
195 } | |
196 | |
197 void SetResult(int32_t result) { | |
198 DCHECK(needs_running_) << "Don't call SetResult when there already is one."; | |
199 needs_running_ = false; | |
200 if (result != PP_OK_COMPLETIONPENDING) | |
201 callback_.Run(result); | |
202 } | |
203 | |
204 PP_CompletionCallback callback() { | |
205 return callback_.pp_completion_callback(); | |
206 } | |
207 | |
208 private: | |
209 void RunCallback(int32_t result) { | |
210 DCHECK(needs_running_); | |
211 needs_running_ = false; | |
212 callback_.Run(result); | |
213 } | |
214 | |
215 bool needs_running_; | |
216 pp::CompletionCallback callback_; | |
217 }; | |
218 | |
219 } // namespace proxy | 173 } // namespace proxy |
220 } // namespace ppapi | 174 } // namespace ppapi |
221 | 175 |
222 #endif // PPAPI_PROXY_ENTER_PROXY_H_ | 176 #endif // PPAPI_PROXY_ENTER_PROXY_H_ |
OLD | NEW |