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.h" | 9 #include "base/message_loop.h" |
10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 protected: | 30 protected: |
31 virtual ~MessageLoopProxyImpl(); | 31 virtual ~MessageLoopProxyImpl(); |
32 | 32 |
33 // Override OnDestruct so that we can delete the object on the target message | 33 // Override OnDestruct so that we can delete the object on the target message |
34 // loop if it still exists. | 34 // loop if it still exists. |
35 virtual void OnDestruct() const OVERRIDE; | 35 virtual void OnDestruct() const OVERRIDE; |
36 | 36 |
37 private: | 37 private: |
38 // Allow the MessageLoop to create a MessageLoopProxyImpl. | 38 // Allow the MessageLoop to create a MessageLoopProxyImpl. |
39 friend class MessageLoop; | 39 friend class MessageLoop; |
| 40 friend class MessageLoopLockTest; |
40 friend class DeleteHelper<MessageLoopProxyImpl>; | 41 friend class DeleteHelper<MessageLoopProxyImpl>; |
41 | 42 |
42 MessageLoopProxyImpl(); | 43 MessageLoopProxyImpl(); |
43 | 44 |
44 // Called directly by MessageLoop::~MessageLoop. | 45 // Called directly by MessageLoop::~MessageLoop. |
45 virtual void WillDestroyCurrentMessageLoop(); | 46 virtual void WillDestroyCurrentMessageLoop(); |
46 | 47 |
| 48 // Takes |message_loop_lock_| and posts a task to |target_message_loop_|. |
| 49 // Posting of all tasks is routed though one these functions ensuring that |
| 50 // |message_loop_lock_| is always while modifying the incoming queue. |
| 51 // |
| 52 // Returns true if the task was successfully added to the queue, otherwise |
| 53 // returns false. In all cases, the ownership of |task| is transferred to the |
| 54 // called method. |
| 55 bool AddToIncomingQueue(const tracked_objects::Location& from_here, |
| 56 const Closure& task, |
| 57 TimeDelta delay, |
| 58 bool nestable); |
47 | 59 |
48 bool PostTaskHelper(const tracked_objects::Location& from_here, | 60 // Same as AddToIncomingQueue() except that it will avoid blocking if the lock |
49 const base::Closure& task, | 61 // is already held, and will in that case (when the lock is contended) fail to |
50 base::TimeDelta delay, | 62 // add the task, and will return false. |
51 bool nestable); | 63 bool TryAddToIncomingQueue(const tracked_objects::Location& from_here, |
| 64 const Closure& task); |
52 | 65 |
53 // The lock that protects access to target_message_loop_. | 66 // The lock that protects access to target_message_loop_. |
54 mutable base::Lock message_loop_lock_; | 67 mutable base::Lock message_loop_lock_; |
55 MessageLoop* target_message_loop_; | 68 MessageLoop* target_message_loop_; |
56 | 69 |
57 DISALLOW_COPY_AND_ASSIGN(MessageLoopProxyImpl); | 70 DISALLOW_COPY_AND_ASSIGN(MessageLoopProxyImpl); |
58 }; | 71 }; |
59 | 72 |
60 } // namespace base | 73 } // namespace base |
61 | 74 |
62 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_PROXY_IMPL_H_ | 75 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_PROXY_IMPL_H_ |
OLD | NEW |