OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_SHARED_IMPL_THREAD_AWARE_CALLBACK_H_ | 5 #ifndef PPAPI_SHARED_IMPL_THREAD_AWARE_CALLBACK_H_ |
6 #define PPAPI_SHARED_IMPL_THREAD_AWARE_CALLBACK_H_ | 6 #define PPAPI_SHARED_IMPL_THREAD_AWARE_CALLBACK_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 public: | 57 public: |
58 // The caller takes ownership of the returned object. | 58 // The caller takes ownership of the returned object. |
59 // NULL is returned if the current thread doesn't have an associated Pepper | 59 // NULL is returned if the current thread doesn't have an associated Pepper |
60 // message loop, or |func| is NULL. | 60 // message loop, or |func| is NULL. |
61 static ThreadAwareCallback* Create(FuncType func) { | 61 static ThreadAwareCallback* Create(FuncType func) { |
62 if (!func || !HasTargetLoop()) | 62 if (!func || !HasTargetLoop()) |
63 return NULL; | 63 return NULL; |
64 return new ThreadAwareCallback(func); | 64 return new ThreadAwareCallback(func); |
65 } | 65 } |
66 | 66 |
67 ~ThreadAwareCallback() { | 67 ~ThreadAwareCallback() {} |
68 } | |
69 | 68 |
70 void RunOnTargetThread() { | 69 void RunOnTargetThread() { InternalRunOnTargetThread(base::Bind(func_)); } |
71 InternalRunOnTargetThread(base::Bind(func_)); | |
72 } | |
73 | 70 |
74 template <class P1> | 71 template <class P1> |
75 void RunOnTargetThread(const P1& p1) { | 72 void RunOnTargetThread(const P1& p1) { |
76 InternalRunOnTargetThread(base::Bind(func_, p1)); | 73 InternalRunOnTargetThread(base::Bind(func_, p1)); |
77 } | 74 } |
78 | 75 |
79 template <class P1, class P2> | 76 template <class P1, class P2> |
80 void RunOnTargetThread(const P1& p1, const P2& p2) { | 77 void RunOnTargetThread(const P1& p1, const P2& p2) { |
81 InternalRunOnTargetThread(base::Bind(func_, p1, p2)); | 78 InternalRunOnTargetThread(base::Bind(func_, p1, p2)); |
82 } | 79 } |
(...skipping 14 matching lines...) Expand all Loading... |
97 template <class P1, class P2, class P3, class P4, class P5> | 94 template <class P1, class P2, class P3, class P4, class P5> |
98 void RunOnTargetThread(const P1& p1, | 95 void RunOnTargetThread(const P1& p1, |
99 const P2& p2, | 96 const P2& p2, |
100 const P3& p3, | 97 const P3& p3, |
101 const P4& p4, | 98 const P4& p4, |
102 const P5& p5) { | 99 const P5& p5) { |
103 InternalRunOnTargetThread(base::Bind(func_, p1, p2, p3, p4, p5)); | 100 InternalRunOnTargetThread(base::Bind(func_, p1, p2, p3, p4, p5)); |
104 } | 101 } |
105 | 102 |
106 private: | 103 private: |
107 explicit ThreadAwareCallback(FuncType func) : func_(func) { | 104 explicit ThreadAwareCallback(FuncType func) : func_(func) {} |
108 } | |
109 | 105 |
110 FuncType func_; | 106 FuncType func_; |
111 }; | 107 }; |
112 | 108 |
113 } // namespace ppapi | 109 } // namespace ppapi |
114 | 110 |
115 #endif // PPAPI_SHARED_IMPL_THREAD_AWARE_CALLBACK_H_ | 111 #endif // PPAPI_SHARED_IMPL_THREAD_AWARE_CALLBACK_H_ |
OLD | NEW |