OLD | NEW |
| 1 // This file was GENERATED by command: |
| 2 // pump.py callback_helper.h.pump |
| 3 // DO NOT EDIT BY HAND!!! |
| 4 |
| 5 |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 6 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 7 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 8 // found in the LICENSE file. |
4 | 9 |
5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CALLBACK_HELPER_H_ | 10 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CALLBACK_HELPER_H_ |
6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CALLBACK_HELPER_H_ | 11 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CALLBACK_HELPER_H_ |
7 | 12 |
8 #include "base/bind.h" | 13 #include "base/bind.h" |
9 #include "base/location.h" | 14 #include "base/location.h" |
10 #include "base/message_loop/message_loop_proxy.h" | 15 #include "base/logging.h" |
| 16 #include "base/thread_task_runner_handle.h" |
| 17 |
| 18 // TODO(tzik): Merge this file to media/base/bind_to_current_loop.h. |
11 | 19 |
12 namespace sync_file_system { | 20 namespace sync_file_system { |
13 namespace drive_backend { | 21 namespace drive_backend { |
14 | 22 |
15 namespace internal { | 23 namespace internal { |
16 | 24 |
17 template <typename T> | 25 template <typename T> |
18 typename base::enable_if< | 26 typename base::enable_if< |
19 base::internal::IsMoveOnlyType<T>::value, | 27 base::internal::IsMoveOnlyType<T>::value, |
20 base::internal::PassedWrapper<T> >::type | 28 base::internal::PassedWrapper<T> >::type |
21 RebindForward(T& t) { | 29 RebindForward(T& t) { |
22 return base::Passed(&t); | 30 return base::Passed(&t); |
23 } | 31 } |
24 | 32 |
25 template <typename T> | 33 template <typename T> |
26 typename base::enable_if< | 34 typename base::enable_if< |
27 !base::internal::IsMoveOnlyType<T>::value, | 35 !base::internal::IsMoveOnlyType<T>::value, |
28 T&>::type | 36 T&>::type |
29 RebindForward(T& t) { | 37 RebindForward(T& t) { |
30 return t; | 38 return t; |
31 } | 39 } |
32 | 40 |
33 template <typename T> | 41 template <typename> |
34 void RelayToTaskRunner1(base::SequencedTaskRunner* task_runner, | 42 struct RelayToTaskRunnerHelper; |
35 const tracked_objects::Location& from_here, | |
36 const base::Callback<void(T)>& callback, | |
37 T arg) { | |
38 task_runner->PostTask( | |
39 from_here, base::Bind(callback, RebindForward(arg))); | |
40 } | |
41 | 43 |
42 template <typename T1, typename T2> | 44 template <> |
43 void RelayToTaskRunner2(base::SequencedTaskRunner* task_runner, | 45 struct RelayToTaskRunnerHelper<void()> { |
44 const tracked_objects::Location& from_here, | 46 static void Run(base::TaskRunner* task_runner, |
45 const base::Callback<void(T1, T2)>& callback, | 47 const tracked_objects::Location& from_here, |
46 T1 arg1, | 48 const base::Callback<void()>& callback) { |
47 T2 arg2) { | 49 task_runner->PostTask(from_here, base::Bind(callback)); |
48 task_runner->PostTask( | 50 } |
49 from_here, base::Bind(callback, | 51 }; |
50 RebindForward(arg1), | 52 |
51 RebindForward(arg2))); | 53 template <typename A1> |
52 } | 54 struct RelayToTaskRunnerHelper<void(A1)> { |
| 55 static void Run(base::TaskRunner* task_runner, |
| 56 const tracked_objects::Location& from_here, |
| 57 const base::Callback<void(A1)>& callback, A1 a1) { |
| 58 task_runner->PostTask(from_here, base::Bind(callback, RebindForward(a1))); |
| 59 } |
| 60 }; |
| 61 |
| 62 template <typename A1, typename A2> |
| 63 struct RelayToTaskRunnerHelper<void(A1, A2)> { |
| 64 static void Run(base::TaskRunner* task_runner, |
| 65 const tracked_objects::Location& from_here, |
| 66 const base::Callback<void(A1, A2)>& callback, A1 a1, A2 a2) { |
| 67 task_runner->PostTask(from_here, base::Bind(callback, RebindForward(a1), |
| 68 RebindForward(a2))); |
| 69 } |
| 70 }; |
| 71 |
| 72 template <typename A1, typename A2, typename A3> |
| 73 struct RelayToTaskRunnerHelper<void(A1, A2, A3)> { |
| 74 static void Run(base::TaskRunner* task_runner, |
| 75 const tracked_objects::Location& from_here, |
| 76 const base::Callback<void(A1, A2, A3)>& callback, A1 a1, |
| 77 A2 a2, A3 a3) { |
| 78 task_runner->PostTask(from_here, base::Bind(callback, RebindForward(a1), |
| 79 RebindForward(a2), RebindForward(a3))); |
| 80 } |
| 81 }; |
| 82 |
| 83 template <typename A1, typename A2, typename A3, typename A4> |
| 84 struct RelayToTaskRunnerHelper<void(A1, A2, A3, A4)> { |
| 85 static void Run(base::TaskRunner* task_runner, |
| 86 const tracked_objects::Location& from_here, |
| 87 const base::Callback<void(A1, A2, A3, A4)>& callback, A1 a1, |
| 88 A2 a2, A3 a3, A4 a4) { |
| 89 task_runner->PostTask(from_here, base::Bind(callback, RebindForward(a1), |
| 90 RebindForward(a2), RebindForward(a3), RebindForward(a4))); |
| 91 } |
| 92 }; |
| 93 |
| 94 template <typename A1, typename A2, typename A3, typename A4, typename A5> |
| 95 struct RelayToTaskRunnerHelper<void(A1, A2, A3, A4, A5)> { |
| 96 static void Run(base::TaskRunner* task_runner, |
| 97 const tracked_objects::Location& from_here, |
| 98 const base::Callback<void(A1, A2, A3, A4, A5)>& callback, |
| 99 A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { |
| 100 task_runner->PostTask(from_here, base::Bind(callback, RebindForward(a1), |
| 101 RebindForward(a2), RebindForward(a3), RebindForward(a4), |
| 102 RebindForward(a5))); |
| 103 } |
| 104 }; |
| 105 |
| 106 template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 107 typename A6> |
| 108 struct RelayToTaskRunnerHelper<void(A1, A2, A3, A4, A5, A6)> { |
| 109 static void Run(base::TaskRunner* task_runner, |
| 110 const tracked_objects::Location& from_here, |
| 111 const base::Callback<void(A1, A2, A3, A4, A5, A6)>& callback, |
| 112 A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) { |
| 113 task_runner->PostTask(from_here, base::Bind(callback, RebindForward(a1), |
| 114 RebindForward(a2), RebindForward(a3), RebindForward(a4), |
| 115 RebindForward(a5), RebindForward(a6))); |
| 116 } |
| 117 }; |
| 118 |
| 119 template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 120 typename A6, typename A7> |
| 121 struct RelayToTaskRunnerHelper<void(A1, A2, A3, A4, A5, A6, A7)> { |
| 122 static void Run(base::TaskRunner* task_runner, |
| 123 const tracked_objects::Location& from_here, |
| 124 const base::Callback<void(A1, A2, A3, A4, A5, A6, |
| 125 A7)>& callback, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, |
| 126 A7 a7) { |
| 127 task_runner->PostTask(from_here, base::Bind(callback, RebindForward(a1), |
| 128 RebindForward(a2), RebindForward(a3), RebindForward(a4), |
| 129 RebindForward(a5), RebindForward(a6), RebindForward(a7))); |
| 130 } |
| 131 }; |
53 | 132 |
54 } // namespace internal | 133 } // namespace internal |
55 | 134 |
56 template <typename T> | 135 template <typename T> |
57 base::Callback<void(T)> CreateRelayedCallback( | 136 base::Callback<T> RelayCallbackToTaskRunner( |
58 const base::Callback<void(T)>& callback) { | 137 base::TaskRunner* task_runner, |
59 return base::Bind(&internal::RelayToTaskRunner1<T>, | 138 const tracked_objects::Location& from_here, |
60 base::MessageLoopProxy::current(), | 139 const base::Callback<T>& callback) { |
61 FROM_HERE, | 140 DCHECK(task_runner->RunsTasksOnCurrentThread()); |
| 141 return base::Bind(&internal::RelayToTaskRunnerHelper<T>::Run, |
| 142 make_scoped_refptr(task_runner), from_here, |
62 callback); | 143 callback); |
63 } | 144 } |
64 | 145 |
65 template <typename T1, typename T2> | 146 template <typename T> |
66 base::Callback<void(T1, T2)> CreateRelayedCallback( | 147 base::Callback<T> RelayCallbackToCurrentThread( |
67 const base::Callback<void(T1, T2)>& callback) { | 148 const tracked_objects::Location& from_here, |
68 return base::Bind(&internal::RelayToTaskRunner2<T1, T2>, | 149 const base::Callback<T>& callback) { |
69 base::MessageLoopProxy::current(), | 150 return RelayCallbackToTaskRunner( |
70 FROM_HERE, | 151 base::ThreadTaskRunnerHandle::Get(), |
71 callback); | 152 from_here, callback); |
72 } | 153 } |
73 | 154 |
74 } // namespace drive_backend | 155 } // namespace drive_backend |
75 } // namespace sync_file_system | 156 } // namespace sync_file_system |
76 | 157 |
77 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CALLBACK_HELPER_H_ | 158 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CALLBACK_HELPER_H_ |
OLD | NEW |