| 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 COMPONENTS_SYNC_BASE_BIND_TO_TASK_RUNNER_H_ | 5 #ifndef COMPONENTS_SYNC_BASE_BIND_TO_TASK_RUNNER_H_ |
| 6 #define COMPONENTS_SYNC_BASE_BIND_TO_TASK_RUNNER_H_ | 6 #define COMPONENTS_SYNC_BASE_BIND_TO_TASK_RUNNER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_vector.h" | |
| 16 #include "base/task_runner.h" | 15 #include "base/task_runner.h" |
| 17 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 18 | 17 |
| 19 // This is a helper utility for Bind()ing callbacks to a given TaskRunner. | 18 // This is a helper utility for Bind()ing callbacks to a given TaskRunner. |
| 20 // The typical use is when |a| (of class |A|) wants to hand a callback such as | 19 // The typical use is when |a| (of class |A|) wants to hand a callback such as |
| 21 // base::Bind(&A::AMethod, a) to |b|, but needs to ensure that when |b| executes | 20 // base::Bind(&A::AMethod, a) to |b|, but needs to ensure that when |b| executes |
| 22 // the callback, it does so on a specific TaskRunner (for example, |a|'s current | 21 // the callback, it does so on a specific TaskRunner (for example, |a|'s current |
| 23 // MessageLoop). | 22 // MessageLoop). |
| 24 // | 23 // |
| 25 // Typical usage: request to be called back on the current thread: | 24 // Typical usage: request to be called back on the current thread: |
| (...skipping 15 matching lines...) Expand all Loading... |
| 41 T& TrampolineForward(T& t) { | 40 T& TrampolineForward(T& t) { |
| 42 return t; | 41 return t; |
| 43 } | 42 } |
| 44 | 43 |
| 45 template <typename T, typename R> | 44 template <typename T, typename R> |
| 46 base::internal::PassedWrapper<std::unique_ptr<T, R>> TrampolineForward( | 45 base::internal::PassedWrapper<std::unique_ptr<T, R>> TrampolineForward( |
| 47 std::unique_ptr<T, R>& p) { | 46 std::unique_ptr<T, R>& p) { |
| 48 return base::Passed(&p); | 47 return base::Passed(&p); |
| 49 } | 48 } |
| 50 | 49 |
| 51 template <typename T> | |
| 52 base::internal::PassedWrapper<ScopedVector<T>> TrampolineForward( | |
| 53 ScopedVector<T>& p) { | |
| 54 return base::Passed(&p); | |
| 55 } | |
| 56 | |
| 57 template <typename Sig> | 50 template <typename Sig> |
| 58 struct BindToTaskRunnerTrampoline; | 51 struct BindToTaskRunnerTrampoline; |
| 59 | 52 |
| 60 template <> | 53 template <> |
| 61 struct BindToTaskRunnerTrampoline<void()> { | 54 struct BindToTaskRunnerTrampoline<void()> { |
| 62 static void Run(const scoped_refptr<base::TaskRunner>& task_runner, | 55 static void Run(const scoped_refptr<base::TaskRunner>& task_runner, |
| 63 const base::Closure& cb) { | 56 const base::Closure& cb) { |
| 64 task_runner->PostTask(FROM_HERE, cb); | 57 task_runner->PostTask(FROM_HERE, cb); |
| 65 } | 58 } |
| 66 }; | 59 }; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 86 } | 79 } |
| 87 | 80 |
| 88 template <typename T> | 81 template <typename T> |
| 89 base::Callback<T> BindToCurrentThread(const base::Callback<T>& cb) { | 82 base::Callback<T> BindToCurrentThread(const base::Callback<T>& cb) { |
| 90 return BindToTaskRunner(base::ThreadTaskRunnerHandle::Get(), cb); | 83 return BindToTaskRunner(base::ThreadTaskRunnerHandle::Get(), cb); |
| 91 } | 84 } |
| 92 | 85 |
| 93 } // namespace syncer | 86 } // namespace syncer |
| 94 | 87 |
| 95 #endif // COMPONENTS_SYNC_BASE_BIND_TO_TASK_RUNNER_H_ | 88 #endif // COMPONENTS_SYNC_BASE_BIND_TO_TASK_RUNNER_H_ |
| OLD | NEW |