Index: base/threading/post_task_and_reply_impl.cc |
diff --git a/base/threading/post_task_and_reply_impl.cc b/base/threading/post_task_and_reply_impl.cc |
index c906866cfb8e61143279a833ed4f5ea04971fb07..280b78638516d8de188b67cf15694b71483772d4 100644 |
--- a/base/threading/post_task_and_reply_impl.cc |
+++ b/base/threading/post_task_and_reply_impl.cc |
@@ -5,41 +5,43 @@ |
#include "base/threading/post_task_and_reply_impl.h" |
#include "base/bind.h" |
-#include "base/location.h" |
-#include "base/single_thread_task_runner.h" |
-#include "base/threading/thread_task_runner_handle.h" |
+#include "base/bind_helpers.h" |
gab
2016/07/25 17:57:44
Ditto
fdoray
2016/07/25 20:40:04
Done.
|
+#include "base/callback.h" |
+#include "base/logging.h" |
+#include "base/memory/ref_counted.h" |
+#include "base/sequence_checker.h" |
+#include "base/sequenced_task_runner.h" |
+#include "base/threading/sequenced_task_runner_handle.h" |
namespace base { |
namespace { |
-// This relay class remembers the MessageLoop that it was created on, and |
-// ensures that both the |task| and |reply| Closures are deleted on this same |
-// thread. Also, |task| is guaranteed to be deleted before |reply| is run or |
-// deleted. |
+// This relay class remembers the sequence it was created on and ensures that |
+// both the |task| and |reply| Closures are deleted on this same sequence. Also, |
+// |task| is guaranteed to be deleted before |reply| is run or deleted. |
// |
-// If this is not possible because the originating MessageLoop is no longer |
-// available, the the |task| and |reply| Closures are leaked. Leaking is |
+// If |reply| doesn't run because the originating execution context is no longer |
+// available, then the |task| and |reply| Closures are leaked. Leaking is |
// considered preferable to having a thread-safetey violations caused by |
-// invoking the Closure destructor on the wrong thread. |
+// invoking the Closure destructor on the wrong sequence. |
class PostTaskAndReplyRelay { |
public: |
PostTaskAndReplyRelay(const tracked_objects::Location& from_here, |
const Closure& task, |
const Closure& reply) |
: from_here_(from_here), |
- origin_task_runner_(ThreadTaskRunnerHandle::Get()) { |
- task_ = task; |
- reply_ = reply; |
- } |
+ origin_task_runner_(SequencedTaskRunnerHandle::Get()), |
+ reply_(reply), |
+ task_(task) {} |
~PostTaskAndReplyRelay() { |
- DCHECK(origin_task_runner_->BelongsToCurrentThread()); |
+ DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
task_.Reset(); |
reply_.Reset(); |
} |
- void Run() { |
+ void RunTaskAndPostReply() { |
task_.Run(); |
origin_task_runner_->PostTask( |
from_here_, Bind(&PostTaskAndReplyRelay::RunReplyAndSelfDestruct, |
@@ -48,7 +50,7 @@ class PostTaskAndReplyRelay { |
private: |
void RunReplyAndSelfDestruct() { |
- DCHECK(origin_task_runner_->BelongsToCurrentThread()); |
+ DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
// Force |task_| to be released before |reply_| is to ensure that no one |
// accidentally depends on |task_| keeping one of its arguments alive while |
@@ -57,12 +59,12 @@ class PostTaskAndReplyRelay { |
reply_.Run(); |
- // Cue mission impossible theme. |
gab
2016/07/25 17:57:44
Aaahhh... this has been my favorite comment in Chr
|
delete this; |
} |
- tracked_objects::Location from_here_; |
- scoped_refptr<SingleThreadTaskRunner> origin_task_runner_; |
+ SequenceChecker sequence_checker_; |
gab
2016/07/25 17:57:44
const (never detached)
fdoray
2016/07/25 20:40:04
Done.
|
+ const tracked_objects::Location from_here_; |
+ const scoped_refptr<SequencedTaskRunner> origin_task_runner_; |
Closure reply_; |
Closure task_; |
}; |
@@ -71,17 +73,18 @@ class PostTaskAndReplyRelay { |
namespace internal { |
-bool PostTaskAndReplyImpl::PostTaskAndReply( |
- const tracked_objects::Location& from_here, |
- const Closure& task, |
- const Closure& reply) { |
- // TODO(tzik): Use DCHECK here once the crash is gone. http://crbug.com/541319 |
- CHECK(!task.is_null()) << from_here.ToString(); |
- CHECK(!reply.is_null()) << from_here.ToString(); |
+bool PostTaskAndReply(const tracked_objects::Location& from_here, |
+ const Closure& task, |
+ const Closure& reply, |
+ const PostTaskCallback& post_task_callback) { |
+ DCHECK(!task.is_null()) << from_here.ToString(); |
+ DCHECK(!reply.is_null()) << from_here.ToString(); |
+ |
PostTaskAndReplyRelay* relay = |
new PostTaskAndReplyRelay(from_here, task, reply); |
- if (!PostTask(from_here, Bind(&PostTaskAndReplyRelay::Run, |
- Unretained(relay)))) { |
+ if (!post_task_callback.Run(from_here, |
+ Bind(&PostTaskAndReplyRelay::RunTaskAndPostReply, |
+ Unretained(relay)))) { |
delete relay; |
return false; |
} |