| 6 |
| 7 | #include <utility> |
| 8 |
| 9 | #include "base/bind.h" |
| 10 | #include "base/compiler_specific.h" |
| 11 | #include "base/logging.h" |
| 12 | #include "base/threading/post_task_and_reply_impl.h" |
| 13 |
| 14 | namespace base { |
| 15 |
| 16 | namespace { |
| 17 |
| 18 | // TODO(akalin): There's only one other implementation of |
| 19 | // PostTaskAndReplyImpl in post_task.cc. Investigate whether it'll be |
| 20 | // possible to merge the two. |
| 21 | class PostTaskAndReplyTaskRunner : public internal::PostTaskAndReplyImpl { |
| 22 | public: |
| 23 | explicit PostTaskAndReplyTaskRunner(TaskRunner* destination); |
| 24 |
| 25 | private: |
| 26 | bool PostTask(const Location& from_here, OnceClosure task) override; |
| 27 |
| 28 | // Non-owning. |
| 29 | TaskRunner* destination_; |
| 30 | }; |
| 31 |
| 32 | PostTaskAndReplyTaskRunner::PostTaskAndReplyTaskRunner( |
| 33 | TaskRunner* destination) : destination_(destination) { |
| 34 | DCHECK(destination_); |
| 35 | } |
| 36 |
| 37 | bool PostTaskAndReplyTaskRunner::PostTask(const Location& from_here, |
| 38 | OnceClosure task) { |
| 39 | return destination_->PostTask(from_here, std::move(task)); |
| 40 | } |
| 41 |
| 42 | } // namespace |
| 43 |
| 44 | bool TaskRunner::PostTask(const Location& from_here, OnceClosure task) { |
| 45 | return PostDelayedTask(from_here, std::move(task), base::TimeDelta()); |
| 46 | } |
| 47 |
| 48 | bool TaskRunner::PostTaskAndReply(const Location& from_here, |
| 49 | OnceClosure task, |
| 50 | OnceClosure reply) { |
| 51 | return PostTaskAndReplyTaskRunner(this).PostTaskAndReply( |
| 52 | from_here, std::move(task), std::move(reply)); |
| 53 | } |
| 54 |
| 55 | TaskRunner::TaskRunner() = default; |
| 56 |
| 57 | TaskRunner::~TaskRunner() = default; |
| 58 |
| 59 | void TaskRunner::OnDestruct() const { |
| 60 | delete this; |
| 61 | } |
| 62 |
| 63 | void TaskRunnerTraits::Destruct(const TaskRunner* task_runner) { |
| 64 | task_runner->OnDestruct(); |
| 65 | } |
| 66 |
| 67 | } // namespace base |
| 68 |