OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // This file contains the implementation shared by | |
6 // TaskRunner::PostTaskAndReply and WorkerPool::PostTaskAndReply. | |
7 | |
8 #ifndef BASE_THREADING_POST_TASK_AND_REPLY_IMPL_H_ | 5 #ifndef BASE_THREADING_POST_TASK_AND_REPLY_IMPL_H_ |
9 #define BASE_THREADING_POST_TASK_AND_REPLY_IMPL_H_ | 6 #define BASE_THREADING_POST_TASK_AND_REPLY_IMPL_H_ |
10 | 7 |
| 8 #include "base/base_export.h" |
11 #include "base/callback_forward.h" | 9 #include "base/callback_forward.h" |
12 #include "base/location.h" | 10 #include "base/location.h" |
13 | 11 |
14 namespace base { | 12 namespace base { |
15 namespace internal { | 13 namespace internal { |
16 | 14 |
17 // Inherit from this in a class that implements PostTask appropriately | 15 using PostTaskCallback = |
18 // for sending to a destination thread. | 16 Callback<bool(const tracked_objects::Location&, const Closure& task)>; |
19 // | |
20 // Note that 'reply' will always get posted back to your current | |
21 // MessageLoop. | |
22 // | |
23 // If you're looking for a concrete implementation of | |
24 // PostTaskAndReply, you probably want base::SingleThreadTaskRunner, or you | |
25 // may want base::WorkerPool. | |
26 class PostTaskAndReplyImpl { | |
27 public: | |
28 virtual ~PostTaskAndReplyImpl() = default; | |
29 | 17 |
30 // Implementation for TaskRunner::PostTaskAndReply and | 18 // Posts |task| via |post_task_callback|. On completion, |reply| is posted to |
31 // WorkerPool::PostTaskAndReply. | 19 // the sequence or thread that called PostTaskAndReply(). Can only be called |
32 bool PostTaskAndReply(const tracked_objects::Location& from_here, | 20 // when SequencedTaskRunnerHandle::IsSet(). Both |task| and |reply| are |
33 const Closure& task, | 21 // guaranteed to be deleted on the sequence or thread from which |
34 const Closure& reply); | 22 // PostTaskAndReply() is invoked. |
35 | 23 bool BASE_EXPORT PostTaskAndReply(const tracked_objects::Location& from_here, |
36 private: | 24 const Closure& task, |
37 virtual bool PostTask(const tracked_objects::Location& from_here, | 25 const Closure& reply, |
38 const Closure& task) = 0; | 26 const PostTaskCallback& post_task_callback); |
39 }; | |
40 | 27 |
41 } // namespace internal | 28 } // namespace internal |
42 } // namespace base | 29 } // namespace base |
43 | 30 |
44 #endif // BASE_THREADING_POST_TASK_AND_REPLY_IMPL_H_ | 31 #endif // BASE_THREADING_POST_TASK_AND_REPLY_IMPL_H_ |
OLD | NEW |