| 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/threading/post_task_and_reply_impl.h" | 5 #include "base/threading/post_task_and_reply_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" |
| 9 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| 10 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
| 11 | 12 |
| 12 namespace base { | 13 namespace base { |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 // This relay class remembers the MessageLoop that it was created on, and | 17 // This relay class remembers the MessageLoop that it was created on, and |
| 17 // ensures that both the |task| and |reply| Closures are deleted on this same | 18 // ensures that both the |task| and |reply| Closures are deleted on this same |
| 18 // thread. Also, |task| is guaranteed to be deleted before |reply| is run or | 19 // thread. Also, |task| is guaranteed to be deleted before |reply| is run or |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 new PostTaskAndReplyRelay(from_here, task, reply); | 80 new PostTaskAndReplyRelay(from_here, task, reply); |
| 80 if (!PostTask(from_here, Bind(&PostTaskAndReplyRelay::Run, | 81 if (!PostTask(from_here, Bind(&PostTaskAndReplyRelay::Run, |
| 81 Unretained(relay)))) { | 82 Unretained(relay)))) { |
| 82 delete relay; | 83 delete relay; |
| 83 return false; | 84 return false; |
| 84 } | 85 } |
| 85 | 86 |
| 86 return true; | 87 return true; |
| 87 } | 88 } |
| 88 | 89 |
| 90 bool PostTaskAndReplyImpl::PostDelayedTaskAndReply( |
| 91 const tracked_objects::Location& from_here, |
| 92 const Closure& task, |
| 93 const Closure& reply, |
| 94 const TimeDelta& delay) { |
| 95 PostTaskAndReplyRelay* relay = |
| 96 new PostTaskAndReplyRelay(from_here, task, reply); |
| 97 if (!PostDelayedTask(from_here, Bind(&PostTaskAndReplyRelay::Run, |
| 98 Unretained(relay)), delay)) { |
| 99 delete relay; |
| 100 return false; |
| 101 } |
| 102 |
| 103 return true; |
| 104 } |
| 105 |
| 89 } // namespace internal | 106 } // namespace internal |
| 90 | 107 |
| 91 } // namespace base | 108 } // namespace base |
| OLD | NEW |