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/scoped_ptr.h" | 17 #include "base/scoped_ptr.h" |
18 #include "base/task.h" | 18 #include "base/task.h" |
19 #include "base/timer.h" | 19 #include "base/timer.h" |
20 | 20 |
21 #if defined(OS_WIN) | 21 #if defined(OS_WIN) |
22 // We need this to declare base::MessagePumpWin::Dispatcher, which we should | 22 // We need this to declare base::MessagePumpWin::Dispatcher, which we should |
23 // really just eliminate. | 23 // really just eliminate. |
24 #include "base/message_pump_win.h" | 24 #include "base/message_pump_win.h" |
25 #elif defined(OS_POSIX) | 25 #elif defined(OS_POSIX) |
26 #include "base/message_pump_libevent.h" | 26 #include "base/message_pump_libevent.h" |
27 #endif | 27 #endif |
| 28 #if defined(OS_LINUX) |
| 29 #include "base/message_pump_glib.h" |
| 30 #endif |
28 | 31 |
29 // A MessageLoop is used to process events for a particular thread. There is | 32 // A MessageLoop is used to process events for a particular thread. There is |
30 // at most one MessageLoop instance per thread. | 33 // at most one MessageLoop instance per thread. |
31 // | 34 // |
32 // Events include at a minimum Task instances submitted to PostTask or those | 35 // Events include at a minimum Task instances submitted to PostTask or those |
33 // managed by TimerManager. Depending on the type of message pump used by the | 36 // managed by TimerManager. Depending on the type of message pump used by the |
34 // MessageLoop other events such as UI messages may be processed. On Windows | 37 // MessageLoop other events such as UI messages may be processed. On Windows |
35 // APC calls (as time permits) and signals sent to a registered set of HANDLEs | 38 // APC calls (as time permits) and signals sent to a registered set of HANDLEs |
36 // may also be processed. | 39 // may also be processed. |
37 // | 40 // |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 MessageLoopForUI() : MessageLoop(TYPE_UI) { | 409 MessageLoopForUI() : MessageLoop(TYPE_UI) { |
407 } | 410 } |
408 | 411 |
409 // Returns the MessageLoopForUI of the current thread. | 412 // Returns the MessageLoopForUI of the current thread. |
410 static MessageLoopForUI* current() { | 413 static MessageLoopForUI* current() { |
411 MessageLoop* loop = MessageLoop::current(); | 414 MessageLoop* loop = MessageLoop::current(); |
412 DCHECK_EQ(MessageLoop::TYPE_UI, loop->type()); | 415 DCHECK_EQ(MessageLoop::TYPE_UI, loop->type()); |
413 return static_cast<MessageLoopForUI*>(loop); | 416 return static_cast<MessageLoopForUI*>(loop); |
414 } | 417 } |
415 | 418 |
| 419 #if defined(OS_LINUX) |
| 420 typedef base::MessagePumpForUI::Observer Observer; |
| 421 |
| 422 // See message_pump_glib for definitions of these methods. |
| 423 void AddObserver(Observer* observer); |
| 424 void RemoveObserver(Observer* observer); |
| 425 #endif |
| 426 |
416 #if defined(OS_WIN) | 427 #if defined(OS_WIN) |
417 typedef base::MessagePumpWin::Dispatcher Dispatcher; | 428 typedef base::MessagePumpWin::Dispatcher Dispatcher; |
418 typedef base::MessagePumpWin::Observer Observer; | 429 typedef base::MessagePumpWin::Observer Observer; |
419 | 430 |
420 // Please see MessagePumpWin for definitions of these methods. | 431 // Please see MessagePumpWin for definitions of these methods. |
421 void Run(Dispatcher* dispatcher); | |
422 void AddObserver(Observer* observer); | 432 void AddObserver(Observer* observer); |
423 void RemoveObserver(Observer* observer); | 433 void RemoveObserver(Observer* observer); |
| 434 void Run(Dispatcher* dispatcher); |
424 void WillProcessMessage(const MSG& message); | 435 void WillProcessMessage(const MSG& message); |
425 void DidProcessMessage(const MSG& message); | 436 void DidProcessMessage(const MSG& message); |
426 void PumpOutPendingPaintMessages(); | 437 void PumpOutPendingPaintMessages(); |
| 438 #endif |
427 | 439 |
| 440 #if defined(OS_WIN) || defined(OS_LINUX) |
428 protected: | 441 protected: |
429 // TODO(rvargas): Make this platform independent. | 442 // TODO(rvargas): Make this platform independent. |
430 base::MessagePumpForUI* pump_ui() { | 443 base::MessagePumpForUI* pump_ui() { |
431 return static_cast<base::MessagePumpForUI*>(pump_.get()); | 444 return static_cast<base::MessagePumpForUI*>(pump_.get()); |
432 } | 445 } |
433 #endif // defined(OS_WIN) | 446 #endif // defined(OS_WIN) |
434 }; | 447 }; |
435 | 448 |
436 // Do not add any member variables to MessageLoopForUI! This is important b/c | 449 // Do not add any member variables to MessageLoopForUI! This is important b/c |
437 // MessageLoopForUI is often allocated via MessageLoop(TYPE_UI). Any extra | 450 // MessageLoopForUI is often allocated via MessageLoop(TYPE_UI). Any extra |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 #endif // defined(OS_POSIX) | 505 #endif // defined(OS_POSIX) |
493 }; | 506 }; |
494 | 507 |
495 // Do not add any member variables to MessageLoopForIO! This is important b/c | 508 // Do not add any member variables to MessageLoopForIO! This is important b/c |
496 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 509 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
497 // data that you need should be stored on the MessageLoop's pump_ instance. | 510 // data that you need should be stored on the MessageLoop's pump_ instance. |
498 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 511 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
499 MessageLoopForIO_should_not_have_extra_member_variables); | 512 MessageLoopForIO_should_not_have_extra_member_variables); |
500 | 513 |
501 #endif // BASE_MESSAGE_LOOP_H_ | 514 #endif // BASE_MESSAGE_LOOP_H_ |
OLD | NEW |