blob: 262e1f8b09eac8d9f91b4113ddeccc27a33323ad [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
7#include "base/compiler_specific.h"
8#include "base/logging.h"
9#include "base/threading/post_task_and_reply_impl.h"
10
11namespace base {
12
13namespace {
14
15// TODO(akalin): There's only one other implementation of
16// PostTaskAndReplyImpl in WorkerPool. Investigate whether it'll be
17// possible to merge the two.
18class PostTaskAndReplyTaskRunner : public internal::PostTaskAndReplyImpl {
19 public:
[email protected]f3c697c52013-01-15 10:52:1120 explicit PostTaskAndReplyTaskRunner(TaskRunner* destination);
[email protected]6b28d942012-02-15 01:43:1921
22 private:
dcheng56488182014-10-21 10:54:5123 bool PostTask(const tracked_objects::Location& from_here,
24 const Closure& task) override;
[email protected]6b28d942012-02-15 01:43:1925
26 // Non-owning.
27 TaskRunner* destination_;
28};
29
30PostTaskAndReplyTaskRunner::PostTaskAndReplyTaskRunner(
31 TaskRunner* destination) : destination_(destination) {
32 DCHECK(destination_);
33}
34
35bool PostTaskAndReplyTaskRunner::PostTask(
36 const tracked_objects::Location& from_here,
37 const Closure& task) {
38 return destination_->PostTask(from_here, task);
39}
40
41} // namespace
42
43bool TaskRunner::PostTask(const tracked_objects::Location& from_here,
44 const Closure& task) {
[email protected]beea9922012-06-21 17:31:5645 return PostDelayedTask(from_here, task, base::TimeDelta());
[email protected]6b28d942012-02-15 01:43:1946}
47
48bool TaskRunner::PostTaskAndReply(
49 const tracked_objects::Location& from_here,
50 const Closure& task,
51 const Closure& reply) {
52 return PostTaskAndReplyTaskRunner(this).PostTaskAndReply(
53 from_here, task, reply);
54}
55
56TaskRunner::TaskRunner() {}
57
58TaskRunner::~TaskRunner() {}
59
60void TaskRunner::OnDestruct() const {
61 delete this;
62}
63
64void TaskRunnerTraits::Destruct(const TaskRunner* task_runner) {
65 task_runner->OnDestruct();
66}
67
68} // namespace base