Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(867)

Unified Diff: base/task.h

Issue 7210053: Implementation of PostTaskAndReply() in MessageLoopProxy and BrowserThread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased and turned into methods Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/message_loop_proxy.cc ('k') | base/task.cc » ('j') | base/task.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_
« no previous file with comments | « base/message_loop_proxy.cc ('k') | base/task.cc » ('j') | base/task.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698