Chromium Code Reviews| 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 #include "base/message_loop.h" | 5 #include "base/message_loop.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/debug/alias.h" | 11 #include "base/debug/alias.h" |
| 12 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
| 13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/message_loop_proxy_impl.h" | 16 #include "base/message_loop_proxy_impl.h" |
| 17 #include "base/message_pump_default.h" | 17 #include "base/message_pump_default.h" |
| 18 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
| 19 #include "base/metrics/statistics_recorder.h" | 19 #include "base/metrics/statistics_recorder.h" |
| 20 #include "base/run_loop.h" | 20 #include "base/run_loop.h" |
| 21 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 21 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| 22 #include "base/thread_task_runner_handle.h" | 22 #include "base/thread_task_runner_handle.h" |
| 23 #include "base/threading/thread_local.h" | 23 #include "base/threading/thread_local.h" |
| 24 #include "base/time.h" | 24 #include "base/time.h" |
| 25 #include "base/tracked_objects.h" | 25 #include "base/tracked_objects.h" |
| 26 | 26 |
| 27 #if defined(OS_MACOSX) | 27 #if defined(OS_MACOSX) |
| 28 #include "base/message_pump_mac.h" | 28 #include "base/message_pump_mac.h" |
| 29 #endif | 29 #endif |
| 30 #if defined(OS_POSIX) | 30 #if defined(OS_POSIX) && !defined(OS_IOS) |
| 31 #include "base/message_pump_libevent.h" | 31 #include "base/message_pump_libevent.h" |
| 32 #endif | 32 #endif |
| 33 #if defined(OS_ANDROID) | 33 #if defined(OS_ANDROID) |
| 34 #include "base/message_pump_android.h" | 34 #include "base/message_pump_android.h" |
| 35 #endif | 35 #endif |
| 36 | 36 |
| 37 #if defined(TOOLKIT_GTK) | 37 #if defined(TOOLKIT_GTK) |
| 38 #include <gdk/gdk.h> | 38 #include <gdk/gdk.h> |
| 39 #include <gdk/gdkx.h> | 39 #include <gdk/gdkx.h> |
| 40 #endif | 40 #endif |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 lazy_tls_ptr.Pointer()->Set(this); | 150 lazy_tls_ptr.Pointer()->Set(this); |
| 151 | 151 |
| 152 message_loop_proxy_ = new base::MessageLoopProxyImpl(); | 152 message_loop_proxy_ = new base::MessageLoopProxyImpl(); |
| 153 thread_task_runner_handle_.reset( | 153 thread_task_runner_handle_.reset( |
| 154 new base::ThreadTaskRunnerHandle(message_loop_proxy_)); | 154 new base::ThreadTaskRunnerHandle(message_loop_proxy_)); |
| 155 | 155 |
| 156 // TODO(rvargas): Get rid of the OS guards. | 156 // TODO(rvargas): Get rid of the OS guards. |
| 157 #if defined(OS_WIN) | 157 #if defined(OS_WIN) |
| 158 #define MESSAGE_PUMP_UI new base::MessagePumpForUI() | 158 #define MESSAGE_PUMP_UI new base::MessagePumpForUI() |
| 159 #define MESSAGE_PUMP_IO new base::MessagePumpForIO() | 159 #define MESSAGE_PUMP_IO new base::MessagePumpForIO() |
| 160 #elif defined(OS_IOS) | |
| 161 #define MESSAGE_PUMP_UI base::MessagePumpMac::Create() | |
| 162 #define MESSAGE_PUMP_IO new base::MessagePumpIOSForIO() | |
| 160 #elif defined(OS_MACOSX) | 163 #elif defined(OS_MACOSX) |
| 161 #define MESSAGE_PUMP_UI base::MessagePumpMac::Create() | 164 #define MESSAGE_PUMP_UI base::MessagePumpMac::Create() |
| 162 #define MESSAGE_PUMP_IO new base::MessagePumpLibevent() | 165 #define MESSAGE_PUMP_IO new base::MessagePumpLibevent() |
| 163 #elif defined(OS_NACL) | 166 #elif defined(OS_NACL) |
| 164 // Currently NaCl doesn't have a UI MessageLoop. | 167 // Currently NaCl doesn't have a UI MessageLoop. |
| 165 // TODO(abarth): Figure out if we need this. | 168 // TODO(abarth): Figure out if we need this. |
| 166 #define MESSAGE_PUMP_UI NULL | 169 #define MESSAGE_PUMP_UI NULL |
| 167 // ipc_channel_nacl.cc uses a worker thread to do socket reads currently, and | 170 // ipc_channel_nacl.cc uses a worker thread to do socket reads currently, and |
| 168 // doesn't require extra support for watching file descriptors. | 171 // doesn't require extra support for watching file descriptors. |
| 169 #define MESSAGE_PUMP_IO new base::MessagePumpDefault(); | 172 #define MESSAGE_PUMP_IO new base::MessagePumpDefault(); |
| (...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 769 } | 772 } |
| 770 | 773 |
| 771 bool MessageLoopForIO::RegisterJobObject(HANDLE job, IOHandler* handler) { | 774 bool MessageLoopForIO::RegisterJobObject(HANDLE job, IOHandler* handler) { |
| 772 return pump_io()->RegisterJobObject(job, handler); | 775 return pump_io()->RegisterJobObject(job, handler); |
| 773 } | 776 } |
| 774 | 777 |
| 775 bool MessageLoopForIO::WaitForIOCompletion(DWORD timeout, IOHandler* filter) { | 778 bool MessageLoopForIO::WaitForIOCompletion(DWORD timeout, IOHandler* filter) { |
| 776 return pump_io()->WaitForIOCompletion(timeout, filter); | 779 return pump_io()->WaitForIOCompletion(timeout, filter); |
| 777 } | 780 } |
| 778 | 781 |
| 782 #elif defined(OS_IOS) | |
| 783 | |
| 784 bool MessageLoopForIO::WatchFileDescriptor(int fd, | |
| 785 bool persistent, | |
| 786 Mode mode, | |
| 787 FileDescriptorWatcher *controller, | |
| 788 Watcher *delegate) { | |
| 789 return pump_io()->WatchFileDescriptor( | |
| 790 fd, | |
| 791 persistent, | |
| 792 static_cast<base::MessagePumpIOSForIO::Mode>(mode), | |
|
Mark Mentovai
2012/11/20 22:29:27
No cast, the callee should be accepting int. See t
blundell
2012/11/21 16:56:52
Done.
| |
| 793 controller, | |
| 794 delegate); | |
| 795 } | |
| 796 | |
| 779 #elif defined(OS_POSIX) && !defined(OS_NACL) | 797 #elif defined(OS_POSIX) && !defined(OS_NACL) |
| 780 | 798 |
| 781 bool MessageLoopForIO::WatchFileDescriptor(int fd, | 799 bool MessageLoopForIO::WatchFileDescriptor(int fd, |
| 782 bool persistent, | 800 bool persistent, |
| 783 Mode mode, | 801 Mode mode, |
| 784 FileDescriptorWatcher *controller, | 802 FileDescriptorWatcher *controller, |
| 785 Watcher *delegate) { | 803 Watcher *delegate) { |
| 786 return pump_libevent()->WatchFileDescriptor( | 804 return pump_libevent()->WatchFileDescriptor( |
| 787 fd, | 805 fd, |
| 788 persistent, | 806 persistent, |
| 789 static_cast<base::MessagePumpLibevent::Mode>(mode), | 807 static_cast<base::MessagePumpLibevent::Mode>(mode), |
| 790 controller, | 808 controller, |
| 791 delegate); | 809 delegate); |
| 792 } | 810 } |
| 793 | 811 |
| 794 #endif | 812 #endif |
| OLD | NEW |