| 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" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 | 50 |
| 51 template <typename T> | 51 template <typename T> |
| 52 base::internal::PassedWrapper<ScopedVector<T>> TrampolineForward( | 52 base::internal::PassedWrapper<ScopedVector<T>> TrampolineForward( |
| 53 ScopedVector<T>& p) { | 53 ScopedVector<T>& p) { |
| 54 return base::Passed(&p); | 54 return base::Passed(&p); |
| 55 } | 55 } |
| 56 | 56 |
| 57 template <typename Sig> | 57 template <typename Sig> |
| 58 struct BindToTaskRunnerTrampoline; | 58 struct BindToTaskRunnerTrampoline; |
| 59 | 59 |
| 60 template <> |
| 61 struct BindToTaskRunnerTrampoline<void()> { |
| 62 static void Run(const scoped_refptr<base::TaskRunner>& task_runner, |
| 63 const base::Closure& cb) { |
| 64 task_runner->PostTask(FROM_HERE, cb); |
| 65 } |
| 66 }; |
| 67 |
| 60 template <typename... Args> | 68 template <typename... Args> |
| 61 struct BindToTaskRunnerTrampoline<void(Args...)> { | 69 struct BindToTaskRunnerTrampoline<void(Args...)> { |
| 62 static void Run(const scoped_refptr<base::TaskRunner>& task_runner, | 70 static void Run(const scoped_refptr<base::TaskRunner>& task_runner, |
| 63 const base::Callback<void(Args...)>& cb, | 71 const base::Callback<void(Args...)>& cb, |
| 64 Args... args) { | 72 Args... args) { |
| 65 task_runner->PostTask(FROM_HERE, | 73 task_runner->PostTask(FROM_HERE, |
| 66 base::Bind(cb, TrampolineForward(args)...)); | 74 base::Bind(cb, TrampolineForward(args)...)); |
| 67 } | 75 } |
| 68 }; | 76 }; |
| 69 | 77 |
| 70 } // namespace bind_helpers | 78 } // namespace bind_helpers |
| 71 | 79 |
| 72 template <typename T> | 80 template <typename T> |
| 73 base::Callback<T> BindToTaskRunner( | 81 base::Callback<T> BindToTaskRunner( |
| 74 const scoped_refptr<base::TaskRunner>& task_runner, | 82 const scoped_refptr<base::TaskRunner>& task_runner, |
| 75 const base::Callback<T>& cb) { | 83 const base::Callback<T>& cb) { |
| 76 return base::Bind(&bind_helpers::BindToTaskRunnerTrampoline<T>::Run, | 84 return base::Bind(&bind_helpers::BindToTaskRunnerTrampoline<T>::Run, |
| 77 task_runner, cb); | 85 task_runner, cb); |
| 78 } | 86 } |
| 79 | 87 |
| 80 template <typename T> | 88 template <typename T> |
| 81 base::Callback<T> BindToCurrentThread(const base::Callback<T>& cb) { | 89 base::Callback<T> BindToCurrentThread(const base::Callback<T>& cb) { |
| 82 return BindToTaskRunner(base::ThreadTaskRunnerHandle::Get(), cb); | 90 return BindToTaskRunner(base::ThreadTaskRunnerHandle::Get(), cb); |
| 83 } | 91 } |
| 84 | 92 |
| 85 } // namespace syncer | 93 } // namespace syncer |
| 86 | 94 |
| 87 #endif // COMPONENTS_SYNC_BASE_BIND_TO_TASK_RUNNER_H_ | 95 #endif // COMPONENTS_SYNC_BASE_BIND_TO_TASK_RUNNER_H_ |
| OLD | NEW |