| 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/message_pump_glib.h" | 5 #include "base/message_loop/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 <glib.h> | 10 #include <glib.h> |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 work_source_ = g_source_new(&WorkSourceFuncs, sizeof(WorkSource)); | 153 work_source_ = g_source_new(&WorkSourceFuncs, sizeof(WorkSource)); |
| 154 static_cast<WorkSource*>(work_source_)->pump = this; | 154 static_cast<WorkSource*>(work_source_)->pump = this; |
| 155 g_source_add_poll(work_source_, wakeup_gpollfd_.get()); | 155 g_source_add_poll(work_source_, wakeup_gpollfd_.get()); |
| 156 // Use a low priority so that we let other events in the queue go first. | 156 // Use a low priority so that we let other events in the queue go first. |
| 157 g_source_set_priority(work_source_, G_PRIORITY_DEFAULT_IDLE); | 157 g_source_set_priority(work_source_, G_PRIORITY_DEFAULT_IDLE); |
| 158 // This is needed to allow Run calls inside Dispatch. | 158 // This is needed to allow Run calls inside Dispatch. |
| 159 g_source_set_can_recurse(work_source_, TRUE); | 159 g_source_set_can_recurse(work_source_, TRUE); |
| 160 g_source_attach(work_source_, context_); | 160 g_source_attach(work_source_, context_); |
| 161 } | 161 } |
| 162 | 162 |
| 163 MessagePumpGlib::~MessagePumpGlib() { |
| 164 g_source_destroy(work_source_); |
| 165 g_source_unref(work_source_); |
| 166 close(wakeup_pipe_read_); |
| 167 close(wakeup_pipe_write_); |
| 168 } |
| 169 |
| 163 void MessagePumpGlib::RunWithDispatcher(Delegate* delegate, | 170 void MessagePumpGlib::RunWithDispatcher(Delegate* delegate, |
| 164 MessagePumpDispatcher* dispatcher) { | 171 MessagePumpDispatcher* dispatcher) { |
| 165 #ifndef NDEBUG | 172 #ifndef NDEBUG |
| 166 // Make sure we only run this on one thread. X/GTK only has one message pump | 173 // Make sure we only run this on one thread. X/GTK only has one message pump |
| 167 // so we can only have one UI loop per process. | 174 // so we can only have one UI loop per process. |
| 168 static PlatformThreadId thread_id = PlatformThread::CurrentId(); | 175 static PlatformThreadId thread_id = PlatformThread::CurrentId(); |
| 169 DCHECK(thread_id == PlatformThread::CurrentId()) << | 176 DCHECK(thread_id == PlatformThread::CurrentId()) << |
| 170 "Running MessagePumpGlib on two different threads; " | 177 "Running MessagePumpGlib on two different threads; " |
| 171 "this is unsupported by GLib!"; | 178 "this is unsupported by GLib!"; |
| 172 #endif | 179 #endif |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 } | 320 } |
| 314 } | 321 } |
| 315 | 322 |
| 316 void MessagePumpGlib::ScheduleDelayedWork(const TimeTicks& delayed_work_time) { | 323 void MessagePumpGlib::ScheduleDelayedWork(const TimeTicks& delayed_work_time) { |
| 317 // We need to wake up the loop in case the poll timeout needs to be | 324 // We need to wake up the loop in case the poll timeout needs to be |
| 318 // adjusted. This will cause us to try to do work, but that's ok. | 325 // adjusted. This will cause us to try to do work, but that's ok. |
| 319 delayed_work_time_ = delayed_work_time; | 326 delayed_work_time_ = delayed_work_time; |
| 320 ScheduleWork(); | 327 ScheduleWork(); |
| 321 } | 328 } |
| 322 | 329 |
| 323 MessagePumpGlib::~MessagePumpGlib() { | |
| 324 g_source_destroy(work_source_); | |
| 325 g_source_unref(work_source_); | |
| 326 close(wakeup_pipe_read_); | |
| 327 close(wakeup_pipe_write_); | |
| 328 } | |
| 329 | |
| 330 MessagePumpDispatcher* MessagePumpGlib::GetDispatcher() { | 330 MessagePumpDispatcher* MessagePumpGlib::GetDispatcher() { |
| 331 return state_ ? state_->dispatcher : NULL; | 331 return state_ ? state_->dispatcher : NULL; |
| 332 } | 332 } |
| 333 | 333 |
| 334 } // namespace base | 334 } // namespace base |
| OLD | NEW |