OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_BASE_BIND_TO_CURRENT_LOOP_H_ | 5 #ifndef MEDIA_BASE_BIND_TO_CURRENT_LOOP_H_ |
6 #define MEDIA_BASE_BIND_TO_CURRENT_LOOP_H_ | 6 #define MEDIA_BASE_BIND_TO_CURRENT_LOOP_H_ |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 12 #include "base/thread_task_runner_handle.h" |
12 | 13 |
13 // This is a helper utility for base::Bind()ing callbacks to the current | 14 // This is a helper utility for base::Bind()ing callbacks to the current |
14 // MessageLoop. The typical use is when |a| (of class |A|) wants to hand a | 15 // MessageLoop. The typical use is when |a| (of class |A|) wants to hand a |
15 // callback such as base::Bind(&A::AMethod, a) to |b|, but needs to ensure that | 16 // callback such as base::Bind(&A::AMethod, a) to |b|, but needs to ensure that |
16 // when |b| executes the callback, it does so on |a|'s current MessageLoop. | 17 // when |b| executes the callback, it does so on |a|'s current MessageLoop. |
17 // | 18 // |
18 // Typical usage: request to be called back on the current thread: | 19 // Typical usage: request to be called back on the current thread: |
19 // other->StartAsyncProcessAndCallMeBack( | 20 // other->StartAsyncProcessAndCallMeBack( |
20 // media::BindToCurrentLoop(base::Bind(&MyClass::MyMethod, this))); | 21 // media::BindToCurrentLoop(base::Bind(&MyClass::MyMethod, this))); |
21 // | 22 // |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 base::Bind(cb, TrampolineForward(args)...)); | 55 base::Bind(cb, TrampolineForward(args)...)); |
55 } | 56 } |
56 }; | 57 }; |
57 | 58 |
58 } // namespace internal | 59 } // namespace internal |
59 | 60 |
60 template<typename T> | 61 template<typename T> |
61 static base::Callback<T> BindToCurrentLoop( | 62 static base::Callback<T> BindToCurrentLoop( |
62 const base::Callback<T>& cb) { | 63 const base::Callback<T>& cb) { |
63 return base::Bind(&internal::TrampolineHelper<T>::Run, | 64 return base::Bind(&internal::TrampolineHelper<T>::Run, |
64 base::MessageLoopProxy::current(), cb); | 65 base::ThreadTaskRunnerHandle::Get(), cb); |
65 } | 66 } |
66 | 67 |
67 } // namespace media | 68 } // namespace media |
68 | 69 |
69 #endif // MEDIA_BASE_BIND_TO_CURRENT_LOOP_H_ | 70 #endif // MEDIA_BASE_BIND_TO_CURRENT_LOOP_H_ |
OLD | NEW |