OLD | NEW |
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 #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 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/histogram.h" | 12 #include "base/lock.h" |
13 #include "base/message_pump.h" | 13 #include "base/message_pump.h" |
14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
15 #include "base/ref_counted.h" | 15 #include "base/ref_counted.h" |
16 #include "base/scoped_ptr.h" | |
17 #include "base/task.h" | 16 #include "base/task.h" |
18 | 17 |
19 #if defined(OS_WIN) | 18 #if defined(OS_WIN) |
20 // We need this to declare base::MessagePumpWin::Dispatcher, which we should | 19 // We need this to declare base::MessagePumpWin::Dispatcher, which we should |
21 // really just eliminate. | 20 // really just eliminate. |
22 #include "base/message_pump_win.h" | 21 #include "base/message_pump_win.h" |
23 #elif defined(OS_POSIX) | 22 #elif defined(OS_POSIX) |
24 #include "base/message_pump_libevent.h" | 23 #include "base/message_pump_libevent.h" |
25 #if !defined(OS_MACOSX) | 24 #if !defined(OS_MACOSX) |
26 #include "base/message_pump_glib.h" | 25 #include "base/message_pump_glib.h" |
27 #endif | 26 #endif |
28 #endif | 27 #endif |
29 | 28 |
| 29 class Histogram; |
| 30 |
30 // A MessageLoop is used to process events for a particular thread. There is | 31 // A MessageLoop is used to process events for a particular thread. There is |
31 // at most one MessageLoop instance per thread. | 32 // at most one MessageLoop instance per thread. |
32 // | 33 // |
33 // Events include at a minimum Task instances submitted to PostTask or those | 34 // Events include at a minimum Task instances submitted to PostTask or those |
34 // managed by TimerManager. Depending on the type of message pump used by the | 35 // managed by TimerManager. Depending on the type of message pump used by the |
35 // MessageLoop other events such as UI messages may be processed. On Windows | 36 // MessageLoop other events such as UI messages may be processed. On Windows |
36 // APC calls (as time permits) and signals sent to a registered set of HANDLEs | 37 // APC calls (as time permits) and signals sent to a registered set of HANDLEs |
37 // may also be processed. | 38 // may also be processed. |
38 // | 39 // |
39 // NOTE: Unless otherwise specified, a MessageLoop's methods may only be called | 40 // NOTE: Unless otherwise specified, a MessageLoop's methods may only be called |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 | 421 |
421 // Start recording histogram info about events and action IF it was enabled | 422 // Start recording histogram info about events and action IF it was enabled |
422 // and IF the statistics recorder can accept a registration of our histogram. | 423 // and IF the statistics recorder can accept a registration of our histogram. |
423 void StartHistogrammer(); | 424 void StartHistogrammer(); |
424 | 425 |
425 // Add occurence of event to our histogram, so that we can see what is being | 426 // Add occurence of event to our histogram, so that we can see what is being |
426 // done in a specific MessageLoop instance (i.e., specific thread). | 427 // done in a specific MessageLoop instance (i.e., specific thread). |
427 // If message_histogram_ is NULL, this is a no-op. | 428 // If message_histogram_ is NULL, this is a no-op. |
428 void HistogramEvent(int event); | 429 void HistogramEvent(int event); |
429 | 430 |
430 static const LinearHistogram::DescriptionPair event_descriptions_[]; | |
431 static bool enable_histogrammer_; | |
432 | |
433 Type type_; | 431 Type type_; |
434 | 432 |
435 // A list of tasks that need to be processed by this instance. Note that | 433 // A list of tasks that need to be processed by this instance. Note that |
436 // this queue is only accessed (push/pop) by our current thread. | 434 // this queue is only accessed (push/pop) by our current thread. |
437 TaskQueue work_queue_; | 435 TaskQueue work_queue_; |
438 | 436 |
439 // Contains delayed tasks, sorted by their 'delayed_run_time' property. | 437 // Contains delayed tasks, sorted by their 'delayed_run_time' property. |
440 DelayedTaskQueue delayed_work_queue_; | 438 DelayedTaskQueue delayed_work_queue_; |
441 | 439 |
442 // A queue of non-nestable tasks that we had to defer because when it came | 440 // A queue of non-nestable tasks that we had to defer because when it came |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 #endif // defined(OS_POSIX) | 593 #endif // defined(OS_POSIX) |
596 }; | 594 }; |
597 | 595 |
598 // Do not add any member variables to MessageLoopForIO! This is important b/c | 596 // Do not add any member variables to MessageLoopForIO! This is important b/c |
599 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 597 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
600 // data that you need should be stored on the MessageLoop's pump_ instance. | 598 // data that you need should be stored on the MessageLoop's pump_ instance. |
601 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 599 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
602 MessageLoopForIO_should_not_have_extra_member_variables); | 600 MessageLoopForIO_should_not_have_extra_member_variables); |
603 | 601 |
604 #endif // BASE_MESSAGE_LOOP_H_ | 602 #endif // BASE_MESSAGE_LOOP_H_ |
OLD | NEW |