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
7 #include <utility>
8
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:
22 explicit PostTaskAndReplyTaskRunner(TaskRunner* destination);
23
24 private:
25 bool PostTask(const Location& from_here, OnceClosure task) override;
26
27 // Non-owning.
28 TaskRunner* destination_;
29 };
30
PostTaskAndReplyTaskRunner(TaskRunner * destination)31 PostTaskAndReplyTaskRunner::PostTaskAndReplyTaskRunner(
32 TaskRunner* destination) : destination_(destination) {
33 DCHECK(destination_);
34 }
35
PostTask(const Location & from_here,OnceClosure task)36 bool PostTaskAndReplyTaskRunner::PostTask(const Location& from_here,
37 OnceClosure task) {
38 return destination_->PostTask(from_here, std::move(task));
39 }
40
41 } // namespace
42
PostTask(const Location & from_here,OnceClosure task)43 bool TaskRunner::PostTask(const Location& from_here, OnceClosure task) {
44 return PostDelayedTask(from_here, std::move(task), base::TimeDelta());
45 }
46
PostTaskAndReply(const Location & from_here,OnceClosure task,OnceClosure reply)47 bool TaskRunner::PostTaskAndReply(const Location& from_here,
48 OnceClosure task,
49 OnceClosure reply) {
50 return PostTaskAndReplyTaskRunner(this).PostTaskAndReply(
51 from_here, std::move(task), std::move(reply));
52 }
53
54 TaskRunner::TaskRunner() = default;
55
56 TaskRunner::~TaskRunner() = default;
57
OnDestruct() const58 void TaskRunner::OnDestruct() const {
59 delete this;
60 }
61
Destruct(const TaskRunner * task_runner)62 void TaskRunnerTraits::Destruct(const TaskRunner* task_runner) {
63 task_runner->OnDestruct();
64 }
65
66 } // namespace base
67