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 | 7 |
8 #include <queue> | 8 #include <queue> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 class RunLoop; | 46 class RunLoop; |
47 class ThreadTaskRunnerHandle; | 47 class ThreadTaskRunnerHandle; |
48 #if defined(OS_ANDROID) | 48 #if defined(OS_ANDROID) |
49 class MessagePumpForUI; | 49 class MessagePumpForUI; |
50 #endif | 50 #endif |
51 } // namespace base | 51 } // namespace base |
52 | 52 |
53 // A MessageLoop is used to process events for a particular thread. There is | 53 // A MessageLoop is used to process events for a particular thread. There is |
54 // at most one MessageLoop instance per thread. | 54 // at most one MessageLoop instance per thread. |
55 // | 55 // |
56 // Events include at a minimum Task instances submitted to PostTask or those | 56 // Events include at a minimum Task instances submitted to PostTask and its |
57 // managed by TimerManager. Depending on the type of message pump used by the | 57 // variants. Depending on the type of message pump used by the MessageLoop |
58 // MessageLoop other events such as UI messages may be processed. On Windows | 58 // other events such as UI messages may be processed. On Windows APC calls (as |
59 // APC calls (as time permits) and signals sent to a registered set of HANDLEs | 59 // time permits) and signals sent to a registered set of HANDLEs may also be |
60 // may also be processed. | 60 // processed. |
61 // | 61 // |
62 // NOTE: Unless otherwise specified, a MessageLoop's methods may only be called | 62 // NOTE: Unless otherwise specified, a MessageLoop's methods may only be called |
63 // on the thread where the MessageLoop's Run method executes. | 63 // on the thread where the MessageLoop's Run method executes. |
64 // | 64 // |
65 // NOTE: MessageLoop has task reentrancy protection. This means that if a | 65 // NOTE: MessageLoop has task reentrancy protection. This means that if a |
66 // task is being processed, a second task cannot start until the first task is | 66 // task is being processed, a second task cannot start until the first task is |
67 // finished. Reentrancy can happen when processing a task, and an inner | 67 // finished. Reentrancy can happen when processing a task, and an inner |
68 // message pump is created. That inner pump then processes native messages | 68 // message pump is created. That inner pump then processes native messages |
69 // which could implicitly start an inner task. Inner message pumps are created | 69 // which could implicitly start an inner task. Inner message pumps are created |
70 // with dialogs (DialogBox), common dialogs (GetOpenFileName), OLE functions | 70 // with dialogs (DialogBox), common dialogs (GetOpenFileName), OLE functions |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 // A recursion block that prevents accidentally running additional tasks when | 483 // A recursion block that prevents accidentally running additional tasks when |
484 // insider a (accidentally induced?) nested message pump. | 484 // insider a (accidentally induced?) nested message pump. |
485 bool nestable_tasks_allowed_; | 485 bool nestable_tasks_allowed_; |
486 | 486 |
487 bool exception_restoration_; | 487 bool exception_restoration_; |
488 | 488 |
489 std::string thread_name_; | 489 std::string thread_name_; |
490 // A profiling histogram showing the counts of various messages and events. | 490 // A profiling histogram showing the counts of various messages and events. |
491 base::Histogram* message_histogram_; | 491 base::Histogram* message_histogram_; |
492 | 492 |
493 // A null terminated list which creates an incoming_queue of tasks that are | 493 // An incoming queue of tasks that are acquired under a mutex for processing |
494 // acquired under a mutex for processing on this instance's thread. These | 494 // on this instance's thread. These tasks have not yet been sorted out into |
495 // tasks have not yet been sorted out into items for our work_queue_ vs items | 495 // items for our work_queue_ vs delayed_work_queue_. |
496 // that will be handled by the TimerManager. | |
497 base::TaskQueue incoming_queue_; | 496 base::TaskQueue incoming_queue_; |
498 // Protect access to incoming_queue_. | 497 // Protect access to incoming_queue_. |
499 mutable base::Lock incoming_queue_lock_; | 498 mutable base::Lock incoming_queue_lock_; |
500 | 499 |
501 base::RunLoop* run_loop_; | 500 base::RunLoop* run_loop_; |
502 | 501 |
503 #if defined(OS_WIN) | 502 #if defined(OS_WIN) |
504 base::TimeTicks high_resolution_timer_expiration_; | 503 base::TimeTicks high_resolution_timer_expiration_; |
505 // Should be set to true before calling Windows APIs like TrackPopupMenu, etc | 504 // Should be set to true before calling Windows APIs like TrackPopupMenu, etc |
506 // which enter a modal message loop. | 505 // which enter a modal message loop. |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 #endif // defined(OS_POSIX) | 697 #endif // defined(OS_POSIX) |
699 }; | 698 }; |
700 | 699 |
701 // Do not add any member variables to MessageLoopForIO! This is important b/c | 700 // Do not add any member variables to MessageLoopForIO! This is important b/c |
702 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 701 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
703 // data that you need should be stored on the MessageLoop's pump_ instance. | 702 // data that you need should be stored on the MessageLoop's pump_ instance. |
704 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 703 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
705 MessageLoopForIO_should_not_have_extra_member_variables); | 704 MessageLoopForIO_should_not_have_extra_member_variables); |
706 | 705 |
707 #endif // BASE_MESSAGE_LOOP_H_ | 706 #endif // BASE_MESSAGE_LOOP_H_ |
OLD | NEW |