OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_PROXY_IMPL_H_ | 5 #ifndef BASE_MESSAGE_LOOP_PROXY_IMPL_H_ |
6 #define BASE_MESSAGE_LOOP_PROXY_IMPL_H_ | 6 #define BASE_MESSAGE_LOOP_PROXY_IMPL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/base_export.h" | 9 #include "base/base_export.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/message_loop_proxy.h" | 11 #include "base/message_loop_proxy.h" |
12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
13 | 13 |
14 namespace base { | 14 namespace base { |
15 | 15 |
16 // A stock implementation of MessageLoopProxy that is created and managed by a | 16 // A stock implementation of MessageLoopProxy that is created and managed by a |
17 // MessageLoop. For now a MessageLoopProxyImpl can only be created as part of a | 17 // MessageLoop. For now a MessageLoopProxyImpl can only be created as part of a |
18 // MessageLoop. | 18 // MessageLoop. |
19 class BASE_EXPORT MessageLoopProxyImpl | 19 class BASE_EXPORT MessageLoopProxyImpl |
20 : public MessageLoopProxy { | 20 : public MessageLoopProxy { |
21 public: | 21 public: |
22 virtual ~MessageLoopProxyImpl(); | 22 virtual ~MessageLoopProxyImpl(); |
23 | 23 |
24 // MessageLoopProxy implementation | 24 // MessageLoopProxy implementation |
25 virtual bool PostTask(const tracked_objects::Location& from_here, | 25 virtual bool PostTask(const tracked_objects::Location& from_here, |
26 Task* task) OVERRIDE; | |
27 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, | |
28 Task* task, | |
29 int64 delay_ms) OVERRIDE; | |
30 virtual bool PostNonNestableTask(const tracked_objects::Location& from_here, | |
31 Task* task) OVERRIDE; | |
32 virtual bool PostNonNestableDelayedTask( | |
33 const tracked_objects::Location& from_here, | |
34 Task* task, | |
35 int64 delay_ms) OVERRIDE; | |
36 virtual bool PostTask(const tracked_objects::Location& from_here, | |
37 const base::Closure& task) OVERRIDE; | 26 const base::Closure& task) OVERRIDE; |
38 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, | 27 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, |
39 const base::Closure& task, | 28 const base::Closure& task, |
40 int64 delay_ms) OVERRIDE; | 29 int64 delay_ms) OVERRIDE; |
41 virtual bool PostNonNestableTask(const tracked_objects::Location& from_here, | 30 virtual bool PostNonNestableTask(const tracked_objects::Location& from_here, |
42 const base::Closure& task) OVERRIDE; | 31 const base::Closure& task) OVERRIDE; |
43 virtual bool PostNonNestableDelayedTask( | 32 virtual bool PostNonNestableDelayedTask( |
44 const tracked_objects::Location& from_here, | 33 const tracked_objects::Location& from_here, |
45 const base::Closure& task, | 34 const base::Closure& task, |
46 int64 delay_ms) OVERRIDE; | 35 int64 delay_ms) OVERRIDE; |
47 virtual bool BelongsToCurrentThread() OVERRIDE; | 36 virtual bool BelongsToCurrentThread() OVERRIDE; |
48 | 37 |
49 protected: | 38 protected: |
50 // Override OnDestruct so that we can delete the object on the target message | 39 // Override OnDestruct so that we can delete the object on the target message |
51 // loop if it still exists. | 40 // loop if it still exists. |
52 virtual void OnDestruct() const OVERRIDE; | 41 virtual void OnDestruct() const OVERRIDE; |
53 | 42 |
54 private: | 43 private: |
55 MessageLoopProxyImpl(); | 44 MessageLoopProxyImpl(); |
56 | 45 |
57 // Called directly by MessageLoop::~MessageLoop. | 46 // Called directly by MessageLoop::~MessageLoop. |
58 virtual void WillDestroyCurrentMessageLoop(); | 47 virtual void WillDestroyCurrentMessageLoop(); |
59 | 48 |
60 | 49 |
61 // TODO(ajwong): Remove this after we've fully migrated to base::Closure. | |
62 bool PostTaskHelper(const tracked_objects::Location& from_here, | |
63 Task* task, | |
64 int64 delay_ms, | |
65 bool nestable); | |
66 bool PostTaskHelper(const tracked_objects::Location& from_here, | 50 bool PostTaskHelper(const tracked_objects::Location& from_here, |
67 const base::Closure& task, | 51 const base::Closure& task, |
68 int64 delay_ms, | 52 int64 delay_ms, |
69 bool nestable); | 53 bool nestable); |
70 | 54 |
71 // Allow the messageLoop to create a MessageLoopProxyImpl. | 55 // Allow the messageLoop to create a MessageLoopProxyImpl. |
72 friend class ::MessageLoop; | 56 friend class ::MessageLoop; |
73 | 57 |
74 // The lock that protects access to target_message_loop_. | 58 // The lock that protects access to target_message_loop_. |
75 mutable base::Lock message_loop_lock_; | 59 mutable base::Lock message_loop_lock_; |
76 MessageLoop* target_message_loop_; | 60 MessageLoop* target_message_loop_; |
77 | 61 |
78 DISALLOW_COPY_AND_ASSIGN(MessageLoopProxyImpl); | 62 DISALLOW_COPY_AND_ASSIGN(MessageLoopProxyImpl); |
79 }; | 63 }; |
80 | 64 |
81 } // namespace base | 65 } // namespace base |
82 | 66 |
83 #endif // BASE_MESSAGE_LOOP_PROXY_IMPL_H_ | 67 #endif // BASE_MESSAGE_LOOP_PROXY_IMPL_H_ |
OLD | NEW |