OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/task.h" | 5 #include "base/task.h" |
6 | 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/message_loop_proxy.h" |
| 9 |
7 Task::Task() { | 10 Task::Task() { |
8 } | 11 } |
9 | 12 |
10 Task::~Task() { | 13 Task::~Task() { |
11 } | 14 } |
12 | 15 |
13 CancelableTask::CancelableTask() { | 16 CancelableTask::CancelableTask() { |
14 } | 17 } |
15 | 18 |
16 CancelableTask::~CancelableTask() { | 19 CancelableTask::~CancelableTask() { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 task_->Run(); | 59 task_->Run(); |
57 delete task_; | 60 delete task_; |
58 task_ = NULL; | 61 task_ = NULL; |
59 } | 62 } |
60 | 63 |
61 // Don't leak tasks by default. | 64 // Don't leak tasks by default. |
62 bool TaskClosureAdapter::kTaskLeakingDefault = false; | 65 bool TaskClosureAdapter::kTaskLeakingDefault = false; |
63 | 66 |
64 } // namespace subtle | 67 } // namespace subtle |
65 | 68 |
| 69 namespace internal { |
| 70 |
| 71 PostTaskAndReplyRelay::PostTaskAndReplyRelay( |
| 72 const tracked_objects::Location& from_here, |
| 73 const Closure& task, |
| 74 const Closure& reply) |
| 75 : from_here_(from_here), |
| 76 origin_loop_(MessageLoopProxy::CreateForCurrentThread()) { |
| 77 task_ = task; |
| 78 reply_ = reply; |
| 79 } |
| 80 |
| 81 PostTaskAndReplyRelay::~PostTaskAndReplyRelay() { |
| 82 DCHECK(origin_loop_->BelongsToCurrentThread()); |
| 83 task_.Reset(); |
| 84 reply_.Reset(); |
| 85 } |
| 86 |
| 87 void PostTaskAndReplyRelay::Run() { |
| 88 task_.Run(); |
| 89 origin_loop_->PostTask( |
| 90 from_here_, |
| 91 Bind(&PostTaskAndReplyRelay::RunReplyAndSelfDestruct, |
| 92 base::Unretained(this))); |
| 93 } |
| 94 |
| 95 void PostTaskAndReplyRelay::RunReplyAndSelfDestruct() { |
| 96 DCHECK(origin_loop_->BelongsToCurrentThread()); |
| 97 task_.Reset(); |
| 98 |
| 99 reply_.Run(); |
| 100 |
| 101 // Cue mission impossible theme. |
| 102 delete this; |
| 103 } |
| 104 |
| 105 } // namespace internal |
| 106 |
66 } // namespace base | 107 } // namespace base |
OLD | NEW |