| 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> |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 typedef base::MessagePumpWin::Dispatcher Dispatcher; | 416 typedef base::MessagePumpWin::Dispatcher Dispatcher; |
| 417 typedef base::MessagePumpWin::Observer Observer; | 417 typedef base::MessagePumpWin::Observer Observer; |
| 418 | 418 |
| 419 // Please see MessagePumpWin for definitions of these methods. | 419 // Please see MessagePumpWin for definitions of these methods. |
| 420 void Run(Dispatcher* dispatcher); | 420 void Run(Dispatcher* dispatcher); |
| 421 void AddObserver(Observer* observer); | 421 void AddObserver(Observer* observer); |
| 422 void RemoveObserver(Observer* observer); | 422 void RemoveObserver(Observer* observer); |
| 423 void WillProcessMessage(const MSG& message); | 423 void WillProcessMessage(const MSG& message); |
| 424 void DidProcessMessage(const MSG& message); | 424 void DidProcessMessage(const MSG& message); |
| 425 void PumpOutPendingPaintMessages(); | 425 void PumpOutPendingPaintMessages(); |
| 426 |
| 427 protected: |
| 428 // TODO(rvargas): Make this platform independent. |
| 429 base::MessagePumpWin* pump_ui() { |
| 430 return static_cast<base::MessagePumpForUI*>(pump_.get()); |
| 431 } |
| 426 #endif // defined(OS_WIN) | 432 #endif // defined(OS_WIN) |
| 427 }; | 433 }; |
| 428 | 434 |
| 429 // Do not add any member variables to MessageLoopForUI! This is important b/c | 435 // Do not add any member variables to MessageLoopForUI! This is important b/c |
| 430 // MessageLoopForUI is often allocated via MessageLoop(TYPE_UI). Any extra | 436 // MessageLoopForUI is often allocated via MessageLoop(TYPE_UI). Any extra |
| 431 // data that you need should be stored on the MessageLoop's pump_ instance. | 437 // data that you need should be stored on the MessageLoop's pump_ instance. |
| 432 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForUI), | 438 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForUI), |
| 433 MessageLoopForUI_should_not_have_extra_member_variables); | 439 MessageLoopForUI_should_not_have_extra_member_variables); |
| 434 | 440 |
| 435 //----------------------------------------------------------------------------- | 441 //----------------------------------------------------------------------------- |
| 436 // MessageLoopForIO extends MessageLoop with methods that are particular to a | 442 // MessageLoopForIO extends MessageLoop with methods that are particular to a |
| 437 // MessageLoop instantiated with TYPE_IO. | 443 // MessageLoop instantiated with TYPE_IO. |
| 438 // | 444 // |
| 439 // This class is typically used like so: | 445 // This class is typically used like so: |
| 440 // MessageLoopForIO::current()->...call some method... | 446 // MessageLoopForIO::current()->...call some method... |
| 441 // | 447 // |
| 442 class MessageLoopForIO : public MessageLoop { | 448 class MessageLoopForIO : public MessageLoop { |
| 443 public: | 449 public: |
| 444 MessageLoopForIO() : MessageLoop(TYPE_IO) { | 450 MessageLoopForIO() : MessageLoop(TYPE_IO) { |
| 445 } | 451 } |
| 446 | 452 |
| 447 // Returns the MessageLoopForIO of the current thread. | 453 // Returns the MessageLoopForIO of the current thread. |
| 448 static MessageLoopForIO* current() { | 454 static MessageLoopForIO* current() { |
| 449 MessageLoop* loop = MessageLoop::current(); | 455 MessageLoop* loop = MessageLoop::current(); |
| 450 DCHECK_EQ(MessageLoop::TYPE_IO, loop->type()); | 456 DCHECK_EQ(MessageLoop::TYPE_IO, loop->type()); |
| 451 return static_cast<MessageLoopForIO*>(loop); | 457 return static_cast<MessageLoopForIO*>(loop); |
| 452 } | 458 } |
| 453 | 459 |
| 454 #if defined(OS_WIN) | 460 #if defined(OS_WIN) |
| 455 typedef base::MessagePumpWin::Watcher Watcher; | 461 typedef base::MessagePumpForIO::Watcher Watcher; |
| 456 | 462 |
| 457 // Please see MessagePumpWin for definitions of these methods. | 463 // Please see MessagePumpWin for definitions of these methods. |
| 458 void WatchObject(HANDLE object, Watcher* watcher); | 464 void WatchObject(HANDLE object, Watcher* watcher); |
| 459 | 465 |
| 466 protected: |
| 467 // TODO(rvargas): Make this platform independent. |
| 468 base::MessagePumpForIO* pump_io() { |
| 469 return static_cast<base::MessagePumpForIO*>(pump_.get()); |
| 470 } |
| 471 |
| 460 #elif defined(OS_POSIX) | 472 #elif defined(OS_POSIX) |
| 461 typedef base::MessagePumpLibevent::Watcher Watcher; | 473 typedef base::MessagePumpLibevent::Watcher Watcher; |
| 462 | 474 |
| 463 // Please see MessagePumpLibevent for definitions of these methods. | 475 // Please see MessagePumpLibevent for definitions of these methods. |
| 464 void WatchSocket(int socket, short interest_mask, | 476 void WatchSocket(int socket, short interest_mask, |
| 465 struct event* e, Watcher* watcher); | 477 struct event* e, Watcher* watcher); |
| 466 void UnwatchSocket(struct event* e); | 478 void UnwatchSocket(struct event* e); |
| 467 #endif // defined(OS_WIN) | 479 #endif // defined(OS_POSIX) |
| 468 }; | 480 }; |
| 469 | 481 |
| 470 // Do not add any member variables to MessageLoopForIO! This is important b/c | 482 // Do not add any member variables to MessageLoopForIO! This is important b/c |
| 471 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 483 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
| 472 // data that you need should be stored on the MessageLoop's pump_ instance. | 484 // data that you need should be stored on the MessageLoop's pump_ instance. |
| 473 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 485 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
| 474 MessageLoopForIO_should_not_have_extra_member_variables); | 486 MessageLoopForIO_should_not_have_extra_member_variables); |
| 475 | 487 |
| 476 #endif // BASE_MESSAGE_LOOP_H_ | 488 #endif // BASE_MESSAGE_LOOP_H_ |
| OLD | NEW |