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

Side by Side Diff: base/message_loop/message_pump_win.cc

Issue 839143002: Roll Chrome into Mojo. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Rebase Created 5 years, 11 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
« no previous file with comments | « base/mac/mac_util_unittest.mm ('k') | base/nix/xdg_util.cc » ('j') | 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) 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 8
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 314
315 state_->delegate->DoDelayedWork(&delayed_work_time_); 315 state_->delegate->DoDelayedWork(&delayed_work_time_);
316 if (!delayed_work_time_.is_null()) { 316 if (!delayed_work_time_.is_null()) {
317 // A bit gratuitous to set delayed_work_time_ again, but oh well. 317 // A bit gratuitous to set delayed_work_time_ again, but oh well.
318 ScheduleDelayedWork(delayed_work_time_); 318 ScheduleDelayedWork(delayed_work_time_);
319 } 319 }
320 } 320 }
321 321
322 bool MessagePumpForUI::ProcessNextWindowsMessage() { 322 bool MessagePumpForUI::ProcessNextWindowsMessage() {
323 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440919 is fixed. 323 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440919 is fixed.
324 tracked_objects::ScopedTracker tracking_profile( 324 tracked_objects::ScopedTracker tracking_profile1(
325 FROM_HERE_WITH_EXPLICIT_FUNCTION( 325 FROM_HERE_WITH_EXPLICIT_FUNCTION(
326 "440919 <<MessagePumpForUI::ProcessNextWindowsMessage>>")); 326 "440919 MessagePumpForUI::ProcessNextWindowsMessage1"));
327 327
328 // If there are sent messages in the queue then PeekMessage internally 328 // If there are sent messages in the queue then PeekMessage internally
329 // dispatches the message and returns false. We return true in this 329 // dispatches the message and returns false. We return true in this
330 // case to ensure that the message loop peeks again instead of calling 330 // case to ensure that the message loop peeks again instead of calling
331 // MsgWaitForMultipleObjectsEx again. 331 // MsgWaitForMultipleObjectsEx again.
332 bool sent_messages_in_queue = false; 332 bool sent_messages_in_queue = false;
333 DWORD queue_status = GetQueueStatus(QS_SENDMESSAGE); 333 DWORD queue_status = GetQueueStatus(QS_SENDMESSAGE);
334 if (HIWORD(queue_status) & QS_SENDMESSAGE) 334 if (HIWORD(queue_status) & QS_SENDMESSAGE)
335 sent_messages_in_queue = true; 335 sent_messages_in_queue = true;
336 336
337 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440919 is fixed.
338 tracked_objects::ScopedTracker tracking_profile2(
339 FROM_HERE_WITH_EXPLICIT_FUNCTION(
340 "440919 MessagePumpForUI::ProcessNextWindowsMessage2"));
341
337 MSG msg; 342 MSG msg;
338 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) != FALSE) 343 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) != FALSE)
339 return ProcessMessageHelper(msg); 344 return ProcessMessageHelper(msg);
340 345
341 return sent_messages_in_queue; 346 return sent_messages_in_queue;
342 } 347 }
343 348
344 bool MessagePumpForUI::ProcessMessageHelper(const MSG& msg) { 349 bool MessagePumpForUI::ProcessMessageHelper(const MSG& msg) {
350 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440919 is fixed.
351 tracked_objects::ScopedTracker tracking_profile1(
352 FROM_HERE_WITH_EXPLICIT_FUNCTION(
353 "440919 MessagePumpForUI::ProcessMessageHelper1"));
354
345 TRACE_EVENT1("base", "MessagePumpForUI::ProcessMessageHelper", 355 TRACE_EVENT1("base", "MessagePumpForUI::ProcessMessageHelper",
346 "message", msg.message); 356 "message", msg.message);
347 if (WM_QUIT == msg.message) { 357 if (WM_QUIT == msg.message) {
348 // Repost the QUIT message so that it will be retrieved by the primary 358 // Repost the QUIT message so that it will be retrieved by the primary
349 // GetMessage() loop. 359 // GetMessage() loop.
350 state_->should_quit = true; 360 state_->should_quit = true;
351 PostQuitMessage(static_cast<int>(msg.wParam)); 361 PostQuitMessage(static_cast<int>(msg.wParam));
352 return false; 362 return false;
353 } 363 }
354 364
355 // While running our main message pump, we discard kMsgHaveWork messages. 365 // While running our main message pump, we discard kMsgHaveWork messages.
356 if (msg.message == kMsgHaveWork && msg.hwnd == message_hwnd_) 366 if (msg.message == kMsgHaveWork && msg.hwnd == message_hwnd_)
357 return ProcessPumpReplacementMessage(); 367 return ProcessPumpReplacementMessage();
358 368
369 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440919 is fixed.
370 tracked_objects::ScopedTracker tracking_profile2(
371 FROM_HERE_WITH_EXPLICIT_FUNCTION(
372 "440919 MessagePumpForUI::ProcessMessageHelper2"));
373
359 if (CallMsgFilter(const_cast<MSG*>(&msg), kMessageFilterCode)) 374 if (CallMsgFilter(const_cast<MSG*>(&msg), kMessageFilterCode))
360 return true; 375 return true;
361 376
377 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440919 is fixed.
378 tracked_objects::ScopedTracker tracking_profile3(
379 FROM_HERE_WITH_EXPLICIT_FUNCTION(
380 "440919 MessagePumpForUI::ProcessMessageHelper3"));
381
362 uint32_t action = MessagePumpDispatcher::POST_DISPATCH_PERFORM_DEFAULT; 382 uint32_t action = MessagePumpDispatcher::POST_DISPATCH_PERFORM_DEFAULT;
363 if (state_->dispatcher) 383 if (state_->dispatcher)
364 action = state_->dispatcher->Dispatch(msg); 384 action = state_->dispatcher->Dispatch(msg);
365 if (action & MessagePumpDispatcher::POST_DISPATCH_QUIT_LOOP) 385 if (action & MessagePumpDispatcher::POST_DISPATCH_QUIT_LOOP)
366 state_->should_quit = true; 386 state_->should_quit = true;
367 if (action & MessagePumpDispatcher::POST_DISPATCH_PERFORM_DEFAULT) { 387 if (action & MessagePumpDispatcher::POST_DISPATCH_PERFORM_DEFAULT) {
368 TranslateMessage(&msg); 388 TranslateMessage(&msg);
369 DispatchMessage(&msg); 389 DispatchMessage(&msg);
370 } 390 }
371 391
372 return true; 392 return true;
373 } 393 }
374 394
375 bool MessagePumpForUI::ProcessPumpReplacementMessage() { 395 bool MessagePumpForUI::ProcessPumpReplacementMessage() {
396 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440919 is fixed.
397 tracked_objects::ScopedTracker tracking_profile(
398 FROM_HERE_WITH_EXPLICIT_FUNCTION(
399 "440919 MessagePumpForUI::ProcessPumpReplacementMessage"));
400
376 // When we encounter a kMsgHaveWork message, this method is called to peek 401 // When we encounter a kMsgHaveWork message, this method is called to peek
377 // and process a replacement message, such as a WM_PAINT or WM_TIMER. The 402 // and process a replacement message, such as a WM_PAINT or WM_TIMER. The
378 // goal is to make the kMsgHaveWork as non-intrusive as possible, even though 403 // goal is to make the kMsgHaveWork as non-intrusive as possible, even though
379 // a continuous stream of such messages are posted. This method carefully 404 // a continuous stream of such messages are posted. This method carefully
380 // peeks a message while there is no chance for a kMsgHaveWork to be pending, 405 // peeks a message while there is no chance for a kMsgHaveWork to be pending,
381 // then resets the have_work_ flag (allowing a replacement kMsgHaveWork to 406 // then resets the have_work_ flag (allowing a replacement kMsgHaveWork to
382 // possibly be posted), and finally dispatches that peeked replacement. Note 407 // possibly be posted), and finally dispatches that peeked replacement. Note
383 // that the re-post of kMsgHaveWork may be asynchronous to this thread!! 408 // that the re-post of kMsgHaveWork may be asynchronous to this thread!!
384 409
385 bool have_message = false; 410 bool have_message = false;
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 658
634 // static 659 // static
635 MessagePumpForIO::IOHandler* MessagePumpForIO::KeyToHandler( 660 MessagePumpForIO::IOHandler* MessagePumpForIO::KeyToHandler(
636 ULONG_PTR key, 661 ULONG_PTR key,
637 bool* has_valid_io_context) { 662 bool* has_valid_io_context) {
638 *has_valid_io_context = ((key & 1) == 0); 663 *has_valid_io_context = ((key & 1) == 0);
639 return reinterpret_cast<IOHandler*>(key & ~static_cast<ULONG_PTR>(1)); 664 return reinterpret_cast<IOHandler*>(key & ~static_cast<ULONG_PTR>(1));
640 } 665 }
641 666
642 } // namespace base 667 } // namespace base
OLDNEW
« no previous file with comments | « base/mac/mac_util_unittest.mm ('k') | base/nix/xdg_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698