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_POSIX) |
| 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_POSIX) |
| 280 base::MessagePumpLibevent* pump_libevent() { |
| 281 return static_cast<base::MessagePumpLibevent*>(pump_.get()); |
| 282 } |
| 283 protected: |
277 #endif | 284 #endif |
278 | 285 |
279 // A function to encapsulate all the exception handling capability in the | 286 // 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 | 287 // 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() | 288 // loop in a SEH try block or not depending on the set_SEH_restoration() |
282 // flag. | 289 // flag. |
283 void RunHandler(); | 290 void RunHandler(); |
284 | 291 |
285 // A surrounding stack frame around the running of the message loop that | 292 // 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) | 293 // supports all saving and restoring of state, as is needed for any/all (ugly) |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 MessageLoop* loop = MessageLoop::current(); | 450 MessageLoop* loop = MessageLoop::current(); |
444 DCHECK_EQ(MessageLoop::TYPE_IO, loop->type()); | 451 DCHECK_EQ(MessageLoop::TYPE_IO, loop->type()); |
445 return static_cast<MessageLoopForIO*>(loop); | 452 return static_cast<MessageLoopForIO*>(loop); |
446 } | 453 } |
447 | 454 |
448 #if defined(OS_WIN) | 455 #if defined(OS_WIN) |
449 typedef base::MessagePumpWin::Watcher Watcher; | 456 typedef base::MessagePumpWin::Watcher Watcher; |
450 | 457 |
451 // Please see MessagePumpWin for definitions of these methods. | 458 // Please see MessagePumpWin for definitions of these methods. |
452 void WatchObject(HANDLE object, Watcher* watcher); | 459 void WatchObject(HANDLE object, Watcher* watcher); |
| 460 |
| 461 #elif defined(OS_POSIX) |
| 462 typedef base::MessagePumpLibevent::Watcher Watcher; |
| 463 |
| 464 // Please see MessagePumpLibevent for definitions of these methods. |
| 465 void WatchSocket(int socket, short interest_mask, |
| 466 struct event* e, Watcher* watcher); |
| 467 void UnwatchSocket(struct event* e); |
453 #endif // defined(OS_WIN) | 468 #endif // defined(OS_WIN) |
454 }; | 469 }; |
455 | 470 |
456 // Do not add any member variables to MessageLoopForIO! This is important b/c | 471 // Do not add any member variables to MessageLoopForIO! This is important b/c |
457 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 472 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
458 // data that you need should be stored on the MessageLoop's pump_ instance. | 473 // data that you need should be stored on the MessageLoop's pump_ instance. |
459 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 474 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
460 MessageLoopForIO_should_not_have_extra_member_variables); | 475 MessageLoopForIO_should_not_have_extra_member_variables); |
461 | 476 |
462 #endif // BASE_MESSAGE_LOOP_H_ | 477 #endif // BASE_MESSAGE_LOOP_H_ |
OLD | NEW |