summaryrefslogtreecommitdiffstats
path: root/ppapi/cpp
diff options
context:
space:
mode:
authorsehr@google.com <sehr@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-02 19:55:06 +0000
committersehr@google.com <sehr@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-02 19:55:06 +0000
commitbd0691cfbd35209a149dab4ddfa4eaf7a376cfdc (patch)
treefc8cff317a9f4c78b280c3e14e8c0a29d7ebdc77 /ppapi/cpp
parent2ac5ce7b076aca8233b0fa1ec3aab7d8121aa787 (diff)
downloadchromium_src-bd0691cfbd35209a149dab4ddfa4eaf7a376cfdc.zip
chromium_src-bd0691cfbd35209a149dab4ddfa4eaf7a376cfdc.tar.gz
chromium_src-bd0691cfbd35209a149dab4ddfa4eaf7a376cfdc.tar.bz2
Add a three parameter (plus method) callback factory.
BUG= none TEST= none Review URL: http://codereview.chromium.org/8386047 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108335 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/cpp')
-rw-r--r--ppapi/cpp/completion_callback.h106
1 files changed, 106 insertions, 0 deletions
diff --git a/ppapi/cpp/completion_callback.h b/ppapi/cpp/completion_callback.h
index 7dee4db..e83616e 100644
--- a/ppapi/cpp/completion_callback.h
+++ b/ppapi/cpp/completion_callback.h
@@ -469,6 +469,93 @@ class CompletionCallbackFactory {
return cc;
}
+ /// NewCallback() allocates a new, single-use
+ /// <code>CompletionCallback</code>.
+ /// The <code>CompletionCallback</code> must be run in order for the memory
+ /// allocated by the methods to be freed.
+ /// NewCallback() is equivalent to NewRequiredCallback() below.
+ ///
+ /// @param method The method taking the callback. Method should be of type:
+ /// <code>
+ /// void (T::*)(int32_t result, const A& a, const B& b, const C& c)
+ /// </code>
+ ///
+ /// @param[in] a Passed to <code>method</code> when the completion callback
+ /// runs.
+ ///
+ /// @param[in] b Passed to <code>method</code> when the completion callback
+ /// runs.
+ ///
+ /// @param[in] c Passed to <code>method</code> when the completion callback
+ /// runs.
+ ///
+ /// @return A <code>CompletionCallback</code>.
+ template <typename Method, typename A, typename B, typename C>
+ CompletionCallback NewCallback(Method method, const A& a, const B& b,
+ const C& c) {
+ PP_DCHECK(object_);
+ return NewCallbackHelper(Dispatcher3<Method, A, B, C>(method, a, b, c));
+ }
+
+ /// NewRequiredCallback() allocates a new, single-use
+ /// <code>CompletionCallback</code> that will always run. The
+ /// <code>CompletionCallback</code> must be run in order for the memory
+ /// allocated by the methods to be freed.
+ ///
+ /// @param method The method taking the callback. Method should be of type:
+ /// <code>
+ /// void (T::*)(int32_t result, const A& a, const B& b, const C& c)
+ /// </code>
+ ///
+ /// @param[in] a Passed to <code>method</code> when the completion callback
+ /// runs.
+ ///
+ /// @param[in] b Passed to <code>method</code> when the completion callback
+ /// runs.
+ ///
+ /// @param[in] c Passed to <code>method</code> when the completion callback
+ /// runs.
+ ///
+ /// @return A <code>CompletionCallback</code>.
+ template <typename Method, typename A, typename B, typename C>
+ CompletionCallback NewRequiredCallback(Method method, const A& a,
+ const B& b, const C& c) {
+ CompletionCallback cc = NewCallback(method, a, b, c);
+ cc.set_flags(cc.flags() & ~PP_COMPLETIONCALLBACK_FLAG_OPTIONAL);
+ return cc;
+ }
+
+ /// NewOptionalCallback() allocates a new, single-use
+ /// <code>CompletionCallback</code> that might not run if the method
+ /// taking it can complete synchronously. Thus, if after passing the
+ /// CompletionCallback to a Pepper method, the method does not return
+ /// PP_OK_COMPLETIONPENDING, then you should manually call the
+ /// CompletionCallback's Run method, or memory will be leaked.
+ ///
+ /// @param[in] method The method taking the callback. Method should be of
+ /// type:
+ /// <code>
+ /// void (T::*)(int32_t result, const A& a, const B& b, const C& c)
+ /// </code>
+ ///
+ /// @param[in] a Passed to <code>method</code> when the completion callback
+ /// runs.
+ ///
+ /// @param[in] b Passed to <code>method</code> when the completion callback
+ /// runs.
+ ///
+ /// @param[in] c Passed to <code>method</code> when the completion callback
+ /// runs.
+ ///
+ /// @return A <code>CompletionCallback</code>.
+ template <typename Method, typename A, typename B, typename C>
+ CompletionCallback NewOptionalCallback(Method method, const A& a,
+ const B& b, const C& c) {
+ CompletionCallback cc = NewCallback(method, a, b, c);
+ cc.set_flags(cc.flags() | PP_COMPLETIONCALLBACK_FLAG_OPTIONAL);
+ return cc;
+ }
+
private:
class BackPointer {
public:
@@ -571,6 +658,25 @@ class CompletionCallbackFactory {
B b_;
};
+ template <typename Method, typename A, typename B, typename C>
+ class Dispatcher3 {
+ public:
+ Dispatcher3(Method method, const A& a, const B& b, const C& c)
+ : method_(method),
+ a_(a),
+ b_(b),
+ c_(c) {
+ }
+ void operator()(T* object, int32_t result) {
+ (object->*method_)(result, a_, b_, c_);
+ }
+ private:
+ Method method_;
+ A a_;
+ B b_;
+ C c_;
+ };
+
void InitBackPointer() {
back_pointer_ = new BackPointer(this);
back_pointer_->AddRef();