[email protected] | 6b28d94 | 2012-02-15 01:43:19 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "base/task_runner.h" |
| 6 | |
tzik | 0352751 | 2017-02-08 12:29:47 | [diff] [blame] | 7 | #include <utility> |
| 8 | |
[email protected] | 6b28d94 | 2012-02-15 01:43:19 | [diff] [blame] | 9 | #include "base/compiler_specific.h" |
| 10 | #include "base/logging.h" |
| 11 | #include "base/threading/post_task_and_reply_impl.h" |
| 12 | |
| 13 | namespace base { |
| 14 | |
| 15 | namespace { |
| 16 | |
| 17 | // TODO(akalin): There's only one other implementation of |
| 18 | // PostTaskAndReplyImpl in WorkerPool. Investigate whether it'll be |
| 19 | // possible to merge the two. |
| 20 | class PostTaskAndReplyTaskRunner : public internal::PostTaskAndReplyImpl { |
| 21 | public: |
[email protected] | f3c697c5 | 2013-01-15 10:52:11 | [diff] [blame] | 22 | explicit PostTaskAndReplyTaskRunner(TaskRunner* destination); |
[email protected] | 6b28d94 | 2012-02-15 01:43:19 | [diff] [blame] | 23 | |
| 24 | private: |
Brett Wilson | 8e88b31 | 2017-09-12 05:22:16 | [diff] [blame] | 25 | bool PostTask(const Location& from_here, OnceClosure task) override; |
[email protected] | 6b28d94 | 2012-02-15 01:43:19 | [diff] [blame] | 26 | |
| 27 | // Non-owning. |
| 28 | TaskRunner* destination_; |
| 29 | }; |
| 30 | |
| 31 | PostTaskAndReplyTaskRunner::PostTaskAndReplyTaskRunner( |
| 32 | TaskRunner* destination) : destination_(destination) { |
| 33 | DCHECK(destination_); |
| 34 | } |
| 35 | |
Brett Wilson | 8e88b31 | 2017-09-12 05:22:16 | [diff] [blame] | 36 | bool PostTaskAndReplyTaskRunner::PostTask(const Location& from_here, |
| 37 | OnceClosure task) { |
tzik | 070c8ffb | 2017-03-29 05:28:12 | [diff] [blame] | 38 | return destination_->PostTask(from_here, std::move(task)); |
[email protected] | 6b28d94 | 2012-02-15 01:43:19 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | } // namespace |
| 42 | |
Brett Wilson | 8e88b31 | 2017-09-12 05:22:16 | [diff] [blame] | 43 | bool TaskRunner::PostTask(const Location& from_here, OnceClosure task) { |
tzik | 070c8ffb | 2017-03-29 05:28:12 | [diff] [blame] | 44 | return PostDelayedTask(from_here, std::move(task), base::TimeDelta()); |
[email protected] | 6b28d94 | 2012-02-15 01:43:19 | [diff] [blame] | 45 | } |
| 46 | |
Brett Wilson | 8e88b31 | 2017-09-12 05:22:16 | [diff] [blame] | 47 | bool TaskRunner::PostTaskAndReply(const Location& from_here, |
tzik | 6e42784 | 2017-04-05 10:13:21 | [diff] [blame] | 48 | OnceClosure task, |
| 49 | OnceClosure reply) { |
[email protected] | 6b28d94 | 2012-02-15 01:43:19 | [diff] [blame] | 50 | return PostTaskAndReplyTaskRunner(this).PostTaskAndReply( |
tzik | 0352751 | 2017-02-08 12:29:47 | [diff] [blame] | 51 | from_here, std::move(task), std::move(reply)); |
[email protected] | 6b28d94 | 2012-02-15 01:43:19 | [diff] [blame] | 52 | } |
| 53 | |
Chris Watkins | bb7211c | 2017-11-29 07:16:38 | [diff] [blame^] | 54 | TaskRunner::TaskRunner() = default; |
[email protected] | 6b28d94 | 2012-02-15 01:43:19 | [diff] [blame] | 55 | |
Chris Watkins | bb7211c | 2017-11-29 07:16:38 | [diff] [blame^] | 56 | TaskRunner::~TaskRunner() = default; |
[email protected] | 6b28d94 | 2012-02-15 01:43:19 | [diff] [blame] | 57 | |
| 58 | void TaskRunner::OnDestruct() const { |
| 59 | delete this; |
| 60 | } |
| 61 | |
| 62 | void TaskRunnerTraits::Destruct(const TaskRunner* task_runner) { |
| 63 | task_runner->OnDestruct(); |
| 64 | } |
| 65 | |
| 66 | } // namespace base |