summaryrefslogtreecommitdiffstats
path: root/base/task.cc
blob: 89d2aa80e7fbb599113e6d6efd4fe5feb9e310ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/task.h"

Task::Task() {
}

Task::~Task() {
}

CancelableTask::CancelableTask() {
}

CancelableTask::~CancelableTask() {
}

namespace base {

ScopedTaskRunner::ScopedTaskRunner(Task* task) : task_(task) {
}

ScopedTaskRunner::~ScopedTaskRunner() {
  if (task_) {
    task_->Run();
    delete task_;
  }
}

Task* ScopedTaskRunner::Release() {
  Task* tmp = task_;
  task_ = NULL;
  return tmp;
}

ScopedClosureRunner::ScopedClosureRunner(const Closure& closure)
    : closure_(closure) {
}

ScopedClosureRunner::~ScopedClosureRunner() {
  if (!closure_.is_null())
    closure_.Run();
}

Closure ScopedClosureRunner::Release() {
  Closure result = closure_;
  closure_.Reset();
  return result;
}

namespace subtle {

TaskClosureAdapter::TaskClosureAdapter(Task* task)
    : task_(task),
      should_leak_task_(&kTaskLeakingDefault) {
}

TaskClosureAdapter::TaskClosureAdapter(Task* task, bool* should_leak_task)
    : task_(task),
      should_leak_task_(should_leak_task) {
}

TaskClosureAdapter::~TaskClosureAdapter() {
  if (!*should_leak_task_) {
    delete task_;
  }
}

void TaskClosureAdapter::Run() {
  task_->Run();
  delete task_;
  task_ = NULL;
}

// Don't leak tasks by default.
bool TaskClosureAdapter::kTaskLeakingDefault = false;

}  // namespace subtle

}  // namespace base