| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_MESSAGE_LOOP_H_ | 5 #ifndef BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ |
| 6 #define BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ | 6 #define BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ |
| 7 | 7 |
| 8 #include <queue> | 8 #include <queue> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 } | 558 } |
| 559 | 559 |
| 560 // Returns the MessageLoopForUI of the current thread. | 560 // Returns the MessageLoopForUI of the current thread. |
| 561 static MessageLoopForUI* current() { | 561 static MessageLoopForUI* current() { |
| 562 MessageLoop* loop = MessageLoop::current(); | 562 MessageLoop* loop = MessageLoop::current(); |
| 563 DCHECK(loop); | 563 DCHECK(loop); |
| 564 DCHECK_EQ(MessageLoop::TYPE_UI, loop->type()); | 564 DCHECK_EQ(MessageLoop::TYPE_UI, loop->type()); |
| 565 return static_cast<MessageLoopForUI*>(loop); | 565 return static_cast<MessageLoopForUI*>(loop); |
| 566 } | 566 } |
| 567 | 567 |
| 568 static bool IsCurrent() { |
| 569 MessageLoop* loop = MessageLoop::current(); |
| 570 return loop && loop->type() == MessageLoop::TYPE_UI; |
| 571 } |
| 572 |
| 568 #if defined(OS_IOS) | 573 #if defined(OS_IOS) |
| 569 // On iOS, the main message loop cannot be Run(). Instead call Attach(), | 574 // On iOS, the main message loop cannot be Run(). Instead call Attach(), |
| 570 // which connects this MessageLoop to the UI thread's CFRunLoop and allows | 575 // which connects this MessageLoop to the UI thread's CFRunLoop and allows |
| 571 // PostTask() to work. | 576 // PostTask() to work. |
| 572 void Attach(); | 577 void Attach(); |
| 573 #endif | 578 #endif |
| 574 | 579 |
| 575 #if defined(OS_ANDROID) | 580 #if defined(OS_ANDROID) |
| 576 // On Android, the UI message loop is handled by Java side. So Run() should | 581 // On Android, the UI message loop is handled by Java side. So Run() should |
| 577 // never be called. Instead use Start(), which will forward all the native UI | 582 // never be called. Instead use Start(), which will forward all the native UI |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 MessageLoopForIO() : MessageLoop(TYPE_IO) { | 662 MessageLoopForIO() : MessageLoop(TYPE_IO) { |
| 658 } | 663 } |
| 659 | 664 |
| 660 // Returns the MessageLoopForIO of the current thread. | 665 // Returns the MessageLoopForIO of the current thread. |
| 661 static MessageLoopForIO* current() { | 666 static MessageLoopForIO* current() { |
| 662 MessageLoop* loop = MessageLoop::current(); | 667 MessageLoop* loop = MessageLoop::current(); |
| 663 DCHECK_EQ(MessageLoop::TYPE_IO, loop->type()); | 668 DCHECK_EQ(MessageLoop::TYPE_IO, loop->type()); |
| 664 return static_cast<MessageLoopForIO*>(loop); | 669 return static_cast<MessageLoopForIO*>(loop); |
| 665 } | 670 } |
| 666 | 671 |
| 672 static bool IsCurrent() { |
| 673 MessageLoop* loop = MessageLoop::current(); |
| 674 return loop && loop->type() == MessageLoop::TYPE_IO; |
| 675 } |
| 676 |
| 667 void AddIOObserver(IOObserver* io_observer) { | 677 void AddIOObserver(IOObserver* io_observer) { |
| 668 pump_io()->AddIOObserver(io_observer); | 678 pump_io()->AddIOObserver(io_observer); |
| 669 } | 679 } |
| 670 | 680 |
| 671 void RemoveIOObserver(IOObserver* io_observer) { | 681 void RemoveIOObserver(IOObserver* io_observer) { |
| 672 pump_io()->RemoveIOObserver(io_observer); | 682 pump_io()->RemoveIOObserver(io_observer); |
| 673 } | 683 } |
| 674 | 684 |
| 675 #if defined(OS_WIN) | 685 #if defined(OS_WIN) |
| 676 // Please see MessagePumpWin for definitions of these methods. | 686 // Please see MessagePumpWin for definitions of these methods. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 | 724 |
| 715 // Do not add any member variables to MessageLoopForIO! This is important b/c | 725 // Do not add any member variables to MessageLoopForIO! This is important b/c |
| 716 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 726 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
| 717 // data that you need should be stored on the MessageLoop's pump_ instance. | 727 // data that you need should be stored on the MessageLoop's pump_ instance. |
| 718 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 728 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
| 719 MessageLoopForIO_should_not_have_extra_member_variables); | 729 MessageLoopForIO_should_not_have_extra_member_variables); |
| 720 | 730 |
| 721 } // namespace base | 731 } // namespace base |
| 722 | 732 |
| 723 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ | 733 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ |
| OLD | NEW |