Add explicit |forceOnlineSignin| to user pod status
[chromium-blink-merge.git] / media / base / bind_to_current_loop.h
blob927850c8aaae4d6de453d3d49b97dd4cd316001b
1 // This file was GENERATED by command:
2 // pump.py bind_to_current_loop.h.pump
3 // DO NOT EDIT BY HAND!!!
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.
10 #ifndef MEDIA_BASE_BIND_TO_CURRENT_LOOP_H_
11 #define MEDIA_BASE_BIND_TO_CURRENT_LOOP_H_
13 #include "base/bind.h"
14 #include "base/location.h"
15 #include "base/message_loop/message_loop_proxy.h"
16 #include "base/single_thread_task_runner.h"
18 // This is a helper utility for base::Bind()ing callbacks to the current
19 // MessageLoop. The 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|'s current MessageLoop.
23 // Typical usage: request to be called back on the current thread:
24 // other->StartAsyncProcessAndCallMeBack(
25 // media::BindToCurrentLoop(base::Bind(&MyClass::MyMethod, this)));
27 // Note that like base::Bind(), BindToCurrentLoop() can't bind non-constant
28 // references, and that *unlike* base::Bind(), BindToCurrentLoop() makes copies
29 // of its arguments, and thus can't be used with arrays.
31 namespace media {
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; }
39 template <typename T>
40 base::internal::PassedWrapper<scoped_ptr<T> > TrampolineForward(
41 scoped_ptr<T>& p) { return base::Passed(&p); }
43 template <typename T, typename R>
44 base::internal::PassedWrapper<scoped_ptr_malloc<T, R> > TrampolineForward(
45 scoped_ptr_malloc<T, R>& p) { return base::Passed(&p); }
47 template <typename T>
48 base::internal::PassedWrapper<ScopedVector<T> > TrampolineForward(
49 ScopedVector<T>& p) { return base::Passed(&p); }
51 template <typename T> struct TrampolineHelper;
53 template <>
54 struct TrampolineHelper<void()> {
55 static void Run(
56 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
57 const base::Callback<void()>& cb) {
58 task_runner->PostTask(FROM_HERE, base::Bind(cb));
63 template <typename A1>
64 struct TrampolineHelper<void(A1)> {
65 static void Run(
66 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
67 const base::Callback<void(A1)>& cb, A1 a1) {
68 task_runner->PostTask(FROM_HERE, base::Bind(cb,
69 internal::TrampolineForward(a1)));
74 template <typename A1, typename A2>
75 struct TrampolineHelper<void(A1, A2)> {
76 static void Run(
77 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
78 const base::Callback<void(A1, A2)>& cb, A1 a1, A2 a2) {
79 task_runner->PostTask(FROM_HERE, base::Bind(cb,
80 internal::TrampolineForward(a1), internal::TrampolineForward(a2)));
85 template <typename A1, typename A2, typename A3>
86 struct TrampolineHelper<void(A1, A2, A3)> {
87 static void Run(
88 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
89 const base::Callback<void(A1, A2, A3)>& cb, A1 a1, A2 a2, A3 a3) {
90 task_runner->PostTask(FROM_HERE, base::Bind(cb,
91 internal::TrampolineForward(a1), internal::TrampolineForward(a2),
92 internal::TrampolineForward(a3)));
97 template <typename A1, typename A2, typename A3, typename A4>
98 struct TrampolineHelper<void(A1, A2, A3, A4)> {
99 static void Run(
100 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
101 const base::Callback<void(A1, A2, A3, A4)>& cb, A1 a1, A2 a2, A3 a3,
102 A4 a4) {
103 task_runner->PostTask(FROM_HERE, base::Bind(cb,
104 internal::TrampolineForward(a1), internal::TrampolineForward(a2),
105 internal::TrampolineForward(a3), internal::TrampolineForward(a4)));
110 template <typename A1, typename A2, typename A3, typename A4, typename A5>
111 struct TrampolineHelper<void(A1, A2, A3, A4, A5)> {
112 static void Run(
113 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
114 const base::Callback<void(A1, A2, A3, A4, A5)>& cb, A1 a1, A2 a2, A3 a3,
115 A4 a4, A5 a5) {
116 task_runner->PostTask(FROM_HERE, base::Bind(cb,
117 internal::TrampolineForward(a1), internal::TrampolineForward(a2),
118 internal::TrampolineForward(a3), internal::TrampolineForward(a4),
119 internal::TrampolineForward(a5)));
124 template <typename A1, typename A2, typename A3, typename A4, typename A5,
125 typename A6>
126 struct TrampolineHelper<void(A1, A2, A3, A4, A5, A6)> {
127 static void Run(
128 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
129 const base::Callback<void(A1, A2, A3, A4, A5, A6)>& cb, A1 a1, A2 a2,
130 A3 a3, A4 a4, A5 a5, A6 a6) {
131 task_runner->PostTask(FROM_HERE, base::Bind(cb,
132 internal::TrampolineForward(a1), internal::TrampolineForward(a2),
133 internal::TrampolineForward(a3), internal::TrampolineForward(a4),
134 internal::TrampolineForward(a5), internal::TrampolineForward(a6)));
139 template <typename A1, typename A2, typename A3, typename A4, typename A5,
140 typename A6, typename A7>
141 struct TrampolineHelper<void(A1, A2, A3, A4, A5, A6, A7)> {
142 static void Run(
143 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
144 const base::Callback<void(A1, A2, A3, A4, A5, A6, A7)>& cb, A1 a1, A2 a2,
145 A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) {
146 task_runner->PostTask(FROM_HERE, base::Bind(cb,
147 internal::TrampolineForward(a1), internal::TrampolineForward(a2),
148 internal::TrampolineForward(a3), internal::TrampolineForward(a4),
149 internal::TrampolineForward(a5), internal::TrampolineForward(a6),
150 internal::TrampolineForward(a7)));
155 } // namespace internal
157 template<typename T>
158 static base::Callback<T> BindToCurrentLoop(
159 const base::Callback<T>& cb) {
160 return base::Bind(&internal::TrampolineHelper<T>::Run,
161 base::MessageLoopProxy::current(), cb);
164 } // namespace media
166 #endif // MEDIA_BASE_BIND_TO_CURRENT_LOOP_H_