| 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; |
| 15 class TimeTicks; | 16 class TimeTicks; |
| 16 | 17 |
| 17 class BASE_EXPORT MessagePump : public NonThreadSafe { | 18 class BASE_EXPORT MessagePump : public NonThreadSafe { |
| 18 public: | 19 public: |
| 19 // Please see the comments above the Run method for an illustration of how | 20 // Please see the comments above the Run method for an illustration of how |
| 20 // these delegate methods are used. | 21 // these delegate methods are used. |
| 21 class BASE_EXPORT Delegate { | 22 class BASE_EXPORT Delegate { |
| 22 public: | 23 public: |
| 23 virtual ~Delegate() {} | 24 virtual ~Delegate() {} |
| 24 | 25 |
| 25 // Called from within Run in response to ScheduleWork or when the message | 26 // Called from within Run in response to ScheduleWork or when the message |
| 26 // pump would otherwise call DoDelayedWork. Returns true to indicate that | 27 // pump would otherwise call DoDelayedWork. Returns true to indicate that |
| 27 // work was done. DoDelayedWork will still be called if DoWork returns | 28 // work was done. DoDelayedWork will still be called if DoWork returns |
| 28 // true, but DoIdleWork will not. | 29 // true, but DoIdleWork will not. |
| 29 virtual bool DoWork() = 0; | 30 virtual bool DoWork() = 0; |
| 30 | 31 |
| 31 // Called from within Run in response to ScheduleDelayedWork or when the | 32 // Called from within Run in response to ScheduleDelayedWork or when the |
| 32 // message pump would otherwise sleep waiting for more work. Returns true | 33 // message pump would otherwise sleep waiting for more work. Returns true |
| 33 // to indicate that delayed work was done. DoIdleWork will not be called | 34 // to indicate that delayed work was done. DoIdleWork will not be called |
| 34 // if DoDelayedWork returns true. Upon return |next_delayed_work_time| | 35 // if DoDelayedWork returns true. Upon return |next_delayed_work_time| |
| 35 // indicates the time when DoDelayedWork should be called again. If | 36 // indicates the time when DoDelayedWork should be called again. If |
| 36 // |next_delayed_work_time| is null (per Time::is_null), then the queue of | 37 // |next_delayed_work_time| is null (per Time::is_null), then the queue of |
| 37 // future delayed work (timer events) is currently empty, and no additional | 38 // future delayed work (timer events) is currently empty, and no additional |
| 38 // calls to this function need to be scheduled. | 39 // calls to this function need to be scheduled. |
| 39 virtual bool DoDelayedWork(TimeTicks* next_delayed_work_time) = 0; | 40 virtual bool DoDelayedWork(TimeTicks* next_delayed_work_time) = 0; |
| 40 | 41 |
| 41 // Called from within Run just before the message pump goes to sleep. | 42 // Called from within Run just before the message pump goes to sleep. |
| 42 // Returns true to indicate that idle work was done. | 43 // Returns true to indicate that idle work was done. |
| 43 virtual bool DoIdleWork() = 0; | 44 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) {} |
| 44 }; | 58 }; |
| 45 | 59 |
| 46 MessagePump(); | 60 MessagePump(); |
| 47 virtual ~MessagePump(); | 61 virtual ~MessagePump(); |
| 48 | 62 |
| 49 // The Run method is called to enter the message pump's run loop. | 63 // The Run method is called to enter the message pump's run loop. |
| 50 // | 64 // |
| 51 // Within the method, the message pump is responsible for processing native | 65 // Within the method, the message pump is responsible for processing native |
| 52 // messages as well as for giving cycles to the delegate periodically. The | 66 // messages as well as for giving cycles to the delegate periodically. The |
| 53 // message pump should take care to mix delegate callbacks with native | 67 // message pump should take care to mix delegate callbacks with native |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 // used on the thread that called Run. | 136 // used on the thread that called Run. |
| 123 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time) = 0; | 137 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time) = 0; |
| 124 | 138 |
| 125 // Sets the timer slack to the specified value. | 139 // Sets the timer slack to the specified value. |
| 126 virtual void SetTimerSlack(TimerSlack timer_slack); | 140 virtual void SetTimerSlack(TimerSlack timer_slack); |
| 127 }; | 141 }; |
| 128 | 142 |
| 129 } // namespace base | 143 } // namespace base |
| 130 | 144 |
| 131 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_H_ | 145 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_H_ |
| OLD | NEW |