blob: 655869d66c5f254922dae090e08bc6b28bcfd744 [file] [log] [blame]
[email protected]6b28d942012-02-15 01:43:191// 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
Patrick Monette643cdf62021-10-15 19:13:425#include "base/task/task_runner.h"
[email protected]6b28d942012-02-15 01:43:196
tzik03527512017-02-08 12:29:477#include <utility>
8
Alex Clarke2b3cba82019-05-13 07:54:449#include "base/bind.h"
Hans Wennborgc3cffa62020-04-27 10:09:1210#include "base/check.h"
[email protected]6b28d942012-02-15 01:43:1911#include "base/compiler_specific.h"
Keishi Hattori0e45c022021-11-27 09:25:5212#include "base/memory/raw_ptr.h"
[email protected]6b28d942012-02-15 01:43:1913#include "base/threading/post_task_and_reply_impl.h"
David Sanders2799ee22022-02-03 05:01:4814#include "base/time/time.h"
[email protected]6b28d942012-02-15 01:43:1915
16namespace base {
17
18namespace {
19
20// TODO(akalin): There's only one other implementation of
Gabriel Charette3e2898f2019-05-01 14:55:0121// PostTaskAndReplyImpl in post_task.cc. Investigate whether it'll be
[email protected]6b28d942012-02-15 01:43:1922// possible to merge the two.
23class PostTaskAndReplyTaskRunner : public internal::PostTaskAndReplyImpl {
24 public:
[email protected]f3c697c52013-01-15 10:52:1125 explicit PostTaskAndReplyTaskRunner(TaskRunner* destination);
[email protected]6b28d942012-02-15 01:43:1926
27 private:
Brett Wilson8e88b312017-09-12 05:22:1628 bool PostTask(const Location& from_here, OnceClosure task) override;
[email protected]6b28d942012-02-15 01:43:1929
30 // Non-owning.
Keishi Hattori0e45c022021-11-27 09:25:5231 raw_ptr<TaskRunner> destination_;
[email protected]6b28d942012-02-15 01:43:1932};
33
34PostTaskAndReplyTaskRunner::PostTaskAndReplyTaskRunner(
35 TaskRunner* destination) : destination_(destination) {
36 DCHECK(destination_);
37}
38
Brett Wilson8e88b312017-09-12 05:22:1639bool PostTaskAndReplyTaskRunner::PostTask(const Location& from_here,
40 OnceClosure task) {
tzik070c8ffb2017-03-29 05:28:1241 return destination_->PostTask(from_here, std::move(task));
[email protected]6b28d942012-02-15 01:43:1942}
43
44} // namespace
45
Brett Wilson8e88b312017-09-12 05:22:1646bool TaskRunner::PostTask(const Location& from_here, OnceClosure task) {
tzik070c8ffb2017-03-29 05:28:1247 return PostDelayedTask(from_here, std::move(task), base::TimeDelta());
[email protected]6b28d942012-02-15 01:43:1948}
49
Brett Wilson8e88b312017-09-12 05:22:1650bool TaskRunner::PostTaskAndReply(const Location& from_here,
tzik6e427842017-04-05 10:13:2151 OnceClosure task,
52 OnceClosure reply) {
[email protected]6b28d942012-02-15 01:43:1953 return PostTaskAndReplyTaskRunner(this).PostTaskAndReply(
tzik03527512017-02-08 12:29:4754 from_here, std::move(task), std::move(reply));
[email protected]6b28d942012-02-15 01:43:1955}
56
Chris Watkinsbb7211c2017-11-29 07:16:3857TaskRunner::TaskRunner() = default;
[email protected]6b28d942012-02-15 01:43:1958
Chris Watkinsbb7211c2017-11-29 07:16:3859TaskRunner::~TaskRunner() = default;
[email protected]6b28d942012-02-15 01:43:1960
61void TaskRunner::OnDestruct() const {
62 delete this;
63}
64
65void TaskRunnerTraits::Destruct(const TaskRunner* task_runner) {
66 task_runner->OnDestruct();
67}
68
69} // namespace base