Index: base/task.h |
diff --git a/base/task.h b/base/task.h |
index 460c8c2e5c9a4dca9318da1c45db848baa7b8007..acc909832e71fab82b52577ca23e89e482c1ed6a 100644 |
--- a/base/task.h |
+++ b/base/task.h |
@@ -7,6 +7,7 @@ |
#pragma once |
#include "base/base_export.h" |
+#include "base/callback.h" |
#include "base/debug/alias.h" |
#include "base/memory/raw_scoped_refptr_mismatch_checker.h" |
#include "base/memory/weak_ptr.h" |
@@ -15,6 +16,7 @@ |
namespace base { |
const size_t kDeadTask = 0xDEAD7A53; |
+class MessageLoopProxy; |
} |
// Task ------------------------------------------------------------------------ |
@@ -602,6 +604,36 @@ class TaskClosureAdapter : public RefCounted<TaskClosureAdapter> { |
} // namespace subtle |
+namespace internal { |
+ |
+// 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. |
+// |
+// If this is not possible because the originating MessageLoop is no longer |
+// available, the 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. |
+class PostTaskAndReplyRelay { |
+ public: |
+ PostTaskAndReplyRelay(const tracked_objects::Location& from_here, |
+ const Closure& task, const Closure& reply); |
+ |
+ ~PostTaskAndReplyRelay(); |
+ |
+ void Run(); |
+ |
+ private: |
+ void RunReplyAndSelfDestruct(); |
+ |
+ tracked_objects::Location from_here_; |
+ scoped_refptr<MessageLoopProxy> origin_loop_; |
+ Closure task_; |
+ Closure reply_; |
+}; |
+ |
+} // namespace internal |
+ |
} // namespace base |
#endif // BASE_TASK_H_ |