| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef BASE_MESSAGE_LOOP_MESSAGE_LOOP_PROXY_IMPL_H_ | 5 #ifndef BASE_MESSAGE_LOOP_MESSAGE_LOOP_PROXY_IMPL_H_ |
| 6 #define BASE_MESSAGE_LOOP_MESSAGE_LOOP_PROXY_IMPL_H_ | 6 #define BASE_MESSAGE_LOOP_MESSAGE_LOOP_PROXY_IMPL_H_ |
| 7 | 7 |
| 8 #include "base/base_export.h" | 8 #include "base/base_export.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| 11 #include "base/synchronization/lock.h" | 11 #include "base/pending_task.h" |
| 12 #include "base/threading/platform_thread.h" |
| 12 | 13 |
| 13 namespace base { | 14 namespace base { |
| 15 namespace internal { |
| 16 |
| 17 class IncomingTaskQueue; |
| 14 | 18 |
| 15 // A stock implementation of MessageLoopProxy that is created and managed by a | 19 // A stock implementation of MessageLoopProxy that is created and managed by a |
| 16 // MessageLoop. For now a MessageLoopProxyImpl can only be created as part of a | 20 // MessageLoop. For now a MessageLoopProxyImpl can only be created as part of a |
| 17 // MessageLoop. | 21 // MessageLoop. |
| 18 class BASE_EXPORT MessageLoopProxyImpl : public MessageLoopProxy { | 22 class BASE_EXPORT MessageLoopProxyImpl : public MessageLoopProxy { |
| 19 public: | 23 public: |
| 24 explicit MessageLoopProxyImpl( |
| 25 scoped_refptr<IncomingTaskQueue> incoming_queue); |
| 26 |
| 20 // MessageLoopProxy implementation | 27 // MessageLoopProxy implementation |
| 21 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, | 28 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, |
| 22 const base::Closure& task, | 29 const base::Closure& task, |
| 23 base::TimeDelta delay) OVERRIDE; | 30 base::TimeDelta delay) OVERRIDE; |
| 24 virtual bool PostNonNestableDelayedTask( | 31 virtual bool PostNonNestableDelayedTask( |
| 25 const tracked_objects::Location& from_here, | 32 const tracked_objects::Location& from_here, |
| 26 const base::Closure& task, | 33 const base::Closure& task, |
| 27 base::TimeDelta delay) OVERRIDE; | 34 base::TimeDelta delay) OVERRIDE; |
| 28 virtual bool RunsTasksOnCurrentThread() const OVERRIDE; | 35 virtual bool RunsTasksOnCurrentThread() const OVERRIDE; |
| 29 | 36 |
| 30 protected: | 37 private: |
| 38 friend class RefCountedThreadSafe<MessageLoopProxyImpl>; |
| 31 virtual ~MessageLoopProxyImpl(); | 39 virtual ~MessageLoopProxyImpl(); |
| 32 | 40 |
| 33 // Override OnDestruct so that we can delete the object on the target message | 41 // THe incoming queue receiving all posted tasks. |
| 34 // loop if it still exists. | 42 scoped_refptr<IncomingTaskQueue> incoming_queue_; |
| 35 virtual void OnDestruct() const OVERRIDE; | |
| 36 | 43 |
| 37 private: | 44 // ID of the thread |this| was created on. |
| 38 // Allow the MessageLoop to create a MessageLoopProxyImpl. | 45 PlatformThreadId valid_thread_id_; |
| 39 friend class MessageLoop; | |
| 40 friend class DeleteHelper<MessageLoopProxyImpl>; | |
| 41 | |
| 42 MessageLoopProxyImpl(); | |
| 43 | |
| 44 // Called directly by MessageLoop::~MessageLoop. | |
| 45 virtual void WillDestroyCurrentMessageLoop(); | |
| 46 | |
| 47 | |
| 48 bool PostTaskHelper(const tracked_objects::Location& from_here, | |
| 49 const base::Closure& task, | |
| 50 base::TimeDelta delay, | |
| 51 bool nestable); | |
| 52 | |
| 53 // The lock that protects access to target_message_loop_. | |
| 54 mutable base::Lock message_loop_lock_; | |
| 55 MessageLoop* target_message_loop_; | |
| 56 | 46 |
| 57 DISALLOW_COPY_AND_ASSIGN(MessageLoopProxyImpl); | 47 DISALLOW_COPY_AND_ASSIGN(MessageLoopProxyImpl); |
| 58 }; | 48 }; |
| 59 | 49 |
| 50 } // namespace internal |
| 60 } // namespace base | 51 } // namespace base |
| 61 | 52 |
| 62 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_PROXY_IMPL_H_ | 53 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_PROXY_IMPL_H_ |
| OLD | NEW |