| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_pump_default.h" | 12 #include "base/message_pump_default.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/thread_local.h" | 14 #include "base/thread_local.h" |
| 15 | 15 |
| 16 #if defined(OS_MACOSX) | 16 #if defined(OS_MACOSX) |
| 17 #include "base/message_pump_mac.h" | 17 #include "base/message_pump_mac.h" |
| 18 #endif | 18 #endif |
| 19 #if defined(OS_POSIX) | 19 #if defined(OS_POSIX) |
| 20 #include "base/message_pump_libevent.h" | 20 #include "base/message_pump_libevent.h" |
| 21 #include "base/third_party/valgrind/valgrind.h" | 21 #include "base/third_party/valgrind/valgrind.h" |
| 22 #endif | 22 #endif |
| 23 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 23 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 24 #include "base/message_pump_glib.h" | 24 #include "base/message_pump_glib.h" |
| 25 #endif | 25 #endif |
| 26 #if defined(TOUCH_UI) |
| 27 #include "base/message_pump_glib_x.h" |
| 28 #endif |
| 26 | 29 |
| 27 using base::Time; | 30 using base::Time; |
| 28 using base::TimeDelta; | 31 using base::TimeDelta; |
| 29 | 32 |
| 30 namespace { | 33 namespace { |
| 31 | 34 |
| 32 // A lazily created thread local storage for quick access to a thread's message | 35 // A lazily created thread local storage for quick access to a thread's message |
| 33 // loop, if one exists. This should be safe and free of static constructors. | 36 // loop, if one exists. This should be safe and free of static constructors. |
| 34 base::LazyInstance<base::ThreadLocalPointer<MessageLoop> > lazy_tls_ptr( | 37 base::LazyInstance<base::ThreadLocalPointer<MessageLoop> > lazy_tls_ptr( |
| 35 base::LINKER_INITIALIZED); | 38 base::LINKER_INITIALIZED); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 DCHECK(!current()) << "should only have one message loop per thread"; | 130 DCHECK(!current()) << "should only have one message loop per thread"; |
| 128 lazy_tls_ptr.Pointer()->Set(this); | 131 lazy_tls_ptr.Pointer()->Set(this); |
| 129 | 132 |
| 130 // TODO(rvargas): Get rid of the OS guards. | 133 // TODO(rvargas): Get rid of the OS guards. |
| 131 #if defined(OS_WIN) | 134 #if defined(OS_WIN) |
| 132 #define MESSAGE_PUMP_UI new base::MessagePumpForUI() | 135 #define MESSAGE_PUMP_UI new base::MessagePumpForUI() |
| 133 #define MESSAGE_PUMP_IO new base::MessagePumpForIO() | 136 #define MESSAGE_PUMP_IO new base::MessagePumpForIO() |
| 134 #elif defined(OS_MACOSX) | 137 #elif defined(OS_MACOSX) |
| 135 #define MESSAGE_PUMP_UI base::MessagePumpMac::Create() | 138 #define MESSAGE_PUMP_UI base::MessagePumpMac::Create() |
| 136 #define MESSAGE_PUMP_IO new base::MessagePumpLibevent() | 139 #define MESSAGE_PUMP_IO new base::MessagePumpLibevent() |
| 140 #elif defined(TOUCH_UI) |
| 141 #define MESSAGE_PUMP_UI new base::MessagePumpGlibX() |
| 142 #define MESSAGE_PUMP_IO new base::MessagePumpLibevent() |
| 137 #elif defined(OS_POSIX) // POSIX but not MACOSX. | 143 #elif defined(OS_POSIX) // POSIX but not MACOSX. |
| 138 #define MESSAGE_PUMP_UI new base::MessagePumpForUI() | 144 #define MESSAGE_PUMP_UI new base::MessagePumpForUI() |
| 139 #define MESSAGE_PUMP_IO new base::MessagePumpLibevent() | 145 #define MESSAGE_PUMP_IO new base::MessagePumpLibevent() |
| 140 #else | 146 #else |
| 141 #error Not implemented | 147 #error Not implemented |
| 142 #endif | 148 #endif |
| 143 | 149 |
| 144 if (type_ == TYPE_UI) { | 150 if (type_ == TYPE_UI) { |
| 145 pump_ = MESSAGE_PUMP_UI; | 151 pump_ = MESSAGE_PUMP_UI; |
| 146 } else if (type_ == TYPE_IO) { | 152 } else if (type_ == TYPE_IO) { |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 if (DeferOrRunPendingTask(pending_task)) | 532 if (DeferOrRunPendingTask(pending_task)) |
| 527 return true; | 533 return true; |
| 528 } | 534 } |
| 529 } while (!work_queue_.empty()); | 535 } while (!work_queue_.empty()); |
| 530 } | 536 } |
| 531 | 537 |
| 532 // Nothing happened. | 538 // Nothing happened. |
| 533 return false; | 539 return false; |
| 534 } | 540 } |
| 535 | 541 |
| 536 bool MessageLoop::DoDelayedWork(Time* next_delayed_work_time) { | 542 bool MessageLoop::DoDelayedWork(base::Time* next_delayed_work_time) { |
| 537 if (!nestable_tasks_allowed_ || delayed_work_queue_.empty()) { | 543 if (!nestable_tasks_allowed_ || delayed_work_queue_.empty()) { |
| 538 *next_delayed_work_time = Time(); | 544 *next_delayed_work_time = base::Time(); |
| 539 return false; | 545 return false; |
| 540 } | 546 } |
| 541 | 547 |
| 542 if (delayed_work_queue_.top().delayed_run_time > Time::Now()) { | 548 if (delayed_work_queue_.top().delayed_run_time > Time::Now()) { |
| 543 *next_delayed_work_time = delayed_work_queue_.top().delayed_run_time; | 549 *next_delayed_work_time = delayed_work_queue_.top().delayed_run_time; |
| 544 return false; | 550 return false; |
| 545 } | 551 } |
| 546 | 552 |
| 547 PendingTask pending_task = delayed_work_queue_.top(); | 553 PendingTask pending_task = delayed_work_queue_.top(); |
| 548 delayed_work_queue_.pop(); | 554 delayed_work_queue_.pop(); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 Watcher *delegate) { | 686 Watcher *delegate) { |
| 681 return pump_libevent()->WatchFileDescriptor( | 687 return pump_libevent()->WatchFileDescriptor( |
| 682 fd, | 688 fd, |
| 683 persistent, | 689 persistent, |
| 684 static_cast<base::MessagePumpLibevent::Mode>(mode), | 690 static_cast<base::MessagePumpLibevent::Mode>(mode), |
| 685 controller, | 691 controller, |
| 686 delegate); | 692 delegate); |
| 687 } | 693 } |
| 688 | 694 |
| 689 #endif | 695 #endif |
| OLD | NEW |