WebKit roll 98705:98715
[chromium-blink-merge.git] / base / task.cc
blob89d2aa80e7fbb599113e6d6efd4fe5feb9e310ae
1 // Copyright (c) 2011 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.
5 #include "base/task.h"
7 Task::Task() {
10 Task::~Task() {
13 CancelableTask::CancelableTask() {
16 CancelableTask::~CancelableTask() {
19 namespace base {
21 ScopedTaskRunner::ScopedTaskRunner(Task* task) : task_(task) {
24 ScopedTaskRunner::~ScopedTaskRunner() {
25 if (task_) {
26 task_->Run();
27 delete task_;
31 Task* ScopedTaskRunner::Release() {
32 Task* tmp = task_;
33 task_ = NULL;
34 return tmp;
37 ScopedClosureRunner::ScopedClosureRunner(const Closure& closure)
38 : closure_(closure) {
41 ScopedClosureRunner::~ScopedClosureRunner() {
42 if (!closure_.is_null())
43 closure_.Run();
46 Closure ScopedClosureRunner::Release() {
47 Closure result = closure_;
48 closure_.Reset();
49 return result;
52 namespace subtle {
54 TaskClosureAdapter::TaskClosureAdapter(Task* task)
55 : task_(task),
56 should_leak_task_(&kTaskLeakingDefault) {
59 TaskClosureAdapter::TaskClosureAdapter(Task* task, bool* should_leak_task)
60 : task_(task),
61 should_leak_task_(should_leak_task) {
64 TaskClosureAdapter::~TaskClosureAdapter() {
65 if (!*should_leak_task_) {
66 delete task_;
70 void TaskClosureAdapter::Run() {
71 task_->Run();
72 delete task_;
73 task_ = NULL;
76 // Don't leak tasks by default.
77 bool TaskClosureAdapter::kTaskLeakingDefault = false;
79 } // namespace subtle
81 } // namespace base