OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef BASE_MESSAGE_LOOP_PROXY_IMPL_H_ | |
6 #define BASE_MESSAGE_LOOP_PROXY_IMPL_H_ | |
7 | |
8 #include "base/base_export.h" | |
9 #include "base/message_loop.h" | |
10 #include "base/message_loop_proxy.h" | |
11 #include "base/synchronization/lock.h" | |
12 | |
13 namespace base { | |
14 | |
15 // 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 | |
17 // MessageLoop. | |
18 class BASE_EXPORT MessageLoopProxyImpl : public MessageLoopProxy { | |
19 public: | |
20 // MessageLoopProxy implementation | |
21 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, | |
22 const base::Closure& task, | |
23 base::TimeDelta delay) OVERRIDE; | |
24 virtual bool PostNonNestableDelayedTask( | |
25 const tracked_objects::Location& from_here, | |
26 const base::Closure& task, | |
27 base::TimeDelta delay) OVERRIDE; | |
28 virtual bool RunsTasksOnCurrentThread() const OVERRIDE; | |
29 | |
30 protected: | |
31 virtual ~MessageLoopProxyImpl(); | |
32 | |
33 // Override OnDestruct so that we can delete the object on the target message | |
34 // loop if it still exists. | |
35 virtual void OnDestruct() const OVERRIDE; | |
36 | |
37 private: | |
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_; | |
56 | |
57 DISALLOW_COPY_AND_ASSIGN(MessageLoopProxyImpl); | |
58 }; | |
59 | |
60 } // namespace base | |
61 | |
62 #endif // BASE_MESSAGE_LOOP_PROXY_IMPL_H_ | |
OLD | NEW |