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 #include "base/message_loop/message_pump_win.h" | 5 #include "base/message_loop/message_pump_win.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <limits> | 10 #include <limits> |
(...skipping 10 matching lines...) Expand all Loading... | |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 enum MessageLoopProblems { | 24 enum MessageLoopProblems { |
25 MESSAGE_POST_ERROR, | 25 MESSAGE_POST_ERROR, |
26 COMPLETION_POST_ERROR, | 26 COMPLETION_POST_ERROR, |
27 SET_TIMER_ERROR, | 27 SET_TIMER_ERROR, |
28 MESSAGE_LOOP_PROBLEM_MAX, | 28 MESSAGE_LOOP_PROBLEM_MAX, |
29 }; | 29 }; |
30 | 30 |
31 // The following define pointer to user32 API's for the API's which are used | |
32 // in this file. These are added to avoid directly depending on user32 from | |
33 // base as there are users of base who don't want this. | |
34 decltype(::TranslateMessage)* g_translate_message = nullptr; | |
35 decltype(::DispatchMessageW)* g_dispatch_message = nullptr; | |
36 decltype(::PeekMessageW)* g_peek_message = nullptr; | |
37 decltype(::PostMessageW)* g_post_message = nullptr; | |
38 decltype(::DefWindowProcW)* g_def_window_proc = nullptr; | |
39 decltype(::PostQuitMessage)* g_post_quit = nullptr; | |
40 decltype(::UnregisterClassW)* g_unregister_class = nullptr; | |
41 decltype(::RegisterClassExW)* g_register_class = nullptr; | |
42 decltype(::CreateWindowExW)* g_create_window_ex = nullptr; | |
43 decltype(::DestroyWindow)* g_destroy_window = nullptr; | |
44 decltype(::CallMsgFilterW)* g_call_msg_filter = nullptr; | |
45 decltype(::GetQueueStatus)* g_get_queue_status = nullptr; | |
46 decltype(::MsgWaitForMultipleObjectsEx)* g_msg_wait_for_multiple_objects_ex = | |
47 nullptr; | |
48 decltype(::SetTimer)* g_set_timer = nullptr; | |
49 decltype(::KillTimer)* g_kill_timer = nullptr; | |
50 | |
51 #define GET_USER32_API(name) \ | |
scottmg
2016/06/14 19:50:36
git cl format
| |
52 reinterpret_cast<decltype(name)*>(::GetProcAddress(\ | |
53 ::GetModuleHandle(L"user32.dll"), #name)) | |
grt (UTC plus 2)
2016/06/14 20:07:13
is this going to get the loader lock twice for eac
ananta
2016/06/14 21:27:40
Yeah. Changed to take the module handle.
| |
54 | |
55 // Initializes the global pointers to user32 APIs for the API's used in this | |
56 // file. | |
57 void InitUser32APIs() { | |
58 if (g_translate_message) | |
59 return; | |
60 | |
61 HMODULE user32_dll = ::GetModuleHandle(L"user32.dll"); | |
scottmg
2016/06/14 19:50:36
Don't need this any more.
ananta
2016/06/14 19:58:54
Done.
| |
62 CHECK(user32_dll); | |
63 | |
64 g_translate_message = GET_USER32_API(TranslateMessage); | |
65 CHECK(g_translate_message); | |
66 | |
67 g_dispatch_message = GET_USER32_API(DispatchMessageW); | |
68 CHECK(g_dispatch_message); | |
69 | |
70 g_peek_message = GET_USER32_API(PeekMessageW); | |
71 CHECK(g_peek_message); | |
72 | |
73 g_post_message = GET_USER32_API(PostMessageW); | |
74 CHECK(g_post_message); | |
75 | |
76 g_def_window_proc = GET_USER32_API(DefWindowProcW); | |
77 CHECK(g_def_window_proc); | |
78 | |
79 g_post_quit = GET_USER32_API(PostQuitMessage); | |
80 CHECK(g_post_quit); | |
81 | |
82 g_unregister_class = GET_USER32_API(UnregisterClassW); | |
83 CHECK(g_unregister_class); | |
84 | |
85 g_register_class = GET_USER32_API(RegisterClassExW); | |
86 CHECK(g_register_class); | |
87 | |
88 g_create_window_ex = GET_USER32_API(CreateWindowExW); | |
89 CHECK(g_create_window_ex); | |
90 | |
91 g_destroy_window = GET_USER32_API(DestroyWindow); | |
92 CHECK(g_destroy_window); | |
93 | |
94 g_call_msg_filter = GET_USER32_API(CallMsgFilterW); | |
95 CHECK(g_call_msg_filter); | |
96 | |
97 g_get_queue_status = GET_USER32_API(GetQueueStatus); | |
98 CHECK(g_get_queue_status); | |
99 | |
100 g_msg_wait_for_multiple_objects_ex = | |
101 GET_USER32_API(MsgWaitForMultipleObjectsEx); | |
102 CHECK(g_msg_wait_for_multiple_objects_ex); | |
103 | |
104 g_set_timer = GET_USER32_API(SetTimer); | |
105 CHECK(g_set_timer); | |
106 | |
107 g_kill_timer = GET_USER32_API(KillTimer); | |
108 CHECK(g_kill_timer); | |
109 } | |
110 | |
31 } // namespace | 111 } // namespace |
32 | 112 |
33 static const wchar_t kWndClassFormat[] = L"Chrome_MessagePumpWindow_%p"; | 113 static const wchar_t kWndClassFormat[] = L"Chrome_MessagePumpWindow_%p"; |
34 | 114 |
35 // Message sent to get an additional time slice for pumping (processing) another | 115 // Message sent to get an additional time slice for pumping (processing) another |
36 // task (a series of such messages creates a continuous task pump). | 116 // task (a series of such messages creates a continuous task pump). |
37 static const int kMsgHaveWork = WM_USER + 1; | 117 static const int kMsgHaveWork = WM_USER + 1; |
38 | 118 |
39 // The application-defined code passed to the hook procedure. | 119 // The application-defined code passed to the hook procedure. |
40 static const int kMessageFilterCode = 0x5001; | 120 static const int kMessageFilterCode = 0x5001; |
41 | 121 |
42 //----------------------------------------------------------------------------- | 122 //----------------------------------------------------------------------------- |
43 // MessagePumpWin public: | 123 // MessagePumpWin public: |
44 | 124 |
125 MessagePumpWin::MessagePumpWin() { | |
126 InitUser32APIs(); | |
127 } | |
128 | |
45 void MessagePumpWin::Run(Delegate* delegate) { | 129 void MessagePumpWin::Run(Delegate* delegate) { |
46 RunState s; | 130 RunState s; |
47 s.delegate = delegate; | 131 s.delegate = delegate; |
48 s.should_quit = false; | 132 s.should_quit = false; |
49 s.run_depth = state_ ? state_->run_depth + 1 : 1; | 133 s.run_depth = state_ ? state_->run_depth + 1 : 1; |
50 | 134 |
51 // TODO(stanisc): crbug.com/596190: Remove this code once the bug is fixed. | 135 // TODO(stanisc): crbug.com/596190: Remove this code once the bug is fixed. |
52 s.schedule_work_error_count = 0; | 136 s.schedule_work_error_count = 0; |
53 s.last_schedule_work_error_time = Time(); | 137 s.last_schedule_work_error_time = Time(); |
54 | 138 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 | 173 |
90 //----------------------------------------------------------------------------- | 174 //----------------------------------------------------------------------------- |
91 // MessagePumpForUI public: | 175 // MessagePumpForUI public: |
92 | 176 |
93 MessagePumpForUI::MessagePumpForUI() | 177 MessagePumpForUI::MessagePumpForUI() |
94 : atom_(0) { | 178 : atom_(0) { |
95 InitMessageWnd(); | 179 InitMessageWnd(); |
96 } | 180 } |
97 | 181 |
98 MessagePumpForUI::~MessagePumpForUI() { | 182 MessagePumpForUI::~MessagePumpForUI() { |
99 DestroyWindow(message_hwnd_); | 183 g_destroy_window(message_hwnd_); |
100 UnregisterClass(MAKEINTATOM(atom_), CURRENT_MODULE()); | 184 g_unregister_class(MAKEINTATOM(atom_), CURRENT_MODULE()); |
101 } | 185 } |
102 | 186 |
103 void MessagePumpForUI::ScheduleWork() { | 187 void MessagePumpForUI::ScheduleWork() { |
104 if (InterlockedExchange(&work_state_, HAVE_WORK) != READY) | 188 if (InterlockedExchange(&work_state_, HAVE_WORK) != READY) |
105 return; // Someone else continued the pumping. | 189 return; // Someone else continued the pumping. |
106 | 190 |
107 // Make sure the MessagePump does some work for us. | 191 // Make sure the MessagePump does some work for us. |
108 BOOL ret = PostMessage(message_hwnd_, kMsgHaveWork, | 192 BOOL ret = g_post_message(message_hwnd_, kMsgHaveWork, |
109 reinterpret_cast<WPARAM>(this), 0); | 193 reinterpret_cast<WPARAM>(this), 0); |
110 if (ret) | 194 if (ret) |
111 return; // There was room in the Window Message queue. | 195 return; // There was room in the Window Message queue. |
112 | 196 |
113 // We have failed to insert a have-work message, so there is a chance that we | 197 // We have failed to insert a have-work message, so there is a chance that we |
114 // will starve tasks/timers while sitting in a nested message loop. Nested | 198 // will starve tasks/timers while sitting in a nested message loop. Nested |
115 // loops only look at Windows Message queues, and don't look at *our* task | 199 // loops only look at Windows Message queues, and don't look at *our* task |
116 // queues, etc., so we might not get a time slice in such. :-( | 200 // queues, etc., so we might not get a time slice in such. :-( |
117 // We could abort here, but the fear is that this failure mode is plausibly | 201 // We could abort here, but the fear is that this failure mode is plausibly |
118 // common (queue is full, of about 2000 messages), so we'll do a near-graceful | 202 // common (queue is full, of about 2000 messages), so we'll do a near-graceful |
119 // recovery. Nested loops are pretty transient (we think), so this will | 203 // recovery. Nested loops are pretty transient (we think), so this will |
(...skipping 19 matching lines...) Expand all Loading... | |
139 LRESULT CALLBACK MessagePumpForUI::WndProcThunk( | 223 LRESULT CALLBACK MessagePumpForUI::WndProcThunk( |
140 HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { | 224 HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { |
141 switch (message) { | 225 switch (message) { |
142 case kMsgHaveWork: | 226 case kMsgHaveWork: |
143 reinterpret_cast<MessagePumpForUI*>(wparam)->HandleWorkMessage(); | 227 reinterpret_cast<MessagePumpForUI*>(wparam)->HandleWorkMessage(); |
144 break; | 228 break; |
145 case WM_TIMER: | 229 case WM_TIMER: |
146 reinterpret_cast<MessagePumpForUI*>(wparam)->HandleTimerMessage(); | 230 reinterpret_cast<MessagePumpForUI*>(wparam)->HandleTimerMessage(); |
147 break; | 231 break; |
148 } | 232 } |
149 return DefWindowProc(hwnd, message, wparam, lparam); | 233 return g_def_window_proc(hwnd, message, wparam, lparam); |
150 } | 234 } |
151 | 235 |
152 void MessagePumpForUI::DoRunLoop() { | 236 void MessagePumpForUI::DoRunLoop() { |
153 // IF this was just a simple PeekMessage() loop (servicing all possible work | 237 // IF this was just a simple PeekMessage() loop (servicing all possible work |
154 // queues), then Windows would try to achieve the following order according | 238 // queues), then Windows would try to achieve the following order according |
155 // to MSDN documentation about PeekMessage with no filter): | 239 // to MSDN documentation about PeekMessage with no filter): |
156 // * Sent messages | 240 // * Sent messages |
157 // * Posted messages | 241 // * Posted messages |
158 // * Sent messages (again) | 242 // * Sent messages (again) |
159 // * WM_PAINT messages | 243 // * WM_PAINT messages |
(...skipping 20 matching lines...) Expand all Loading... | |
180 if (state_->should_quit) | 264 if (state_->should_quit) |
181 break; | 265 break; |
182 | 266 |
183 more_work_is_plausible |= | 267 more_work_is_plausible |= |
184 state_->delegate->DoDelayedWork(&delayed_work_time_); | 268 state_->delegate->DoDelayedWork(&delayed_work_time_); |
185 // If we did not process any delayed work, then we can assume that our | 269 // If we did not process any delayed work, then we can assume that our |
186 // existing WM_TIMER if any will fire when delayed work should run. We | 270 // existing WM_TIMER if any will fire when delayed work should run. We |
187 // don't want to disturb that timer if it is already in flight. However, | 271 // don't want to disturb that timer if it is already in flight. However, |
188 // if we did do all remaining delayed work, then lets kill the WM_TIMER. | 272 // if we did do all remaining delayed work, then lets kill the WM_TIMER. |
189 if (more_work_is_plausible && delayed_work_time_.is_null()) | 273 if (more_work_is_plausible && delayed_work_time_.is_null()) |
190 KillTimer(message_hwnd_, reinterpret_cast<UINT_PTR>(this)); | 274 g_kill_timer(message_hwnd_, reinterpret_cast<UINT_PTR>(this)); |
191 if (state_->should_quit) | 275 if (state_->should_quit) |
192 break; | 276 break; |
193 | 277 |
194 if (more_work_is_plausible) | 278 if (more_work_is_plausible) |
195 continue; | 279 continue; |
196 | 280 |
197 more_work_is_plausible = state_->delegate->DoIdleWork(); | 281 more_work_is_plausible = state_->delegate->DoIdleWork(); |
198 if (state_->should_quit) | 282 if (state_->should_quit) |
199 break; | 283 break; |
200 | 284 |
201 if (more_work_is_plausible) | 285 if (more_work_is_plausible) |
202 continue; | 286 continue; |
203 | 287 |
204 WaitForWork(); // Wait (sleep) until we have work to do again. | 288 WaitForWork(); // Wait (sleep) until we have work to do again. |
205 } | 289 } |
206 } | 290 } |
207 | 291 |
208 void MessagePumpForUI::InitMessageWnd() { | 292 void MessagePumpForUI::InitMessageWnd() { |
209 // Generate a unique window class name. | 293 // Generate a unique window class name. |
210 string16 class_name = StringPrintf(kWndClassFormat, this); | 294 string16 class_name = StringPrintf(kWndClassFormat, this); |
211 | 295 |
212 HINSTANCE instance = CURRENT_MODULE(); | 296 HINSTANCE instance = CURRENT_MODULE(); |
213 WNDCLASSEX wc = {0}; | 297 WNDCLASSEX wc = {0}; |
214 wc.cbSize = sizeof(wc); | 298 wc.cbSize = sizeof(wc); |
215 wc.lpfnWndProc = base::win::WrappedWindowProc<WndProcThunk>; | 299 wc.lpfnWndProc = base::win::WrappedWindowProc<WndProcThunk>; |
216 wc.hInstance = instance; | 300 wc.hInstance = instance; |
217 wc.lpszClassName = class_name.c_str(); | 301 wc.lpszClassName = class_name.c_str(); |
218 atom_ = RegisterClassEx(&wc); | 302 atom_ = g_register_class(&wc); |
219 DCHECK(atom_); | 303 DCHECK(atom_); |
220 | 304 |
221 message_hwnd_ = CreateWindow(MAKEINTATOM(atom_), 0, 0, 0, 0, 0, 0, | 305 message_hwnd_ = g_create_window_ex(0, MAKEINTATOM(atom_), 0, 0, 0, 0, 0, 0, |
222 HWND_MESSAGE, 0, instance, 0); | 306 HWND_MESSAGE, 0, instance, 0); |
223 DCHECK(message_hwnd_); | 307 DCHECK(message_hwnd_); |
224 } | 308 } |
225 | 309 |
226 void MessagePumpForUI::WaitForWork() { | 310 void MessagePumpForUI::WaitForWork() { |
227 // Wait until a message is available, up to the time needed by the timer | 311 // Wait until a message is available, up to the time needed by the timer |
228 // manager to fire the next set of timers. | 312 // manager to fire the next set of timers. |
229 int delay; | 313 int delay; |
230 DWORD wait_flags = MWMO_INPUTAVAILABLE; | 314 DWORD wait_flags = MWMO_INPUTAVAILABLE; |
231 | 315 |
232 while ((delay = GetCurrentDelay()) != 0) { | 316 while ((delay = GetCurrentDelay()) != 0) { |
233 if (delay < 0) // Negative value means no timers waiting. | 317 if (delay < 0) // Negative value means no timers waiting. |
234 delay = INFINITE; | 318 delay = INFINITE; |
235 | 319 |
236 DWORD result = | 320 DWORD result = g_msg_wait_for_multiple_objects_ex(0, NULL, delay, |
237 MsgWaitForMultipleObjectsEx(0, NULL, delay, QS_ALLINPUT, wait_flags); | 321 QS_ALLINPUT, wait_flags); |
238 | 322 |
239 if (WAIT_OBJECT_0 == result) { | 323 if (WAIT_OBJECT_0 == result) { |
240 // A WM_* message is available. | 324 // A WM_* message is available. |
241 // If a parent child relationship exists between windows across threads | 325 // If a parent child relationship exists between windows across threads |
242 // then their thread inputs are implicitly attached. | 326 // then their thread inputs are implicitly attached. |
243 // This causes the MsgWaitForMultipleObjectsEx API to return indicating | 327 // This causes the MsgWaitForMultipleObjectsEx API to return indicating |
244 // that messages are ready for processing (Specifically, mouse messages | 328 // that messages are ready for processing (Specifically, mouse messages |
245 // intended for the child window may appear if the child window has | 329 // intended for the child window may appear if the child window has |
246 // capture). | 330 // capture). |
247 // The subsequent PeekMessages call may fail to return any messages thus | 331 // The subsequent PeekMessages call may fail to return any messages thus |
248 // causing us to enter a tight loop at times. | 332 // causing us to enter a tight loop at times. |
249 // The code below is a workaround to give the child window | 333 // The code below is a workaround to give the child window |
250 // some time to process its input messages by looping back to | 334 // some time to process its input messages by looping back to |
251 // MsgWaitForMultipleObjectsEx above when there are no messages for the | 335 // MsgWaitForMultipleObjectsEx above when there are no messages for the |
252 // current thread. | 336 // current thread. |
253 MSG msg = {0}; | 337 MSG msg = {0}; |
254 bool has_pending_sent_message = | 338 bool has_pending_sent_message = |
255 (HIWORD(GetQueueStatus(QS_SENDMESSAGE)) & QS_SENDMESSAGE) != 0; | 339 (HIWORD(g_get_queue_status(QS_SENDMESSAGE)) & QS_SENDMESSAGE) != 0; |
256 if (has_pending_sent_message || | 340 if (has_pending_sent_message || |
257 PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { | 341 g_peek_message(&msg, NULL, 0, 0, PM_NOREMOVE)) { |
258 return; | 342 return; |
259 } | 343 } |
260 | 344 |
261 // We know there are no more messages for this thread because PeekMessage | 345 // We know there are no more messages for this thread because PeekMessage |
262 // has returned false. Reset |wait_flags| so that we wait for a *new* | 346 // has returned false. Reset |wait_flags| so that we wait for a *new* |
263 // message. | 347 // message. |
264 wait_flags = 0; | 348 wait_flags = 0; |
265 } | 349 } |
266 | 350 |
267 DCHECK_NE(WAIT_FAILED, result) << GetLastError(); | 351 DCHECK_NE(WAIT_FAILED, result) << GetLastError(); |
(...skipping 17 matching lines...) Expand all Loading... | |
285 | 369 |
286 // Now give the delegate a chance to do some work. He'll let us know if he | 370 // Now give the delegate a chance to do some work. He'll let us know if he |
287 // needs to do more work. | 371 // needs to do more work. |
288 if (state_->delegate->DoWork()) | 372 if (state_->delegate->DoWork()) |
289 ScheduleWork(); | 373 ScheduleWork(); |
290 state_->delegate->DoDelayedWork(&delayed_work_time_); | 374 state_->delegate->DoDelayedWork(&delayed_work_time_); |
291 RescheduleTimer(); | 375 RescheduleTimer(); |
292 } | 376 } |
293 | 377 |
294 void MessagePumpForUI::HandleTimerMessage() { | 378 void MessagePumpForUI::HandleTimerMessage() { |
295 KillTimer(message_hwnd_, reinterpret_cast<UINT_PTR>(this)); | 379 g_kill_timer(message_hwnd_, reinterpret_cast<UINT_PTR>(this)); |
296 | 380 |
297 // If we are being called outside of the context of Run, then don't do | 381 // If we are being called outside of the context of Run, then don't do |
298 // anything. This could correspond to a MessageBox call or something of | 382 // anything. This could correspond to a MessageBox call or something of |
299 // that sort. | 383 // that sort. |
300 if (!state_) | 384 if (!state_) |
301 return; | 385 return; |
302 | 386 |
303 state_->delegate->DoDelayedWork(&delayed_work_time_); | 387 state_->delegate->DoDelayedWork(&delayed_work_time_); |
304 RescheduleTimer(); | 388 RescheduleTimer(); |
305 } | 389 } |
(...skipping 24 matching lines...) Expand all Loading... | |
330 int delay_msec = GetCurrentDelay(); | 414 int delay_msec = GetCurrentDelay(); |
331 DCHECK_GE(delay_msec, 0); | 415 DCHECK_GE(delay_msec, 0); |
332 if (delay_msec == 0) { | 416 if (delay_msec == 0) { |
333 ScheduleWork(); | 417 ScheduleWork(); |
334 } else { | 418 } else { |
335 if (delay_msec < USER_TIMER_MINIMUM) | 419 if (delay_msec < USER_TIMER_MINIMUM) |
336 delay_msec = USER_TIMER_MINIMUM; | 420 delay_msec = USER_TIMER_MINIMUM; |
337 | 421 |
338 // Create a WM_TIMER event that will wake us up to check for any pending | 422 // Create a WM_TIMER event that will wake us up to check for any pending |
339 // timers (in case we are running within a nested, external sub-pump). | 423 // timers (in case we are running within a nested, external sub-pump). |
340 BOOL ret = SetTimer(message_hwnd_, reinterpret_cast<UINT_PTR>(this), | 424 BOOL ret = g_set_timer(message_hwnd_, reinterpret_cast<UINT_PTR>(this), |
341 delay_msec, NULL); | 425 delay_msec, NULL); |
342 if (ret) | 426 if (ret) |
343 return; | 427 return; |
344 // If we can't set timers, we are in big trouble... but cross our fingers | 428 // If we can't set timers, we are in big trouble... but cross our fingers |
345 // for now. | 429 // for now. |
346 // TODO(jar): If we don't see this error, use a CHECK() here instead. | 430 // TODO(jar): If we don't see this error, use a CHECK() here instead. |
347 UMA_HISTOGRAM_ENUMERATION("Chrome.MessageLoopProblem", SET_TIMER_ERROR, | 431 UMA_HISTOGRAM_ENUMERATION("Chrome.MessageLoopProblem", SET_TIMER_ERROR, |
348 MESSAGE_LOOP_PROBLEM_MAX); | 432 MESSAGE_LOOP_PROBLEM_MAX); |
349 } | 433 } |
350 } | 434 } |
351 | 435 |
352 bool MessagePumpForUI::ProcessNextWindowsMessage() { | 436 bool MessagePumpForUI::ProcessNextWindowsMessage() { |
353 // If there are sent messages in the queue then PeekMessage internally | 437 // If there are sent messages in the queue then PeekMessage internally |
354 // dispatches the message and returns false. We return true in this | 438 // dispatches the message and returns false. We return true in this |
355 // case to ensure that the message loop peeks again instead of calling | 439 // case to ensure that the message loop peeks again instead of calling |
356 // MsgWaitForMultipleObjectsEx again. | 440 // MsgWaitForMultipleObjectsEx again. |
357 bool sent_messages_in_queue = false; | 441 bool sent_messages_in_queue = false; |
358 DWORD queue_status = GetQueueStatus(QS_SENDMESSAGE); | 442 DWORD queue_status = g_get_queue_status(QS_SENDMESSAGE); |
359 if (HIWORD(queue_status) & QS_SENDMESSAGE) | 443 if (HIWORD(queue_status) & QS_SENDMESSAGE) |
360 sent_messages_in_queue = true; | 444 sent_messages_in_queue = true; |
361 | 445 |
362 MSG msg; | 446 MSG msg; |
363 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) != FALSE) | 447 if (g_peek_message(&msg, NULL, 0, 0, PM_REMOVE) != FALSE) |
364 return ProcessMessageHelper(msg); | 448 return ProcessMessageHelper(msg); |
365 | 449 |
366 return sent_messages_in_queue; | 450 return sent_messages_in_queue; |
367 } | 451 } |
368 | 452 |
369 bool MessagePumpForUI::ProcessMessageHelper(const MSG& msg) { | 453 bool MessagePumpForUI::ProcessMessageHelper(const MSG& msg) { |
370 TRACE_EVENT1("base", "MessagePumpForUI::ProcessMessageHelper", | 454 TRACE_EVENT1("base", "MessagePumpForUI::ProcessMessageHelper", |
371 "message", msg.message); | 455 "message", msg.message); |
372 if (WM_QUIT == msg.message) { | 456 if (WM_QUIT == msg.message) { |
373 // Repost the QUIT message so that it will be retrieved by the primary | 457 // Repost the QUIT message so that it will be retrieved by the primary |
374 // GetMessage() loop. | 458 // GetMessage() loop. |
375 state_->should_quit = true; | 459 state_->should_quit = true; |
376 PostQuitMessage(static_cast<int>(msg.wParam)); | 460 g_post_quit(static_cast<int>(msg.wParam)); |
377 return false; | 461 return false; |
378 } | 462 } |
379 | 463 |
380 // While running our main message pump, we discard kMsgHaveWork messages. | 464 // While running our main message pump, we discard kMsgHaveWork messages. |
381 if (msg.message == kMsgHaveWork && msg.hwnd == message_hwnd_) | 465 if (msg.message == kMsgHaveWork && msg.hwnd == message_hwnd_) |
382 return ProcessPumpReplacementMessage(); | 466 return ProcessPumpReplacementMessage(); |
383 | 467 |
384 if (CallMsgFilter(const_cast<MSG*>(&msg), kMessageFilterCode)) | 468 if (g_call_msg_filter(const_cast<MSG*>(&msg), kMessageFilterCode)) |
385 return true; | 469 return true; |
386 | 470 |
387 TranslateMessage(&msg); | 471 g_translate_message(&msg); |
388 DispatchMessage(&msg); | 472 g_dispatch_message(&msg); |
389 | 473 |
390 return true; | 474 return true; |
391 } | 475 } |
392 | 476 |
393 bool MessagePumpForUI::ProcessPumpReplacementMessage() { | 477 bool MessagePumpForUI::ProcessPumpReplacementMessage() { |
394 // When we encounter a kMsgHaveWork message, this method is called to peek and | 478 // When we encounter a kMsgHaveWork message, this method is called to peek and |
395 // process a replacement message. The goal is to make the kMsgHaveWork as non- | 479 // process a replacement message. The goal is to make the kMsgHaveWork as non- |
396 // intrusive as possible, even though a continuous stream of such messages are | 480 // intrusive as possible, even though a continuous stream of such messages are |
397 // posted. This method carefully peeks a message while there is no chance for | 481 // posted. This method carefully peeks a message while there is no chance for |
398 // a kMsgHaveWork to be pending, then resets the |have_work_| flag (allowing a | 482 // a kMsgHaveWork to be pending, then resets the |have_work_| flag (allowing a |
399 // replacement kMsgHaveWork to possibly be posted), and finally dispatches | 483 // replacement kMsgHaveWork to possibly be posted), and finally dispatches |
400 // that peeked replacement. Note that the re-post of kMsgHaveWork may be | 484 // that peeked replacement. Note that the re-post of kMsgHaveWork may be |
401 // asynchronous to this thread!! | 485 // asynchronous to this thread!! |
402 | 486 |
403 MSG msg; | 487 MSG msg; |
404 const bool have_message = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) != FALSE; | 488 const bool have_message = |
489 g_peek_message(&msg, NULL, 0, 0, PM_REMOVE) != FALSE; | |
405 | 490 |
406 // Expect no message or a message different than kMsgHaveWork. | 491 // Expect no message or a message different than kMsgHaveWork. |
407 DCHECK(!have_message || kMsgHaveWork != msg.message || | 492 DCHECK(!have_message || kMsgHaveWork != msg.message || |
408 msg.hwnd != message_hwnd_); | 493 msg.hwnd != message_hwnd_); |
409 | 494 |
410 // Since we discarded a kMsgHaveWork message, we must update the flag. | 495 // Since we discarded a kMsgHaveWork message, we must update the flag. |
411 int old_work_state_ = InterlockedExchange(&work_state_, READY); | 496 int old_work_state_ = InterlockedExchange(&work_state_, READY); |
412 DCHECK_EQ(HAVE_WORK, old_work_state_); | 497 DCHECK_EQ(HAVE_WORK, old_work_state_); |
413 | 498 |
414 // We don't need a special time slice if we didn't have_message to process. | 499 // We don't need a special time slice if we didn't have_message to process. |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
524 if (delay < 0) // Negative value means no timers waiting. | 609 if (delay < 0) // Negative value means no timers waiting. |
525 delay = INFINITE; | 610 delay = INFINITE; |
526 | 611 |
527 // TODO(stanisc): crbug.com/596190: Preserve for crash dump analysis. | 612 // TODO(stanisc): crbug.com/596190: Preserve for crash dump analysis. |
528 // Remove this when the bug is fixed. | 613 // Remove this when the bug is fixed. |
529 TimeTicks wait_for_work_timeticks = TimeTicks::Now(); | 614 TimeTicks wait_for_work_timeticks = TimeTicks::Now(); |
530 debug::Alias(&wait_for_work_timeticks); | 615 debug::Alias(&wait_for_work_timeticks); |
531 debug::Alias(&delay); | 616 debug::Alias(&delay); |
532 | 617 |
533 DWORD result = | 618 DWORD result = |
534 MsgWaitForMultipleObjectsEx(1, &event_, delay, QS_ALLINPUT, 0); | 619 g_msg_wait_for_multiple_objects_ex(1, &event_, delay, QS_ALLINPUT, 0); |
535 DCHECK_NE(WAIT_FAILED, result) << GetLastError(); | 620 DCHECK_NE(WAIT_FAILED, result) << GetLastError(); |
536 if (result != WAIT_TIMEOUT) { | 621 if (result != WAIT_TIMEOUT) { |
537 // Either work or message available. | 622 // Either work or message available. |
538 return; | 623 return; |
539 } | 624 } |
540 } | 625 } |
541 } | 626 } |
542 | 627 |
543 bool MessagePumpForGpu::ProcessNextMessage() { | 628 bool MessagePumpForGpu::ProcessNextMessage() { |
544 MSG msg; | 629 MSG msg; |
545 if (!PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) | 630 if (!g_peek_message(&msg, nullptr, 0, 0, PM_REMOVE)) |
546 return false; | 631 return false; |
547 | 632 |
548 if (msg.message == WM_QUIT) { | 633 if (msg.message == WM_QUIT) { |
549 // Repost the QUIT message so that it will be retrieved by the primary | 634 // Repost the QUIT message so that it will be retrieved by the primary |
550 // GetMessage() loop. | 635 // GetMessage() loop. |
551 state_->should_quit = true; | 636 state_->should_quit = true; |
552 PostQuitMessage(static_cast<int>(msg.wParam)); | 637 g_post_quit(static_cast<int>(msg.wParam)); |
553 return false; | 638 return false; |
554 } | 639 } |
555 | 640 |
556 if (!CallMsgFilter(const_cast<MSG*>(&msg), kMessageFilterCode)) { | 641 if (!g_call_msg_filter(const_cast<MSG*>(&msg), kMessageFilterCode)) { |
557 TranslateMessage(&msg); | 642 g_translate_message(&msg); |
558 DispatchMessage(&msg); | 643 g_dispatch_message(&msg); |
559 } | 644 } |
560 | 645 |
561 return true; | 646 return true; |
562 } | 647 } |
563 | 648 |
564 //----------------------------------------------------------------------------- | 649 //----------------------------------------------------------------------------- |
565 // MessagePumpForIO public: | 650 // MessagePumpForIO public: |
566 | 651 |
567 MessagePumpForIO::IOContext::IOContext() { | 652 MessagePumpForIO::IOContext::IOContext() { |
568 memset(&overlapped, 0, sizeof(overlapped)); | 653 memset(&overlapped, 0, sizeof(overlapped)); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
732 if (!filter || it->handler == filter) { | 817 if (!filter || it->handler == filter) { |
733 *item = *it; | 818 *item = *it; |
734 completed_io_.erase(it); | 819 completed_io_.erase(it); |
735 return true; | 820 return true; |
736 } | 821 } |
737 } | 822 } |
738 return false; | 823 return false; |
739 } | 824 } |
740 | 825 |
741 } // namespace base | 826 } // namespace base |
OLD | NEW |