| 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 <deque> | 8 #include <deque> |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/histogram.h" | 13 #include "base/histogram.h" |
| 14 #include "base/message_pump.h" | 14 #include "base/message_pump.h" |
| 15 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
| 16 #include "base/ref_counted.h" | 16 #include "base/ref_counted.h" |
| 17 #include "base/task.h" | 17 #include "base/task.h" |
| 18 #include "base/timer.h" | 18 #include "base/timer.h" |
| 19 | 19 |
| 20 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
| 21 // We need this to declare base::MessagePumpWin::Dispatcher, which we should | 21 // We need this to declare base::MessagePumpWin::Dispatcher, which we should |
| 22 // really just eliminate. | 22 // really just eliminate. |
| 23 #include "base/message_pump_win.h" | 23 #include "base/message_pump_win.h" |
| 24 #elif defined(OS_LINUX) |
| 25 #include "base/message_pump_libevent.h" |
| 24 #endif | 26 #endif |
| 25 | 27 |
| 26 // A MessageLoop is used to process events for a particular thread. There is | 28 // A MessageLoop is used to process events for a particular thread. There is |
| 27 // at most one MessageLoop instance per thread. | 29 // at most one MessageLoop instance per thread. |
| 28 // | 30 // |
| 29 // Events include at a minimum Task instances submitted to PostTask or those | 31 // Events include at a minimum Task instances submitted to PostTask or those |
| 30 // managed by TimerManager. Depending on the type of message pump used by the | 32 // managed by TimerManager. Depending on the type of message pump used by the |
| 31 // MessageLoop other events such as UI messages may be processed. On Windows | 33 // MessageLoop other events such as UI messages may be processed. On Windows |
| 32 // APC calls (as time permits) and signals sent to a registered set of HANDLEs | 34 // APC calls (as time permits) and signals sent to a registered set of HANDLEs |
| 33 // may also be processed. | 35 // may also be processed. |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 bool operator<(const PendingTask& other) const; | 269 bool operator<(const PendingTask& other) const; |
| 268 }; | 270 }; |
| 269 | 271 |
| 270 typedef std::queue<PendingTask> TaskQueue; | 272 typedef std::queue<PendingTask> TaskQueue; |
| 271 typedef std::priority_queue<PendingTask> DelayedTaskQueue; | 273 typedef std::priority_queue<PendingTask> DelayedTaskQueue; |
| 272 | 274 |
| 273 #if defined(OS_WIN) | 275 #if defined(OS_WIN) |
| 274 base::MessagePumpWin* pump_win() { | 276 base::MessagePumpWin* pump_win() { |
| 275 return static_cast<base::MessagePumpWin*>(pump_.get()); | 277 return static_cast<base::MessagePumpWin*>(pump_.get()); |
| 276 } | 278 } |
| 279 #elif defined(OS_LINUX) |
| 280 public: |
| 281 base::MessagePumpLibevent* pump_libevent() { |
| 282 return static_cast<base::MessagePumpLibevent*>(pump_.get()); |
| 283 } |
| 284 protected: |
| 277 #endif | 285 #endif |
| 278 | 286 |
| 279 // A function to encapsulate all the exception handling capability in the | 287 // A function to encapsulate all the exception handling capability in the |
| 280 // stacks around the running of a main message loop. It will run the message | 288 // stacks around the running of a main message loop. It will run the message |
| 281 // loop in a SEH try block or not depending on the set_SEH_restoration() | 289 // loop in a SEH try block or not depending on the set_SEH_restoration() |
| 282 // flag. | 290 // flag. |
| 283 void RunHandler(); | 291 void RunHandler(); |
| 284 | 292 |
| 285 // A surrounding stack frame around the running of the message loop that | 293 // A surrounding stack frame around the running of the message loop that |
| 286 // supports all saving and restoring of state, as is needed for any/all (ugly) | 294 // supports all saving and restoring of state, as is needed for any/all (ugly) |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 // Contains delayed tasks, sorted by their 'delayed_run_time' property. | 360 // Contains delayed tasks, sorted by their 'delayed_run_time' property. |
| 353 DelayedTaskQueue delayed_work_queue_; | 361 DelayedTaskQueue delayed_work_queue_; |
| 354 | 362 |
| 355 // A queue of non-nestable tasks that we had to defer because when it came | 363 // A queue of non-nestable tasks that we had to defer because when it came |
| 356 // time to execute them we were in a nested message loop. They will execute | 364 // time to execute them we were in a nested message loop. They will execute |
| 357 // once we're out of nested message loops. | 365 // once we're out of nested message loops. |
| 358 TaskQueue deferred_non_nestable_work_queue_; | 366 TaskQueue deferred_non_nestable_work_queue_; |
| 359 | 367 |
| 360 scoped_refptr<base::MessagePump> pump_; | 368 scoped_refptr<base::MessagePump> pump_; |
| 361 | 369 |
| 370 #if defined(OS_LINUX) |
| 371 //struct event_base *iopump_; |
| 372 #endif |
| 373 |
| 362 ObserverList<DestructionObserver> destruction_observers_; | 374 ObserverList<DestructionObserver> destruction_observers_; |
| 363 | 375 |
| 364 // A recursion block that prevents accidentally running additonal tasks when | 376 // A recursion block that prevents accidentally running additonal tasks when |
| 365 // insider a (accidentally induced?) nested message pump. | 377 // insider a (accidentally induced?) nested message pump. |
| 366 bool nestable_tasks_allowed_; | 378 bool nestable_tasks_allowed_; |
| 367 | 379 |
| 368 bool exception_restoration_; | 380 bool exception_restoration_; |
| 369 | 381 |
| 370 std::string thread_name_; | 382 std::string thread_name_; |
| 371 // A profiling histogram showing the counts of various messages and events. | 383 // A profiling histogram showing the counts of various messages and events. |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 #endif // defined(OS_WIN) | 465 #endif // defined(OS_WIN) |
| 454 }; | 466 }; |
| 455 | 467 |
| 456 // Do not add any member variables to MessageLoopForIO! This is important b/c | 468 // Do not add any member variables to MessageLoopForIO! This is important b/c |
| 457 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 469 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
| 458 // data that you need should be stored on the MessageLoop's pump_ instance. | 470 // data that you need should be stored on the MessageLoop's pump_ instance. |
| 459 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 471 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
| 460 MessageLoopForIO_should_not_have_extra_member_variables); | 472 MessageLoopForIO_should_not_have_extra_member_variables); |
| 461 | 473 |
| 462 #endif // BASE_MESSAGE_LOOP_H_ | 474 #endif // BASE_MESSAGE_LOOP_H_ |
| OLD | NEW |