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 #ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_GLIB_H_ | 5 #ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_GLIB_H_ |
6 #define BASE_MESSAGE_LOOP_MESSAGE_PUMP_GLIB_H_ | 6 #define BASE_MESSAGE_LOOP_MESSAGE_PUMP_GLIB_H_ |
7 | 7 |
8 #include "base/base_export.h" | 8 #include "base/base_export.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_pump.h" | 10 #include "base/message_loop/message_pump.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 // Internal methods used for processing the pump callbacks. They are | 44 // Internal methods used for processing the pump callbacks. They are |
45 // public for simplicity but should not be used directly. HandlePrepare | 45 // public for simplicity but should not be used directly. HandlePrepare |
46 // is called during the prepare step of glib, and returns a timeout that | 46 // is called during the prepare step of glib, and returns a timeout that |
47 // will be passed to the poll. HandleCheck is called after the poll | 47 // will be passed to the poll. HandleCheck is called after the poll |
48 // has completed, and returns whether or not HandleDispatch should be called. | 48 // has completed, and returns whether or not HandleDispatch should be called. |
49 // HandleDispatch is called if HandleCheck returned true. | 49 // HandleDispatch is called if HandleCheck returned true. |
50 int HandlePrepare(); | 50 int HandlePrepare(); |
51 bool HandleCheck(); | 51 bool HandleCheck(); |
52 void HandleDispatch(); | 52 void HandleDispatch(); |
53 | 53 |
54 // Adds an Observer, which will start receiving notifications immediately. | |
55 void AddObserver(MessagePumpObserver* observer); | |
56 | |
57 // Removes an Observer. It is safe to call this method while an Observer is | |
58 // receiving a notification callback. | |
59 void RemoveObserver(MessagePumpObserver* observer); | |
60 | |
61 // Overridden from MessagePump: | 54 // Overridden from MessagePump: |
62 virtual void Run(Delegate* delegate) OVERRIDE; | 55 virtual void Run(Delegate* delegate) OVERRIDE; |
63 virtual void Quit() OVERRIDE; | 56 virtual void Quit() OVERRIDE; |
64 virtual void ScheduleWork() OVERRIDE; | 57 virtual void ScheduleWork() OVERRIDE; |
65 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time) OVERRIDE; | 58 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time) OVERRIDE; |
66 | 59 |
67 protected: | 60 protected: |
68 // Returns the dispatcher for the current run state (|state_->dispatcher|). | 61 // Returns the dispatcher for the current run state (|state_->dispatcher|). |
69 MessagePumpDispatcher* GetDispatcher(); | 62 MessagePumpDispatcher* GetDispatcher(); |
70 | 63 |
71 ObserverList<MessagePumpObserver>& observers() { return observers_; } | |
72 | |
73 private: | 64 private: |
74 // We may make recursive calls to Run, so we save state that needs to be | 65 // We may make recursive calls to Run, so we save state that needs to be |
75 // separate between them in this structure type. | 66 // separate between them in this structure type. |
76 struct RunState; | 67 struct RunState; |
77 | 68 |
78 RunState* state_; | 69 RunState* state_; |
79 | 70 |
80 // This is a GLib structure that we can add event sources to. We use the | 71 // This is a GLib structure that we can add event sources to. We use the |
81 // default GLib context, which is the one to which all GTK events are | 72 // default GLib context, which is the one to which all GTK events are |
82 // dispatched. | 73 // dispatched. |
83 GMainContext* context_; | 74 GMainContext* context_; |
84 | 75 |
85 // This is the time when we need to do delayed work. | 76 // This is the time when we need to do delayed work. |
86 TimeTicks delayed_work_time_; | 77 TimeTicks delayed_work_time_; |
87 | 78 |
88 // The work source. It is shared by all calls to Run and destroyed when | 79 // The work source. It is shared by all calls to Run and destroyed when |
89 // the message pump is destroyed. | 80 // the message pump is destroyed. |
90 GSource* work_source_; | 81 GSource* work_source_; |
91 | 82 |
92 // We use a wakeup pipe to make sure we'll get out of the glib polling phase | 83 // We use a wakeup pipe to make sure we'll get out of the glib polling phase |
93 // when another thread has scheduled us to do some work. There is a glib | 84 // when another thread has scheduled us to do some work. There is a glib |
94 // mechanism g_main_context_wakeup, but this won't guarantee that our event's | 85 // mechanism g_main_context_wakeup, but this won't guarantee that our event's |
95 // Dispatch() will be called. | 86 // Dispatch() will be called. |
96 int wakeup_pipe_read_; | 87 int wakeup_pipe_read_; |
97 int wakeup_pipe_write_; | 88 int wakeup_pipe_write_; |
98 // Use a scoped_ptr to avoid needing the definition of GPollFD in the header. | 89 // Use a scoped_ptr to avoid needing the definition of GPollFD in the header. |
99 scoped_ptr<GPollFD> wakeup_gpollfd_; | 90 scoped_ptr<GPollFD> wakeup_gpollfd_; |
100 | 91 |
101 // List of observers. | |
102 ObserverList<MessagePumpObserver> observers_; | |
103 | |
104 DISALLOW_COPY_AND_ASSIGN(MessagePumpGlib); | 92 DISALLOW_COPY_AND_ASSIGN(MessagePumpGlib); |
105 }; | 93 }; |
106 | 94 |
107 } // namespace base | 95 } // namespace base |
108 | 96 |
109 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_GLIB_H_ | 97 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_GLIB_H_ |
OLD | NEW |