Ignore title parameter for navigator.registerProtocolHandler
[chromium-blink-merge.git] / media / base / bind_to_current_loop.h
blob6461b1c9af9f5208f355bee96f6f7a48fe319144
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, typename R>
40 base::internal::PassedWrapper<scoped_ptr<T, R> > TrampolineForward(
41 scoped_ptr<T, R>& p) { return base::Passed(&p); }
43 template <typename T>
44 base::internal::PassedWrapper<ScopedVector<T> > TrampolineForward(
45 ScopedVector<T>& p) { return base::Passed(&p); }
47 template <typename T> struct TrampolineHelper;
49 template <>
50 struct TrampolineHelper<void()> {
51 static void Run(
52 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
53 const base::Callback<void()>& cb) {
54 task_runner->PostTask(FROM_HERE, base::Bind(cb));
59 template <typename A1>
60 struct TrampolineHelper<void(A1)> {
61 static void Run(
62 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
63 const base::Callback<void(A1)>& cb, A1 a1) {
64 task_runner->PostTask(FROM_HERE, base::Bind(cb,
65 internal::TrampolineForward(a1)));
70 template <typename A1, typename A2>
71 struct TrampolineHelper<void(A1, A2)> {
72 static void Run(
73 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
74 const base::Callback<void(A1, A2)>& cb, A1 a1, A2 a2) {
75 task_runner->PostTask(FROM_HERE, base::Bind(cb,
76 internal::TrampolineForward(a1), internal::TrampolineForward(a2)));
81 template <typename A1, typename A2, typename A3>
82 struct TrampolineHelper<void(A1, A2, A3)> {
83 static void Run(
84 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
85 const base::Callback<void(A1, A2, A3)>& cb, A1 a1, A2 a2, A3 a3) {
86 task_runner->PostTask(FROM_HERE, base::Bind(cb,
87 internal::TrampolineForward(a1), internal::TrampolineForward(a2),
88 internal::TrampolineForward(a3)));
93 template <typename A1, typename A2, typename A3, typename A4>
94 struct TrampolineHelper<void(A1, A2, A3, A4)> {
95 static void Run(
96 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
97 const base::Callback<void(A1, A2, A3, A4)>& cb, A1 a1, A2 a2, A3 a3,
98 A4 a4) {
99 task_runner->PostTask(FROM_HERE, base::Bind(cb,
100 internal::TrampolineForward(a1), internal::TrampolineForward(a2),
101 internal::TrampolineForward(a3), internal::TrampolineForward(a4)));
106 template <typename A1, typename A2, typename A3, typename A4, typename A5>
107 struct TrampolineHelper<void(A1, A2, A3, A4, A5)> {
108 static void Run(
109 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
110 const base::Callback<void(A1, A2, A3, A4, A5)>& cb, A1 a1, A2 a2, A3 a3,
111 A4 a4, A5 a5) {
112 task_runner->PostTask(FROM_HERE, base::Bind(cb,
113 internal::TrampolineForward(a1), internal::TrampolineForward(a2),
114 internal::TrampolineForward(a3), internal::TrampolineForward(a4),
115 internal::TrampolineForward(a5)));
120 template <typename A1, typename A2, typename A3, typename A4, typename A5,
121 typename A6>
122 struct TrampolineHelper<void(A1, A2, A3, A4, A5, A6)> {
123 static void Run(
124 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
125 const base::Callback<void(A1, A2, A3, A4, A5, A6)>& cb, A1 a1, A2 a2,
126 A3 a3, A4 a4, A5 a5, A6 a6) {
127 task_runner->PostTask(FROM_HERE, base::Bind(cb,
128 internal::TrampolineForward(a1), internal::TrampolineForward(a2),
129 internal::TrampolineForward(a3), internal::TrampolineForward(a4),
130 internal::TrampolineForward(a5), internal::TrampolineForward(a6)));
135 template <typename A1, typename A2, typename A3, typename A4, typename A5,
136 typename A6, typename A7>
137 struct TrampolineHelper<void(A1, A2, A3, A4, A5, A6, A7)> {
138 static void Run(
139 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
140 const base::Callback<void(A1, A2, A3, A4, A5, A6, A7)>& cb, A1 a1, A2 a2,
141 A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) {
142 task_runner->PostTask(FROM_HERE, base::Bind(cb,
143 internal::TrampolineForward(a1), internal::TrampolineForward(a2),
144 internal::TrampolineForward(a3), internal::TrampolineForward(a4),
145 internal::TrampolineForward(a5), internal::TrampolineForward(a6),
146 internal::TrampolineForward(a7)));
151 } // namespace internal
153 template<typename T>
154 static base::Callback<T> BindToCurrentLoop(
155 const base::Callback<T>& cb) {
156 return base::Bind(&internal::TrampolineHelper<T>::Run,
157 base::MessageLoopProxy::current(), cb);
160 } // namespace media
162 #endif // MEDIA_BASE_BIND_TO_CURRENT_LOOP_H_