Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(755)

Side by Side Diff: base/message_loop.h

Issue 7276045: Give a CFRunLoop to the IO message loop type on Mac OS X. Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #pragma once 7 #pragma once
8 8
9 #include <queue> 9 #include <queue>
10 #include <string> 10 #include <string>
11 11
12 #include "base/base_api.h" 12 #include "base/base_api.h"
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/message_pump.h" 16 #include "base/message_pump.h"
17 #include "base/observer_list.h" 17 #include "base/observer_list.h"
18 #include "base/synchronization/lock.h" 18 #include "base/synchronization/lock.h"
19 #include "base/task.h" 19 #include "base/task.h"
20 #include "base/time.h" 20 #include "base/time.h"
21 #include "base/tracked.h" 21 #include "base/tracked.h"
22 22
23 #if defined(OS_WIN) 23 #if defined(OS_WIN)
24 // We need this to declare base::MessagePumpWin::Dispatcher, which we should 24 // We need this to declare base::MessagePumpWin::Dispatcher, which we should
25 // really just eliminate. 25 // really just eliminate.
26 #include "base/message_pump_win.h" 26 #include "base/message_pump_win.h"
27 #elif defined(OS_MACOSX)
28 #include "base/message_pump_mac.h"
27 #elif defined(OS_POSIX) 29 #elif defined(OS_POSIX)
28 #include "base/message_pump_libevent.h" 30 #include "base/message_pump_libevent.h"
29 #if !defined(OS_MACOSX)
30 #if defined(TOUCH_UI) 31 #if defined(TOUCH_UI)
31 #include "base/message_pump_x.h" 32 #include "base/message_pump_x.h"
32 #else 33 #else
33 #include "base/message_pump_gtk.h" 34 #include "base/message_pump_gtk.h"
34 #endif 35 #endif
35 typedef struct _XDisplay Display; 36 typedef struct _XDisplay Display;
36 #endif 37 #endif
37 #endif
38 38
39 namespace base { 39 namespace base {
40 class Histogram; 40 class Histogram;
41 } 41 }
42 42
43 #if defined(TRACK_ALL_TASK_OBJECTS) 43 #if defined(TRACK_ALL_TASK_OBJECTS)
44 namespace tracked_objects { 44 namespace tracked_objects {
45 class Births; 45 class Births;
46 } 46 }
47 #endif // defined(TRACK_ALL_TASK_OBJECTS) 47 #endif // defined(TRACK_ALL_TASK_OBJECTS)
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 c.swap(queue->c); // Calls std::deque::swap 424 c.swap(queue->c); // Calls std::deque::swap
425 } 425 }
426 }; 426 };
427 427
428 typedef std::priority_queue<PendingTask> DelayedTaskQueue; 428 typedef std::priority_queue<PendingTask> DelayedTaskQueue;
429 429
430 #if defined(OS_WIN) 430 #if defined(OS_WIN)
431 base::MessagePumpWin* pump_win() { 431 base::MessagePumpWin* pump_win() {
432 return static_cast<base::MessagePumpWin*>(pump_.get()); 432 return static_cast<base::MessagePumpWin*>(pump_.get());
433 } 433 }
434 #elif defined(OS_MACOSX)
435 base::MessagePumpCFRunLoopBase* pump_mac() {
436 return static_cast<base::MessagePumpCFRunLoopBase*>(pump_.get());
437 }
434 #elif defined(OS_POSIX) 438 #elif defined(OS_POSIX)
435 base::MessagePumpLibevent* pump_libevent() { 439 base::MessagePumpLibevent* pump_libevent() {
436 return static_cast<base::MessagePumpLibevent*>(pump_.get()); 440 return static_cast<base::MessagePumpLibevent*>(pump_.get());
437 } 441 }
438 #endif 442 #endif
439 443
440 // A function to encapsulate all the exception handling capability in the 444 // A function to encapsulate all the exception handling capability in the
441 // stacks around the running of a main message loop. It will run the message 445 // stacks around the running of a main message loop. It will run the message
442 // loop in a SEH try block or not depending on the set_SEH_restoration() 446 // loop in a SEH try block or not depending on the set_SEH_restoration()
443 // flag invoking respectively RunInternalInSEHFrame() or RunInternal(). 447 // flag invoking respectively RunInternalInSEHFrame() or RunInternal().
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 // 627 //
624 // This class is typically used like so: 628 // This class is typically used like so:
625 // MessageLoopForIO::current()->...call some method... 629 // MessageLoopForIO::current()->...call some method...
626 // 630 //
627 class BASE_API MessageLoopForIO : public MessageLoop { 631 class BASE_API MessageLoopForIO : public MessageLoop {
628 public: 632 public:
629 #if defined(OS_WIN) 633 #if defined(OS_WIN)
630 typedef base::MessagePumpForIO::IOHandler IOHandler; 634 typedef base::MessagePumpForIO::IOHandler IOHandler;
631 typedef base::MessagePumpForIO::IOContext IOContext; 635 typedef base::MessagePumpForIO::IOContext IOContext;
632 typedef base::MessagePumpForIO::IOObserver IOObserver; 636 typedef base::MessagePumpForIO::IOObserver IOObserver;
637 #elif defined(OS_MACOSX)
638 typedef base::MessagePumpCFRunLoopBase::Watcher Watcher;
639 typedef base::MessagePumpCFRunLoopBase::FileDescriptorWatcher
640 FileDescriptorWatcher;
641 typedef base::MessagePumpCFRunLoopBase::IOObserver IOObserver;
642
643 enum Mode {
644 WATCH_READ = base::MessagePumpCFRunLoopBase::WATCH_READ,
645 WATCH_WRITE = base::MessagePumpCFRunLoopBase::WATCH_WRITE,
646 WATCH_READ_WRITE = base::MessagePumpCFRunLoopBase::WATCH_READ_WRITE
647 };
633 #elif defined(OS_POSIX) 648 #elif defined(OS_POSIX)
634 typedef base::MessagePumpLibevent::Watcher Watcher; 649 typedef base::MessagePumpLibevent::Watcher Watcher;
635 typedef base::MessagePumpLibevent::FileDescriptorWatcher 650 typedef base::MessagePumpLibevent::FileDescriptorWatcher
636 FileDescriptorWatcher; 651 FileDescriptorWatcher;
637 typedef base::MessagePumpLibevent::IOObserver IOObserver; 652 typedef base::MessagePumpLibevent::IOObserver IOObserver;
638 653
639 enum Mode { 654 enum Mode {
640 WATCH_READ = base::MessagePumpLibevent::WATCH_READ, 655 WATCH_READ = base::MessagePumpLibevent::WATCH_READ,
641 WATCH_WRITE = base::MessagePumpLibevent::WATCH_WRITE, 656 WATCH_WRITE = base::MessagePumpLibevent::WATCH_WRITE,
642 WATCH_READ_WRITE = base::MessagePumpLibevent::WATCH_READ_WRITE 657 WATCH_READ_WRITE = base::MessagePumpLibevent::WATCH_READ_WRITE
643 }; 658 };
644
645 #endif 659 #endif
646 660
647 MessageLoopForIO() : MessageLoop(TYPE_IO) { 661 MessageLoopForIO() : MessageLoop(TYPE_IO) {
648 } 662 }
649 663
650 // Returns the MessageLoopForIO of the current thread. 664 // Returns the MessageLoopForIO of the current thread.
651 static MessageLoopForIO* current() { 665 static MessageLoopForIO* current() {
652 MessageLoop* loop = MessageLoop::current(); 666 MessageLoop* loop = MessageLoop::current();
653 DCHECK_EQ(MessageLoop::TYPE_IO, loop->type()); 667 DCHECK_EQ(MessageLoop::TYPE_IO, loop->type());
654 return static_cast<MessageLoopForIO*>(loop); 668 return static_cast<MessageLoopForIO*>(loop);
(...skipping 11 matching lines...) Expand all
666 // Please see MessagePumpWin for definitions of these methods. 680 // Please see MessagePumpWin for definitions of these methods.
667 void RegisterIOHandler(HANDLE file_handle, IOHandler* handler); 681 void RegisterIOHandler(HANDLE file_handle, IOHandler* handler);
668 bool WaitForIOCompletion(DWORD timeout, IOHandler* filter); 682 bool WaitForIOCompletion(DWORD timeout, IOHandler* filter);
669 683
670 protected: 684 protected:
671 // TODO(rvargas): Make this platform independent. 685 // TODO(rvargas): Make this platform independent.
672 base::MessagePumpForIO* pump_io() { 686 base::MessagePumpForIO* pump_io() {
673 return static_cast<base::MessagePumpForIO*>(pump_.get()); 687 return static_cast<base::MessagePumpForIO*>(pump_.get());
674 } 688 }
675 689
690 #elif defined(OS_MACOSX)
691 // Please see MessagePumpCFRunLoopBase for definition.
692 bool WatchFileDescriptor(int fd,
693 bool persistent,
694 Mode mode,
695 FileDescriptorWatcher *controller,
696 Watcher *delegate);
697
698 private:
699 base::MessagePumpCFRunLoopBase* pump_io() {
700 return static_cast<base::MessagePumpCFRunLoopBase*>(pump_.get());
701 }
676 #elif defined(OS_POSIX) 702 #elif defined(OS_POSIX)
677 // Please see MessagePumpLibevent for definition. 703 // Please see MessagePumpLibevent for definition.
678 bool WatchFileDescriptor(int fd, 704 bool WatchFileDescriptor(int fd,
679 bool persistent, 705 bool persistent,
680 Mode mode, 706 Mode mode,
681 FileDescriptorWatcher *controller, 707 FileDescriptorWatcher *controller,
682 Watcher *delegate); 708 Watcher *delegate);
683 709
684 private: 710 private:
685 base::MessagePumpLibevent* pump_io() { 711 base::MessagePumpLibevent* pump_io() {
686 return static_cast<base::MessagePumpLibevent*>(pump_.get()); 712 return static_cast<base::MessagePumpLibevent*>(pump_.get());
687 } 713 }
688 #endif // defined(OS_POSIX) 714 #endif // defined(OS_POSIX)
689 }; 715 };
690 716
691 // Do not add any member variables to MessageLoopForIO! This is important b/c 717 // Do not add any member variables to MessageLoopForIO! This is important b/c
692 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra 718 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra
693 // data that you need should be stored on the MessageLoop's pump_ instance. 719 // data that you need should be stored on the MessageLoop's pump_ instance.
694 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), 720 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO),
695 MessageLoopForIO_should_not_have_extra_member_variables); 721 MessageLoopForIO_should_not_have_extra_member_variables);
696 722
697 #endif // BASE_MESSAGE_LOOP_H_ 723 #endif // BASE_MESSAGE_LOOP_H_
OLDNEW
« no previous file with comments | « base/base.gypi ('k') | base/message_loop.cc » ('j') | base/message_loop.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698