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

Unified Diff: base/task.cc

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/task.h ('k') | content/browser/browser_thread.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/task.cc
diff --git a/base/task.cc b/base/task.cc
index 8c614734863fb5c8e34959dd2b00b4ac8c80e538..a6b674e55558e93100a640e561ce7223a2d2e5e0 100644
--- a/base/task.cc
+++ b/base/task.cc
@@ -4,6 +4,9 @@
#include "base/task.h"
+#include "base/bind.h"
+#include "base/message_loop_proxy.h"
+
Task::Task() {
}
@@ -63,4 +66,38 @@ bool TaskClosureAdapter::kTaskLeakingDefault = false;
} // namespace subtle
+namespace internal {
+
+PostTaskAndReplyRelay::PostTaskAndReplyRelay(
+ const tracked_objects::Location& from_here,
+ const Closure& task,
+ const Closure& reply)
+ : from_here_(from_here),
+ origin_loop_(MessageLoopProxy::CreateForCurrentThread()) {
+ task_ = task;
+ reply_ = reply;
+}
+
+PostTaskAndReplyRelay::~PostTaskAndReplyRelay() {
+ DCHECK(origin_loop_->BelongsToCurrentThread());
+}
+
+void PostTaskAndReplyRelay::Run() {
+ task_.Run();
+ origin_loop_->PostTask(
+ from_here_,
+ Bind(&PostTaskAndReplyRelay::RunReplyAndSelfDestruct,
+ base::Unretained(this)));
+}
+
+void PostTaskAndReplyRelay::RunReplyAndSelfDestruct() {
willchan no longer on Chromium 2011/08/16 02:00:12 Should |task_| be set to NULL at this point, which
awong 2011/08/16 02:12:13 I think the delete this is good enough to force th
willchan no longer on Chromium 2011/08/16 14:50:56 I won't push further, but I just wonder if there's
awong 2011/08/17 03:36:59 AH! I see what you're saying now. Yes. I can see
+ DCHECK(origin_loop_->BelongsToCurrentThread());
+ reply_.Run();
+
+ // Cue mission impossible theme.
+ delete this;
+}
+
+} // namespace internal
+
} // namespace base
« no previous file with comments | « base/task.h ('k') | content/browser/browser_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698