| OLD | NEW |
| 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/location.h" | 14 #include "base/location.h" |
| 15 #include "base/message_loop/message_loop_proxy.h" | 15 #include "base/message_loop/message_loop_proxy.h" |
| 16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 | 17 |
| 18 // This is a helper utility for base::Bind()ing callbacks on to particular | 18 // This is a helper utility for base::Bind()ing callbacks to the current |
| 19 // MessageLoops. A typical use is when |a| (of class |A|) wants to hand a | 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 | 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. | 21 // when |b| executes the callback, it does so on |a|'s current MessageLoop. |
| 22 // | 22 // |
| 23 // Typical usage: request to be called back on the current thread: | 23 // Typical usage: request to be called back on the current thread: |
| 24 // other->StartAsyncProcessAndCallMeBack( | 24 // other->StartAsyncProcessAndCallMeBack( |
| 25 // media::BindToLoop(MessageLoopProxy::current(), | 25 // media::BindToCurrentLoop(base::Bind(&MyClass::MyMethod, this))); |
| 26 // 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(), BindToCurrentLoop() can't bind non-constant |
| 29 // and that *unlike* base::Bind(), BindToLoop() makes copies of its arguments, | 28 // references, and that *unlike* base::Bind(), BindToCurrentLoop() makes copies |
| 30 // and thus can't be used with arrays. | 29 // of its arguments, and thus can't be used with arrays. |
| 31 | 30 |
| 32 namespace media { | 31 namespace media { |
| 33 | 32 |
| 34 // Mimic base::internal::CallbackForward, replacing p.Pass() with | 33 // Mimic base::internal::CallbackForward, replacing p.Pass() with |
| 35 // base::Passed(&p) to account for the extra layer of indirection. | 34 // base::Passed(&p) to account for the extra layer of indirection. |
| 36 namespace internal { | 35 namespace internal { |
| 37 template <typename T> | 36 template <typename T> |
| 38 T& TrampolineForward(T& t) { return t; } | 37 T& TrampolineForward(T& t) { return t; } |
| 39 | 38 |
| 40 template <typename T> | 39 template <typename T> |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 internal::TrampolineForward(a1), internal::TrampolineForward(a2), | 147 internal::TrampolineForward(a1), internal::TrampolineForward(a2), |
| 149 internal::TrampolineForward(a3), internal::TrampolineForward(a4), | 148 internal::TrampolineForward(a3), internal::TrampolineForward(a4), |
| 150 internal::TrampolineForward(a5), internal::TrampolineForward(a6), | 149 internal::TrampolineForward(a5), internal::TrampolineForward(a6), |
| 151 internal::TrampolineForward(a7))); | 150 internal::TrampolineForward(a7))); |
| 152 } | 151 } |
| 153 }; | 152 }; |
| 154 | 153 |
| 155 | 154 |
| 156 } // namespace internal | 155 } // namespace internal |
| 157 | 156 |
| 158 template<typename T> | 157 // TODO(scherkus): Rename me to something that emphasizes the asynchrony |
| 159 static base::Callback<T> BindToLoop( | 158 // http://crbug.com/167240 |
| 160 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | |
| 161 const base::Callback<T>& cb) { | |
| 162 return base::Bind(&internal::TrampolineHelper<T>::Run, task_runner, cb); | |
| 163 } | |
| 164 | |
| 165 template<typename T> | 159 template<typename T> |
| 166 static base::Callback<T> BindToCurrentLoop( | 160 static base::Callback<T> BindToCurrentLoop( |
| 167 const base::Callback<T>& cb) { | 161 const base::Callback<T>& cb) { |
| 168 return BindToLoop(base::MessageLoopProxy::current(), cb); | 162 return base::Bind(&internal::TrampolineHelper<T>::Run, |
| 163 base::MessageLoopProxy::current(), cb); |
| 169 } | 164 } |
| 170 | 165 |
| 171 } // namespace media | 166 } // namespace media |
| 172 | 167 |
| 173 #endif // MEDIA_BASE_BIND_TO_LOOP_H_ | 168 #endif // MEDIA_BASE_BIND_TO_LOOP_H_ |
| OLD | NEW |