Chromium Code Reviews| 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 } | |
| 84 | |
| 85 void PostTaskAndReplyRelay::Run() { | |
| 86 task_.Run(); | |
| 87 origin_loop_->PostTask( | |
| 88 from_here_, | |
| 89 Bind(&PostTaskAndReplyRelay::RunReplyAndSelfDestruct, | |
| 90 base::Unretained(this))); | |
| 91 } | |
| 92 | |
| 93 void PostTaskAndReplyRelay::RunReplyAndSelfDestruct() { | |
|
willchan no longer on Chromium
2011/08/16 02:00:12
Should |task_| be set to NULL at this point, which
awong
2011/08/16 02:12:13
I think the delete this is good enough to force th
willchan no longer on Chromium
2011/08/16 14:50:56
I won't push further, but I just wonder if there's
awong
2011/08/17 03:36:59
AH! I see what you're saying now. Yes. I can see
| |
| 94 DCHECK(origin_loop_->BelongsToCurrentThread()); | |
| 95 reply_.Run(); | |
| 96 | |
| 97 // Cue mission impossible theme. | |
| 98 delete this; | |
| 99 } | |
| 100 | |
| 101 } // namespace internal | |
| 102 | |
| 66 } // namespace base | 103 } // namespace base |
| OLD | NEW |