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/message_window.h" |
20 #include "base/win/scoped_handle.h" | 21 #include "base/win/scoped_handle.h" |
21 | 22 |
22 namespace base { | 23 namespace base { |
23 | 24 |
24 // MessagePumpWin serves as the base for specialized versions of the MessagePump | 25 // MessagePumpWin serves as the base for specialized versions of the MessagePump |
25 // for Windows. It provides basic functionality like handling of observers and | 26 // for Windows. It provides basic functionality like handling of observers and |
26 // controlling the lifetime of the message pump. | 27 // controlling the lifetime of the message pump. |
27 class BASE_EXPORT MessagePumpWin : public MessagePump { | 28 class BASE_EXPORT MessagePumpWin : public MessagePump { |
28 public: | 29 public: |
29 MessagePumpWin() : have_work_(0), state_(NULL) {} | 30 MessagePumpWin() : have_work_(0), state_(NULL) {} |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 // kMsgHaveWork messages. As a result, care is taken to do some peeking in | 119 // kMsgHaveWork messages. As a result, care is taken to do some peeking in |
119 // between the posting of each kMsgHaveWork message (i.e., after kMsgHaveWork | 120 // between the posting of each kMsgHaveWork message (i.e., after kMsgHaveWork |
120 // is peeked, and before a replacement kMsgHaveWork is posted). | 121 // is peeked, and before a replacement kMsgHaveWork is posted). |
121 // | 122 // |
122 // NOTE: Although it may seem odd that messages are used to start and stop this | 123 // NOTE: Although it may seem odd that messages are used to start and stop this |
123 // flow (as opposed to signaling objects, etc.), it should be understood that | 124 // flow (as opposed to signaling objects, etc.), it should be understood that |
124 // the native message pump will *only* respond to messages. As a result, it is | 125 // the native message pump will *only* respond to messages. As a result, it is |
125 // an excellent choice. It is also helpful that the starter messages that are | 126 // an excellent choice. It is also helpful that the starter messages that are |
126 // placed in the queue when new task arrive also awakens DoRunLoop. | 127 // placed in the queue when new task arrive also awakens DoRunLoop. |
127 // | 128 // |
128 class BASE_EXPORT MessagePumpForUI : public MessagePumpWin { | 129 class BASE_EXPORT MessagePumpForUI |
| 130 : public MessagePumpWin, |
| 131 public win::MessageWindow::Delegate { |
129 public: | 132 public: |
130 // A MessageFilter implements the common Peek/Translate/Dispatch code to deal | 133 // A MessageFilter implements the common Peek/Translate/Dispatch code to deal |
131 // with windows messages. | 134 // with windows messages. |
132 // This abstraction is used to inject TSF message peeking. See | 135 // This abstraction is used to inject TSF message peeking. See |
133 // TextServicesMessageFilter. | 136 // TextServicesMessageFilter. |
134 class BASE_EXPORT MessageFilter { | 137 class BASE_EXPORT MessageFilter { |
135 public: | 138 public: |
136 virtual ~MessageFilter() {} | 139 virtual ~MessageFilter() {} |
137 // Implements the functionality exposed by the OS through PeekMessage. | 140 // Implements the functionality exposed by the OS through PeekMessage. |
138 virtual BOOL DoPeekMessage(MSG* msg, | 141 virtual BOOL DoPeekMessage(MSG* msg, |
(...skipping 29 matching lines...) Expand all Loading... |
168 // MessagePump methods: | 171 // MessagePump methods: |
169 virtual void ScheduleWork(); | 172 virtual void ScheduleWork(); |
170 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time); | 173 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time); |
171 | 174 |
172 // Applications can call this to encourage us to process all pending WM_PAINT | 175 // 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 | 176 // 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). | 177 // queue can provide, up to some fixed number (to avoid any infinite loops). |
175 void PumpOutPendingPaintMessages(); | 178 void PumpOutPendingPaintMessages(); |
176 | 179 |
177 private: | 180 private: |
178 static LRESULT CALLBACK WndProcThunk(HWND window_handle, | 181 // win::MessageWindow::Delegate interface. |
179 UINT message, | 182 virtual bool HandleMessage(HWND hwnd, |
180 WPARAM wparam, | 183 UINT message, |
181 LPARAM lparam); | 184 WPARAM wparam, |
| 185 LPARAM lparam, |
| 186 LRESULT* result) OVERRIDE; |
| 187 |
182 virtual void DoRunLoop(); | 188 virtual void DoRunLoop(); |
183 void InitMessageWnd(); | |
184 void WaitForWork(); | 189 void WaitForWork(); |
185 void HandleWorkMessage(); | 190 void HandleWorkMessage(); |
186 void HandleTimerMessage(); | 191 void HandleTimerMessage(); |
187 bool ProcessNextWindowsMessage(); | 192 bool ProcessNextWindowsMessage(); |
188 bool ProcessMessageHelper(const MSG& msg); | 193 bool ProcessMessageHelper(const MSG& msg); |
189 bool ProcessPumpReplacementMessage(); | 194 bool ProcessPumpReplacementMessage(); |
190 | 195 |
191 // Instance of the module containing the window procedure. | 196 scoped_ptr<MessageFilter> message_filter_; |
192 HMODULE instance_; | |
193 | 197 |
194 // A hidden message-only window. | 198 // A hidden message-only window. |
195 HWND message_hwnd_; | 199 scoped_ptr<base::win::MessageWindow> window_; |
196 | |
197 scoped_ptr<MessageFilter> message_filter_; | |
198 }; | 200 }; |
199 | 201 |
200 //----------------------------------------------------------------------------- | 202 //----------------------------------------------------------------------------- |
201 // MessagePumpForIO extends MessagePumpWin with methods that are particular to a | 203 // MessagePumpForIO extends MessagePumpWin with methods that are particular to a |
202 // MessageLoop instantiated with TYPE_IO. This version of MessagePump does not | 204 // MessageLoop instantiated with TYPE_IO. This version of MessagePump does not |
203 // deal with Windows mesagges, and instead has a Run loop based on Completion | 205 // deal with Windows mesagges, and instead has a Run loop based on Completion |
204 // Ports so it is better suited for IO operations. | 206 // Ports so it is better suited for IO operations. |
205 // | 207 // |
206 class BASE_EXPORT MessagePumpForIO : public MessagePumpWin { | 208 class BASE_EXPORT MessagePumpForIO : public MessagePumpWin { |
207 public: | 209 public: |
(...skipping 179 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 | 389 // This list will be empty almost always. It stores IO completions that have |
388 // not been delivered yet because somebody was doing cleanup. | 390 // not been delivered yet because somebody was doing cleanup. |
389 std::list<IOItem> completed_io_; | 391 std::list<IOItem> completed_io_; |
390 | 392 |
391 ObserverList<IOObserver> io_observers_; | 393 ObserverList<IOObserver> io_observers_; |
392 }; | 394 }; |
393 | 395 |
394 } // namespace base | 396 } // namespace base |
395 | 397 |
396 #endif // BASE_MESSAGE_PUMP_WIN_H_ | 398 #endif // BASE_MESSAGE_PUMP_WIN_H_ |
OLD | NEW |