| OLD | NEW |
| 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 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 #ifndef BASE_MESSAGE_PUMP_GLIB_H_ | 5 #ifndef BASE_MESSAGE_PUMP_GLIB_H_ |
| 6 #define BASE_MESSAGE_PUMP_GLIB_H_ | 6 #define BASE_MESSAGE_PUMP_GLIB_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/message_pump.h" | 9 #include "base/message_pump.h" |
| 10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 virtual void RunWithDispatcher(Delegate* delegate, Dispatcher* dispatcher); | 58 virtual void RunWithDispatcher(Delegate* delegate, Dispatcher* dispatcher); |
| 59 | 59 |
| 60 // Run a single iteration of the mainloop. A return value of true indicates | 60 // Run a single iteration of the mainloop. A return value of true indicates |
| 61 // that an event was handled. |block| indicates if it should wait if no event | 61 // that an event was handled. |block| indicates if it should wait if no event |
| 62 // is ready for processing. | 62 // is ready for processing. |
| 63 virtual bool RunOnce(GMainContext* context, bool block); | 63 virtual bool RunOnce(GMainContext* context, bool block); |
| 64 | 64 |
| 65 virtual void Run(Delegate* delegate) { RunWithDispatcher(delegate, NULL); } | 65 virtual void Run(Delegate* delegate) { RunWithDispatcher(delegate, NULL); } |
| 66 virtual void Quit(); | 66 virtual void Quit(); |
| 67 virtual void ScheduleWork(); | 67 virtual void ScheduleWork(); |
| 68 virtual void ScheduleDelayedWork(const Time& delayed_work_time); | 68 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time); |
| 69 | 69 |
| 70 // Internal methods used for processing the pump callbacks. They are | 70 // Internal methods used for processing the pump callbacks. They are |
| 71 // public for simplicity but should not be used directly. HandlePrepare | 71 // public for simplicity but should not be used directly. HandlePrepare |
| 72 // is called during the prepare step of glib, and returns a timeout that | 72 // is called during the prepare step of glib, and returns a timeout that |
| 73 // will be passed to the poll. HandleCheck is called after the poll | 73 // will be passed to the poll. HandleCheck is called after the poll |
| 74 // has completed, and returns whether or not HandleDispatch should be called. | 74 // has completed, and returns whether or not HandleDispatch should be called. |
| 75 // HandleDispatch is called if HandleCheck returned true. | 75 // HandleDispatch is called if HandleCheck returned true. |
| 76 int HandlePrepare(); | 76 int HandlePrepare(); |
| 77 bool HandleCheck(); | 77 bool HandleCheck(); |
| 78 void HandleDispatch(); | 78 void HandleDispatch(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 109 static void EventDispatcher(GdkEvent* event, void* data); | 109 static void EventDispatcher(GdkEvent* event, void* data); |
| 110 | 110 |
| 111 RunState* state_; | 111 RunState* state_; |
| 112 | 112 |
| 113 // This is a GLib structure that we can add event sources to. We use the | 113 // This is a GLib structure that we can add event sources to. We use the |
| 114 // default GLib context, which is the one to which all GTK events are | 114 // default GLib context, which is the one to which all GTK events are |
| 115 // dispatched. | 115 // dispatched. |
| 116 GMainContext* context_; | 116 GMainContext* context_; |
| 117 | 117 |
| 118 // This is the time when we need to do delayed work. | 118 // This is the time when we need to do delayed work. |
| 119 Time delayed_work_time_; | 119 TimeTicks delayed_work_time_; |
| 120 | 120 |
| 121 // The work source. It is shared by all calls to Run and destroyed when | 121 // The work source. It is shared by all calls to Run and destroyed when |
| 122 // the message pump is destroyed. | 122 // the message pump is destroyed. |
| 123 GSource* work_source_; | 123 GSource* work_source_; |
| 124 | 124 |
| 125 // We use a wakeup pipe to make sure we'll get out of the glib polling phase | 125 // We use a wakeup pipe to make sure we'll get out of the glib polling phase |
| 126 // when another thread has scheduled us to do some work. There is a glib | 126 // when another thread has scheduled us to do some work. There is a glib |
| 127 // mechanism g_main_context_wakeup, but this won't guarantee that our event's | 127 // mechanism g_main_context_wakeup, but this won't guarantee that our event's |
| 128 // Dispatch() will be called. | 128 // Dispatch() will be called. |
| 129 int wakeup_pipe_read_; | 129 int wakeup_pipe_read_; |
| 130 int wakeup_pipe_write_; | 130 int wakeup_pipe_write_; |
| 131 // Use a scoped_ptr to avoid needing the definition of GPollFD in the header. | 131 // Use a scoped_ptr to avoid needing the definition of GPollFD in the header. |
| 132 scoped_ptr<GPollFD> wakeup_gpollfd_; | 132 scoped_ptr<GPollFD> wakeup_gpollfd_; |
| 133 | 133 |
| 134 // List of observers. | 134 // List of observers. |
| 135 ObserverList<Observer> observers_; | 135 ObserverList<Observer> observers_; |
| 136 | 136 |
| 137 DISALLOW_COPY_AND_ASSIGN(MessagePumpForUI); | 137 DISALLOW_COPY_AND_ASSIGN(MessagePumpForUI); |
| 138 }; | 138 }; |
| 139 | 139 |
| 140 } // namespace base | 140 } // namespace base |
| 141 | 141 |
| 142 #endif // BASE_MESSAGE_PUMP_GLIB_H_ | 142 #endif // BASE_MESSAGE_PUMP_GLIB_H_ |
| OLD | NEW |