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

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

Issue 10855188: media::BindToLoop() is born, with example uses to slim down WebMediaPlayerProxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 8 years, 4 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
« no previous file with comments | « no previous file | media/base/bind_to_loop.h.pump » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // This file was GENERATED by command:
2 // pump.py bind_to_loop.h.pump
3 // DO NOT EDIT BY HAND!!!
4
5
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
8 // found in the LICENSE file.
9
10 #ifndef MEDIA_BASE_BIND_TO_LOOP_H_
11 #define MEDIA_BASE_BIND_TO_LOOP_H_
12
13 #include "base/bind.h"
14 #include "base/callback_internal.h" // Avoid re-inventing CallbackForward.
15 #include "base/location.h"
16 #include "base/message_loop_proxy.h"
17
18 // 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
20 // 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.
22 //
23 // Typical usage: request to be called back on the current thread:
24 // other->StartAsyncProcessAndCallMeBack(
25 // media::BindToLoop(MessageLoopProxy::current(),
26 // base::Bind(&MyClass::MyMethod, this)));
27 //
28 // Note that like base::Bind(), BindToLoop() can't bind non-constant references,
29 // and that *unlike* base::Bind(), BindToLoop() makes copies of its arguments,
30 // and thus can't be used with arrays.
31
32 namespace media {
33
34 template <typename T> struct TrampolineHelper;
35
36 template <>
37 struct TrampolineHelper<void()> {
38 static void Run(
39 const scoped_refptr<base::MessageLoopProxy>& loop,
40 const base::Callback<void()>& cb) {
41 loop->PostTask(FROM_HERE, base::Bind(cb));
42 }
43 };
44
45
46 template <typename A1>
47 struct TrampolineHelper<void(A1)> {
48 static void Run(
49 const scoped_refptr<base::MessageLoopProxy>& loop,
50 const base::Callback<void(A1)>& cb, A1 a1) {
51 loop->PostTask(FROM_HERE, base::Bind(cb,
52 base::internal::CallbackForward(a1)));
53 }
54 };
55
56
57 template <typename A1, typename A2>
58 struct TrampolineHelper<void(A1, A2)> {
59 static void Run(
60 const scoped_refptr<base::MessageLoopProxy>& loop,
61 const base::Callback<void(A1, A2)>& cb, A1 a1, A2 a2) {
62 loop->PostTask(FROM_HERE, base::Bind(cb,
63 base::internal::CallbackForward(a1),
64 base::internal::CallbackForward(a2)));
65 }
66 };
67
68
69 template <typename A1, typename A2, typename A3>
70 struct TrampolineHelper<void(A1, A2, A3)> {
71 static void Run(
72 const scoped_refptr<base::MessageLoopProxy>& loop,
73 const base::Callback<void(A1, A2, A3)>& cb, A1 a1, A2 a2, A3 a3) {
74 loop->PostTask(FROM_HERE, base::Bind(cb,
75 base::internal::CallbackForward(a1),
76 base::internal::CallbackForward(a2),
77 base::internal::CallbackForward(a3)));
78 }
79 };
80
81
82 template <typename A1, typename A2, typename A3, typename A4>
83 struct TrampolineHelper<void(A1, A2, A3, A4)> {
84 static void Run(
85 const scoped_refptr<base::MessageLoopProxy>& loop,
86 const base::Callback<void(A1, A2, A3, A4)>& cb, A1 a1, A2 a2, A3 a3,
87 A4 a4) {
88 loop->PostTask(FROM_HERE, base::Bind(cb,
89 base::internal::CallbackForward(a1),
90 base::internal::CallbackForward(a2),
91 base::internal::CallbackForward(a3),
92 base::internal::CallbackForward(a4)));
93 }
94 };
95
96
97 template <typename A1, typename A2, typename A3, typename A4, typename A5>
98 struct TrampolineHelper<void(A1, A2, A3, A4, A5)> {
99 static void Run(
100 const scoped_refptr<base::MessageLoopProxy>& loop,
101 const base::Callback<void(A1, A2, A3, A4, A5)>& cb, A1 a1, A2 a2, A3 a3,
102 A4 a4, A5 a5) {
103 loop->PostTask(FROM_HERE, base::Bind(cb,
104 base::internal::CallbackForward(a1),
105 base::internal::CallbackForward(a2),
106 base::internal::CallbackForward(a3),
107 base::internal::CallbackForward(a4),
108 base::internal::CallbackForward(a5)));
109 }
110 };
111
112
113 template <typename A1, typename A2, typename A3, typename A4, typename A5,
114 typename A6>
115 struct TrampolineHelper<void(A1, A2, A3, A4, A5, A6)> {
116 static void Run(
117 const scoped_refptr<base::MessageLoopProxy>& loop,
118 const base::Callback<void(A1, A2, A3, A4, A5, A6)>& cb, A1 a1, A2 a2,
119 A3 a3, A4 a4, A5 a5, A6 a6) {
120 loop->PostTask(FROM_HERE, base::Bind(cb,
121 base::internal::CallbackForward(a1),
122 base::internal::CallbackForward(a2),
123 base::internal::CallbackForward(a3),
124 base::internal::CallbackForward(a4),
125 base::internal::CallbackForward(a5),
126 base::internal::CallbackForward(a6)));
127 }
128 };
129
130
131 template <typename A1, typename A2, typename A3, typename A4, typename A5,
132 typename A6, typename A7>
133 struct TrampolineHelper<void(A1, A2, A3, A4, A5, A6, A7)> {
134 static void Run(
135 const scoped_refptr<base::MessageLoopProxy>& loop,
136 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) {
138 loop->PostTask(FROM_HERE, base::Bind(cb,
139 base::internal::CallbackForward(a1),
140 base::internal::CallbackForward(a2),
141 base::internal::CallbackForward(a3),
142 base::internal::CallbackForward(a4),
143 base::internal::CallbackForward(a5),
144 base::internal::CallbackForward(a6),
145 base::internal::CallbackForward(a7)));
146 }
147 };
148
149
150 template<typename T>
151 static base::Callback<T> BindToLoop(
152 const scoped_refptr<base::MessageLoopProxy>& loop,
153 const base::Callback<T>& cb) {
154 return base::Bind(&TrampolineHelper<T>::Run, loop, cb);
155 }
156
157 } // namespace media
158
159 #endif // MEDIA_BASE_BIND_TO_LOOP_H_
OLDNEW
« no previous file with comments | « no previous file | media/base/bind_to_loop.h.pump » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698