| OLD | NEW |
| 1 // This file was GENERATED by command: | 1 // This file was GENERATED by command: |
| 2 // pump.py callback_helper.h.pump | 2 // pump.py callback_helper.h.pump |
| 3 // DO NOT EDIT BY HAND!!! | 3 // DO NOT EDIT BY HAND!!! |
| 4 | 4 |
| 5 | 5 |
| 6 // Copyright 2014 The Chromium Authors. All rights reserved. | 6 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 7 // 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 |
| 8 // found in the LICENSE file. | 8 // found in the LICENSE file. |
| 9 | 9 |
| 10 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CALLBACK_HELPER_H_ | 10 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CALLBACK_HELPER_H_ |
| 11 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CALLBACK_HELPER_H_ | 11 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CALLBACK_HELPER_H_ |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/location.h" | 14 #include "base/location.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/sequenced_task_runner.h" |
| 16 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
| 17 | 18 |
| 18 // TODO(tzik): Merge this file to media/base/bind_to_current_loop.h. | 19 // TODO(tzik): Merge this file to media/base/bind_to_current_loop.h. |
| 19 | 20 |
| 20 namespace sync_file_system { | 21 namespace sync_file_system { |
| 21 namespace drive_backend { | 22 namespace drive_backend { |
| 22 | 23 |
| 23 namespace internal { | 24 namespace internal { |
| 24 | 25 |
| 25 template <typename T> | 26 template <typename T> |
| 26 typename base::enable_if< | 27 typename base::enable_if< |
| 27 base::internal::IsMoveOnlyType<T>::value, | 28 base::internal::IsMoveOnlyType<T>::value, |
| 28 base::internal::PassedWrapper<T> >::type | 29 base::internal::PassedWrapper<T> >::type |
| 29 RebindForward(T& t) { | 30 RebindForward(T& t) { |
| 30 return base::Passed(&t); | 31 return base::Passed(&t); |
| 31 } | 32 } |
| 32 | 33 |
| 33 template <typename T> | 34 template <typename T> |
| 34 typename base::enable_if< | 35 typename base::enable_if< |
| 35 !base::internal::IsMoveOnlyType<T>::value, | 36 !base::internal::IsMoveOnlyType<T>::value, |
| 36 T&>::type | 37 T&>::type |
| 37 RebindForward(T& t) { | 38 RebindForward(T& t) { |
| 38 return t; | 39 return t; |
| 39 } | 40 } |
| 40 | 41 |
| 42 template <typename T> |
| 43 class CallbackHolder { |
| 44 public: |
| 45 CallbackHolder(base::SequencedTaskRunner* task_runner, |
| 46 const tracked_objects::Location& from_here, |
| 47 const base::Callback<T>& callback) |
| 48 : task_runner_(task_runner), |
| 49 from_here_(from_here), |
| 50 callback_(new base::Callback<T>(callback)) { |
| 51 DCHECK(task_runner_); |
| 52 } |
| 53 |
| 54 ~CallbackHolder() { |
| 55 base::Callback<T>* callback = callback_.release(); |
| 56 if (!task_runner_->DeleteSoon(from_here_, callback)) |
| 57 delete callback; |
| 58 } |
| 59 |
| 60 base::SequencedTaskRunner* task_runner() const { return task_runner_; } |
| 61 const tracked_objects::Location& from_here() const { return from_here_; } |
| 62 const base::Callback<T>& callback() const { return *callback_; } |
| 63 |
| 64 private: |
| 65 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 66 const tracked_objects::Location from_here_; |
| 67 scoped_ptr<base::Callback<T> > callback_; |
| 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(CallbackHolder); |
| 70 }; |
| 71 |
| 41 template <typename> | 72 template <typename> |
| 42 struct RelayToTaskRunnerHelper; | 73 struct RelayToTaskRunnerHelper; |
| 43 | 74 |
| 44 template <> | 75 template <> |
| 45 struct RelayToTaskRunnerHelper<void()> { | 76 struct RelayToTaskRunnerHelper<void()> { |
| 46 static void Run(base::TaskRunner* task_runner, | 77 static void Run(CallbackHolder<void()>* holder) { |
| 47 const tracked_objects::Location& from_here, | 78 holder->task_runner()->PostTask( |
| 48 const base::Callback<void()>& callback) { | 79 holder->from_here(), base::Bind(holder->callback())); |
| 49 task_runner->PostTask(from_here, base::Bind(callback)); | |
| 50 } | 80 } |
| 51 }; | 81 }; |
| 52 | 82 |
| 53 template <typename A1> | 83 template <typename A1> |
| 54 struct RelayToTaskRunnerHelper<void(A1)> { | 84 struct RelayToTaskRunnerHelper<void(A1)> { |
| 55 static void Run(base::TaskRunner* task_runner, | 85 static void Run(CallbackHolder<void(A1)>* holder, A1 a1) { |
| 56 const tracked_objects::Location& from_here, | 86 holder->task_runner()->PostTask( |
| 57 const base::Callback<void(A1)>& callback, A1 a1) { | 87 holder->from_here(), base::Bind(holder->callback(), RebindForward(a1))); |
| 58 task_runner->PostTask(from_here, base::Bind(callback, RebindForward(a1))); | |
| 59 } | 88 } |
| 60 }; | 89 }; |
| 61 | 90 |
| 62 template <typename A1, typename A2> | 91 template <typename A1, typename A2> |
| 63 struct RelayToTaskRunnerHelper<void(A1, A2)> { | 92 struct RelayToTaskRunnerHelper<void(A1, A2)> { |
| 64 static void Run(base::TaskRunner* task_runner, | 93 static void Run(CallbackHolder<void(A1, A2)>* holder, A1 a1, A2 a2) { |
| 65 const tracked_objects::Location& from_here, | 94 holder->task_runner()->PostTask( |
| 66 const base::Callback<void(A1, A2)>& callback, A1 a1, A2 a2) { | 95 holder->from_here(), base::Bind(holder->callback(), RebindForward(a1), |
| 67 task_runner->PostTask(from_here, base::Bind(callback, RebindForward(a1), | 96 RebindForward(a2))); |
| 68 RebindForward(a2))); | |
| 69 } | 97 } |
| 70 }; | 98 }; |
| 71 | 99 |
| 72 template <typename A1, typename A2, typename A3> | 100 template <typename A1, typename A2, typename A3> |
| 73 struct RelayToTaskRunnerHelper<void(A1, A2, A3)> { | 101 struct RelayToTaskRunnerHelper<void(A1, A2, A3)> { |
| 74 static void Run(base::TaskRunner* task_runner, | 102 static void Run(CallbackHolder<void(A1, A2, A3)>* holder, A1 a1, A2 a2, |
| 75 const tracked_objects::Location& from_here, | 103 A3 a3) { |
| 76 const base::Callback<void(A1, A2, A3)>& callback, A1 a1, | 104 holder->task_runner()->PostTask( |
| 77 A2 a2, A3 a3) { | 105 holder->from_here(), base::Bind(holder->callback(), RebindForward(a1), |
| 78 task_runner->PostTask(from_here, base::Bind(callback, RebindForward(a1), | 106 RebindForward(a2), RebindForward(a3))); |
| 79 RebindForward(a2), RebindForward(a3))); | |
| 80 } | 107 } |
| 81 }; | 108 }; |
| 82 | 109 |
| 83 template <typename A1, typename A2, typename A3, typename A4> | 110 template <typename A1, typename A2, typename A3, typename A4> |
| 84 struct RelayToTaskRunnerHelper<void(A1, A2, A3, A4)> { | 111 struct RelayToTaskRunnerHelper<void(A1, A2, A3, A4)> { |
| 85 static void Run(base::TaskRunner* task_runner, | 112 static void Run(CallbackHolder<void(A1, A2, A3, A4)>* holder, A1 a1, A2 a2, |
| 86 const tracked_objects::Location& from_here, | 113 A3 a3, A4 a4) { |
| 87 const base::Callback<void(A1, A2, A3, A4)>& callback, A1 a1, | 114 holder->task_runner()->PostTask( |
| 88 A2 a2, A3 a3, A4 a4) { | 115 holder->from_here(), base::Bind(holder->callback(), RebindForward(a1), |
| 89 task_runner->PostTask(from_here, base::Bind(callback, RebindForward(a1), | 116 RebindForward(a2), RebindForward(a3), RebindForward(a4))); |
| 90 RebindForward(a2), RebindForward(a3), RebindForward(a4))); | |
| 91 } | 117 } |
| 92 }; | 118 }; |
| 93 | 119 |
| 94 template <typename A1, typename A2, typename A3, typename A4, typename A5> | 120 template <typename A1, typename A2, typename A3, typename A4, typename A5> |
| 95 struct RelayToTaskRunnerHelper<void(A1, A2, A3, A4, A5)> { | 121 struct RelayToTaskRunnerHelper<void(A1, A2, A3, A4, A5)> { |
| 96 static void Run(base::TaskRunner* task_runner, | 122 static void Run(CallbackHolder<void(A1, A2, A3, A4, A5)>* holder, A1 a1, |
| 97 const tracked_objects::Location& from_here, | 123 A2 a2, A3 a3, A4 a4, A5 a5) { |
| 98 const base::Callback<void(A1, A2, A3, A4, A5)>& callback, | 124 holder->task_runner()->PostTask( |
| 99 A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { | 125 holder->from_here(), base::Bind(holder->callback(), RebindForward(a1), |
| 100 task_runner->PostTask(from_here, base::Bind(callback, RebindForward(a1), | 126 RebindForward(a2), RebindForward(a3), RebindForward(a4), |
| 101 RebindForward(a2), RebindForward(a3), RebindForward(a4), | 127 RebindForward(a5))); |
| 102 RebindForward(a5))); | |
| 103 } | 128 } |
| 104 }; | 129 }; |
| 105 | 130 |
| 106 template <typename A1, typename A2, typename A3, typename A4, typename A5, | 131 template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 107 typename A6> | 132 typename A6> |
| 108 struct RelayToTaskRunnerHelper<void(A1, A2, A3, A4, A5, A6)> { | 133 struct RelayToTaskRunnerHelper<void(A1, A2, A3, A4, A5, A6)> { |
| 109 static void Run(base::TaskRunner* task_runner, | 134 static void Run(CallbackHolder<void(A1, A2, A3, A4, A5, A6)>* holder, A1 a1, |
| 110 const tracked_objects::Location& from_here, | 135 A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) { |
| 111 const base::Callback<void(A1, A2, A3, A4, A5, A6)>& callback, | 136 holder->task_runner()->PostTask( |
| 112 A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) { | 137 holder->from_here(), base::Bind(holder->callback(), RebindForward(a1), |
| 113 task_runner->PostTask(from_here, base::Bind(callback, RebindForward(a1), | 138 RebindForward(a2), RebindForward(a3), RebindForward(a4), |
| 114 RebindForward(a2), RebindForward(a3), RebindForward(a4), | 139 RebindForward(a5), RebindForward(a6))); |
| 115 RebindForward(a5), RebindForward(a6))); | |
| 116 } | 140 } |
| 117 }; | 141 }; |
| 118 | 142 |
| 119 template <typename A1, typename A2, typename A3, typename A4, typename A5, | 143 template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 120 typename A6, typename A7> | 144 typename A6, typename A7> |
| 121 struct RelayToTaskRunnerHelper<void(A1, A2, A3, A4, A5, A6, A7)> { | 145 struct RelayToTaskRunnerHelper<void(A1, A2, A3, A4, A5, A6, A7)> { |
| 122 static void Run(base::TaskRunner* task_runner, | 146 static void Run(CallbackHolder<void(A1, A2, A3, A4, A5, A6, A7)>* holder, |
| 123 const tracked_objects::Location& from_here, | 147 A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) { |
| 124 const base::Callback<void(A1, A2, A3, A4, A5, A6, | 148 holder->task_runner()->PostTask( |
| 125 A7)>& callback, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, | 149 holder->from_here(), base::Bind(holder->callback(), RebindForward(a1), |
| 126 A7 a7) { | 150 RebindForward(a2), RebindForward(a3), RebindForward(a4), |
| 127 task_runner->PostTask(from_here, base::Bind(callback, RebindForward(a1), | 151 RebindForward(a5), RebindForward(a6), RebindForward(a7))); |
| 128 RebindForward(a2), RebindForward(a3), RebindForward(a4), | |
| 129 RebindForward(a5), RebindForward(a6), RebindForward(a7))); | |
| 130 } | 152 } |
| 131 }; | 153 }; |
| 132 | 154 |
| 133 } // namespace internal | 155 } // namespace internal |
| 134 | 156 |
| 135 template <typename T> | 157 template <typename T> |
| 136 base::Callback<T> RelayCallbackToTaskRunner( | 158 base::Callback<T> RelayCallbackToTaskRunner( |
| 137 base::TaskRunner* task_runner, | 159 base::SequencedTaskRunner* task_runner, |
| 138 const tracked_objects::Location& from_here, | 160 const tracked_objects::Location& from_here, |
| 139 const base::Callback<T>& callback) { | 161 const base::Callback<T>& callback) { |
| 140 DCHECK(task_runner->RunsTasksOnCurrentThread()); | 162 DCHECK(task_runner->RunsTasksOnCurrentThread()); |
| 141 | 163 |
| 142 if (callback.is_null()) | 164 if (callback.is_null()) |
| 143 return base::Callback<T>(); | 165 return base::Callback<T>(); |
| 144 | 166 |
| 145 return base::Bind(&internal::RelayToTaskRunnerHelper<T>::Run, | 167 return base::Bind(&internal::RelayToTaskRunnerHelper<T>::Run, |
| 146 make_scoped_refptr(task_runner), from_here, | 168 base::Owned(new internal::CallbackHolder<T>( |
| 147 callback); | 169 task_runner, from_here, callback))); |
| 148 } | 170 } |
| 149 | 171 |
| 150 template <typename T> | 172 template <typename T> |
| 151 base::Callback<T> RelayCallbackToCurrentThread( | 173 base::Callback<T> RelayCallbackToCurrentThread( |
| 152 const tracked_objects::Location& from_here, | 174 const tracked_objects::Location& from_here, |
| 153 const base::Callback<T>& callback) { | 175 const base::Callback<T>& callback) { |
| 154 return RelayCallbackToTaskRunner( | 176 return RelayCallbackToTaskRunner( |
| 155 base::ThreadTaskRunnerHandle::Get(), | 177 base::ThreadTaskRunnerHandle::Get(), |
| 156 from_here, callback); | 178 from_here, callback); |
| 157 } | 179 } |
| 158 | 180 |
| 159 } // namespace drive_backend | 181 } // namespace drive_backend |
| 160 } // namespace sync_file_system | 182 } // namespace sync_file_system |
| 161 | 183 |
| 162 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CALLBACK_HELPER_H_ | 184 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CALLBACK_HELPER_H_ |
| OLD | NEW |