xref: /aosp_15_r20/external/cronet/base/task/task_runner.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2012 The Chromium Authors
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/task_runner.h"
6 
7 #include <utility>
8 
9 #include "base/check.h"
10 #include "base/compiler_specific.h"
11 #include "base/functional/bind.h"
12 #include "base/memory/raw_ptr.h"
13 #include "base/threading/post_task_and_reply_impl.h"
14 #include "base/time/time.h"
15 
16 namespace base {
17 
PostTask(const Location & from_here,OnceClosure task)18 bool TaskRunner::PostTask(const Location& from_here, OnceClosure task) {
19   return PostDelayedTask(from_here, std::move(task), base::TimeDelta());
20 }
21 
PostTaskAndReply(const Location & from_here,OnceClosure task,OnceClosure reply)22 bool TaskRunner::PostTaskAndReply(const Location& from_here,
23                                   OnceClosure task,
24                                   OnceClosure reply) {
25   return internal::PostTaskAndReplyImpl(
26       [this](const Location& location, OnceClosure task) {
27         return PostTask(location, std::move(task));
28       },
29       from_here, std::move(task), std::move(reply));
30 }
31 
32 TaskRunner::TaskRunner() = default;
33 
34 TaskRunner::~TaskRunner() = default;
35 
OnDestruct() const36 void TaskRunner::OnDestruct() const {
37   delete this;
38 }
39 
Destruct(const TaskRunner * task_runner)40 void TaskRunnerTraits::Destruct(const TaskRunner* task_runner) {
41   task_runner->OnDestruct();
42 }
43 
44 }  // namespace base
45