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_PUMP_WIN_H_ | 5 #ifndef BASE_MESSAGE_PUMP_WIN_H_ |
6 #define BASE_MESSAGE_PUMP_WIN_H_ | 6 #define BASE_MESSAGE_PUMP_WIN_H_ |
7 | 7 |
8 #include <windows.h> | 8 #include <windows.h> |
9 | 9 |
10 #include <list> | 10 #include <list> |
11 | 11 |
12 #include "base/base_export.h" | 12 #include "base/base_export.h" |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/message_pump.h" | 15 #include "base/message_pump.h" |
16 #include "base/message_pump_dispatcher.h" | 16 #include "base/message_pump_dispatcher.h" |
17 #include "base/message_pump_observer.h" | 17 #include "base/message_pump_observer.h" |
18 #include "base/observer_list.h" | 18 #include "base/observer_list.h" |
19 #include "base/time.h" | 19 #include "base/time.h" |
20 #include "base/win/scoped_handle.h" | 20 #include "base/win/scoped_handle.h" |
21 | 21 |
22 namespace base { | 22 namespace base { |
23 | 23 |
24 // MessagePumpWin serves as the base for specialized versions of the MessagePump | 24 // MessagePumpWin serves as the base for specialized versions of the MessagePump |
25 // for Windows. It provides basic functionality like handling of observers and | 25 // for Windows. It provides basic functionality like handling of observers and |
26 // controlling the lifetime of the message pump. | 26 // controlling the lifetime of the message pump. |
27 class BASE_EXPORT MessagePumpWin : public MessagePump { | 27 class BASE_EXPORT MessagePumpWin : public MessagePump { |
28 public: | 28 public: |
29 MessagePumpWin() : have_work_(0), state_(NULL) {} | 29 MessagePumpWin(); |
30 virtual ~MessagePumpWin() {} | 30 virtual ~MessagePumpWin() {} |
31 | 31 |
32 // Add an Observer, which will start receiving notifications immediately. | 32 // Add an Observer, which will start receiving notifications immediately. |
33 void AddObserver(MessagePumpObserver* observer); | 33 void AddObserver(MessagePumpObserver* observer); |
34 | 34 |
35 // Remove an Observer. It is safe to call this method while an Observer is | 35 // Remove an Observer. It is safe to call this method while an Observer is |
36 // receiving a notification callback. | 36 // receiving a notification callback. |
37 void RemoveObserver(MessagePumpObserver* observer); | 37 void RemoveObserver(MessagePumpObserver* observer); |
38 | 38 |
39 // Give a chance to code processing additional messages to notify the | 39 // Give a chance to code processing additional messages to notify the |
(...skipping 21 matching lines...) Expand all Loading... |
61 }; | 61 }; |
62 | 62 |
63 virtual void DoRunLoop() = 0; | 63 virtual void DoRunLoop() = 0; |
64 int GetCurrentDelay() const; | 64 int GetCurrentDelay() const; |
65 | 65 |
66 ObserverList<MessagePumpObserver> observers_; | 66 ObserverList<MessagePumpObserver> observers_; |
67 | 67 |
68 // The time at which delayed work should run. | 68 // The time at which delayed work should run. |
69 TimeTicks delayed_work_time_; | 69 TimeTicks delayed_work_time_; |
70 | 70 |
71 // A boolean value used to indicate if there is a kMsgDoWork message pending | 71 // Used to indicate if there is a kMsgDoWork message pending in the Windows |
72 // in the Windows Message queue. There is at most one such message, and it | 72 // Message queue. There is at most one such message, and it can drive |
73 // can drive execution of tasks when a native message pump is running. | 73 // execution of tasks when a native message pump is running. |
74 LONG have_work_; | 74 LONG pump_state_; |
75 | 75 |
76 // State for the current invocation of Run. | 76 // State for the current invocation of Run. |
77 RunState* state_; | 77 RunState* state_; |
| 78 |
| 79 // Used to post an APC to the thread running the message pump. |
| 80 win::ScopedHandle thread_; |
78 }; | 81 }; |
79 | 82 |
80 //----------------------------------------------------------------------------- | 83 //----------------------------------------------------------------------------- |
81 // MessagePumpForUI extends MessagePumpWin with methods that are particular to a | 84 // MessagePumpForUI extends MessagePumpWin with methods that are particular to a |
82 // MessageLoop instantiated with TYPE_UI. | 85 // MessageLoop instantiated with TYPE_UI. |
83 // | 86 // |
84 // MessagePumpForUI implements a "traditional" Windows message pump. It contains | 87 // MessagePumpForUI implements a "traditional" Windows message pump. It contains |
85 // a nearly infinite loop that peeks out messages, and then dispatches them. | 88 // a nearly infinite loop that peeks out messages, and then dispatches them. |
86 // Intermixed with those peeks are callouts to DoWork for pending tasks, and | 89 // Intermixed with those peeks are callouts to DoWork for pending tasks, and |
87 // DoDelayedWork for pending timers. When there are no events to be serviced, | 90 // DoDelayedWork for pending timers. When there are no events to be serviced, |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 | 162 |
160 MessagePumpForUI(); | 163 MessagePumpForUI(); |
161 virtual ~MessagePumpForUI(); | 164 virtual ~MessagePumpForUI(); |
162 | 165 |
163 // Sets a new MessageFilter. MessagePumpForUI takes ownership of | 166 // Sets a new MessageFilter. MessagePumpForUI takes ownership of |
164 // |message_filter|. When SetMessageFilter is called, old MessageFilter is | 167 // |message_filter|. When SetMessageFilter is called, old MessageFilter is |
165 // deleted. | 168 // deleted. |
166 void SetMessageFilter(scoped_ptr<MessageFilter> message_filter); | 169 void SetMessageFilter(scoped_ptr<MessageFilter> message_filter); |
167 | 170 |
168 // MessagePump methods: | 171 // MessagePump methods: |
169 virtual void ScheduleWork(); | 172 virtual void ScheduleWork() OVERRIDE; |
170 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time); | 173 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time) OVERRIDE; |
| 174 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; |
171 | 175 |
172 // Applications can call this to encourage us to process all pending WM_PAINT | 176 // Applications can call this to encourage us to process all pending WM_PAINT |
173 // messages. This method will process all paint messages the Windows Message | 177 // messages. This method will process all paint messages the Windows Message |
174 // queue can provide, up to some fixed number (to avoid any infinite loops). | 178 // queue can provide, up to some fixed number (to avoid any infinite loops). |
175 void PumpOutPendingPaintMessages(); | 179 void PumpOutPendingPaintMessages(); |
176 | 180 |
177 private: | 181 private: |
178 static LRESULT CALLBACK WndProcThunk(HWND window_handle, | 182 static LRESULT CALLBACK WndProcThunk(HWND window_handle, |
179 UINT message, | 183 UINT message, |
180 WPARAM wparam, | 184 WPARAM wparam, |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 // This list will be empty almost always. It stores IO completions that have | 391 // This list will be empty almost always. It stores IO completions that have |
388 // not been delivered yet because somebody was doing cleanup. | 392 // not been delivered yet because somebody was doing cleanup. |
389 std::list<IOItem> completed_io_; | 393 std::list<IOItem> completed_io_; |
390 | 394 |
391 ObserverList<IOObserver> io_observers_; | 395 ObserverList<IOObserver> io_observers_; |
392 }; | 396 }; |
393 | 397 |
394 } // namespace base | 398 } // namespace base |
395 | 399 |
396 #endif // BASE_MESSAGE_PUMP_WIN_H_ | 400 #endif // BASE_MESSAGE_PUMP_WIN_H_ |
OLD | NEW |