OLD | NEW |
1 // Copyright (c) 2008 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_pump_glib.h" | 5 #include "base/message_pump_glib.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <math.h> | 8 #include <math.h> |
9 | 9 |
10 #include <gtk/gtk.h> | 10 #include <gtk/gtk.h> |
11 #include <glib.h> | 11 #include <glib.h> |
12 | 12 |
13 #include "base/eintr_wrapper.h" | 13 #include "base/eintr_wrapper.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/platform_thread.h" | 15 #include "base/threading/platform_thread.h" |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 // We send a byte across a pipe to wakeup the event loop. | 19 // We send a byte across a pipe to wakeup the event loop. |
20 const char kWorkScheduled = '\0'; | 20 const char kWorkScheduled = '\0'; |
21 | 21 |
22 // Return a timeout suitable for the glib loop, -1 to block forever, | 22 // Return a timeout suitable for the glib loop, -1 to block forever, |
23 // 0 to return right away, or a timeout in milliseconds from now. | 23 // 0 to return right away, or a timeout in milliseconds from now. |
24 int GetTimeIntervalMilliseconds(const base::TimeTicks& from) { | 24 int GetTimeIntervalMilliseconds(const base::TimeTicks& from) { |
25 if (from.is_null()) | 25 if (from.is_null()) |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 g_source_unref(work_source_); | 170 g_source_unref(work_source_); |
171 close(wakeup_pipe_read_); | 171 close(wakeup_pipe_read_); |
172 close(wakeup_pipe_write_); | 172 close(wakeup_pipe_write_); |
173 } | 173 } |
174 | 174 |
175 void MessagePumpForUI::RunWithDispatcher(Delegate* delegate, | 175 void MessagePumpForUI::RunWithDispatcher(Delegate* delegate, |
176 Dispatcher* dispatcher) { | 176 Dispatcher* dispatcher) { |
177 #ifndef NDEBUG | 177 #ifndef NDEBUG |
178 // Make sure we only run this on one thread. GTK only has one message pump | 178 // Make sure we only run this on one thread. GTK only has one message pump |
179 // so we can only have one UI loop per process. | 179 // so we can only have one UI loop per process. |
180 static PlatformThreadId thread_id = PlatformThread::CurrentId(); | 180 static base::PlatformThreadId thread_id = base::PlatformThread::CurrentId(); |
181 DCHECK(thread_id == PlatformThread::CurrentId()) << | 181 DCHECK(thread_id == base::PlatformThread::CurrentId()) << |
182 "Running MessagePumpForUI on two different threads; " | 182 "Running MessagePumpForUI on two different threads; " |
183 "this is unsupported by GLib!"; | 183 "this is unsupported by GLib!"; |
184 #endif | 184 #endif |
185 | 185 |
186 RunState state; | 186 RunState state; |
187 state.delegate = delegate; | 187 state.delegate = delegate; |
188 state.dispatcher = dispatcher; | 188 state.dispatcher = dispatcher; |
189 state.should_quit = false; | 189 state.should_quit = false; |
190 state.run_depth = state_ ? state_->run_depth + 1 : 1; | 190 state.run_depth = state_ ? state_->run_depth + 1 : 1; |
191 state.has_work = false; | 191 state.has_work = false; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 DidProcessEvent(event); | 355 DidProcessEvent(event); |
356 } | 356 } |
357 | 357 |
358 // static | 358 // static |
359 void MessagePumpForUI::EventDispatcher(GdkEvent* event, gpointer data) { | 359 void MessagePumpForUI::EventDispatcher(GdkEvent* event, gpointer data) { |
360 MessagePumpForUI* message_pump = reinterpret_cast<MessagePumpForUI*>(data); | 360 MessagePumpForUI* message_pump = reinterpret_cast<MessagePumpForUI*>(data); |
361 message_pump->DispatchEvents(event); | 361 message_pump->DispatchEvents(event); |
362 } | 362 } |
363 | 363 |
364 } // namespace base | 364 } // namespace base |
OLD | NEW |