| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-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_LIBEVENT_H_ | 5 #ifndef BASE_MESSAGE_PUMP_LIBEVENT_H_ |
| 6 #define BASE_MESSAGE_PUMP_LIBEVENT_H_ | 6 #define BASE_MESSAGE_PUMP_LIBEVENT_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/message_pump.h" | 10 #include "base/message_pump.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 FileDescriptorWatcher *controller, | 112 FileDescriptorWatcher *controller, |
| 113 Watcher *delegate); | 113 Watcher *delegate); |
| 114 | 114 |
| 115 void AddIOObserver(IOObserver* obs); | 115 void AddIOObserver(IOObserver* obs); |
| 116 void RemoveIOObserver(IOObserver* obs); | 116 void RemoveIOObserver(IOObserver* obs); |
| 117 | 117 |
| 118 // MessagePump methods: | 118 // MessagePump methods: |
| 119 virtual void Run(Delegate* delegate); | 119 virtual void Run(Delegate* delegate); |
| 120 virtual void Quit(); | 120 virtual void Quit(); |
| 121 virtual void ScheduleWork(); | 121 virtual void ScheduleWork(); |
| 122 virtual void ScheduleDelayedWork(const Time& delayed_work_time); | 122 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time); |
| 123 | 123 |
| 124 private: | 124 private: |
| 125 void WillProcessIOEvent(); | 125 void WillProcessIOEvent(); |
| 126 void DidProcessIOEvent(); | 126 void DidProcessIOEvent(); |
| 127 | 127 |
| 128 // Risky part of constructor. Returns true on success. | 128 // Risky part of constructor. Returns true on success. |
| 129 bool Init(); | 129 bool Init(); |
| 130 | 130 |
| 131 // This flag is set to false when Run should return. | 131 // This flag is set to false when Run should return. |
| 132 bool keep_running_; | 132 bool keep_running_; |
| 133 | 133 |
| 134 // This flag is set when inside Run. | 134 // This flag is set when inside Run. |
| 135 bool in_run_; | 135 bool in_run_; |
| 136 | 136 |
| 137 // The time at which we should call DoDelayedWork. | 137 // The time at which we should call DoDelayedWork. |
| 138 Time delayed_work_time_; | 138 TimeTicks delayed_work_time_; |
| 139 | 139 |
| 140 // Libevent dispatcher. Watches all sockets registered with it, and sends | 140 // Libevent dispatcher. Watches all sockets registered with it, and sends |
| 141 // readiness callbacks when a socket is ready for I/O. | 141 // readiness callbacks when a socket is ready for I/O. |
| 142 event_base* event_base_; | 142 event_base* event_base_; |
| 143 | 143 |
| 144 // Called by libevent to tell us a registered FD can be read/written to. | 144 // Called by libevent to tell us a registered FD can be read/written to. |
| 145 static void OnLibeventNotification(int fd, short flags, | 145 static void OnLibeventNotification(int fd, short flags, |
| 146 void* context); | 146 void* context); |
| 147 | 147 |
| 148 // Unix pipe used to implement ScheduleWork() | 148 // Unix pipe used to implement ScheduleWork() |
| 149 // ... callback; called by libevent inside Run() when pipe is ready to read | 149 // ... callback; called by libevent inside Run() when pipe is ready to read |
| 150 static void OnWakeup(int socket, short flags, void* context); | 150 static void OnWakeup(int socket, short flags, void* context); |
| 151 // ... write end; ScheduleWork() writes a single byte to it | 151 // ... write end; ScheduleWork() writes a single byte to it |
| 152 int wakeup_pipe_in_; | 152 int wakeup_pipe_in_; |
| 153 // ... read end; OnWakeup reads it and then breaks Run() out of its sleep | 153 // ... read end; OnWakeup reads it and then breaks Run() out of its sleep |
| 154 int wakeup_pipe_out_; | 154 int wakeup_pipe_out_; |
| 155 // ... libevent wrapper for read end | 155 // ... libevent wrapper for read end |
| 156 event* wakeup_event_; | 156 event* wakeup_event_; |
| 157 | 157 |
| 158 ObserverList<IOObserver> io_observers_; | 158 ObserverList<IOObserver> io_observers_; |
| 159 | 159 |
| 160 DISALLOW_COPY_AND_ASSIGN(MessagePumpLibevent); | 160 DISALLOW_COPY_AND_ASSIGN(MessagePumpLibevent); |
| 161 }; | 161 }; |
| 162 | 162 |
| 163 } // namespace base | 163 } // namespace base |
| 164 | 164 |
| 165 #endif // BASE_MESSAGE_PUMP_LIBEVENT_H_ | 165 #endif // BASE_MESSAGE_PUMP_LIBEVENT_H_ |
| OLD | NEW |