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

Side by Side Diff: media/base/bind_to_loop.h

Issue 11092054: Teach BindToLoop to create callbacks that accept scoped parameters. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: xhwang CR Created 8 years, 1 month 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 // This file was GENERATED by command: 1 // This file was GENERATED by command:
2 // pump.py bind_to_loop.h.pump 2 // pump.py bind_to_loop.h.pump
3 // DO NOT EDIT BY HAND!!! 3 // DO NOT EDIT BY HAND!!!
4 4
5 5
6 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 6 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
7 // Use of this source code is governed by a BSD-style license that can be 7 // Use of this source code is governed by a BSD-style license that can be
8 // found in the LICENSE file. 8 // found in the LICENSE file.
9 9
10 #ifndef MEDIA_BASE_BIND_TO_LOOP_H_ 10 #ifndef MEDIA_BASE_BIND_TO_LOOP_H_
11 #define MEDIA_BASE_BIND_TO_LOOP_H_ 11 #define MEDIA_BASE_BIND_TO_LOOP_H_
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/callback_internal.h" // Avoid re-inventing CallbackForward.
15 #include "base/location.h" 14 #include "base/location.h"
16 #include "base/message_loop_proxy.h" 15 #include "base/message_loop_proxy.h"
17 16
18 // This is a helper utility for base::Bind()ing callbacks on to particular 17 // This is a helper utility for base::Bind()ing callbacks on to particular
19 // MessageLoops. A typical use is when |a| (of class |A|) wants to hand a 18 // MessageLoops. A typical use is when |a| (of class |A|) wants to hand a
20 // callback such as base::Bind(&A::AMethod, a) to |b|, but needs to ensure that 19 // callback such as base::Bind(&A::AMethod, a) to |b|, but needs to ensure that
21 // when |b| executes the callback, it does so on a particular MessageLoop. 20 // when |b| executes the callback, it does so on a particular MessageLoop.
22 // 21 //
23 // Typical usage: request to be called back on the current thread: 22 // Typical usage: request to be called back on the current thread:
24 // other->StartAsyncProcessAndCallMeBack( 23 // other->StartAsyncProcessAndCallMeBack(
25 // media::BindToLoop(MessageLoopProxy::current(), 24 // media::BindToLoop(MessageLoopProxy::current(),
26 // base::Bind(&MyClass::MyMethod, this))); 25 // base::Bind(&MyClass::MyMethod, this)));
27 // 26 //
28 // Note that like base::Bind(), BindToLoop() can't bind non-constant references, 27 // Note that like base::Bind(), BindToLoop() can't bind non-constant references,
29 // and that *unlike* base::Bind(), BindToLoop() makes copies of its arguments, 28 // and that *unlike* base::Bind(), BindToLoop() makes copies of its arguments,
30 // and thus can't be used with arrays. 29 // and thus can't be used with arrays.
31 30
32 namespace media { 31 namespace media {
33 32
33 // Mimic base::internal::CallbackForward, replacing p.Pass() with
34 // base::Passed(&p) to account for the extra layer of indirection.
35 namespace internal {
36 template <typename T>
37 T& TrampolineForward(T& t) { return t; }
38
39 template <typename T>
40 base::internal::PassedWrapper<scoped_ptr<T> > TrampolineForward(
41 scoped_ptr<T>& p) { return base::Passed(&p); }
42
43 template <typename T>
44 base::internal::PassedWrapper<scoped_array<T> > TrampolineForward(
45 scoped_array<T>& p) { return base::Passed(&p); }
46
47 template <typename T, typename R>
48 base::internal::PassedWrapper<scoped_ptr_malloc<T, R> > TrampolineForward(
49 scoped_ptr_malloc<T, R>& p) { base::Passed(&p); }
50
51 template <typename T>
52 base::internal::PassedWrapper<ScopedVector<T> > TrampolineForward(
53 ScopedVector<T>& p) { return base::Passed(&p); }
54
34 template <typename T> struct TrampolineHelper; 55 template <typename T> struct TrampolineHelper;
35 56
36 template <> 57 template <>
37 struct TrampolineHelper<void()> { 58 struct TrampolineHelper<void()> {
38 static void Run( 59 static void Run(
39 const scoped_refptr<base::MessageLoopProxy>& loop, 60 const scoped_refptr<base::MessageLoopProxy>& loop,
40 const base::Callback<void()>& cb) { 61 const base::Callback<void()>& cb) {
41 loop->PostTask(FROM_HERE, base::Bind(cb)); 62 loop->PostTask(FROM_HERE, base::Bind(cb));
42 } 63 }
43 }; 64 };
44 65
45 66
46 template <typename A1> 67 template <typename A1>
47 struct TrampolineHelper<void(A1)> { 68 struct TrampolineHelper<void(A1)> {
48 static void Run( 69 static void Run(
49 const scoped_refptr<base::MessageLoopProxy>& loop, 70 const scoped_refptr<base::MessageLoopProxy>& loop,
50 const base::Callback<void(A1)>& cb, A1 a1) { 71 const base::Callback<void(A1)>& cb, A1 a1) {
51 loop->PostTask(FROM_HERE, base::Bind(cb, 72 loop->PostTask(FROM_HERE, base::Bind(cb, internal::TrampolineForward(a1)));
52 base::internal::CallbackForward(a1)));
53 } 73 }
54 }; 74 };
55 75
56 76
57 template <typename A1, typename A2> 77 template <typename A1, typename A2>
58 struct TrampolineHelper<void(A1, A2)> { 78 struct TrampolineHelper<void(A1, A2)> {
59 static void Run( 79 static void Run(
60 const scoped_refptr<base::MessageLoopProxy>& loop, 80 const scoped_refptr<base::MessageLoopProxy>& loop,
61 const base::Callback<void(A1, A2)>& cb, A1 a1, A2 a2) { 81 const base::Callback<void(A1, A2)>& cb, A1 a1, A2 a2) {
62 loop->PostTask(FROM_HERE, base::Bind(cb, 82 loop->PostTask(FROM_HERE, base::Bind(cb, internal::TrampolineForward(a1),
63 base::internal::CallbackForward(a1), 83 internal::TrampolineForward(a2)));
64 base::internal::CallbackForward(a2)));
65 } 84 }
66 }; 85 };
67 86
68 87
69 template <typename A1, typename A2, typename A3> 88 template <typename A1, typename A2, typename A3>
70 struct TrampolineHelper<void(A1, A2, A3)> { 89 struct TrampolineHelper<void(A1, A2, A3)> {
71 static void Run( 90 static void Run(
72 const scoped_refptr<base::MessageLoopProxy>& loop, 91 const scoped_refptr<base::MessageLoopProxy>& loop,
73 const base::Callback<void(A1, A2, A3)>& cb, A1 a1, A2 a2, A3 a3) { 92 const base::Callback<void(A1, A2, A3)>& cb, A1 a1, A2 a2, A3 a3) {
74 loop->PostTask(FROM_HERE, base::Bind(cb, 93 loop->PostTask(FROM_HERE, base::Bind(cb, internal::TrampolineForward(a1),
75 base::internal::CallbackForward(a1), 94 internal::TrampolineForward(a2), internal::TrampolineForward(a3)));
76 base::internal::CallbackForward(a2),
77 base::internal::CallbackForward(a3)));
78 } 95 }
79 }; 96 };
80 97
81 98
82 template <typename A1, typename A2, typename A3, typename A4> 99 template <typename A1, typename A2, typename A3, typename A4>
83 struct TrampolineHelper<void(A1, A2, A3, A4)> { 100 struct TrampolineHelper<void(A1, A2, A3, A4)> {
84 static void Run( 101 static void Run(
85 const scoped_refptr<base::MessageLoopProxy>& loop, 102 const scoped_refptr<base::MessageLoopProxy>& loop,
86 const base::Callback<void(A1, A2, A3, A4)>& cb, A1 a1, A2 a2, A3 a3, 103 const base::Callback<void(A1, A2, A3, A4)>& cb, A1 a1, A2 a2, A3 a3,
87 A4 a4) { 104 A4 a4) {
88 loop->PostTask(FROM_HERE, base::Bind(cb, 105 loop->PostTask(FROM_HERE, base::Bind(cb, internal::TrampolineForward(a1),
89 base::internal::CallbackForward(a1), 106 internal::TrampolineForward(a2), internal::TrampolineForward(a3),
90 base::internal::CallbackForward(a2), 107 internal::TrampolineForward(a4)));
91 base::internal::CallbackForward(a3),
92 base::internal::CallbackForward(a4)));
93 } 108 }
94 }; 109 };
95 110
96 111
97 template <typename A1, typename A2, typename A3, typename A4, typename A5> 112 template <typename A1, typename A2, typename A3, typename A4, typename A5>
98 struct TrampolineHelper<void(A1, A2, A3, A4, A5)> { 113 struct TrampolineHelper<void(A1, A2, A3, A4, A5)> {
99 static void Run( 114 static void Run(
100 const scoped_refptr<base::MessageLoopProxy>& loop, 115 const scoped_refptr<base::MessageLoopProxy>& loop,
101 const base::Callback<void(A1, A2, A3, A4, A5)>& cb, A1 a1, A2 a2, A3 a3, 116 const base::Callback<void(A1, A2, A3, A4, A5)>& cb, A1 a1, A2 a2, A3 a3,
102 A4 a4, A5 a5) { 117 A4 a4, A5 a5) {
103 loop->PostTask(FROM_HERE, base::Bind(cb, 118 loop->PostTask(FROM_HERE, base::Bind(cb, internal::TrampolineForward(a1),
104 base::internal::CallbackForward(a1), 119 internal::TrampolineForward(a2), internal::TrampolineForward(a3),
105 base::internal::CallbackForward(a2), 120 internal::TrampolineForward(a4), internal::TrampolineForward(a5)));
106 base::internal::CallbackForward(a3),
107 base::internal::CallbackForward(a4),
108 base::internal::CallbackForward(a5)));
109 } 121 }
110 }; 122 };
111 123
112 124
113 template <typename A1, typename A2, typename A3, typename A4, typename A5, 125 template <typename A1, typename A2, typename A3, typename A4, typename A5,
114 typename A6> 126 typename A6>
115 struct TrampolineHelper<void(A1, A2, A3, A4, A5, A6)> { 127 struct TrampolineHelper<void(A1, A2, A3, A4, A5, A6)> {
116 static void Run( 128 static void Run(
117 const scoped_refptr<base::MessageLoopProxy>& loop, 129 const scoped_refptr<base::MessageLoopProxy>& loop,
118 const base::Callback<void(A1, A2, A3, A4, A5, A6)>& cb, A1 a1, A2 a2, 130 const base::Callback<void(A1, A2, A3, A4, A5, A6)>& cb, A1 a1, A2 a2,
119 A3 a3, A4 a4, A5 a5, A6 a6) { 131 A3 a3, A4 a4, A5 a5, A6 a6) {
120 loop->PostTask(FROM_HERE, base::Bind(cb, 132 loop->PostTask(FROM_HERE, base::Bind(cb, internal::TrampolineForward(a1),
121 base::internal::CallbackForward(a1), 133 internal::TrampolineForward(a2), internal::TrampolineForward(a3),
122 base::internal::CallbackForward(a2), 134 internal::TrampolineForward(a4), internal::TrampolineForward(a5),
123 base::internal::CallbackForward(a3), 135 internal::TrampolineForward(a6)));
124 base::internal::CallbackForward(a4),
125 base::internal::CallbackForward(a5),
126 base::internal::CallbackForward(a6)));
127 } 136 }
128 }; 137 };
129 138
130 139
131 template <typename A1, typename A2, typename A3, typename A4, typename A5, 140 template <typename A1, typename A2, typename A3, typename A4, typename A5,
132 typename A6, typename A7> 141 typename A6, typename A7>
133 struct TrampolineHelper<void(A1, A2, A3, A4, A5, A6, A7)> { 142 struct TrampolineHelper<void(A1, A2, A3, A4, A5, A6, A7)> {
134 static void Run( 143 static void Run(
135 const scoped_refptr<base::MessageLoopProxy>& loop, 144 const scoped_refptr<base::MessageLoopProxy>& loop,
136 const base::Callback<void(A1, A2, A3, A4, A5, A6, A7)>& cb, A1 a1, A2 a2, 145 const base::Callback<void(A1, A2, A3, A4, A5, A6, A7)>& cb, A1 a1, A2 a2,
137 A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) { 146 A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) {
138 loop->PostTask(FROM_HERE, base::Bind(cb, 147 loop->PostTask(FROM_HERE, base::Bind(cb, internal::TrampolineForward(a1),
139 base::internal::CallbackForward(a1), 148 internal::TrampolineForward(a2), internal::TrampolineForward(a3),
140 base::internal::CallbackForward(a2), 149 internal::TrampolineForward(a4), internal::TrampolineForward(a5),
141 base::internal::CallbackForward(a3), 150 internal::TrampolineForward(a6), internal::TrampolineForward(a7)));
142 base::internal::CallbackForward(a4),
143 base::internal::CallbackForward(a5),
144 base::internal::CallbackForward(a6),
145 base::internal::CallbackForward(a7)));
146 } 151 }
147 }; 152 };
148 153
149 154
155 } // namespace internal
156
150 template<typename T> 157 template<typename T>
151 static base::Callback<T> BindToLoop( 158 static base::Callback<T> BindToLoop(
152 const scoped_refptr<base::MessageLoopProxy>& loop, 159 const scoped_refptr<base::MessageLoopProxy>& loop,
153 const base::Callback<T>& cb) { 160 const base::Callback<T>& cb) {
154 return base::Bind(&TrampolineHelper<T>::Run, loop, cb); 161 return base::Bind(&internal::TrampolineHelper<T>::Run, loop, cb);
155 } 162 }
156 163
157 } // namespace media 164 } // namespace media
158 165
159 #endif // MEDIA_BASE_BIND_TO_LOOP_H_ 166 #endif // MEDIA_BASE_BIND_TO_LOOP_H_
OLDNEW
« no previous file with comments | « content/common/gpu/media/vaapi_video_decode_accelerator.cc ('k') | media/base/bind_to_loop.h.pump » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698