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