Chromium Code Reviews| 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/message_pump.h" | 15 #include "base/message_pump.h" |
| 15 #include "base/message_pump_dispatcher.h" | 16 #include "base/message_pump_dispatcher.h" |
| 16 #include "base/message_pump_observer.h" | 17 #include "base/message_pump_observer.h" |
| 17 #include "base/observer_list.h" | 18 #include "base/observer_list.h" |
| 18 #include "base/time.h" | 19 #include "base/time.h" |
| 19 #include "base/win/scoped_handle.h" | 20 #include "base/win/scoped_handle.h" |
| 20 | 21 |
| 21 namespace base { | 22 namespace base { |
| 23 namespace win { | |
| 24 class TextServicesBridge; | |
|
rvargas (doing something else)
2012/08/21 19:45:37
remove this.
yoichio
2012/08/22 08:06:50
Done.
| |
| 25 } // namespace win | |
| 22 | 26 |
| 23 // MessagePumpWin serves as the base for specialized versions of the MessagePump | 27 // MessagePumpWin serves as the base for specialized versions of the MessagePump |
| 24 // for Windows. It provides basic functionality like handling of observers and | 28 // for Windows. It provides basic functionality like handling of observers and |
| 25 // controlling the lifetime of the message pump. | 29 // controlling the lifetime of the message pump. |
| 26 class BASE_EXPORT MessagePumpWin : public MessagePump { | 30 class BASE_EXPORT MessagePumpWin : public MessagePump { |
| 27 public: | 31 public: |
| 28 MessagePumpWin() : have_work_(0), state_(NULL) {} | 32 MessagePumpWin() : have_work_(0), state_(NULL) {} |
| 29 virtual ~MessagePumpWin() {} | 33 virtual ~MessagePumpWin() {} |
| 30 | 34 |
| 31 // Add an Observer, which will start receiving notifications immediately. | 35 // Add an Observer, which will start receiving notifications immediately. |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 // is peeked, and before a replacement kMsgHaveWork is posted). | 123 // is peeked, and before a replacement kMsgHaveWork is posted). |
| 120 // | 124 // |
| 121 // NOTE: Although it may seem odd that messages are used to start and stop this | 125 // NOTE: Although it may seem odd that messages are used to start and stop this |
| 122 // flow (as opposed to signaling objects, etc.), it should be understood that | 126 // flow (as opposed to signaling objects, etc.), it should be understood that |
| 123 // the native message pump will *only* respond to messages. As a result, it is | 127 // the native message pump will *only* respond to messages. As a result, it is |
| 124 // an excellent choice. It is also helpful that the starter messages that are | 128 // an excellent choice. It is also helpful that the starter messages that are |
| 125 // placed in the queue when new task arrive also awakens DoRunLoop. | 129 // placed in the queue when new task arrive also awakens DoRunLoop. |
| 126 // | 130 // |
| 127 class BASE_EXPORT MessagePumpForUI : public MessagePumpWin { | 131 class BASE_EXPORT MessagePumpForUI : public MessagePumpWin { |
| 128 public: | 132 public: |
| 133 // Interface gets message and may process it. | |
|
rvargas (doing something else)
2012/08/21 19:45:37
How about:
A MessageFilter implements the common P
yoichio
2012/08/22 08:06:50
Done.
| |
| 134 class MessageFilter { | |
| 135 public: | |
| 136 virtual ~MessageFilter() {} | |
| 137 virtual bool Init() = 0; | |
| 138 // Implements the functionality exposed by the OS through PeekMessage. | |
| 139 virtual BOOL DoPeekMessage(MSG* msg, | |
|
rvargas (doing something else)
2012/08/21 19:45:37
nit: message
yoichio
2012/08/22 08:06:50
Done.
| |
| 140 HWND hwnd, | |
| 141 UINT msg_filter_min, | |
| 142 UINT msg_filter_max, | |
| 143 UINT remove_msg) = 0; | |
| 144 // Returns true if |message| was completely consumed by the filter and | |
|
rvargas (doing something else)
2012/08/21 19:45:37
It is not clear what is expected from an implement
yoichio
2012/08/22 08:06:50
How about this?
| |
| 145 // should not be dispatched. | |
| 146 virtual bool ProcessMessage(const MSG& msg) = 0; | |
|
rvargas (doing something else)
2012/08/21 19:45:37
nit: message
rvargas (doing something else)
2012/08/21 19:45:37
On a more serious note, the interaction between a
yoichio
2012/08/22 08:06:50
Done.
yoichio
2012/08/22 08:06:50
Add comments.
| |
| 147 }; | |
| 148 | |
| 129 // The application-defined code passed to the hook procedure. | 149 // The application-defined code passed to the hook procedure. |
| 130 static const int kMessageFilterCode = 0x5001; | 150 static const int kMessageFilterCode = 0x5001; |
| 131 | 151 |
| 132 MessagePumpForUI(); | 152 MessagePumpForUI(); |
| 133 virtual ~MessagePumpForUI(); | 153 virtual ~MessagePumpForUI(); |
| 134 | 154 |
| 135 // MessagePump methods: | 155 // MessagePump methods: |
| 136 virtual void ScheduleWork(); | 156 virtual void ScheduleWork(); |
| 137 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time); | 157 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time); |
| 138 | 158 |
| 139 // Applications can call this to encourage us to process all pending WM_PAINT | 159 // Applications can call this to encourage us to process all pending WM_PAINT |
| 140 // messages. This method will process all paint messages the Windows Message | 160 // messages. This method will process all paint messages the Windows Message |
| 141 // queue can provide, up to some fixed number (to avoid any infinite loops). | 161 // queue can provide, up to some fixed number (to avoid any infinite loops). |
| 142 void PumpOutPendingPaintMessages(); | 162 void PumpOutPendingPaintMessages(); |
| 143 | 163 |
| 144 private: | 164 private: |
| 145 static LRESULT CALLBACK WndProcThunk( | 165 static LRESULT CALLBACK WndProcThunk(HWND hwnd, |
| 146 HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); | 166 UINT message, |
| 167 WPARAM wparam, | |
| 168 LPARAM lparam); | |
| 147 virtual void DoRunLoop(); | 169 virtual void DoRunLoop(); |
| 148 void InitMessageWnd(); | 170 void InitMessageWnd(); |
| 149 void WaitForWork(); | 171 void WaitForWork(); |
| 150 void HandleWorkMessage(); | 172 void HandleWorkMessage(); |
| 151 void HandleTimerMessage(); | 173 void HandleTimerMessage(); |
| 152 bool ProcessNextWindowsMessage(); | 174 bool ProcessNextWindowsMessage(); |
| 153 bool ProcessMessageHelper(const MSG& msg); | 175 bool ProcessMessageHelper(const MSG& msg); |
| 154 bool ProcessPumpReplacementMessage(); | 176 bool ProcessPumpReplacementMessage(); |
| 155 | 177 |
| 156 // Instance of the module containing the window procedure. | 178 // Instance of the module containing the window procedure. |
| 157 HMODULE instance_; | 179 HMODULE instance_; |
| 158 | 180 |
| 159 // A hidden message-only window. | 181 // A hidden message-only window. |
| 160 HWND message_hwnd_; | 182 HWND message_hwnd_; |
| 183 | |
| 184 // A Proxy which gets message. | |
|
rvargas (doing something else)
2012/08/21 19:45:37
nit: remove comment
yoichio
2012/08/22 08:06:50
Done.
| |
| 185 scoped_ptr<MessageFilter> message_filter_; | |
| 161 }; | 186 }; |
| 162 | 187 |
| 163 //----------------------------------------------------------------------------- | 188 //----------------------------------------------------------------------------- |
| 164 // MessagePumpForIO extends MessagePumpWin with methods that are particular to a | 189 // MessagePumpForIO extends MessagePumpWin with methods that are particular to a |
| 165 // MessageLoop instantiated with TYPE_IO. This version of MessagePump does not | 190 // MessageLoop instantiated with TYPE_IO. This version of MessagePump does not |
| 166 // deal with Windows mesagges, and instead has a Run loop based on Completion | 191 // deal with Windows mesagges, and instead has a Run loop based on Completion |
| 167 // Ports so it is better suited for IO operations. | 192 // Ports so it is better suited for IO operations. |
| 168 // | 193 // |
| 169 class BASE_EXPORT MessagePumpForIO : public MessagePumpWin { | 194 class BASE_EXPORT MessagePumpForIO : public MessagePumpWin { |
| 170 public: | 195 public: |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 350 // This list will be empty almost always. It stores IO completions that have | 375 // This list will be empty almost always. It stores IO completions that have |
| 351 // not been delivered yet because somebody was doing cleanup. | 376 // not been delivered yet because somebody was doing cleanup. |
| 352 std::list<IOItem> completed_io_; | 377 std::list<IOItem> completed_io_; |
| 353 | 378 |
| 354 ObserverList<IOObserver> io_observers_; | 379 ObserverList<IOObserver> io_observers_; |
| 355 }; | 380 }; |
| 356 | 381 |
| 357 } // namespace base | 382 } // namespace base |
| 358 | 383 |
| 359 #endif // BASE_MESSAGE_PUMP_WIN_H_ | 384 #endif // BASE_MESSAGE_PUMP_WIN_H_ |
| OLD | NEW |