Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(572)

Side by Side Diff: ppapi/proxy/enter_proxy.h

Issue 8226009: Remove the proxy callback tracker. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: PostMessage define. Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 void RunCallback(int32_t result) { 158 void RunCallback(int32_t result) {
159 DCHECK(needs_running_); 159 DCHECK(needs_running_);
160 needs_running_ = false; 160 needs_running_ = false;
161 callback_.Run(result); 161 callback_.Run(result);
162 } 162 }
163 163
164 bool needs_running_; 164 bool needs_running_;
165 pp::CompletionCallback callback_; 165 pp::CompletionCallback callback_;
166 }; 166 };
167 167
168 // Like EnterHostFromHostResourceForceCallback but for Function APIs. It takes
169 // an instance instead of a resource ID.
170 template<typename FunctionT>
171 class EnterHostFunctionForceCallback
172 : public thunk::EnterFunctionNoLock<FunctionT> {
173 public:
174 // For callbacks that take no parameters except the "int32_t result". Most
175 // implementations will use the 1-extra-argument constructor below.
176 template<class CallbackFactory, typename Method>
177 EnterHostFunctionForceCallback(PP_Instance instance,
178 CallbackFactory& factory,
179 Method method)
180 : thunk::EnterFunctionNoLock<FunctionT>(instance, false),
181 needs_running_(true),
182 callback_(factory.NewOptionalCallback(method)) {
183 if (this->failed())
184 RunCallback(PP_ERROR_BADARGUMENT);
185 }
186
187 // For callbacks that take an extra parameter as a closure.
188 template<class CallbackFactory, typename Method, typename A>
189 EnterHostFunctionForceCallback(PP_Instance instance,
190 CallbackFactory& factory,
191 Method method,
192 const A& a)
193 : thunk::EnterFunctionNoLock<FunctionT>(instance, false),
194 needs_running_(true),
195 callback_(factory.NewOptionalCallback(method, a)) {
196 if (this->failed())
197 RunCallback(PP_ERROR_BADARGUMENT);
198 }
199
200 // For callbacks that take two extra parameters as a closure.
201 template<class CallbackFactory, typename Method, typename A, typename B>
202 EnterHostFunctionForceCallback(PP_Instance instance,
203 CallbackFactory& factory,
204 Method method,
205 const A& a,
206 const B& b)
207 : thunk::EnterFunctionNoLock<FunctionT>(instance),
208 needs_running_(true),
209 callback_(factory.NewOptionalCallback(method, a, b)) {
210 if (this->failed())
211 RunCallback(PP_ERROR_BADARGUMENT);
212 }
213
214 ~EnterHostFunctionForceCallback() {
215 if (needs_running_) {
216 NOTREACHED() << "Should always call SetResult except in the "
217 "initialization failed case.";
218 RunCallback(PP_ERROR_FAILED);
219 }
220 }
221
222 void SetResult(int32_t result) {
223 DCHECK(needs_running_) << "Don't call SetResult when there already is one.";
224 needs_running_ = false;
225 if (result != PP_OK_COMPLETIONPENDING)
226 callback_.Run(result);
227 }
228
229 PP_CompletionCallback callback() {
230 return callback_.pp_completion_callback();
231 }
232
233 private:
234 void RunCallback(int32_t result) {
235 DCHECK(needs_running_);
236 needs_running_ = false;
237 callback_.Run(result);
238 }
239
240 bool needs_running_;
241 pp::CompletionCallback callback_;
242 };
243
168 } // namespace proxy 244 } // namespace proxy
169 } // namespace ppapi 245 } // namespace ppapi
170 246
171 #endif // PPAPI_PROXY_ENTER_PROXY_H_ 247 #endif // PPAPI_PROXY_ENTER_PROXY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698