OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <queue> | 8 #include <queue> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/base_export.h" | 11 #include "base/base_export.h" |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
14 #include "base/location.h" | 14 #include "base/location.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/message_loop_proxy.h" | 16 #include "base/message_loop_proxy.h" |
17 #include "base/message_pump.h" | 17 #include "base/message_pump.h" |
18 #include "base/observer_list.h" | 18 #include "base/observer_list.h" |
19 #include "base/pending_task.h" | 19 #include "base/pending_task.h" |
20 #include "base/sequenced_task_runner_helpers.h" | 20 #include "base/sequenced_task_runner_helpers.h" |
21 #include "base/synchronization/lock.h" | 21 #include "base/synchronization/lock.h" |
22 #include "base/tracking_info.h" | 22 #include "base/tracking_info.h" |
23 #include "base/time.h" | 23 #include "base/time.h" |
24 | 24 |
25 #if defined(OS_WIN) | 25 #if defined(OS_WIN) |
26 // We need this to declare base::MessagePumpWin::Dispatcher, which we should | 26 // We need this to declare base::MessagePumpWin::Dispatcher, which we should |
27 // really just eliminate. | 27 // really just eliminate. |
28 #include "base/message_pump_win.h" | 28 #include "base/message_pump_win.h" |
| 29 #elif defined(OS_IOS) |
| 30 #include "base/message_pump_io_ios.h" |
29 #elif defined(OS_POSIX) | 31 #elif defined(OS_POSIX) |
30 #include "base/message_pump_libevent.h" | 32 #include "base/message_pump_libevent.h" |
31 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | 33 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
32 | 34 |
33 #if defined(USE_AURA) && defined(USE_X11) && !defined(OS_NACL) | 35 #if defined(USE_AURA) && defined(USE_X11) && !defined(OS_NACL) |
34 #include "base/message_pump_aurax11.h" | 36 #include "base/message_pump_aurax11.h" |
35 #else | 37 #else |
36 #include "base/message_pump_gtk.h" | 38 #include "base/message_pump_gtk.h" |
37 #endif | 39 #endif |
38 | 40 |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 bool is_running() const; | 383 bool is_running() const; |
382 | 384 |
383 //---------------------------------------------------------------------------- | 385 //---------------------------------------------------------------------------- |
384 protected: | 386 protected: |
385 friend class base::RunLoop; | 387 friend class base::RunLoop; |
386 | 388 |
387 #if defined(OS_WIN) | 389 #if defined(OS_WIN) |
388 base::MessagePumpWin* pump_win() { | 390 base::MessagePumpWin* pump_win() { |
389 return static_cast<base::MessagePumpWin*>(pump_.get()); | 391 return static_cast<base::MessagePumpWin*>(pump_.get()); |
390 } | 392 } |
391 #elif defined(OS_POSIX) | 393 #elif defined(OS_POSIX) && !defined(OS_IOS) |
392 base::MessagePumpLibevent* pump_libevent() { | 394 base::MessagePumpLibevent* pump_libevent() { |
393 return static_cast<base::MessagePumpLibevent*>(pump_.get()); | 395 return static_cast<base::MessagePumpLibevent*>(pump_.get()); |
394 } | 396 } |
395 #endif | 397 #endif |
396 | 398 |
397 // A function to encapsulate all the exception handling capability in the | 399 // A function to encapsulate all the exception handling capability in the |
398 // stacks around the running of a main message loop. It will run the message | 400 // stacks around the running of a main message loop. It will run the message |
399 // loop in a SEH try block or not depending on the set_SEH_restoration() | 401 // loop in a SEH try block or not depending on the set_SEH_restoration() |
400 // flag invoking respectively RunInternalInSEHFrame() or RunInternal(). | 402 // flag invoking respectively RunInternalInSEHFrame() or RunInternal(). |
401 void RunHandler(); | 403 void RunHandler(); |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 // | 608 // |
607 // This class is typically used like so: | 609 // This class is typically used like so: |
608 // MessageLoopForIO::current()->...call some method... | 610 // MessageLoopForIO::current()->...call some method... |
609 // | 611 // |
610 class BASE_EXPORT MessageLoopForIO : public MessageLoop { | 612 class BASE_EXPORT MessageLoopForIO : public MessageLoop { |
611 public: | 613 public: |
612 #if defined(OS_WIN) | 614 #if defined(OS_WIN) |
613 typedef base::MessagePumpForIO::IOHandler IOHandler; | 615 typedef base::MessagePumpForIO::IOHandler IOHandler; |
614 typedef base::MessagePumpForIO::IOContext IOContext; | 616 typedef base::MessagePumpForIO::IOContext IOContext; |
615 typedef base::MessagePumpForIO::IOObserver IOObserver; | 617 typedef base::MessagePumpForIO::IOObserver IOObserver; |
| 618 #elif defined(OS_IOS) |
| 619 typedef base::MessagePumpIOSForIO::Watcher Watcher; |
| 620 typedef base::MessagePumpIOSForIO::FileDescriptorWatcher |
| 621 FileDescriptorWatcher; |
| 622 typedef base::MessagePumpIOSForIO::IOObserver IOObserver; |
| 623 |
| 624 enum Mode { |
| 625 WATCH_READ = base::MessagePumpIOSForIO::WATCH_READ, |
| 626 WATCH_WRITE = base::MessagePumpIOSForIO::WATCH_WRITE, |
| 627 WATCH_READ_WRITE = base::MessagePumpIOSForIO::WATCH_READ_WRITE |
| 628 }; |
616 #elif defined(OS_POSIX) | 629 #elif defined(OS_POSIX) |
617 typedef base::MessagePumpLibevent::Watcher Watcher; | 630 typedef base::MessagePumpLibevent::Watcher Watcher; |
618 typedef base::MessagePumpLibevent::FileDescriptorWatcher | 631 typedef base::MessagePumpLibevent::FileDescriptorWatcher |
619 FileDescriptorWatcher; | 632 FileDescriptorWatcher; |
620 typedef base::MessagePumpLibevent::IOObserver IOObserver; | 633 typedef base::MessagePumpLibevent::IOObserver IOObserver; |
621 | 634 |
622 enum Mode { | 635 enum Mode { |
623 WATCH_READ = base::MessagePumpLibevent::WATCH_READ, | 636 WATCH_READ = base::MessagePumpLibevent::WATCH_READ, |
624 WATCH_WRITE = base::MessagePumpLibevent::WATCH_WRITE, | 637 WATCH_WRITE = base::MessagePumpLibevent::WATCH_WRITE, |
625 WATCH_READ_WRITE = base::MessagePumpLibevent::WATCH_READ_WRITE | 638 WATCH_READ_WRITE = base::MessagePumpLibevent::WATCH_READ_WRITE |
(...skipping 24 matching lines...) Expand all Loading... |
650 void RegisterIOHandler(HANDLE file, IOHandler* handler); | 663 void RegisterIOHandler(HANDLE file, IOHandler* handler); |
651 bool RegisterJobObject(HANDLE job, IOHandler* handler); | 664 bool RegisterJobObject(HANDLE job, IOHandler* handler); |
652 bool WaitForIOCompletion(DWORD timeout, IOHandler* filter); | 665 bool WaitForIOCompletion(DWORD timeout, IOHandler* filter); |
653 | 666 |
654 protected: | 667 protected: |
655 // TODO(rvargas): Make this platform independent. | 668 // TODO(rvargas): Make this platform independent. |
656 base::MessagePumpForIO* pump_io() { | 669 base::MessagePumpForIO* pump_io() { |
657 return static_cast<base::MessagePumpForIO*>(pump_.get()); | 670 return static_cast<base::MessagePumpForIO*>(pump_.get()); |
658 } | 671 } |
659 | 672 |
| 673 #elif defined(OS_IOS) |
| 674 // Please see MessagePumpIOSForIO for definition. |
| 675 bool WatchFileDescriptor(int fd, |
| 676 bool persistent, |
| 677 Mode mode, |
| 678 FileDescriptorWatcher *controller, |
| 679 Watcher *delegate); |
| 680 |
| 681 private: |
| 682 base::MessagePumpIOSForIO* pump_io() { |
| 683 return static_cast<base::MessagePumpIOSForIO*>(pump_.get()); |
| 684 } |
| 685 |
660 #elif defined(OS_POSIX) | 686 #elif defined(OS_POSIX) |
661 // Please see MessagePumpLibevent for definition. | 687 // Please see MessagePumpLibevent for definition. |
662 bool WatchFileDescriptor(int fd, | 688 bool WatchFileDescriptor(int fd, |
663 bool persistent, | 689 bool persistent, |
664 Mode mode, | 690 Mode mode, |
665 FileDescriptorWatcher* controller, | 691 FileDescriptorWatcher* controller, |
666 Watcher* delegate); | 692 Watcher* delegate); |
667 | 693 |
668 private: | 694 private: |
669 base::MessagePumpLibevent* pump_io() { | 695 base::MessagePumpLibevent* pump_io() { |
670 return static_cast<base::MessagePumpLibevent*>(pump_.get()); | 696 return static_cast<base::MessagePumpLibevent*>(pump_.get()); |
671 } | 697 } |
672 #endif // defined(OS_POSIX) | 698 #endif // defined(OS_POSIX) |
673 }; | 699 }; |
674 | 700 |
675 // Do not add any member variables to MessageLoopForIO! This is important b/c | 701 // Do not add any member variables to MessageLoopForIO! This is important b/c |
676 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 702 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
677 // data that you need should be stored on the MessageLoop's pump_ instance. | 703 // data that you need should be stored on the MessageLoop's pump_ instance. |
678 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 704 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
679 MessageLoopForIO_should_not_have_extra_member_variables); | 705 MessageLoopForIO_should_not_have_extra_member_variables); |
680 | 706 |
681 #endif // BASE_MESSAGE_LOOP_H_ | 707 #endif // BASE_MESSAGE_LOOP_H_ |
OLD | NEW |