blob: aae9f9ec4f3bb763856a4330833f2c09e077f68c [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
5#include "base/task_runner.h"
6
tzik03527512017-02-08 12:29:477#include <utility>
8
[email protected]6b28d942012-02-15 01:43:199#include "base/compiler_specific.h"
10#include "base/logging.h"
11#include "base/threading/post_task_and_reply_impl.h"
12
13namespace base {
14
15namespace {
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.
20class PostTaskAndReplyTaskRunner : public internal::PostTaskAndReplyImpl {
21 public:
[email protected]f3c697c52013-01-15 10:52:1122 explicit PostTaskAndReplyTaskRunner(TaskRunner* destination);
[email protected]6b28d942012-02-15 01:43:1923
24 private:
Brett Wilson8e88b312017-09-12 05:22:1625 bool PostTask(const Location& from_here, OnceClosure task) override;
[email protected]6b28d942012-02-15 01:43:1926
27 // Non-owning.
28 TaskRunner* destination_;
29};
30
31PostTaskAndReplyTaskRunner::PostTaskAndReplyTaskRunner(
32 TaskRunner* destination) : destination_(destination) {
33 DCHECK(destination_);
34}
35
Brett Wilson8e88b312017-09-12 05:22:1636bool PostTaskAndReplyTaskRunner::PostTask(const Location& from_here,
37 OnceClosure task) {
tzik070c8ffb2017-03-29 05:28:1238 return destination_->PostTask(from_here, std::move(task));
[email protected]6b28d942012-02-15 01:43:1939}
40
41} // namespace
42
Brett Wilson8e88b312017-09-12 05:22:1643bool TaskRunner::PostTask(const Location& from_here, OnceClosure task) {
tzik070c8ffb2017-03-29 05:28:1244 return PostDelayedTask(from_here, std::move(task), base::TimeDelta());
[email protected]6b28d942012-02-15 01:43:1945}
46
Brett Wilson8e88b312017-09-12 05:22:1647bool TaskRunner::PostTaskAndReply(const Location& from_here,
tzik6e427842017-04-05 10:13:2148 OnceClosure task,
49 OnceClosure reply) {
[email protected]6b28d942012-02-15 01:43:1950 return PostTaskAndReplyTaskRunner(this).PostTaskAndReply(
tzik03527512017-02-08 12:29:4751 from_here, std::move(task), std::move(reply));
[email protected]6b28d942012-02-15 01:43:1952}
53
Chris Watkinsbb7211c2017-11-29 07:16:3854TaskRunner::TaskRunner() = default;
[email protected]6b28d942012-02-15 01:43:1955
Chris Watkinsbb7211c2017-11-29 07:16:3856TaskRunner::~TaskRunner() = default;
[email protected]6b28d942012-02-15 01:43:1957
58void TaskRunner::OnDestruct() const {
59 delete this;
60}
61
62void TaskRunnerTraits::Destruct(const TaskRunner* task_runner) {
63 task_runner->OnDestruct();
64}
65
66} // namespace base