| 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_WIN_H_ | 5 #ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_WIN_H_ |
| 6 #define BASE_MESSAGE_LOOP_MESSAGE_PUMP_WIN_H_ | 6 #define BASE_MESSAGE_LOOP_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" | |
| 15 #include "base/message_loop/message_pump.h" | 14 #include "base/message_loop/message_pump.h" |
| 16 #include "base/message_loop/message_pump_dispatcher.h" | 15 #include "base/message_loop/message_pump_dispatcher.h" |
| 17 #include "base/message_loop/message_pump_observer.h" | 16 #include "base/message_loop/message_pump_observer.h" |
| 18 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 19 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 20 #include "base/win/scoped_handle.h" | 19 #include "base/win/scoped_handle.h" |
| 21 | 20 |
| 22 namespace base { | 21 namespace base { |
| 23 | 22 |
| 24 // MessagePumpWin serves as the base for specialized versions of the MessagePump | 23 // MessagePumpWin serves as the base for specialized versions of the MessagePump |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 // is peeked, and before a replacement kMsgHaveWork is posted). | 119 // is peeked, and before a replacement kMsgHaveWork is posted). |
| 121 // | 120 // |
| 122 // NOTE: Although it may seem odd that messages are used to start and stop this | 121 // 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 | 122 // 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 | 123 // 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 | 124 // 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. | 125 // placed in the queue when new task arrive also awakens DoRunLoop. |
| 127 // | 126 // |
| 128 class BASE_EXPORT MessagePumpForUI : public MessagePumpWin { | 127 class BASE_EXPORT MessagePumpForUI : public MessagePumpWin { |
| 129 public: | 128 public: |
| 130 // A MessageFilter implements the common Peek/Translate/Dispatch code to deal | |
| 131 // with windows messages. | |
| 132 // This abstraction is used to inject TSF message peeking. See | |
| 133 // TextServicesMessageFilter. | |
| 134 class BASE_EXPORT MessageFilter { | |
| 135 public: | |
| 136 virtual ~MessageFilter() {} | |
| 137 // Implements the functionality exposed by the OS through PeekMessage. | |
| 138 virtual BOOL DoPeekMessage(MSG* msg, | |
| 139 HWND window_handle, | |
| 140 UINT msg_filter_min, | |
| 141 UINT msg_filter_max, | |
| 142 UINT remove_msg) { | |
| 143 return PeekMessage(msg, window_handle, msg_filter_min, msg_filter_max, | |
| 144 remove_msg); | |
| 145 } | |
| 146 // Returns true if |message| was consumed by the filter and no extra | |
| 147 // processing is required. If this method returns false, it is the | |
| 148 // responsibility of the caller to ensure that normal processing takes | |
| 149 // place. | |
| 150 // The priority to consume messages is the following: | |
| 151 // - Native Windows' message filter (CallMsgFilter). | |
| 152 // - MessageFilter::ProcessMessage. | |
| 153 // - MessagePumpDispatcher. | |
| 154 // - TranslateMessage / DispatchMessage. | |
| 155 virtual bool ProcessMessage(const MSG& msg) { return false;} | |
| 156 }; | |
| 157 // The application-defined code passed to the hook procedure. | 129 // The application-defined code passed to the hook procedure. |
| 158 static const int kMessageFilterCode = 0x5001; | 130 static const int kMessageFilterCode = 0x5001; |
| 159 | 131 |
| 160 MessagePumpForUI(); | 132 MessagePumpForUI(); |
| 161 virtual ~MessagePumpForUI(); | 133 virtual ~MessagePumpForUI(); |
| 162 | 134 |
| 163 // Sets a new MessageFilter. MessagePumpForUI takes ownership of | |
| 164 // |message_filter|. When SetMessageFilter is called, old MessageFilter is | |
| 165 // deleted. | |
| 166 void SetMessageFilter(scoped_ptr<MessageFilter> message_filter); | |
| 167 | |
| 168 // MessagePump methods: | 135 // MessagePump methods: |
| 169 virtual void ScheduleWork(); | 136 virtual void ScheduleWork(); |
| 170 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time); | 137 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time); |
| 171 | 138 |
| 172 private: | 139 private: |
| 173 static LRESULT CALLBACK WndProcThunk(HWND window_handle, | 140 static LRESULT CALLBACK WndProcThunk(HWND window_handle, |
| 174 UINT message, | 141 UINT message, |
| 175 WPARAM wparam, | 142 WPARAM wparam, |
| 176 LPARAM lparam); | 143 LPARAM lparam); |
| 177 virtual void DoRunLoop(); | 144 virtual void DoRunLoop(); |
| 178 void InitMessageWnd(); | 145 void InitMessageWnd(); |
| 179 void WaitForWork(); | 146 void WaitForWork(); |
| 180 void HandleWorkMessage(); | 147 void HandleWorkMessage(); |
| 181 void HandleTimerMessage(); | 148 void HandleTimerMessage(); |
| 182 bool ProcessNextWindowsMessage(); | 149 bool ProcessNextWindowsMessage(); |
| 183 bool ProcessMessageHelper(const MSG& msg); | 150 bool ProcessMessageHelper(const MSG& msg); |
| 184 bool ProcessPumpReplacementMessage(); | 151 bool ProcessPumpReplacementMessage(); |
| 185 | 152 |
| 186 // Atom representing the registered window class. | 153 // Atom representing the registered window class. |
| 187 ATOM atom_; | 154 ATOM atom_; |
| 188 | 155 |
| 189 // A hidden message-only window. | 156 // A hidden message-only window. |
| 190 HWND message_hwnd_; | 157 HWND message_hwnd_; |
| 191 | |
| 192 scoped_ptr<MessageFilter> message_filter_; | |
| 193 }; | 158 }; |
| 194 | 159 |
| 195 //----------------------------------------------------------------------------- | 160 //----------------------------------------------------------------------------- |
| 196 // MessagePumpForIO extends MessagePumpWin with methods that are particular to a | 161 // MessagePumpForIO extends MessagePumpWin with methods that are particular to a |
| 197 // MessageLoop instantiated with TYPE_IO. This version of MessagePump does not | 162 // MessageLoop instantiated with TYPE_IO. This version of MessagePump does not |
| 198 // deal with Windows mesagges, and instead has a Run loop based on Completion | 163 // deal with Windows mesagges, and instead has a Run loop based on Completion |
| 199 // Ports so it is better suited for IO operations. | 164 // Ports so it is better suited for IO operations. |
| 200 // | 165 // |
| 201 class BASE_EXPORT MessagePumpForIO : public MessagePumpWin { | 166 class BASE_EXPORT MessagePumpForIO : public MessagePumpWin { |
| 202 public: | 167 public: |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 // This list will be empty almost always. It stores IO completions that have | 347 // This list will be empty almost always. It stores IO completions that have |
| 383 // not been delivered yet because somebody was doing cleanup. | 348 // not been delivered yet because somebody was doing cleanup. |
| 384 std::list<IOItem> completed_io_; | 349 std::list<IOItem> completed_io_; |
| 385 | 350 |
| 386 ObserverList<IOObserver> io_observers_; | 351 ObserverList<IOObserver> io_observers_; |
| 387 }; | 352 }; |
| 388 | 353 |
| 389 } // namespace base | 354 } // namespace base |
| 390 | 355 |
| 391 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_WIN_H_ | 356 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_WIN_H_ |
| OLD | NEW |