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

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: Created 8 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 // 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; }
awong 2012/10/11 00:18:22 Crazy idea...can we do anything really trick with
Ami GONE FROM CHROMIUM 2012/10/11 07:20:39 Played with this for a while and failed at it (and
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 }
55
34 template <typename T> struct TrampolineHelper; 56 template <typename T> struct TrampolineHelper;
35 57
36 template <> 58 template <>
37 struct TrampolineHelper<void()> { 59 struct TrampolineHelper<void()> {
38 static void Run( 60 static void Run(
39 const scoped_refptr<base::MessageLoopProxy>& loop, 61 const scoped_refptr<base::MessageLoopProxy>& loop,
40 const base::Callback<void()>& cb) { 62 const base::Callback<void()>& cb) {
41 loop->PostTask(FROM_HERE, base::Bind(cb)); 63 loop->PostTask(FROM_HERE, base::Bind(cb));
42 } 64 }
43 }; 65 };
44 66
45 67
46 template <typename A1> 68 template <typename A1>
47 struct TrampolineHelper<void(A1)> { 69 struct TrampolineHelper<void(A1)> {
48 static void Run( 70 static void Run(
49 const scoped_refptr<base::MessageLoopProxy>& loop, 71 const scoped_refptr<base::MessageLoopProxy>& loop,
50 const base::Callback<void(A1)>& cb, A1 a1) { 72 const base::Callback<void(A1)>& cb, A1 a1) {
51 loop->PostTask(FROM_HERE, base::Bind(cb, 73 loop->PostTask(FROM_HERE, base::Bind(cb, internal::TrampolineForward(a1)));
52 base::internal::CallbackForward(a1)));
53 } 74 }
54 }; 75 };
55 76
56 77
57 template <typename A1, typename A2> 78 template <typename A1, typename A2>
58 struct TrampolineHelper<void(A1, A2)> { 79 struct TrampolineHelper<void(A1, A2)> {
59 static void Run( 80 static void Run(
60 const scoped_refptr<base::MessageLoopProxy>& loop, 81 const scoped_refptr<base::MessageLoopProxy>& loop,
61 const base::Callback<void(A1, A2)>& cb, A1 a1, A2 a2) { 82 const base::Callback<void(A1, A2)>& cb, A1 a1, A2 a2) {
62 loop->PostTask(FROM_HERE, base::Bind(cb, 83 loop->PostTask(FROM_HERE, base::Bind(cb, internal::TrampolineForward(a1),
63 base::internal::CallbackForward(a1), 84 internal::TrampolineForward(a2)));
64 base::internal::CallbackForward(a2)));
65 } 85 }
66 }; 86 };
67 87
68 88
69 template <typename A1, typename A2, typename A3> 89 template <typename A1, typename A2, typename A3>
70 struct TrampolineHelper<void(A1, A2, A3)> { 90 struct TrampolineHelper<void(A1, A2, A3)> {
71 static void Run( 91 static void Run(
72 const scoped_refptr<base::MessageLoopProxy>& loop, 92 const scoped_refptr<base::MessageLoopProxy>& loop,
73 const base::Callback<void(A1, A2, A3)>& cb, A1 a1, A2 a2, A3 a3) { 93 const base::Callback<void(A1, A2, A3)>& cb, A1 a1, A2 a2, A3 a3) {
74 loop->PostTask(FROM_HERE, base::Bind(cb, 94 loop->PostTask(FROM_HERE, base::Bind(cb, internal::TrampolineForward(a1),
75 base::internal::CallbackForward(a1), 95 internal::TrampolineForward(a2), internal::TrampolineForward(a3)));
76 base::internal::CallbackForward(a2),
77 base::internal::CallbackForward(a3)));
78 } 96 }
79 }; 97 };
80 98
81 99
82 template <typename A1, typename A2, typename A3, typename A4> 100 template <typename A1, typename A2, typename A3, typename A4>
83 struct TrampolineHelper<void(A1, A2, A3, A4)> { 101 struct TrampolineHelper<void(A1, A2, A3, A4)> {
84 static void Run( 102 static void Run(
85 const scoped_refptr<base::MessageLoopProxy>& loop, 103 const scoped_refptr<base::MessageLoopProxy>& loop,
86 const base::Callback<void(A1, A2, A3, A4)>& cb, A1 a1, A2 a2, A3 a3, 104 const base::Callback<void(A1, A2, A3, A4)>& cb, A1 a1, A2 a2, A3 a3,
87 A4 a4) { 105 A4 a4) {
88 loop->PostTask(FROM_HERE, base::Bind(cb, 106 loop->PostTask(FROM_HERE, base::Bind(cb, internal::TrampolineForward(a1),
89 base::internal::CallbackForward(a1), 107 internal::TrampolineForward(a2), internal::TrampolineForward(a3),
90 base::internal::CallbackForward(a2), 108 internal::TrampolineForward(a4)));
91 base::internal::CallbackForward(a3),
92 base::internal::CallbackForward(a4)));
93 } 109 }
94 }; 110 };
95 111
96 112
97 template <typename A1, typename A2, typename A3, typename A4, typename A5> 113 template <typename A1, typename A2, typename A3, typename A4, typename A5>
98 struct TrampolineHelper<void(A1, A2, A3, A4, A5)> { 114 struct TrampolineHelper<void(A1, A2, A3, A4, A5)> {
99 static void Run( 115 static void Run(
100 const scoped_refptr<base::MessageLoopProxy>& loop, 116 const scoped_refptr<base::MessageLoopProxy>& loop,
101 const base::Callback<void(A1, A2, A3, A4, A5)>& cb, A1 a1, A2 a2, A3 a3, 117 const base::Callback<void(A1, A2, A3, A4, A5)>& cb, A1 a1, A2 a2, A3 a3,
102 A4 a4, A5 a5) { 118 A4 a4, A5 a5) {
103 loop->PostTask(FROM_HERE, base::Bind(cb, 119 loop->PostTask(FROM_HERE, base::Bind(cb, internal::TrampolineForward(a1),
104 base::internal::CallbackForward(a1), 120 internal::TrampolineForward(a2), internal::TrampolineForward(a3),
105 base::internal::CallbackForward(a2), 121 internal::TrampolineForward(a4), internal::TrampolineForward(a5)));
106 base::internal::CallbackForward(a3),
107 base::internal::CallbackForward(a4),
108 base::internal::CallbackForward(a5)));
109 } 122 }
110 }; 123 };
111 124
112 125
113 template <typename A1, typename A2, typename A3, typename A4, typename A5, 126 template <typename A1, typename A2, typename A3, typename A4, typename A5,
114 typename A6> 127 typename A6>
115 struct TrampolineHelper<void(A1, A2, A3, A4, A5, A6)> { 128 struct TrampolineHelper<void(A1, A2, A3, A4, A5, A6)> {
116 static void Run( 129 static void Run(
117 const scoped_refptr<base::MessageLoopProxy>& loop, 130 const scoped_refptr<base::MessageLoopProxy>& loop,
118 const base::Callback<void(A1, A2, A3, A4, A5, A6)>& cb, A1 a1, A2 a2, 131 const base::Callback<void(A1, A2, A3, A4, A5, A6)>& cb, A1 a1, A2 a2,
119 A3 a3, A4 a4, A5 a5, A6 a6) { 132 A3 a3, A4 a4, A5 a5, A6 a6) {
120 loop->PostTask(FROM_HERE, base::Bind(cb, 133 loop->PostTask(FROM_HERE, base::Bind(cb, internal::TrampolineForward(a1),
121 base::internal::CallbackForward(a1), 134 internal::TrampolineForward(a2), internal::TrampolineForward(a3),
122 base::internal::CallbackForward(a2), 135 internal::TrampolineForward(a4), internal::TrampolineForward(a5),
123 base::internal::CallbackForward(a3), 136 internal::TrampolineForward(a6)));
124 base::internal::CallbackForward(a4),
125 base::internal::CallbackForward(a5),
126 base::internal::CallbackForward(a6)));
127 } 137 }
128 }; 138 };
129 139
130 140
131 template <typename A1, typename A2, typename A3, typename A4, typename A5, 141 template <typename A1, typename A2, typename A3, typename A4, typename A5,
132 typename A6, typename A7> 142 typename A6, typename A7>
133 struct TrampolineHelper<void(A1, A2, A3, A4, A5, A6, A7)> { 143 struct TrampolineHelper<void(A1, A2, A3, A4, A5, A6, A7)> {
134 static void Run( 144 static void Run(
135 const scoped_refptr<base::MessageLoopProxy>& loop, 145 const scoped_refptr<base::MessageLoopProxy>& loop,
136 const base::Callback<void(A1, A2, A3, A4, A5, A6, A7)>& cb, A1 a1, A2 a2, 146 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) { 147 A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) {
138 loop->PostTask(FROM_HERE, base::Bind(cb, 148 loop->PostTask(FROM_HERE, base::Bind(cb, internal::TrampolineForward(a1),
139 base::internal::CallbackForward(a1), 149 internal::TrampolineForward(a2), internal::TrampolineForward(a3),
140 base::internal::CallbackForward(a2), 150 internal::TrampolineForward(a4), internal::TrampolineForward(a5),
141 base::internal::CallbackForward(a3), 151 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 } 152 }
147 }; 153 };
148 154
149 155
150 template<typename T> 156 template<typename T>
151 static base::Callback<T> BindToLoop( 157 static base::Callback<T> BindToLoop(
152 const scoped_refptr<base::MessageLoopProxy>& loop, 158 const scoped_refptr<base::MessageLoopProxy>& loop,
153 const base::Callback<T>& cb) { 159 const base::Callback<T>& cb) {
154 return base::Bind(&TrampolineHelper<T>::Run, loop, cb); 160 return base::Bind(&TrampolineHelper<T>::Run, loop, cb);
155 } 161 }
156 162
157 } // namespace media 163 } // namespace media
158 164
159 #endif // MEDIA_BASE_BIND_TO_LOOP_H_ 165 #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