OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 BASE_TASK_RUNNER_UTIL_H_ | 5 #ifndef BASE_TASK_RUNNER_UTIL_H_ |
6 #define BASE_TASK_RUNNER_UTIL_H_ | 6 #define BASE_TASK_RUNNER_UTIL_H_ |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 // and want to call them in a PostTaskAndReply kind of fashion where the | 21 // and want to call them in a PostTaskAndReply kind of fashion where the |
22 // result of DoWorkAndReturn is passed to the Callback, you can use | 22 // result of DoWorkAndReturn is passed to the Callback, you can use |
23 // PostTaskAndReplyWithResult as in this example: | 23 // PostTaskAndReplyWithResult as in this example: |
24 // | 24 // |
25 // PostTaskAndReplyWithResult( | 25 // PostTaskAndReplyWithResult( |
26 // target_thread_.task_runner(), | 26 // target_thread_.task_runner(), |
27 // FROM_HERE, | 27 // FROM_HERE, |
28 // Bind(&DoWorkAndReturn), | 28 // Bind(&DoWorkAndReturn), |
29 // Bind(&Callback)); | 29 // Bind(&Callback)); |
30 template <typename TaskReturnType, typename ReplyArgType> | 30 template <typename TaskReturnType, typename ReplyArgType> |
31 bool PostTaskAndReplyWithResult( | 31 bool PostTaskAndReplyWithResult(TaskRunner* task_runner, |
32 TaskRunner* task_runner, | 32 const tracked_objects::Location& from_here, |
33 const tracked_objects::Location& from_here, | 33 Callback<TaskReturnType()> task, |
34 const Callback<TaskReturnType(void)>& task, | 34 Callback<void(ReplyArgType)> reply) { |
35 const Callback<void(ReplyArgType)>& reply) { | |
36 DCHECK(task); | 35 DCHECK(task); |
37 DCHECK(reply); | 36 DCHECK(reply); |
38 TaskReturnType* result = new TaskReturnType(); | 37 TaskReturnType* result = new TaskReturnType(); |
39 return task_runner->PostTaskAndReply( | 38 return task_runner->PostTaskAndReply( |
40 from_here, | 39 from_here, base::Bind(&internal::ReturnAsParamAdapter<TaskReturnType>, |
41 base::Bind(&internal::ReturnAsParamAdapter<TaskReturnType>, task, | 40 std::move(task), result), |
42 result), | 41 base::Bind(&internal::ReplyAdapter<TaskReturnType, ReplyArgType>, |
43 base::Bind(&internal::ReplyAdapter<TaskReturnType, ReplyArgType>, reply, | 42 std::move(reply), base::Owned(result))); |
44 base::Owned(result))); | |
45 } | 43 } |
46 | 44 |
47 } // namespace base | 45 } // namespace base |
48 | 46 |
49 #endif // BASE_TASK_RUNNER_UTIL_H_ | 47 #endif // BASE_TASK_RUNNER_UTIL_H_ |
OLD | NEW |