OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_PUMP_H_ | 5 #ifndef BASE_MESSAGE_PUMP_H_ |
6 #define BASE_MESSAGE_PUMP_H_ | 6 #define BASE_MESSAGE_PUMP_H_ |
7 | 7 |
8 #include "base/ref_counted.h" | 8 #include "base/ref_counted.h" |
9 | 9 |
| 10 namespace base { |
| 11 |
10 class Time; | 12 class Time; |
11 | 13 |
12 namespace base { | |
13 | |
14 class MessagePump : public RefCountedThreadSafe<MessagePump> { | 14 class MessagePump : public RefCountedThreadSafe<MessagePump> { |
15 public: | 15 public: |
16 // Please see the comments above the Run method for an illustration of how | 16 // Please see the comments above the Run method for an illustration of how |
17 // these delegate methods are used. | 17 // these delegate methods are used. |
18 class Delegate { | 18 class Delegate { |
19 public: | 19 public: |
20 virtual ~Delegate() {} | 20 virtual ~Delegate() {} |
21 | 21 |
22 // Called from within Run in response to ScheduleWork or when the message | 22 // Called from within Run in response to ScheduleWork or when the message |
23 // pump would otherwise call DoDelayedWork. Returns true to indicate that | 23 // pump would otherwise call DoDelayedWork. Returns true to indicate that |
24 // work was done. DoDelayedWork will not be called if DoWork returns true. | 24 // work was done. DoDelayedWork will not be called if DoWork returns true. |
25 virtual bool DoWork() = 0; | 25 virtual bool DoWork() = 0; |
26 | 26 |
27 // Called from within Run in response to ScheduleDelayedWork or when the | 27 // Called from within Run in response to ScheduleDelayedWork or when the |
28 // message pump would otherwise sleep waiting for more work. Returns true | 28 // message pump would otherwise sleep waiting for more work. Returns true |
29 // to indicate that delayed work was done. DoIdleWork will not be called | 29 // to indicate that delayed work was done. DoIdleWork will not be called |
30 // if DoDelayedWork returns true. Upon return |next_delayed_work_time| | 30 // if DoDelayedWork returns true. Upon return |next_delayed_work_time| |
31 // indicates the time when DoDelayedWork should be called again. If | 31 // indicates the time when DoDelayedWork should be called again. If |
32 // |next_delayed_work_time| is null (per Time::is_null), then the queue of | 32 // |next_delayed_work_time| is null (per Time::is_null), then the queue of |
33 // future delayed work (timer events) is currently empty, and no additional | 33 // future delayed work (timer events) is currently empty, and no additional |
34 // calls to this function need to be scheduled. | 34 // calls to this function need to be scheduled. |
35 virtual bool DoDelayedWork(Time* next_delayed_work_time) = 0; | 35 virtual bool DoDelayedWork(base::Time* next_delayed_work_time) = 0; |
36 | 36 |
37 // Called from within Run just before the message pump goes to sleep. | 37 // Called from within Run just before the message pump goes to sleep. |
38 // Returns true to indicate that idle work was done. | 38 // Returns true to indicate that idle work was done. |
39 virtual bool DoIdleWork() = 0; | 39 virtual bool DoIdleWork() = 0; |
40 }; | 40 }; |
41 | 41 |
42 virtual ~MessagePump() {} | 42 virtual ~MessagePump() {} |
43 | 43 |
44 // The Run method is called to enter the message pump's run loop. | 44 // The Run method is called to enter the message pump's run loop. |
45 // | 45 // |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 107 |
108 // Schedule a DoWork callback to happen reasonably soon. Does nothing if a | 108 // Schedule a DoWork callback to happen reasonably soon. Does nothing if a |
109 // DoWork callback is already scheduled. This method may be called from any | 109 // DoWork callback is already scheduled. This method may be called from any |
110 // thread. Once this call is made, DoWork should not be "starved" at least | 110 // thread. Once this call is made, DoWork should not be "starved" at least |
111 // until it returns a value of false. | 111 // until it returns a value of false. |
112 virtual void ScheduleWork() = 0; | 112 virtual void ScheduleWork() = 0; |
113 | 113 |
114 // Schedule a DoDelayedWork callback to happen at the specified time, | 114 // Schedule a DoDelayedWork callback to happen at the specified time, |
115 // cancelling any pending DoDelayedWork callback. This method may only be | 115 // cancelling any pending DoDelayedWork callback. This method may only be |
116 // used on the thread that called Run. | 116 // used on the thread that called Run. |
117 virtual void ScheduleDelayedWork(const Time& delayed_work_time) = 0; | 117 virtual void ScheduleDelayedWork(const base::Time& delayed_work_time) = 0; |
118 }; | 118 }; |
119 | 119 |
120 } // namespace base | 120 } // namespace base |
121 | 121 |
122 #endif // BASE_MESSAGE_PUMP_H_ | 122 #endif // BASE_MESSAGE_PUMP_H_ |
123 | |
OLD | NEW |