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

Side by Side Diff: ppapi/utility/completion_callback_factory.h

Issue 9615050: Remove NewRequiredCallback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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_UTILITY_COMPLETION_CALLBACK_FACTORY_H_ 5 #ifndef PPAPI_UTILITY_COMPLETION_CALLBACK_FACTORY_H_
6 #define PPAPI_UTILITY_COMPLETION_CALLBACK_FACTORY_H_ 6 #define PPAPI_UTILITY_COMPLETION_CALLBACK_FACTORY_H_
7 7
8 #include "ppapi/cpp/completion_callback.h" 8 #include "ppapi/cpp/completion_callback.h"
9 #include "ppapi/utility/non_thread_safe_ref_count.h" 9 #include "ppapi/utility/non_thread_safe_ref_count.h"
10 10
(...skipping 21 matching lines...) Expand all
32 /// @code 32 /// @code
33 /// 33 ///
34 /// class MyHandler { 34 /// class MyHandler {
35 /// public: 35 /// public:
36 /// // If an compiler warns on following using |this| in the initializer 36 /// // If an compiler warns on following using |this| in the initializer
37 /// // list, use PP_ALLOW_THIS_IN_INITIALIZER_LIST macro. 37 /// // list, use PP_ALLOW_THIS_IN_INITIALIZER_LIST macro.
38 /// MyHandler() : factory_(this), offset_(0) { 38 /// MyHandler() : factory_(this), offset_(0) {
39 /// } 39 /// }
40 /// 40 ///
41 /// void ProcessFile(const FileRef& file) { 41 /// void ProcessFile(const FileRef& file) {
42 /// CompletionCallback cc = factory_.NewRequiredCallback( 42 /// CompletionCallback cc = factory_.NewCallback(
43 /// &MyHandler::DidOpen); 43 /// &MyHandler::DidOpen);
44 /// int32_t rv = fio_.Open(file, PP_FileOpenFlag_Read, cc); 44 /// int32_t rv = fio_.Open(file, PP_FileOpenFlag_Read, cc);
45 /// CHECK(rv == PP_OK_COMPLETIONPENDING); 45 /// CHECK(rv == PP_OK_COMPLETIONPENDING);
46 /// } 46 /// }
47 /// 47 ///
48 /// private: 48 /// private:
49 /// CompletionCallback NewCallback() { 49 /// CompletionCallback NewCallback() {
50 /// return factory_.NewCallback(&MyHandler::DidCompleteIO); 50 /// return factory_.NewCallback(&MyHandler::DidCompleteIO);
51 /// } 51 /// }
52 /// 52 ///
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 /// Intialize(). 140 /// Intialize().
141 /// 141 ///
142 /// @return the object passed to the constructor or Intialize(). 142 /// @return the object passed to the constructor or Intialize().
143 T* GetObject() { 143 T* GetObject() {
144 return object_; 144 return object_;
145 } 145 }
146 146
147 /// NewCallback allocates a new, single-use <code>CompletionCallback</code>. 147 /// NewCallback allocates a new, single-use <code>CompletionCallback</code>.
148 /// The <code>CompletionCallback</code> must be run in order for the memory 148 /// The <code>CompletionCallback</code> must be run in order for the memory
149 /// allocated by the methods to be freed. 149 /// allocated by the methods to be freed.
150 /// NewCallback() is equivalent to NewRequiredCallback() below.
151 /// 150 ///
152 /// @param[in] method The method to be invoked upon completion of the 151 /// @param[in] method The method to be invoked upon completion of the
153 /// operation. 152 /// operation.
154 /// 153 ///
155 /// @return A <code>CompletionCallback</code>. 154 /// @return A <code>CompletionCallback</code>.
156 template <typename Method> 155 template <typename Method>
157 CompletionCallback NewCallback(Method method) { 156 CompletionCallback NewCallback(Method method) {
158 PP_DCHECK(object_); 157 PP_DCHECK(object_);
159 return NewCallbackHelper(Dispatcher0<Method>(method)); 158 return NewCallbackHelper(Dispatcher0<Method>(method));
160 } 159 }
161 160
162 /// NewRequiredCallback() allocates a new, single-use
163 /// <code>CompletionCallback</code> that will always run. The
164 /// <code>CompletionCallback</code> must be run in order for the memory
165 /// allocated by the methods to be freed.
166 ///
167 /// @param[in] method The method to be invoked upon completion of the
168 /// operation.
169 ///
170 /// @return A <code>CompletionCallback</code>.
171 template <typename Method>
172 CompletionCallback NewRequiredCallback(Method method) {
173 CompletionCallback cc = NewCallback(method);
174 cc.set_flags(cc.flags() & ~PP_COMPLETIONCALLBACK_FLAG_OPTIONAL);
175 return cc;
176 }
177
178 /// NewOptionalCallback() allocates a new, single-use 161 /// NewOptionalCallback() allocates a new, single-use
179 /// <code>CompletionCallback</code> that might not run if the method 162 /// <code>CompletionCallback</code> that might not run if the method
180 /// taking it can complete synchronously. Thus, if after passing the 163 /// taking it can complete synchronously. Thus, if after passing the
181 /// CompletionCallback to a Pepper method, the method does not return 164 /// CompletionCallback to a Pepper method, the method does not return
182 /// PP_OK_COMPLETIONPENDING, then you should manually call the 165 /// PP_OK_COMPLETIONPENDING, then you should manually call the
183 /// CompletionCallback's Run method, or memory will be leaked. 166 /// CompletionCallback's Run method, or memory will be leaked.
184 /// 167 ///
185 /// @param[in] method The method to be invoked upon completion of the 168 /// @param[in] method The method to be invoked upon completion of the
186 /// operation. 169 /// operation.
187 /// 170 ///
188 /// @return A <code>CompletionCallback</code>. 171 /// @return A <code>CompletionCallback</code>.
189 template <typename Method> 172 template <typename Method>
190 CompletionCallback NewOptionalCallback(Method method) { 173 CompletionCallback NewOptionalCallback(Method method) {
191 CompletionCallback cc = NewCallback(method); 174 CompletionCallback cc = NewCallback(method);
192 cc.set_flags(cc.flags() | PP_COMPLETIONCALLBACK_FLAG_OPTIONAL); 175 cc.set_flags(cc.flags() | PP_COMPLETIONCALLBACK_FLAG_OPTIONAL);
193 return cc; 176 return cc;
194 } 177 }
195 178
196 /// NewCallback() allocates a new, single-use <code>CompletionCallback</code>. 179 /// NewCallback() allocates a new, single-use <code>CompletionCallback</code>.
197 /// The <code>CompletionCallback</code> must be run in order for the memory 180 /// The <code>CompletionCallback</code> must be run in order for the memory
198 /// allocated by the methods to be freed. 181 /// allocated by the methods to be freed.
199 /// NewCallback() is equivalent to NewRequiredCallback() below.
200 /// 182 ///
201 /// @param[in] method The method to be invoked upon completion of the 183 /// @param[in] method The method to be invoked upon completion of the
202 /// operation. Method should be of type: 184 /// operation. Method should be of type:
203 /// <code>void (T::*)(int32_t result, const A& a)</code> 185 /// <code>void (T::*)(int32_t result, const A& a)</code>
204 /// 186 ///
205 /// @param[in] a Passed to <code>method</code> when the completion callback 187 /// @param[in] a Passed to <code>method</code> when the completion callback
206 /// runs. 188 /// runs.
207 /// 189 ///
208 /// @return A <code>CompletionCallback</code>. 190 /// @return A <code>CompletionCallback</code>.
209 template <typename Method, typename A> 191 template <typename Method, typename A>
210 CompletionCallback NewCallback(Method method, const A& a) { 192 CompletionCallback NewCallback(Method method, const A& a) {
211 PP_DCHECK(object_); 193 PP_DCHECK(object_);
212 return NewCallbackHelper(Dispatcher1<Method, A>(method, a)); 194 return NewCallbackHelper(Dispatcher1<Method, A>(method, a));
213 } 195 }
214 196
215 /// NewRequiredCallback() allocates a new, single-use
216 /// <code>CompletionCallback</code> that will always run. The
217 /// <code>CompletionCallback</code> must be run in order for the memory
218 /// allocated by the methods to be freed.
219 ///
220 /// @param[in] method The method to be invoked upon completion of the
221 /// operation. Method should be of type:
222 /// <code>void (T::*)(int32_t result, const A& a)</code>
223 ///
224 /// @param[in] a Passed to <code>method</code> when the completion callback
225 /// runs.
226 ///
227 /// @return A <code>CompletionCallback</code>.
228 template <typename Method, typename A>
229 CompletionCallback NewRequiredCallback(Method method, const A& a) {
230 CompletionCallback cc = NewCallback(method, a);
231 cc.set_flags(cc.flags() & ~PP_COMPLETIONCALLBACK_FLAG_OPTIONAL);
232 return cc;
233 }
234
235 /// NewOptionalCallback() allocates a new, single-use 197 /// NewOptionalCallback() allocates a new, single-use
236 /// <code>CompletionCallback</code> that might not run if the method 198 /// <code>CompletionCallback</code> that might not run if the method
237 /// taking it can complete synchronously. Thus, if after passing the 199 /// taking it can complete synchronously. Thus, if after passing the
238 /// CompletionCallback to a Pepper method, the method does not return 200 /// CompletionCallback to a Pepper method, the method does not return
239 /// PP_OK_COMPLETIONPENDING, then you should manually call the 201 /// PP_OK_COMPLETIONPENDING, then you should manually call the
240 /// CompletionCallback's Run method, or memory will be leaked. 202 /// CompletionCallback's Run method, or memory will be leaked.
241 /// 203 ///
242 /// @param[in] method The method to be invoked upon completion of the 204 /// @param[in] method The method to be invoked upon completion of the
243 /// operation. Method should be of type: 205 /// operation. Method should be of type:
244 /// <code>void (T::*)(int32_t result, const A& a)</code> 206 /// <code>void (T::*)(int32_t result, const A& a)</code>
245 /// 207 ///
246 /// @param[in] a Passed to <code>method</code> when the completion callback 208 /// @param[in] a Passed to <code>method</code> when the completion callback
247 /// runs. 209 /// runs.
248 /// 210 ///
249 /// @return A <code>CompletionCallback</code>. 211 /// @return A <code>CompletionCallback</code>.
250 template <typename Method, typename A> 212 template <typename Method, typename A>
251 CompletionCallback NewOptionalCallback(Method method, const A& a) { 213 CompletionCallback NewOptionalCallback(Method method, const A& a) {
252 CompletionCallback cc = NewCallback(method, a); 214 CompletionCallback cc = NewCallback(method, a);
253 cc.set_flags(cc.flags() | PP_COMPLETIONCALLBACK_FLAG_OPTIONAL); 215 cc.set_flags(cc.flags() | PP_COMPLETIONCALLBACK_FLAG_OPTIONAL);
254 return cc; 216 return cc;
255 } 217 }
256 218
257 /// NewCallback() allocates a new, single-use 219 /// NewCallback() allocates a new, single-use
258 /// <code>CompletionCallback</code>. 220 /// <code>CompletionCallback</code>.
259 /// The <code>CompletionCallback</code> must be run in order for the memory 221 /// The <code>CompletionCallback</code> must be run in order for the memory
260 /// allocated by the methods to be freed. 222 /// allocated by the methods to be freed.
261 /// NewCallback() is equivalent to NewRequiredCallback() below.
262 /// 223 ///
263 /// @param method The method taking the callback. Method should be of type: 224 /// @param method The method taking the callback. Method should be of type:
264 /// <code>void (T::*)(int32_t result, const A& a, const B& b)</code> 225 /// <code>void (T::*)(int32_t result, const A& a, const B& b)</code>
265 /// 226 ///
266 /// @param[in] a Passed to <code>method</code> when the completion callback 227 /// @param[in] a Passed to <code>method</code> when the completion callback
267 /// runs. 228 /// runs.
268 /// 229 ///
269 /// @param[in] b Passed to <code>method</code> when the completion callback 230 /// @param[in] b Passed to <code>method</code> when the completion callback
270 /// runs. 231 /// runs.
271 /// 232 ///
272 /// @return A <code>CompletionCallback</code>. 233 /// @return A <code>CompletionCallback</code>.
273 template <typename Method, typename A, typename B> 234 template <typename Method, typename A, typename B>
274 CompletionCallback NewCallback(Method method, const A& a, const B& b) { 235 CompletionCallback NewCallback(Method method, const A& a, const B& b) {
275 PP_DCHECK(object_); 236 PP_DCHECK(object_);
276 return NewCallbackHelper(Dispatcher2<Method, A, B>(method, a, b)); 237 return NewCallbackHelper(Dispatcher2<Method, A, B>(method, a, b));
277 } 238 }
278 239
279 /// NewRequiredCallback() allocates a new, single-use
280 /// <code>CompletionCallback</code> that will always run. The
281 /// <code>CompletionCallback</code> must be run in order for the memory
282 /// allocated by the methods to be freed.
283 ///
284 /// @param method The method taking the callback. Method should be of type:
285 /// <code>void (T::*)(int32_t result, const A& a, const B& b)</code>
286 ///
287 /// @param[in] a Passed to <code>method</code> when the completion callback
288 /// runs.
289 ///
290 /// @param[in] b Passed to <code>method</code> when the completion callback
291 /// runs.
292 ///
293 /// @return A <code>CompletionCallback</code>.
294 template <typename Method, typename A, typename B>
295 CompletionCallback NewRequiredCallback(Method method, const A& a,
296 const B& b) {
297 CompletionCallback cc = NewCallback(method, a, b);
298 cc.set_flags(cc.flags() & ~PP_COMPLETIONCALLBACK_FLAG_OPTIONAL);
299 return cc;
300 }
301
302 /// NewOptionalCallback() allocates a new, single-use 240 /// NewOptionalCallback() allocates a new, single-use
303 /// <code>CompletionCallback</code> that might not run if the method 241 /// <code>CompletionCallback</code> that might not run if the method
304 /// taking it can complete synchronously. Thus, if after passing the 242 /// taking it can complete synchronously. Thus, if after passing the
305 /// CompletionCallback to a Pepper method, the method does not return 243 /// CompletionCallback to a Pepper method, the method does not return
306 /// PP_OK_COMPLETIONPENDING, then you should manually call the 244 /// PP_OK_COMPLETIONPENDING, then you should manually call the
307 /// CompletionCallback's Run method, or memory will be leaked. 245 /// CompletionCallback's Run method, or memory will be leaked.
308 /// 246 ///
309 /// @param[in] method The method taking the callback. Method should be of 247 /// @param[in] method The method taking the callback. Method should be of
310 /// type: 248 /// type:
311 /// <code>void (T::*)(int32_t result, const A& a, const B& b)</code> 249 /// <code>void (T::*)(int32_t result, const A& a, const B& b)</code>
(...skipping 10 matching lines...) Expand all
322 const B& b) { 260 const B& b) {
323 CompletionCallback cc = NewCallback(method, a, b); 261 CompletionCallback cc = NewCallback(method, a, b);
324 cc.set_flags(cc.flags() | PP_COMPLETIONCALLBACK_FLAG_OPTIONAL); 262 cc.set_flags(cc.flags() | PP_COMPLETIONCALLBACK_FLAG_OPTIONAL);
325 return cc; 263 return cc;
326 } 264 }
327 265
328 /// NewCallback() allocates a new, single-use 266 /// NewCallback() allocates a new, single-use
329 /// <code>CompletionCallback</code>. 267 /// <code>CompletionCallback</code>.
330 /// The <code>CompletionCallback</code> must be run in order for the memory 268 /// The <code>CompletionCallback</code> must be run in order for the memory
331 /// allocated by the methods to be freed. 269 /// allocated by the methods to be freed.
332 /// NewCallback() is equivalent to NewRequiredCallback() below.
333 /// 270 ///
334 /// @param method The method taking the callback. Method should be of type: 271 /// @param method The method taking the callback. Method should be of type:
335 /// <code> 272 /// <code>
336 /// void (T::*)(int32_t result, const A& a, const B& b, const C& c) 273 /// void (T::*)(int32_t result, const A& a, const B& b, const C& c)
337 /// </code> 274 /// </code>
338 /// 275 ///
339 /// @param[in] a Passed to <code>method</code> when the completion callback 276 /// @param[in] a Passed to <code>method</code> when the completion callback
340 /// runs. 277 /// runs.
341 /// 278 ///
342 /// @param[in] b Passed to <code>method</code> when the completion callback 279 /// @param[in] b Passed to <code>method</code> when the completion callback
343 /// runs. 280 /// runs.
344 /// 281 ///
345 /// @param[in] c Passed to <code>method</code> when the completion callback 282 /// @param[in] c Passed to <code>method</code> when the completion callback
346 /// runs. 283 /// runs.
347 /// 284 ///
348 /// @return A <code>CompletionCallback</code>. 285 /// @return A <code>CompletionCallback</code>.
349 template <typename Method, typename A, typename B, typename C> 286 template <typename Method, typename A, typename B, typename C>
350 CompletionCallback NewCallback(Method method, const A& a, const B& b, 287 CompletionCallback NewCallback(Method method, const A& a, const B& b,
351 const C& c) { 288 const C& c) {
352 PP_DCHECK(object_); 289 PP_DCHECK(object_);
353 return NewCallbackHelper(Dispatcher3<Method, A, B, C>(method, a, b, c)); 290 return NewCallbackHelper(Dispatcher3<Method, A, B, C>(method, a, b, c));
354 } 291 }
355 292
356 /// NewRequiredCallback() allocates a new, single-use
357 /// <code>CompletionCallback</code> that will always run. The
358 /// <code>CompletionCallback</code> must be run in order for the memory
359 /// allocated by the methods to be freed.
360 ///
361 /// @param method The method taking the callback. Method should be of type:
362 /// <code>
363 /// void (T::*)(int32_t result, const A& a, const B& b, const C& c)
364 /// </code>
365 ///
366 /// @param[in] a Passed to <code>method</code> when the completion callback
367 /// runs.
368 ///
369 /// @param[in] b Passed to <code>method</code> when the completion callback
370 /// runs.
371 ///
372 /// @param[in] c Passed to <code>method</code> when the completion callback
373 /// runs.
374 ///
375 /// @return A <code>CompletionCallback</code>.
376 template <typename Method, typename A, typename B, typename C>
377 CompletionCallback NewRequiredCallback(Method method, const A& a,
378 const B& b, const C& c) {
379 CompletionCallback cc = NewCallback(method, a, b, c);
380 cc.set_flags(cc.flags() & ~PP_COMPLETIONCALLBACK_FLAG_OPTIONAL);
381 return cc;
382 }
383
384 /// NewOptionalCallback() allocates a new, single-use 293 /// NewOptionalCallback() allocates a new, single-use
385 /// <code>CompletionCallback</code> that might not run if the method 294 /// <code>CompletionCallback</code> that might not run if the method
386 /// taking it can complete synchronously. Thus, if after passing the 295 /// taking it can complete synchronously. Thus, if after passing the
387 /// CompletionCallback to a Pepper method, the method does not return 296 /// CompletionCallback to a Pepper method, the method does not return
388 /// PP_OK_COMPLETIONPENDING, then you should manually call the 297 /// PP_OK_COMPLETIONPENDING, then you should manually call the
389 /// CompletionCallback's Run method, or memory will be leaked. 298 /// CompletionCallback's Run method, or memory will be leaked.
390 /// 299 ///
391 /// @param[in] method The method taking the callback. Method should be of 300 /// @param[in] method The method taking the callback. Method should be of
392 /// type: 301 /// type:
393 /// <code> 302 /// <code>
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 CompletionCallbackFactory(const CompletionCallbackFactory&); 464 CompletionCallbackFactory(const CompletionCallbackFactory&);
556 CompletionCallbackFactory& operator=(const CompletionCallbackFactory&); 465 CompletionCallbackFactory& operator=(const CompletionCallbackFactory&);
557 466
558 T* object_; 467 T* object_;
559 BackPointer* back_pointer_; 468 BackPointer* back_pointer_;
560 }; 469 };
561 470
562 } // namespace pp 471 } // namespace pp
563 472
564 #endif // PPAPI_UTILITY_COMPLETION_CALLBACK_FACTORY_H_ 473 #endif // PPAPI_UTILITY_COMPLETION_CALLBACK_FACTORY_H_
OLDNEW
« no previous file with comments | « ppapi/tests/test_flash_message_loop.cc ('k') | remoting/protocol/pepper_transport_socket_adapter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698