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

Side by Side Diff: base/message_pump_win.cc

Issue 6021: This fixes http://code.google.com/p/chromium/issues/detail?id=772,... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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_pump_win.h" 5 #include "base/message_pump_win.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include "base/histogram.h" 9 #include "base/histogram.h"
10 #include "base/win_util.h" 10 #include "base/win_util.h"
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 return; 206 return;
207 207
208 state_->delegate->DoDelayedWork(&delayed_work_time_); 208 state_->delegate->DoDelayedWork(&delayed_work_time_);
209 if (!delayed_work_time_.is_null()) { 209 if (!delayed_work_time_.is_null()) {
210 // A bit gratuitous to set delayed_work_time_ again, but oh well. 210 // A bit gratuitous to set delayed_work_time_ again, but oh well.
211 ScheduleDelayedWork(delayed_work_time_); 211 ScheduleDelayedWork(delayed_work_time_);
212 } 212 }
213 } 213 }
214 214
215 bool MessagePumpWin::ProcessNextWindowsMessage() { 215 bool MessagePumpWin::ProcessNextWindowsMessage() {
216 // If there are sent messages in the queue then PeekMessage internally
217 // dispatches the message and returns false. We return true in this
218 // case to ensure that the message loop peeks again instead of calling
219 // MsgWaitForMultipleObjectsEx again.
220 bool sent_messages_in_queue = false;
221 DWORD queue_status = GetQueueStatus(QS_SENDMESSAGE);
222 if (HIWORD(queue_status) & QS_SENDMESSAGE)
223 sent_messages_in_queue = true;
224
216 MSG msg; 225 MSG msg;
217 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) 226 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
218 return ProcessMessageHelper(msg); 227 return ProcessMessageHelper(msg);
219 return false; 228
229 return sent_messages_in_queue;
220 } 230 }
221 231
222 bool MessagePumpWin::ProcessMessageHelper(const MSG& msg) { 232 bool MessagePumpWin::ProcessMessageHelper(const MSG& msg) {
223 if (WM_QUIT == msg.message) { 233 if (WM_QUIT == msg.message) {
224 // Repost the QUIT message so that it will be retrieved by the primary 234 // Repost the QUIT message so that it will be retrieved by the primary
225 // GetMessage() loop. 235 // GetMessage() loop.
226 state_->should_quit = true; 236 state_->should_quit = true;
227 PostQuitMessage(static_cast<int>(msg.wParam)); 237 PostQuitMessage(static_cast<int>(msg.wParam));
228 return false; 238 return false;
229 } 239 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 // Wait until a message is available, up to the time needed by the timer 361 // Wait until a message is available, up to the time needed by the timer
352 // manager to fire the next set of timers. 362 // manager to fire the next set of timers.
353 int delay = GetCurrentDelay(); 363 int delay = GetCurrentDelay();
354 if (delay < 0) // Negative value means no timers waiting. 364 if (delay < 0) // Negative value means no timers waiting.
355 delay = INFINITE; 365 delay = INFINITE;
356 366
357 DWORD result; 367 DWORD result;
358 result = MsgWaitForMultipleObjectsEx(0, NULL, delay, QS_ALLINPUT, 368 result = MsgWaitForMultipleObjectsEx(0, NULL, delay, QS_ALLINPUT,
359 MWMO_INPUTAVAILABLE); 369 MWMO_INPUTAVAILABLE);
360 370
361 if (WAIT_OBJECT_0 == result) 371 if (WAIT_OBJECT_0 == result) {
362 return; // A WM_* message is available. 372 // A WM_* message is available.
373 // If a parent child relationship exists between windows across threads
374 // then their thread inputs are implicitly attached.
375 // This causes the MsgWaitForMultipleObjectsEx API to return indicating
376 // that messages are ready for processing (specifically mouse messages
377 // intended for the child window. Occurs if the child window has capture)
378 // The subsequent PeekMessages call fails to return any messages thus
379 // causing us to enter a tight loop at times.
380 // The WaitMessage call below is a workaround to give the child window
381 // sometime to process its input messages.
382 MSG msg = {0};
383 DWORD queue_status = GetQueueStatus(QS_MOUSE);
384 if (HIWORD(queue_status) & QS_MOUSE &&
385 !PeekMessage(&msg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_NOREMOVE)) {
386 WaitMessage();
387 }
388 return;
389 }
363 390
364 DCHECK_NE(WAIT_FAILED, result) << GetLastError(); 391 DCHECK_NE(WAIT_FAILED, result) << GetLastError();
365 } 392 }
366 393
367 //----------------------------------------------------------------------------- 394 //-----------------------------------------------------------------------------
368 // MessagePumpForIO public: 395 // MessagePumpForIO public:
369 396
370 void MessagePumpForIO::WatchObject(HANDLE object, Watcher* watcher) { 397 void MessagePumpForIO::WatchObject(HANDLE object, Watcher* watcher) {
371 DCHECK(object); 398 DCHECK(object);
372 DCHECK_NE(object, INVALID_HANDLE_VALUE); 399 DCHECK_NE(object, INVALID_HANDLE_VALUE);
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 watchers_[object_index]->OnObjectSignaled(objects_[object_index]); 618 watchers_[object_index]->OnObjectSignaled(objects_[object_index]);
592 619
593 // Signaled objects tend to be removed from the watch list, and then added 620 // Signaled objects tend to be removed from the watch list, and then added
594 // back (appended). As a result, they move to the end of the objects_ array, 621 // back (appended). As a result, they move to the end of the objects_ array,
595 // and this should make their service "fair" (no HANDLEs should be starved). 622 // and this should make their service "fair" (no HANDLEs should be starved).
596 623
597 return true; 624 return true;
598 } 625 }
599 626
600 } // namespace base 627 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698