OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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> |
11 | 11 |
12 #include "base/base_export.h" | 12 #include "base/base_export.h" |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/location.h" | 15 #include "base/location.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/message_loop_proxy.h" | 17 #include "base/message_loop_proxy.h" |
18 #include "base/message_pump.h" | 18 #include "base/message_pump.h" |
19 #include "base/observer_list.h" | 19 #include "base/observer_list.h" |
20 #include "base/synchronization/lock.h" | 20 #include "base/synchronization/lock.h" |
21 #include "base/task.h" | 21 #include "base/task.h" |
| 22 #include "base/tracking_info.h" |
22 #include "base/time.h" | 23 #include "base/time.h" |
23 | 24 |
24 #if defined(OS_WIN) | 25 #if defined(OS_WIN) |
25 // We need this to declare base::MessagePumpWin::Dispatcher, which we should | 26 // We need this to declare base::MessagePumpWin::Dispatcher, which we should |
26 // really just eliminate. | 27 // really just eliminate. |
27 #include "base/message_pump_win.h" | 28 #include "base/message_pump_win.h" |
28 #elif defined(OS_POSIX) | 29 #elif defined(OS_POSIX) |
29 #include "base/message_pump_libevent.h" | 30 #include "base/message_pump_libevent.h" |
30 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | 31 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
31 | 32 |
32 #if defined(USE_WAYLAND) | 33 #if defined(USE_WAYLAND) |
33 #include "base/message_pump_wayland.h" | 34 #include "base/message_pump_wayland.h" |
34 #elif defined(TOUCH_UI) || defined(USE_AURA) | 35 #elif defined(TOUCH_UI) || defined(USE_AURA) |
35 #include "base/message_pump_x.h" | 36 #include "base/message_pump_x.h" |
36 #else | 37 #else |
37 #include "base/message_pump_gtk.h" | 38 #include "base/message_pump_gtk.h" |
38 #endif | 39 #endif |
39 | 40 |
40 #endif | 41 #endif |
41 #endif | 42 #endif |
42 | 43 |
43 namespace base { | 44 namespace base { |
44 class Histogram; | 45 class Histogram; |
45 } | 46 } |
46 | 47 |
47 #if defined(TRACK_ALL_TASK_OBJECTS) | |
48 namespace tracked_objects { | 48 namespace tracked_objects { |
49 class Births; | 49 class Births; |
50 } | 50 } |
51 #endif // defined(TRACK_ALL_TASK_OBJECTS) | |
52 | 51 |
53 // A MessageLoop is used to process events for a particular thread. There is | 52 // A MessageLoop is used to process events for a particular thread. There is |
54 // at most one MessageLoop instance per thread. | 53 // at most one MessageLoop instance per thread. |
55 // | 54 // |
56 // Events include at a minimum Task instances submitted to PostTask or those | 55 // Events include at a minimum Task instances submitted to PostTask or those |
57 // managed by TimerManager. Depending on the type of message pump used by the | 56 // managed by TimerManager. Depending on the type of message pump used by the |
58 // MessageLoop other events such as UI messages may be processed. On Windows | 57 // MessageLoop other events such as UI messages may be processed. On Windows |
59 // APC calls (as time permits) and signals sent to a registered set of HANDLEs | 58 // APC calls (as time permits) and signals sent to a registered set of HANDLEs |
60 // may also be processed. | 59 // may also be processed. |
61 // | 60 // |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 ~AutoRunState(); | 402 ~AutoRunState(); |
404 private: | 403 private: |
405 MessageLoop* loop_; | 404 MessageLoop* loop_; |
406 RunState* previous_state_; | 405 RunState* previous_state_; |
407 }; | 406 }; |
408 #if defined(OS_ANDROID) | 407 #if defined(OS_ANDROID) |
409 protected: | 408 protected: |
410 #endif | 409 #endif |
411 | 410 |
412 // This structure is copied around by value. | 411 // This structure is copied around by value. |
413 struct PendingTask { | 412 struct PendingTask : public base::TrackingInfo { |
414 PendingTask(const base::Closure& task, | 413 PendingTask(const base::Closure& task, |
415 const tracked_objects::Location& posted_from, | 414 const tracked_objects::Location& posted_from, |
416 base::TimeTicks delayed_run_time, | 415 base::TimeTicks delayed_run_time, |
417 bool nestable); | 416 bool nestable); |
418 ~PendingTask(); | 417 ~PendingTask(); |
419 | 418 |
420 // Used to support sorting. | 419 // Used to support sorting. |
421 bool operator<(const PendingTask& other) const; | 420 bool operator<(const PendingTask& other) const; |
422 | 421 |
423 // The task to run. | 422 // The task to run. |
424 base::Closure task; | 423 base::Closure task; |
425 | 424 |
426 #if defined(TRACK_ALL_TASK_OBJECTS) | |
427 // Counter for location where the Closure was posted from. | |
428 tracked_objects::Births* post_births; | |
429 #endif // defined(TRACK_ALL_TASK_OBJECTS) | |
430 | |
431 // Time this PendingTask was posted. | |
432 base::TimeTicks time_posted; | |
433 | |
434 // The time when the task should be run. | |
435 base::TimeTicks delayed_run_time; | |
436 | |
437 // The site this PendingTask was posted from. | 425 // The site this PendingTask was posted from. |
438 tracked_objects::Location posted_from; | 426 tracked_objects::Location posted_from; |
439 | 427 |
440 // Secondary sort key for run time. | 428 // Secondary sort key for run time. |
441 int sequence_num; | 429 int sequence_num; |
442 | 430 |
443 // OK to dispatch from a nested loop. | 431 // OK to dispatch from a nested loop. |
444 bool nestable; | 432 bool nestable; |
445 }; | 433 }; |
446 | 434 |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 #endif // defined(OS_POSIX) | 699 #endif // defined(OS_POSIX) |
712 }; | 700 }; |
713 | 701 |
714 // Do not add any member variables to MessageLoopForIO! This is important b/c | 702 // Do not add any member variables to MessageLoopForIO! This is important b/c |
715 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 703 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
716 // data that you need should be stored on the MessageLoop's pump_ instance. | 704 // data that you need should be stored on the MessageLoop's pump_ instance. |
717 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 705 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
718 MessageLoopForIO_should_not_have_extra_member_variables); | 706 MessageLoopForIO_should_not_have_extra_member_variables); |
719 | 707 |
720 #endif // BASE_MESSAGE_LOOP_H_ | 708 #endif // BASE_MESSAGE_LOOP_H_ |
OLD | NEW |