OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 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 CHROMECAST_BASE_BIND_TO_TASK_RUNNER_H_ | 5 #ifndef CHROMECAST_BASE_BIND_TO_TASK_RUNNER_H_ |
6 #define CHROMECAST_BASE_BIND_TO_TASK_RUNNER_H_ | 6 #define CHROMECAST_BASE_BIND_TO_TASK_RUNNER_H_ |
7 | 7 |
| 8 #include <memory> |
| 9 |
8 #include "base/bind.h" | 10 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
10 #include "base/callback.h" | 12 #include "base/callback.h" |
11 #include "base/location.h" | 13 #include "base/location.h" |
12 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
15 #include "base/task_runner.h" | 16 #include "base/task_runner.h" |
16 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
17 | 18 |
18 // This is a helper utility for Bind()ing callbacks to a given TaskRunner. | 19 // This is a helper utility for Bind()ing callbacks to a given TaskRunner. |
19 // The typical use is when |a| (of class |A|) wants to hand a callback such as | 20 // The typical use is when |a| (of class |A|) wants to hand a callback such as |
20 // base::Bind(&A::AMethod, a) to |b|, but needs to ensure that when |b| executes | 21 // base::Bind(&A::AMethod, a) to |b|, but needs to ensure that when |b| executes |
21 // the callback, it does so on a specific TaskRunner (for example, |a|'s current | 22 // the callback, it does so on a specific TaskRunner (for example, |a|'s current |
22 // MessageLoop). | 23 // MessageLoop). |
23 // | 24 // |
(...skipping 11 matching lines...) Expand all Loading... |
35 | 36 |
36 namespace chromecast { | 37 namespace chromecast { |
37 namespace bind_helpers { | 38 namespace bind_helpers { |
38 | 39 |
39 template <typename T> | 40 template <typename T> |
40 T& TrampolineForward(T& t) { | 41 T& TrampolineForward(T& t) { |
41 return t; | 42 return t; |
42 } | 43 } |
43 | 44 |
44 template <typename T, typename R> | 45 template <typename T, typename R> |
45 base::internal::PassedWrapper<scoped_ptr<T, R>> TrampolineForward( | 46 base::internal::PassedWrapper<std::unique_ptr<T, R>> TrampolineForward( |
46 scoped_ptr<T, R>& p) { | 47 std::unique_ptr<T, R>& p) { |
47 return base::Passed(&p); | 48 return base::Passed(&p); |
48 } | 49 } |
49 | 50 |
50 template <typename T> | 51 template <typename T> |
51 base::internal::PassedWrapper<ScopedVector<T>> TrampolineForward( | 52 base::internal::PassedWrapper<ScopedVector<T>> TrampolineForward( |
52 ScopedVector<T>& p) { | 53 ScopedVector<T>& p) { |
53 return base::Passed(&p); | 54 return base::Passed(&p); |
54 } | 55 } |
55 | 56 |
56 template <typename Sig> | 57 template <typename Sig> |
(...skipping 20 matching lines...) Expand all Loading... |
77 } | 78 } |
78 | 79 |
79 template <typename T> | 80 template <typename T> |
80 base::Callback<T> BindToCurrentThread(const base::Callback<T>& cb) { | 81 base::Callback<T> BindToCurrentThread(const base::Callback<T>& cb) { |
81 return BindToTaskRunner(base::ThreadTaskRunnerHandle::Get(), cb); | 82 return BindToTaskRunner(base::ThreadTaskRunnerHandle::Get(), cb); |
82 } | 83 } |
83 | 84 |
84 } // namespace chromecast | 85 } // namespace chromecast |
85 | 86 |
86 #endif // CHROMECAST_BASE_BIND_TO_TASK_RUNNER_H_ | 87 #endif // CHROMECAST_BASE_BIND_TO_TASK_RUNNER_H_ |
OLD | NEW |