Chromium Code Reviews| Index: base/message_loop_proxy.cc |
| diff --git a/base/message_loop_proxy.cc b/base/message_loop_proxy.cc |
| index a38db393f6e4aa63412455d435804b608f86c682..6d60016ca9a53e6c46ce531d557bde4a79b7d9c7 100644 |
| --- a/base/message_loop_proxy.cc |
| +++ b/base/message_loop_proxy.cc |
| @@ -4,6 +4,8 @@ |
| #include "base/message_loop_proxy.h" |
| +#include "base/bind.h" |
| + |
| namespace base { |
| MessageLoopProxy::MessageLoopProxy() { |
| @@ -12,8 +14,61 @@ MessageLoopProxy::MessageLoopProxy() { |
| MessageLoopProxy::~MessageLoopProxy() { |
| } |
| +bool MessageLoopProxy::PostTaskAndReply( |
| + const tracked_objects::Location& from_here, |
| + const Closure& task, |
| + const Closure& reply) { |
| + internal::PostTaskAndReplyRelay* relay = |
| + new internal::PostTaskAndReplyRelay(from_here, task, reply); |
| + if (!PostTask(from_here, base::Bind(&internal::PostTaskAndReplyRelay::Run, |
| + base::Unretained(relay)))) { |
|
darin (slow to review)
2011/08/17 17:20:39
nit: indent by 4 fewer characters? since this is
awong
2011/08/17 18:46:46
Done.
|
| + delete relay; |
| + return false; |
| + } |
| + |
| + return true; |
| +} |
| + |
| void MessageLoopProxy::OnDestruct() const { |
| delete this; |
| } |
| +namespace internal { |
| + |
| +PostTaskAndReplyRelay::PostTaskAndReplyRelay( |
| + const tracked_objects::Location& from_here, |
| + const Closure& task, |
| + const Closure& reply) |
| + : from_here_(from_here), |
| + origin_loop_(MessageLoopProxy::current()) { |
| + task_ = task; |
| + reply_ = reply; |
| +} |
| + |
| +PostTaskAndReplyRelay::~PostTaskAndReplyRelay() { |
| + DCHECK(origin_loop_->BelongsToCurrentThread()); |
| + task_.Reset(); |
| + reply_.Reset(); |
| +} |
| + |
| +void PostTaskAndReplyRelay::Run() { |
| + task_.Run(); |
| + origin_loop_->PostTask( |
| + from_here_, |
|
darin (slow to review)
2011/08/17 17:20:39
this could make the data in about:objects look con
awong
2011/08/17 18:46:46
Do you think so? As is, the "FROM_HERE" is going
|
| + Bind(&PostTaskAndReplyRelay::RunReplyAndSelfDestruct, |
| + base::Unretained(this))); |
| +} |
| + |
| +void PostTaskAndReplyRelay::RunReplyAndSelfDestruct() { |
| + DCHECK(origin_loop_->BelongsToCurrentThread()); |
| + task_.Reset(); |
|
darin (slow to review)
2011/08/17 17:20:39
it seems like there might be some subtle, non-triv
awong
2011/08/17 18:46:46
Done.
|
| + |
| + reply_.Run(); |
| + |
| + // Cue mission impossible theme. |
| + delete this; |
| +} |
| + |
| +} // namespace internal |
| + |
| } // namespace base |