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/basictypes.h" |
10 #include "base/message_loop/timer_slack.h" | 10 #include "base/message_loop/timer_slack.h" |
11 #include "base/threading/non_thread_safe.h" | 11 #include "base/threading/non_thread_safe.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 | 14 |
15 class TimeDelta; | |
16 class TimeTicks; | 15 class TimeTicks; |
17 | 16 |
18 class BASE_EXPORT MessagePump : public NonThreadSafe { | 17 class BASE_EXPORT MessagePump : public NonThreadSafe { |
19 public: | 18 public: |
20 // 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 |
21 // these delegate methods are used. | 20 // these delegate methods are used. |
22 class BASE_EXPORT Delegate { | 21 class BASE_EXPORT Delegate { |
23 public: | 22 public: |
24 virtual ~Delegate() {} | 23 virtual ~Delegate() {} |
25 | 24 |
26 // 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 |
27 // pump would otherwise call DoDelayedWork. Returns true to indicate that | 26 // pump would otherwise call DoDelayedWork. Returns true to indicate that |
28 // work was done. DoDelayedWork will still be called if DoWork returns | 27 // work was done. DoDelayedWork will still be called if DoWork returns |
29 // true, but DoIdleWork will not. | 28 // true, but DoIdleWork will not. |
30 virtual bool DoWork() = 0; | 29 virtual bool DoWork() = 0; |
31 | 30 |
32 // Called from within Run in response to ScheduleDelayedWork or when the | 31 // Called from within Run in response to ScheduleDelayedWork or when the |
33 // message pump would otherwise sleep waiting for more work. Returns true | 32 // message pump would otherwise sleep waiting for more work. Returns true |
34 // 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 |
35 // if DoDelayedWork returns true. Upon return |next_delayed_work_time| | 34 // if DoDelayedWork returns true. Upon return |next_delayed_work_time| |
36 // indicates the time when DoDelayedWork should be called again. If | 35 // indicates the time when DoDelayedWork should be called again. If |
37 // |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 |
38 // future delayed work (timer events) is currently empty, and no additional | 37 // future delayed work (timer events) is currently empty, and no additional |
39 // calls to this function need to be scheduled. | 38 // calls to this function need to be scheduled. |
40 virtual bool DoDelayedWork(TimeTicks* next_delayed_work_time) = 0; | 39 virtual bool DoDelayedWork(TimeTicks* next_delayed_work_time) = 0; |
41 | 40 |
42 // 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. |
43 // Returns true to indicate that idle work was done. | 42 // Returns true to indicate that idle work was done. |
44 virtual bool DoIdleWork() = 0; | 43 virtual bool DoIdleWork() = 0; |
45 | |
46 // Via the two required out pointers, returns the length of the Delegate's | |
47 // work queue and the length of time that the first item in the queue has | |
48 // been waiting to run. If the work queue is empty, the count and delay | |
49 // will both be zero. | |
50 // Note that this only counts the tasks in the ready-to-run queue and not | |
51 // the incoming queue that is used by other threads to post tasks. The | |
52 // latter queue requires holding a lock, which is deemed too expensive for | |
53 // instrumentation code. Under normal conditions, the incoming queue should | |
54 // be small or zero, but under heavy loads it may be much larger and | |
55 // |queue_count| may be up to 1/4 the size of the incoming queue. | |
56 virtual void GetQueueingInformation(size_t* queue_count, | |
57 TimeDelta* queueing_delay) {} | |
58 }; | 44 }; |
59 | 45 |
60 MessagePump(); | 46 MessagePump(); |
61 virtual ~MessagePump(); | 47 virtual ~MessagePump(); |
62 | 48 |
63 // The Run method is called to enter the message pump's run loop. | 49 // The Run method is called to enter the message pump's run loop. |
64 // | 50 // |
65 // Within the method, the message pump is responsible for processing native | 51 // Within the method, the message pump is responsible for processing native |
66 // messages as well as for giving cycles to the delegate periodically. The | 52 // messages as well as for giving cycles to the delegate periodically. The |
67 // message pump should take care to mix delegate callbacks with native | 53 // message pump should take care to mix delegate callbacks with native |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 // used on the thread that called Run. | 122 // used on the thread that called Run. |
137 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time) = 0; | 123 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time) = 0; |
138 | 124 |
139 // Sets the timer slack to the specified value. | 125 // Sets the timer slack to the specified value. |
140 virtual void SetTimerSlack(TimerSlack timer_slack); | 126 virtual void SetTimerSlack(TimerSlack timer_slack); |
141 }; | 127 }; |
142 | 128 |
143 } // namespace base | 129 } // namespace base |
144 | 130 |
145 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_H_ | 131 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_H_ |
OLD | NEW |