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