| 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 COMPONENTS_SYNC_BASE_BIND_TO_TASK_RUNNER_H_ |
| 6 #define CHROMECAST_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" | 15 #include "base/memory/scoped_vector.h" |
| 16 #include "base/task_runner.h" | 16 #include "base/task_runner.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 27 // BindToTaskRunner(my_task_runner_, base::Bind(&MyClass::MyMethod, this))); | 27 // BindToTaskRunner(my_task_runner_, base::Bind(&MyClass::MyMethod, this))); |
| 28 // | 28 // |
| 29 // Note that like base::Bind(), BindToTaskRunner() can't bind non-constant | 29 // Note that like base::Bind(), BindToTaskRunner() can't bind non-constant |
| 30 // references, and that *unlike* base::Bind(), BindToTaskRunner() makes copies | 30 // references, and that *unlike* base::Bind(), BindToTaskRunner() makes copies |
| 31 // of its arguments, and thus can't be used with arrays. Note that the callback | 31 // of its arguments, and thus can't be used with arrays. Note that the callback |
| 32 // is always posted to the target TaskRunner. | 32 // is always posted to the target TaskRunner. |
| 33 // | 33 // |
| 34 // As a convenience, you can use BindToCurrentThread() to bind to the | 34 // As a convenience, you can use BindToCurrentThread() to bind to the |
| 35 // TaskRunner for the current thread (ie, base::ThreadTaskRunnerHandle::Get()). | 35 // TaskRunner for the current thread (ie, base::ThreadTaskRunnerHandle::Get()). |
| 36 | 36 |
| 37 namespace chromecast { | 37 namespace syncer { |
| 38 namespace bind_helpers { | 38 namespace bind_helpers { |
| 39 | 39 |
| 40 template <typename T> | 40 template <typename T> |
| 41 T& TrampolineForward(T& t) { | 41 T& TrampolineForward(T& t) { |
| 42 return t; | 42 return t; |
| 43 } | 43 } |
| 44 | 44 |
| 45 template <typename T, typename R> | 45 template <typename T, typename R> |
| 46 base::internal::PassedWrapper<std::unique_ptr<T, R>> TrampolineForward( | 46 base::internal::PassedWrapper<std::unique_ptr<T, R>> TrampolineForward( |
| 47 std::unique_ptr<T, R>& p) { | 47 std::unique_ptr<T, R>& p) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 75 const base::Callback<T>& cb) { | 75 const base::Callback<T>& cb) { |
| 76 return base::Bind(&bind_helpers::BindToTaskRunnerTrampoline<T>::Run, | 76 return base::Bind(&bind_helpers::BindToTaskRunnerTrampoline<T>::Run, |
| 77 task_runner, cb); | 77 task_runner, cb); |
| 78 } | 78 } |
| 79 | 79 |
| 80 template <typename T> | 80 template <typename T> |
| 81 base::Callback<T> BindToCurrentThread(const base::Callback<T>& cb) { | 81 base::Callback<T> BindToCurrentThread(const base::Callback<T>& cb) { |
| 82 return BindToTaskRunner(base::ThreadTaskRunnerHandle::Get(), cb); | 82 return BindToTaskRunner(base::ThreadTaskRunnerHandle::Get(), cb); |
| 83 } | 83 } |
| 84 | 84 |
| 85 } // namespace chromecast | 85 } // namespace syncer |
| 86 | 86 |
| 87 #endif // CHROMECAST_BASE_BIND_TO_TASK_RUNNER_H_ | 87 #endif // COMPONENTS_SYNC_BASE_BIND_TO_TASK_RUNNER_H_ |
| OLD | NEW |