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