[email protected] | c31af70db2 | 2011-08-18 23:13:01 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | d4799a3 | 2010-09-28 22:54:58 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "base/message_loop_proxy.h" |
| 6 | |
[email protected] | c31af70db2 | 2011-08-18 23:13:01 | [diff] [blame] | 7 | #include "base/bind.h" |
[email protected] | 2837654 | 2011-10-14 17:30:37 | [diff] [blame] | 8 | #include "base/compiler_specific.h" |
[email protected] | c62dd9d | 2011-09-21 18:05:41 | [diff] [blame] | 9 | #include "base/location.h" |
[email protected] | 2837654 | 2011-10-14 17:30:37 | [diff] [blame] | 10 | #include "base/threading/post_task_and_reply_impl.h" |
[email protected] | c31af70db2 | 2011-08-18 23:13:01 | [diff] [blame] | 11 | |
[email protected] | d4799a3 | 2010-09-28 22:54:58 | [diff] [blame] | 12 | namespace base { |
| 13 | |
[email protected] | c31af70db2 | 2011-08-18 23:13:01 | [diff] [blame] | 14 | namespace { |
| 15 | |
[email protected] | 2837654 | 2011-10-14 17:30:37 | [diff] [blame] | 16 | class PostTaskAndReplyMessageLoopProxy : public internal::PostTaskAndReplyImpl { |
[email protected] | c31af70db2 | 2011-08-18 23:13:01 | [diff] [blame] | 17 | public: |
[email protected] | 2837654 | 2011-10-14 17:30:37 | [diff] [blame] | 18 | PostTaskAndReplyMessageLoopProxy(MessageLoopProxy* destination) |
| 19 | : destination_(destination) { |
[email protected] | c31af70db2 | 2011-08-18 23:13:01 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | private: |
[email protected] | 2837654 | 2011-10-14 17:30:37 | [diff] [blame] | 23 | virtual bool PostTask(const tracked_objects::Location& from_here, |
| 24 | const base::Closure& task) OVERRIDE { |
| 25 | return destination_->PostTask(from_here, task); |
[email protected] | c31af70db2 | 2011-08-18 23:13:01 | [diff] [blame] | 26 | } |
| 27 | |
[email protected] | 2837654 | 2011-10-14 17:30:37 | [diff] [blame] | 28 | // Non-owning. |
| 29 | MessageLoopProxy* destination_; |
[email protected] | c31af70db2 | 2011-08-18 23:13:01 | [diff] [blame] | 30 | }; |
| 31 | |
| 32 | } // namespace |
| 33 | |
[email protected] | d4799a3 | 2010-09-28 22:54:58 | [diff] [blame] | 34 | MessageLoopProxy::MessageLoopProxy() { |
| 35 | } |
| 36 | |
| 37 | MessageLoopProxy::~MessageLoopProxy() { |
| 38 | } |
| 39 | |
[email protected] | c31af70db2 | 2011-08-18 23:13:01 | [diff] [blame] | 40 | bool MessageLoopProxy::PostTaskAndReply( |
| 41 | const tracked_objects::Location& from_here, |
| 42 | const Closure& task, |
| 43 | const Closure& reply) { |
[email protected] | 2837654 | 2011-10-14 17:30:37 | [diff] [blame] | 44 | return PostTaskAndReplyMessageLoopProxy(this).PostTaskAndReply( |
| 45 | from_here, task, reply); |
[email protected] | c31af70db2 | 2011-08-18 23:13:01 | [diff] [blame] | 46 | } |
| 47 | |
[email protected] | 00ed48f | 2010-10-22 22:19:24 | [diff] [blame] | 48 | void MessageLoopProxy::OnDestruct() const { |
[email protected] | d4799a3 | 2010-09-28 22:54:58 | [diff] [blame] | 49 | delete this; |
| 50 | } |
| 51 | |
[email protected] | b1d18328 | 2011-12-30 04:32:58 | [diff] [blame] | 52 | bool MessageLoopProxy::DeleteSoonInternal( |
| 53 | const tracked_objects::Location& from_here, |
| 54 | void(*deleter)(const void*), |
| 55 | const void* object) { |
| 56 | return PostNonNestableTask(from_here, base::Bind(deleter, object)); |
| 57 | } |
| 58 | |
[email protected] | c29985e | 2011-12-30 06:46:30 | [diff] [blame] | 59 | bool MessageLoopProxy::ReleaseSoonInternal( |
| 60 | const tracked_objects::Location& from_here, |
| 61 | void(*releaser)(const void*), |
| 62 | const void* object) { |
| 63 | return PostNonNestableTask(from_here, base::Bind(releaser, object)); |
| 64 | } |
| 65 | |
[email protected] | d4799a3 | 2010-09-28 22:54:58 | [diff] [blame] | 66 | } // namespace base |