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 | 7 |
8 #include <glib.h> | 8 #include <glib.h> |
9 | 9 |
10 #include "base/message_pump.h" | 10 #include "base/message_pump.h" |
11 #include "base/time.h" | 11 #include "base/time.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 | 14 |
15 // This class implements a MessagePump needed for TYPE_UI MessageLoops on | 15 // This class implements a MessagePump needed for TYPE_UI MessageLoops on |
16 // OS_LINUX platforms using GLib. | 16 // OS_LINUX platforms using GLib. |
17 class MessagePumpForUI : public MessagePump { | 17 class MessagePumpForUI : public MessagePump { |
18 public: | 18 public: |
19 MessagePumpForUI(); | 19 MessagePumpForUI(); |
20 ~MessagePumpForUI(); | 20 ~MessagePumpForUI(); |
21 | 21 |
22 virtual void Run(Delegate* delegate); | 22 virtual void Run(Delegate* delegate); |
23 virtual void Quit(); | 23 virtual void Quit(); |
24 virtual void ScheduleWork(); | 24 virtual void ScheduleWork(); |
25 virtual void ScheduleDelayedWork(const Time& delayed_work_time); | 25 virtual void ScheduleDelayedWork(const base::Time& delayed_work_time); |
26 | 26 |
27 private: | 27 private: |
28 // We may make recursive calls to Run, so we save state that needs to be | 28 // We may make recursive calls to Run, so we save state that needs to be |
29 // separate between them in this structure type. | 29 // separate between them in this structure type. |
30 struct RunState { | 30 struct RunState { |
31 // This is the delegate argument passed to Run. | 31 // This is the delegate argument passed to Run. |
32 Delegate* delegate; | 32 Delegate* delegate; |
33 // This tells us when to exit the event pump. | 33 // This tells us when to exit the event pump. |
34 bool keep_running; | 34 bool keep_running; |
35 // This tells our work source when to dispatch DoWork and DoDelayedWork. | 35 // This tells our work source when to dispatch DoWork and DoDelayedWork. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 GPollFD* optional_poll_fd); | 71 GPollFD* optional_poll_fd); |
72 | 72 |
73 RunState* state_; | 73 RunState* state_; |
74 | 74 |
75 // This is a GLib structure that we can add event sources to. We use the | 75 // This is a GLib structure that we can add event sources to. We use the |
76 // default GLib context, which is the one to which all GTK events are | 76 // default GLib context, which is the one to which all GTK events are |
77 // dispatched. | 77 // dispatched. |
78 GMainContext* context_; | 78 GMainContext* context_; |
79 | 79 |
80 // This is the time when we need to do delayed work. | 80 // This is the time when we need to do delayed work. |
81 Time delayed_work_time_; | 81 base::Time delayed_work_time_; |
82 | 82 |
83 // We use a pipe to schedule work in a thread-safe way that doesn't interfere | 83 // We use a pipe to schedule work in a thread-safe way that doesn't interfere |
84 // with our state. When ScheduleWork is called, we write into the pipe which | 84 // with our state. When ScheduleWork is called, we write into the pipe which |
85 // ensures poll will not sleep, since we use the read end as an event source. | 85 // ensures poll will not sleep, since we use the read end as an event source. |
86 // When we find data pending on the pipe, we clear it out and know we have | 86 // When we find data pending on the pipe, we clear it out and know we have |
87 // been given new work. | 87 // been given new work. |
88 int write_fd_work_scheduled_; | 88 int write_fd_work_scheduled_; |
89 int read_fd_work_scheduled_; | 89 int read_fd_work_scheduled_; |
90 | 90 |
91 // The work source. It is shared by all calls to Run and destroyed when | 91 // The work source. It is shared by all calls to Run and destroyed when |
92 // the message pump is destroyed. | 92 // the message pump is destroyed. |
93 GSource* work_source_; | 93 GSource* work_source_; |
94 | 94 |
95 DISALLOW_COPY_AND_ASSIGN(MessagePumpForUI); | 95 DISALLOW_COPY_AND_ASSIGN(MessagePumpForUI); |
96 }; | 96 }; |
97 | 97 |
98 } // namespace base | 98 } // namespace base |
99 | 99 |
100 #endif // BASE_MESSAGE_PUMP_GLIB_H_ | 100 #endif // BASE_MESSAGE_PUMP_GLIB_H_ |
OLD | NEW |