OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <windows.h> | 9 #include <windows.h> |
10 | 10 |
11 #include <list> | 11 #include <list> |
12 | 12 |
13 #include "base/base_api.h" | 13 #include "base/base_export.h" |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "base/message_pump.h" | 15 #include "base/message_pump.h" |
16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
17 #include "base/time.h" | 17 #include "base/time.h" |
18 #include "base/win/scoped_handle.h" | 18 #include "base/win/scoped_handle.h" |
19 | 19 |
20 namespace base { | 20 namespace base { |
21 | 21 |
22 // MessagePumpWin serves as the base for specialized versions of the MessagePump | 22 // MessagePumpWin serves as the base for specialized versions of the MessagePump |
23 // for Windows. It provides basic functionality like handling of observers and | 23 // for Windows. It provides basic functionality like handling of observers and |
24 // controlling the lifetime of the message pump. | 24 // controlling the lifetime of the message pump. |
25 class BASE_API MessagePumpWin : public MessagePump { | 25 class BASE_EXPORT MessagePumpWin : public MessagePump { |
26 public: | 26 public: |
27 // An Observer is an object that receives global notifications from the | 27 // An Observer is an object that receives global notifications from the |
28 // UI MessageLoop. | 28 // UI MessageLoop. |
29 // | 29 // |
30 // NOTE: An Observer implementation should be extremely fast! | 30 // NOTE: An Observer implementation should be extremely fast! |
31 // | 31 // |
32 class BASE_API Observer { | 32 class BASE_EXPORT Observer { |
33 public: | 33 public: |
34 virtual ~Observer() {} | 34 virtual ~Observer() {} |
35 | 35 |
36 // This method is called before processing a message. | 36 // This method is called before processing a message. |
37 // The message may be undefined in which case msg.message is 0 | 37 // The message may be undefined in which case msg.message is 0 |
38 virtual void WillProcessMessage(const MSG& msg) = 0; | 38 virtual void WillProcessMessage(const MSG& msg) = 0; |
39 | 39 |
40 // This method is called when control returns from processing a UI message. | 40 // This method is called when control returns from processing a UI message. |
41 // The message may be undefined in which case msg.message is 0 | 41 // The message may be undefined in which case msg.message is 0 |
42 virtual void DidProcessMessage(const MSG& msg) = 0; | 42 virtual void DidProcessMessage(const MSG& msg) = 0; |
43 }; | 43 }; |
44 | 44 |
45 // Dispatcher is used during a nested invocation of Run to dispatch events. | 45 // Dispatcher is used during a nested invocation of Run to dispatch events. |
46 // If Run is invoked with a non-NULL Dispatcher, MessageLoop does not | 46 // If Run is invoked with a non-NULL Dispatcher, MessageLoop does not |
47 // dispatch events (or invoke TranslateMessage), rather every message is | 47 // dispatch events (or invoke TranslateMessage), rather every message is |
48 // passed to Dispatcher's Dispatch method for dispatch. It is up to the | 48 // passed to Dispatcher's Dispatch method for dispatch. It is up to the |
49 // Dispatcher to dispatch, or not, the event. | 49 // Dispatcher to dispatch, or not, the event. |
50 // | 50 // |
51 // The nested loop is exited by either posting a quit, or returning false | 51 // The nested loop is exited by either posting a quit, or returning false |
52 // from Dispatch. | 52 // from Dispatch. |
53 class BASE_API Dispatcher { | 53 class BASE_EXPORT Dispatcher { |
54 public: | 54 public: |
55 virtual ~Dispatcher() {} | 55 virtual ~Dispatcher() {} |
56 // Dispatches the event. If true is returned processing continues as | 56 // Dispatches the event. If true is returned processing continues as |
57 // normal. If false is returned, the nested loop exits immediately. | 57 // normal. If false is returned, the nested loop exits immediately. |
58 virtual bool Dispatch(const MSG& msg) = 0; | 58 virtual bool Dispatch(const MSG& msg) = 0; |
59 }; | 59 }; |
60 | 60 |
61 MessagePumpWin() : have_work_(0), state_(NULL) {} | 61 MessagePumpWin() : have_work_(0), state_(NULL) {} |
62 virtual ~MessagePumpWin() {} | 62 virtual ~MessagePumpWin() {} |
63 | 63 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 // kMsgHaveWork messages. As a result, care is taken to do some peeking in | 150 // kMsgHaveWork messages. As a result, care is taken to do some peeking in |
151 // between the posting of each kMsgHaveWork message (i.e., after kMsgHaveWork | 151 // between the posting of each kMsgHaveWork message (i.e., after kMsgHaveWork |
152 // is peeked, and before a replacement kMsgHaveWork is posted). | 152 // is peeked, and before a replacement kMsgHaveWork is posted). |
153 // | 153 // |
154 // NOTE: Although it may seem odd that messages are used to start and stop this | 154 // NOTE: Although it may seem odd that messages are used to start and stop this |
155 // flow (as opposed to signaling objects, etc.), it should be understood that | 155 // flow (as opposed to signaling objects, etc.), it should be understood that |
156 // the native message pump will *only* respond to messages. As a result, it is | 156 // the native message pump will *only* respond to messages. As a result, it is |
157 // an excellent choice. It is also helpful that the starter messages that are | 157 // an excellent choice. It is also helpful that the starter messages that are |
158 // placed in the queue when new task arrive also awakens DoRunLoop. | 158 // placed in the queue when new task arrive also awakens DoRunLoop. |
159 // | 159 // |
160 class BASE_API MessagePumpForUI : public MessagePumpWin { | 160 class BASE_EXPORT MessagePumpForUI : public MessagePumpWin { |
161 public: | 161 public: |
162 // The application-defined code passed to the hook procedure. | 162 // The application-defined code passed to the hook procedure. |
163 static const int kMessageFilterCode = 0x5001; | 163 static const int kMessageFilterCode = 0x5001; |
164 | 164 |
165 MessagePumpForUI(); | 165 MessagePumpForUI(); |
166 virtual ~MessagePumpForUI(); | 166 virtual ~MessagePumpForUI(); |
167 | 167 |
168 // MessagePump methods: | 168 // MessagePump methods: |
169 virtual void ScheduleWork(); | 169 virtual void ScheduleWork(); |
170 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time); | 170 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time); |
(...skipping 18 matching lines...) Expand all Loading... |
189 // A hidden message-only window. | 189 // A hidden message-only window. |
190 HWND message_hwnd_; | 190 HWND message_hwnd_; |
191 }; | 191 }; |
192 | 192 |
193 //----------------------------------------------------------------------------- | 193 //----------------------------------------------------------------------------- |
194 // MessagePumpForIO extends MessagePumpWin with methods that are particular to a | 194 // MessagePumpForIO extends MessagePumpWin with methods that are particular to a |
195 // MessageLoop instantiated with TYPE_IO. This version of MessagePump does not | 195 // MessageLoop instantiated with TYPE_IO. This version of MessagePump does not |
196 // deal with Windows mesagges, and instead has a Run loop based on Completion | 196 // deal with Windows mesagges, and instead has a Run loop based on Completion |
197 // Ports so it is better suited for IO operations. | 197 // Ports so it is better suited for IO operations. |
198 // | 198 // |
199 class BASE_API MessagePumpForIO : public MessagePumpWin { | 199 class BASE_EXPORT MessagePumpForIO : public MessagePumpWin { |
200 public: | 200 public: |
201 struct IOContext; | 201 struct IOContext; |
202 | 202 |
203 // Clients interested in receiving OS notifications when asynchronous IO | 203 // Clients interested in receiving OS notifications when asynchronous IO |
204 // operations complete should implement this interface and register themselves | 204 // operations complete should implement this interface and register themselves |
205 // with the message pump. | 205 // with the message pump. |
206 // | 206 // |
207 // Typical use #1: | 207 // Typical use #1: |
208 // // Use only when there are no user's buffers involved on the actual IO, | 208 // // Use only when there are no user's buffers involved on the actual IO, |
209 // // so that all the cleanup can be done by the message pump. | 209 // // so that all the cleanup can be done by the message pump. |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 // This list will be empty almost always. It stores IO completions that have | 361 // This list will be empty almost always. It stores IO completions that have |
362 // not been delivered yet because somebody was doing cleanup. | 362 // not been delivered yet because somebody was doing cleanup. |
363 std::list<IOItem> completed_io_; | 363 std::list<IOItem> completed_io_; |
364 | 364 |
365 ObserverList<IOObserver> io_observers_; | 365 ObserverList<IOObserver> io_observers_; |
366 }; | 366 }; |
367 | 367 |
368 } // namespace base | 368 } // namespace base |
369 | 369 |
370 #endif // BASE_MESSAGE_PUMP_WIN_H_ | 370 #endif // BASE_MESSAGE_PUMP_WIN_H_ |
OLD | NEW |