blob: 89d2aa80e7fbb599113e6d6efd4fe5feb9e310ae [file] [log] [blame]
wez@chromium.org6d4ad682011-05-28 04:35:11 +09001// Copyright (c) 2011 The Chromium Authors. All rights reserved.
erg@chromium.org493f5f62010-07-16 06:03:54 +09002// 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.h"
6
7Task::Task() {
8}
9
10Task::~Task() {
11}
12
13CancelableTask::CancelableTask() {
14}
15
16CancelableTask::~CancelableTask() {
17}
wez@chromium.org6d4ad682011-05-28 04:35:11 +090018
19namespace base {
20
21ScopedTaskRunner::ScopedTaskRunner(Task* task) : task_(task) {
22}
23
24ScopedTaskRunner::~ScopedTaskRunner() {
25 if (task_) {
26 task_->Run();
27 delete task_;
28 }
29}
30
31Task* ScopedTaskRunner::Release() {
32 Task* tmp = task_;
33 task_ = NULL;
34 return tmp;
35}
36
sergeyu@chromium.org17c67352011-10-05 00:28:03 +090037ScopedClosureRunner::ScopedClosureRunner(const Closure& closure)
38 : closure_(closure) {
39}
40
41ScopedClosureRunner::~ScopedClosureRunner() {
42 if (!closure_.is_null())
43 closure_.Run();
44}
45
46Closure ScopedClosureRunner::Release() {
47 Closure result = closure_;
48 closure_.Reset();
49 return result;
50}
51
ajwong@chromium.org12fa0922011-07-27 03:25:16 +090052namespace subtle {
53
54TaskClosureAdapter::TaskClosureAdapter(Task* task)
55 : task_(task),
56 should_leak_task_(&kTaskLeakingDefault) {
57}
58
59TaskClosureAdapter::TaskClosureAdapter(Task* task, bool* should_leak_task)
60 : task_(task),
61 should_leak_task_(should_leak_task) {
62}
63
64TaskClosureAdapter::~TaskClosureAdapter() {
65 if (!*should_leak_task_) {
66 delete task_;
67 }
68}
69
70void TaskClosureAdapter::Run() {
apatrick@chromium.orgcd211392011-08-09 10:44:21 +090071 task_->Run();
72 delete task_;
73 task_ = NULL;
ajwong@chromium.org12fa0922011-07-27 03:25:16 +090074}
75
76// Don't leak tasks by default.
77bool TaskClosureAdapter::kTaskLeakingDefault = false;
78
79} // namespace subtle
80
wez@chromium.org6d4ad682011-05-28 04:35:11 +090081} // namespace base