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_PUMP_H_ | 5 #ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_H_ |
6 #define BASE_MESSAGE_LOOP_MESSAGE_PUMP_H_ | 6 #define BASE_MESSAGE_LOOP_MESSAGE_PUMP_H_ |
7 | 7 |
8 #include "base/base_export.h" | 8 #include "base/base_export.h" |
| 9 #include "base/basictypes.h" |
9 #include "base/threading/non_thread_safe.h" | 10 #include "base/threading/non_thread_safe.h" |
10 | 11 |
11 namespace base { | 12 namespace base { |
12 | 13 |
| 14 class TimeDelta; |
13 class TimeTicks; | 15 class TimeTicks; |
14 | 16 |
15 class BASE_EXPORT MessagePump : public NonThreadSafe { | 17 class BASE_EXPORT MessagePump : public NonThreadSafe { |
16 public: | 18 public: |
17 // Please see the comments above the Run method for an illustration of how | 19 // Please see the comments above the Run method for an illustration of how |
18 // these delegate methods are used. | 20 // these delegate methods are used. |
19 class BASE_EXPORT Delegate { | 21 class BASE_EXPORT Delegate { |
20 public: | 22 public: |
21 virtual ~Delegate() {} | 23 virtual ~Delegate() {} |
22 | 24 |
23 // Called from within Run in response to ScheduleWork or when the message | 25 // Called from within Run in response to ScheduleWork or when the message |
24 // pump would otherwise call DoDelayedWork. Returns true to indicate that | 26 // pump would otherwise call DoDelayedWork. Returns true to indicate that |
25 // work was done. DoDelayedWork will still be called if DoWork returns | 27 // work was done. DoDelayedWork will still be called if DoWork returns |
26 // true, but DoIdleWork will not. | 28 // true, but DoIdleWork will not. |
27 virtual bool DoWork() = 0; | 29 virtual bool DoWork() = 0; |
28 | 30 |
29 // Called from within Run in response to ScheduleDelayedWork or when the | 31 // Called from within Run in response to ScheduleDelayedWork or when the |
30 // message pump would otherwise sleep waiting for more work. Returns true | 32 // message pump would otherwise sleep waiting for more work. Returns true |
31 // to indicate that delayed work was done. DoIdleWork will not be called | 33 // to indicate that delayed work was done. DoIdleWork will not be called |
32 // if DoDelayedWork returns true. Upon return |next_delayed_work_time| | 34 // if DoDelayedWork returns true. Upon return |next_delayed_work_time| |
33 // indicates the time when DoDelayedWork should be called again. If | 35 // indicates the time when DoDelayedWork should be called again. If |
34 // |next_delayed_work_time| is null (per Time::is_null), then the queue of | 36 // |next_delayed_work_time| is null (per Time::is_null), then the queue of |
35 // future delayed work (timer events) is currently empty, and no additional | 37 // future delayed work (timer events) is currently empty, and no additional |
36 // calls to this function need to be scheduled. | 38 // calls to this function need to be scheduled. |
37 virtual bool DoDelayedWork(TimeTicks* next_delayed_work_time) = 0; | 39 virtual bool DoDelayedWork(TimeTicks* next_delayed_work_time) = 0; |
38 | 40 |
39 // Called from within Run just before the message pump goes to sleep. | 41 // Called from within Run just before the message pump goes to sleep. |
40 // Returns true to indicate that idle work was done. | 42 // Returns true to indicate that idle work was done. |
41 virtual bool DoIdleWork() = 0; | 43 virtual bool DoIdleWork() = 0; |
| 44 |
| 45 // Via the two optional out pointers, returns the length of the Delegate's |
| 46 // work queue and the length of time that the first item in the queue has |
| 47 // been waiting to run. |
| 48 virtual void GetQueueingInformation(size_t* queue_count, |
| 49 TimeDelta* queueing_delay) {} |
42 }; | 50 }; |
43 | 51 |
44 MessagePump(); | 52 MessagePump(); |
45 virtual ~MessagePump(); | 53 virtual ~MessagePump(); |
46 | 54 |
47 // The Run method is called to enter the message pump's run loop. | 55 // The Run method is called to enter the message pump's run loop. |
48 // | 56 // |
49 // Within the method, the message pump is responsible for processing native | 57 // Within the method, the message pump is responsible for processing native |
50 // messages as well as for giving cycles to the delegate periodically. The | 58 // messages as well as for giving cycles to the delegate periodically. The |
51 // message pump should take care to mix delegate callbacks with native | 59 // message pump should take care to mix delegate callbacks with native |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 125 |
118 // Schedule a DoDelayedWork callback to happen at the specified time, | 126 // Schedule a DoDelayedWork callback to happen at the specified time, |
119 // cancelling any pending DoDelayedWork callback. This method may only be | 127 // cancelling any pending DoDelayedWork callback. This method may only be |
120 // used on the thread that called Run. | 128 // used on the thread that called Run. |
121 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time) = 0; | 129 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time) = 0; |
122 }; | 130 }; |
123 | 131 |
124 } // namespace base | 132 } // namespace base |
125 | 133 |
126 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_H_ | 134 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_H_ |
OLD | NEW |