Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: base/message_pump_win.h

Issue 10826223: Replace PeekMessage for TSF awareness (Closed) Base URL: http://git.chromium.org/chromium/src.git@yukawa
Patch Set: use just PeekMessage for WM_PAINT/TIMER messages Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 {
22 23
23 // MessagePumpWin serves as the base for specialized versions of the MessagePump 24 // MessagePumpWin serves as the base for specialized versions of the MessagePump
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // is peeked, and before a replacement kMsgHaveWork is posted). 120 // is peeked, and before a replacement kMsgHaveWork is posted).
120 // 121 //
121 // NOTE: Although it may seem odd that messages are used to start and stop this 122 // 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 123 // 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 124 // 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 125 // 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. 126 // placed in the queue when new task arrive also awakens DoRunLoop.
126 // 127 //
127 class BASE_EXPORT MessagePumpForUI : public MessagePumpWin { 128 class BASE_EXPORT MessagePumpForUI : public MessagePumpWin {
128 public: 129 public:
130 // A MessageFilter implements the common Peek/Translate/Dispatch code to deal
131 // with windows messages.
132 class BASE_EXPORT MessageFilter {
133 public:
134 virtual ~MessageFilter() {}
135 virtual bool Init() = 0;
136 // Implements the functionality exposed by the OS through PeekMessage.
137 virtual BOOL DoPeekMessage(MSG* messge,
138 HWND window_handle,
139 UINT msg_filter_min,
140 UINT msg_filter_max,
141 UINT remove_msg) = 0;
142 // Returns true if |message| was consumed by the filter and no extra
143 // processing is required. If this method returns false, the normal message
144 // processing will take place.
145 // The priority to consume messages is the following:
146 // - Native Windows' message filter (CallMsgFilter).
147 // - MessageFilter::ProcessMessage.
148 // - MessagePumpDispatcher.
149 // - TranslateMessage / DispatchMessage.
150 virtual bool ProcessMessage(const MSG& message) = 0;
151 };
129 // The application-defined code passed to the hook procedure. 152 // The application-defined code passed to the hook procedure.
130 static const int kMessageFilterCode = 0x5001; 153 static const int kMessageFilterCode = 0x5001;
131 154
132 MessagePumpForUI(); 155 MessagePumpForUI();
133 virtual ~MessagePumpForUI(); 156 virtual ~MessagePumpForUI();
134 157
158 // Sets a new MessageFilter. MessagePumpForUI has ownership of
rvargas (doing something else) 2012/08/31 21:39:49 nit: has -> takes
yoichio 2012/09/03 04:45:08 Done.
159 // |message_filter|.
160 void SetMessageFilter(MessageFilter* message_filter);
rvargas (doing something else) 2012/08/31 21:39:49 There has to be documentation somewhere that state
yoichio 2012/09/03 04:45:08 Done.
161
135 // MessagePump methods: 162 // MessagePump methods:
136 virtual void ScheduleWork(); 163 virtual void ScheduleWork();
137 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time); 164 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time);
138 165
139 // Applications can call this to encourage us to process all pending WM_PAINT 166 // 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 167 // 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). 168 // queue can provide, up to some fixed number (to avoid any infinite loops).
142 void PumpOutPendingPaintMessages(); 169 void PumpOutPendingPaintMessages();
143 170
144 private: 171 private:
rvargas (doing something else) 2012/08/31 21:39:49 nit: don't remove the space
yoichio 2012/09/03 04:45:08 Done.
145 static LRESULT CALLBACK WndProcThunk( 172 static LRESULT CALLBACK WndProcThunk(HWND window_handle,
146 HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); 173 UINT message,
174 WPARAM wparam,
175 LPARAM lparam);
147 virtual void DoRunLoop(); 176 virtual void DoRunLoop();
148 void InitMessageWnd(); 177 void InitMessageWnd();
149 void WaitForWork(); 178 void WaitForWork();
150 void HandleWorkMessage(); 179 void HandleWorkMessage();
151 void HandleTimerMessage(); 180 void HandleTimerMessage();
152 bool ProcessNextWindowsMessage(); 181 bool ProcessNextWindowsMessage();
153 bool ProcessMessageHelper(const MSG& msg); 182 bool ProcessMessageHelper(const MSG& message);
154 bool ProcessPumpReplacementMessage(); 183 bool ProcessPumpReplacementMessage();
155 184
156 // Instance of the module containing the window procedure. 185 // Instance of the module containing the window procedure.
157 HMODULE instance_; 186 HMODULE instance_;
158 187
159 // A hidden message-only window. 188 // A hidden message-only window.
160 HWND message_hwnd_; 189 HWND message_hwnd_;
190
191 scoped_ptr<MessageFilter> message_filter_;
161 }; 192 };
162 193
163 //----------------------------------------------------------------------------- 194 //-----------------------------------------------------------------------------
164 // MessagePumpForIO extends MessagePumpWin with methods that are particular to a 195 // MessagePumpForIO extends MessagePumpWin with methods that are particular to a
165 // MessageLoop instantiated with TYPE_IO. This version of MessagePump does not 196 // 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 197 // deal with Windows mesagges, and instead has a Run loop based on Completion
167 // Ports so it is better suited for IO operations. 198 // Ports so it is better suited for IO operations.
168 // 199 //
169 class BASE_EXPORT MessagePumpForIO : public MessagePumpWin { 200 class BASE_EXPORT MessagePumpForIO : public MessagePumpWin {
170 public: 201 public:
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 // This list will be empty almost always. It stores IO completions that have 381 // This list will be empty almost always. It stores IO completions that have
351 // not been delivered yet because somebody was doing cleanup. 382 // not been delivered yet because somebody was doing cleanup.
352 std::list<IOItem> completed_io_; 383 std::list<IOItem> completed_io_;
353 384
354 ObserverList<IOObserver> io_observers_; 385 ObserverList<IOObserver> io_observers_;
355 }; 386 };
356 387
357 } // namespace base 388 } // namespace base
358 389
359 #endif // BASE_MESSAGE_PUMP_WIN_H_ 390 #endif // BASE_MESSAGE_PUMP_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698