Chromium Code Reviews| 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_H_ | 5 #ifndef BASE_MESSAGE_LOOP_H_ |
| 6 #define BASE_MESSAGE_LOOP_H_ | 6 #define BASE_MESSAGE_LOOP_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 // | 60 // |
| 61 // NOTE: MessageLoop has task reentrancy protection. This means that if a | 61 // NOTE: MessageLoop has task reentrancy protection. This means that if a |
| 62 // task is being processed, a second task cannot start until the first task is | 62 // task is being processed, a second task cannot start until the first task is |
| 63 // finished. Reentrancy can happen when processing a task, and an inner | 63 // finished. Reentrancy can happen when processing a task, and an inner |
| 64 // message pump is created. That inner pump then processes native messages | 64 // message pump is created. That inner pump then processes native messages |
| 65 // which could implicitly start an inner task. Inner message pumps are created | 65 // which could implicitly start an inner task. Inner message pumps are created |
| 66 // with dialogs (DialogBox), common dialogs (GetOpenFileName), OLE functions | 66 // with dialogs (DialogBox), common dialogs (GetOpenFileName), OLE functions |
| 67 // (DoDragDrop), printer functions (StartDoc) and *many* others. | 67 // (DoDragDrop), printer functions (StartDoc) and *many* others. |
| 68 // | 68 // |
| 69 // Sample workaround when inner task processing is needed: | 69 // Sample workaround when inner task processing is needed: |
| 70 // bool old_state = MessageLoop::current()->NestableTasksAllowed(); | 70 // { |
| 71 // MessageLoop::current()->SetNestableTasksAllowed(true); | 71 // MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); |
| 72 // HRESULT hr = DoDragDrop(...); // Implicitly runs a modal message loop here. | 72 // HRESULT hr = DoDragDrop(...); // Implicitly runs a modal message loop. |
| 73 // MessageLoop::current()->SetNestableTasksAllowed(old_state); | 73 // } |
| 74 // // Process hr (the result returned by DoDragDrop(). | 74 // // Process |hr| (the result returned by DoDragDrop()). |
|
Ryan Sleevi
2012/02/11 02:17:22
Comment bug: |hr| is now out of scope once outside
dhollowa
2012/02/13 17:44:26
Done.
| |
| 75 // | 75 // |
| 76 // Please be SURE your task is reentrant (nestable) and all global variables | 76 // Please be SURE your task is reentrant (nestable) and all global variables |
| 77 // are stable and accessible before calling SetNestableTasksAllowed(true). | 77 // are stable and accessible before calling SetNestableTasksAllowed(true). |
| 78 // | 78 // |
| 79 class BASE_EXPORT MessageLoop : public base::MessagePump::Delegate { | 79 class BASE_EXPORT MessageLoop : public base::MessagePump::Delegate { |
| 80 public: | 80 public: |
| 81 #if defined(OS_WIN) | 81 #if defined(OS_WIN) |
| 82 typedef base::MessagePumpWin::Dispatcher Dispatcher; | 82 typedef base::MessagePumpWin::Dispatcher Dispatcher; |
| 83 typedef base::MessagePumpObserver Observer; | 83 typedef base::MessagePumpObserver Observer; |
| 84 #elif !defined(OS_MACOSX) && !defined(OS_ANDROID) | 84 #elif !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| (...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 659 #endif // defined(OS_POSIX) | 659 #endif // defined(OS_POSIX) |
| 660 }; | 660 }; |
| 661 | 661 |
| 662 // Do not add any member variables to MessageLoopForIO! This is important b/c | 662 // Do not add any member variables to MessageLoopForIO! This is important b/c |
| 663 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 663 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
| 664 // data that you need should be stored on the MessageLoop's pump_ instance. | 664 // data that you need should be stored on the MessageLoop's pump_ instance. |
| 665 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 665 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
| 666 MessageLoopForIO_should_not_have_extra_member_variables); | 666 MessageLoopForIO_should_not_have_extra_member_variables); |
| 667 | 667 |
| 668 #endif // BASE_MESSAGE_LOOP_H_ | 668 #endif // BASE_MESSAGE_LOOP_H_ |
| OLD | NEW |