| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/debug/leak_annotations.h" | 10 #include "base/debug/leak_annotations.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 reply_(std::move(reply)), | 37 reply_(std::move(reply)), |
| 38 task_(std::move(task)) {} | 38 task_(std::move(task)) {} |
| 39 | 39 |
| 40 ~PostTaskAndReplyRelay() { | 40 ~PostTaskAndReplyRelay() { |
| 41 DCHECK(sequence_checker_.CalledOnValidSequence()); | 41 DCHECK(sequence_checker_.CalledOnValidSequence()); |
| 42 } | 42 } |
| 43 | 43 |
| 44 void RunTaskAndPostReply() { | 44 void RunTaskAndPostReply() { |
| 45 std::move(task_).Run(); | 45 std::move(task_).Run(); |
| 46 origin_task_runner_->PostTask( | 46 origin_task_runner_->PostTask( |
| 47 from_here_, Bind(&PostTaskAndReplyRelay::RunReplyAndSelfDestruct, | 47 from_here_, BindOnce(&PostTaskAndReplyRelay::RunReplyAndSelfDestruct, |
| 48 base::Unretained(this))); | 48 base::Unretained(this))); |
| 49 } | 49 } |
| 50 | 50 |
| 51 private: | 51 private: |
| 52 void RunReplyAndSelfDestruct() { | 52 void RunReplyAndSelfDestruct() { |
| 53 DCHECK(sequence_checker_.CalledOnValidSequence()); | 53 DCHECK(sequence_checker_.CalledOnValidSequence()); |
| 54 | 54 |
| 55 // Ensure |task_| has already been released before |reply_| to ensure that | 55 // Ensure |task_| has already been released before |reply_| to ensure that |
| 56 // no one accidentally depends on |task_| keeping one of its arguments alive | 56 // no one accidentally depends on |task_| keeping one of its arguments alive |
| 57 // while |reply_| is executing. | 57 // while |reply_| is executing. |
| 58 DCHECK(!task_); | 58 DCHECK(!task_); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 81 DCHECK(!task.is_null()) << from_here.ToString(); | 81 DCHECK(!task.is_null()) << from_here.ToString(); |
| 82 DCHECK(!reply.is_null()) << from_here.ToString(); | 82 DCHECK(!reply.is_null()) << from_here.ToString(); |
| 83 PostTaskAndReplyRelay* relay = | 83 PostTaskAndReplyRelay* relay = |
| 84 new PostTaskAndReplyRelay(from_here, std::move(task), std::move(reply)); | 84 new PostTaskAndReplyRelay(from_here, std::move(task), std::move(reply)); |
| 85 // PostTaskAndReplyRelay self-destructs after executing |reply|. On the flip | 85 // PostTaskAndReplyRelay self-destructs after executing |reply|. On the flip |
| 86 // side though, it is intentionally leaked if the |task| doesn't complete | 86 // side though, it is intentionally leaked if the |task| doesn't complete |
| 87 // before the origin sequence stops executing tasks. Annotate |relay| as leaky | 87 // before the origin sequence stops executing tasks. Annotate |relay| as leaky |
| 88 // to avoid having to suppress every callsite which happens to flakily trigger | 88 // to avoid having to suppress every callsite which happens to flakily trigger |
| 89 // this race. | 89 // this race. |
| 90 ANNOTATE_LEAKING_OBJECT_PTR(relay); | 90 ANNOTATE_LEAKING_OBJECT_PTR(relay); |
| 91 if (!PostTask(from_here, Bind(&PostTaskAndReplyRelay::RunTaskAndPostReply, | 91 if (!PostTask(from_here, BindOnce(&PostTaskAndReplyRelay::RunTaskAndPostReply, |
| 92 Unretained(relay)))) { | 92 Unretained(relay)))) { |
| 93 delete relay; | 93 delete relay; |
| 94 return false; | 94 return false; |
| 95 } | 95 } |
| 96 | 96 |
| 97 return true; | 97 return true; |
| 98 } | 98 } |
| 99 | 99 |
| 100 } // namespace internal | 100 } // namespace internal |
| 101 | 101 |
| 102 } // namespace base | 102 } // namespace base |
| OLD | NEW |