Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/message_loop_proxy.h" | 5 #include "base/message_loop_proxy.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | |
| 8 | |
| 7 namespace base { | 9 namespace base { |
| 8 | 10 |
| 9 MessageLoopProxy::MessageLoopProxy() { | 11 MessageLoopProxy::MessageLoopProxy() { |
| 10 } | 12 } |
| 11 | 13 |
| 12 MessageLoopProxy::~MessageLoopProxy() { | 14 MessageLoopProxy::~MessageLoopProxy() { |
| 13 } | 15 } |
| 14 | 16 |
| 17 bool MessageLoopProxy::PostTaskAndReply( | |
| 18 const tracked_objects::Location& from_here, | |
| 19 const Closure& task, | |
| 20 const Closure& reply) { | |
| 21 internal::PostTaskAndReplyRelay* relay = | |
| 22 new internal::PostTaskAndReplyRelay(from_here, task, reply); | |
| 23 if (!PostTask(from_here, base::Bind(&internal::PostTaskAndReplyRelay::Run, | |
| 24 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.
| |
| 25 delete relay; | |
| 26 return false; | |
| 27 } | |
| 28 | |
| 29 return true; | |
| 30 } | |
| 31 | |
| 15 void MessageLoopProxy::OnDestruct() const { | 32 void MessageLoopProxy::OnDestruct() const { |
| 16 delete this; | 33 delete this; |
| 17 } | 34 } |
| 18 | 35 |
| 36 namespace internal { | |
| 37 | |
| 38 PostTaskAndReplyRelay::PostTaskAndReplyRelay( | |
| 39 const tracked_objects::Location& from_here, | |
| 40 const Closure& task, | |
| 41 const Closure& reply) | |
| 42 : from_here_(from_here), | |
| 43 origin_loop_(MessageLoopProxy::current()) { | |
| 44 task_ = task; | |
| 45 reply_ = reply; | |
| 46 } | |
| 47 | |
| 48 PostTaskAndReplyRelay::~PostTaskAndReplyRelay() { | |
| 49 DCHECK(origin_loop_->BelongsToCurrentThread()); | |
| 50 task_.Reset(); | |
| 51 reply_.Reset(); | |
| 52 } | |
| 53 | |
| 54 void PostTaskAndReplyRelay::Run() { | |
| 55 task_.Run(); | |
| 56 origin_loop_->PostTask( | |
| 57 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
| |
| 58 Bind(&PostTaskAndReplyRelay::RunReplyAndSelfDestruct, | |
| 59 base::Unretained(this))); | |
| 60 } | |
| 61 | |
| 62 void PostTaskAndReplyRelay::RunReplyAndSelfDestruct() { | |
| 63 DCHECK(origin_loop_->BelongsToCurrentThread()); | |
| 64 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.
| |
| 65 | |
| 66 reply_.Run(); | |
| 67 | |
| 68 // Cue mission impossible theme. | |
| 69 delete this; | |
| 70 } | |
| 71 | |
| 72 } // namespace internal | |
| 73 | |
| 19 } // namespace base | 74 } // namespace base |
| OLD | NEW |