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_WIN_H_ | 5 #ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_WIN_H_ |
6 #define BASE_MESSAGE_LOOP_MESSAGE_PUMP_WIN_H_ | 6 #define BASE_MESSAGE_LOOP_MESSAGE_PUMP_WIN_H_ |
7 | 7 |
8 #include <windows.h> | 8 #include <windows.h> |
9 | 9 |
10 #include <list> | 10 #include <list> |
11 | 11 |
12 #include "base/base_export.h" | 12 #include "base/base_export.h" |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/message_loop/message_pump.h" | 14 #include "base/message_loop/message_pump.h" |
16 #include "base/message_loop/message_pump_dispatcher.h" | 15 #include "base/message_loop/message_pump_dispatcher.h" |
17 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
18 #include "base/time/time.h" | 17 #include "base/time/time.h" |
19 #include "base/win/scoped_handle.h" | 18 #include "base/win/scoped_handle.h" |
20 | 19 |
21 namespace base { | 20 namespace base { |
22 | 21 |
23 class Thread; | |
24 | |
25 // MessagePumpWin serves as the base for specialized versions of the MessagePump | 22 // MessagePumpWin serves as the base for specialized versions of the MessagePump |
26 // for Windows. It provides basic functionality like handling of observers and | 23 // for Windows. It provides basic functionality like handling of observers and |
27 // controlling the lifetime of the message pump. | 24 // controlling the lifetime of the message pump. |
28 class BASE_EXPORT MessagePumpWin : public MessagePump { | 25 class BASE_EXPORT MessagePumpWin : public MessagePump { |
29 public: | 26 public: |
30 MessagePumpWin() : have_work_(0), state_(NULL) {} | 27 MessagePumpWin() : have_work_(0), state_(NULL) {} |
31 | 28 |
32 // Like MessagePump::Run, but MSG objects are routed through dispatcher. | 29 // Like MessagePump::Run, but MSG objects are routed through dispatcher. |
33 void RunWithDispatcher(Delegate* delegate, MessagePumpDispatcher* dispatcher); | 30 void RunWithDispatcher(Delegate* delegate, MessagePumpDispatcher* dispatcher); |
34 | 31 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 void DoRunLoop() override; | 128 void DoRunLoop() override; |
132 void InitMessageWnd(); | 129 void InitMessageWnd(); |
133 void WaitForWork(); | 130 void WaitForWork(); |
134 void HandleWorkMessage(); | 131 void HandleWorkMessage(); |
135 void HandleTimerMessage(); | 132 void HandleTimerMessage(); |
136 void RescheduleTimer(); | 133 void RescheduleTimer(); |
137 bool ProcessNextWindowsMessage(); | 134 bool ProcessNextWindowsMessage(); |
138 bool ProcessMessageHelper(const MSG& msg); | 135 bool ProcessMessageHelper(const MSG& msg); |
139 bool ProcessPumpReplacementMessage(); | 136 bool ProcessPumpReplacementMessage(); |
140 | 137 |
141 // We spawn a worker thread to periodically post (3 ms) the kMsgHaveWork | |
142 // message to the UI message pump. This is to ensure that the main thread | |
143 // gets to process tasks and delayed tasks when there is no activity in the | |
144 // Windows message pump or when there is a nested modal loop (sizing/moving/ | |
145 // drag drop/message boxes) etc. | |
146 void DoWorkerThreadRunLoop(); | |
147 | |
148 // This function is posted as part of a user mode APC to shutdown the worker | |
149 // thread when the main message pump is shutting down. | |
150 static void CALLBACK ShutdownWorkerThread(ULONG_PTR param); | |
151 | |
152 // Helper function for posting the kMsgHaveWork message to wake up the pump | |
153 // for processing tasks. | |
154 void PostWorkMessage(); | |
155 | |
156 // Helper function to set the waitable timer used to wake up the UI worker | |
157 // thread for processing delayed tasks. | |
158 // |delay_ms| : The delay in milliseconds. | |
159 void SetWakeupTimer(int64 delay_ms); | |
160 | |
161 // Helper function to ensure that the message pump processes tasks and | |
162 // delayed tasks. | |
163 void ScheduleWorkHelper(); | |
164 | |
165 // Atom representing the registered window class. | 138 // Atom representing the registered window class. |
166 ATOM atom_; | 139 ATOM atom_; |
167 | 140 |
168 // A hidden message-only window. | 141 // A hidden message-only window. |
169 HWND message_hwnd_; | 142 HWND message_hwnd_; |
170 | |
171 // This thread is used to periodically wake up the main thread to process | |
172 // tasks. | |
173 scoped_ptr<base::Thread> ui_worker_thread_; | |
174 | |
175 // The UI worker thread waits on this timer indefinitely. When the main | |
176 // thread has tasks ready to be processed it sets the timer. | |
177 base::win::ScopedHandle ui_worker_thread_timer_; | |
178 | |
179 // This flag controls whether the UI worker thread sets the waitable timer | |
180 // to ensure that tasks missed in one timer iteration get picked in the | |
181 // second. | |
182 long force_fallback_timer_for_tasks_; | |
183 }; | 143 }; |
184 | 144 |
185 //----------------------------------------------------------------------------- | 145 //----------------------------------------------------------------------------- |
186 // MessagePumpForIO extends MessagePumpWin with methods that are particular to a | 146 // MessagePumpForIO extends MessagePumpWin with methods that are particular to a |
187 // MessageLoop instantiated with TYPE_IO. This version of MessagePump does not | 147 // MessageLoop instantiated with TYPE_IO. This version of MessagePump does not |
188 // deal with Windows mesagges, and instead has a Run loop based on Completion | 148 // deal with Windows mesagges, and instead has a Run loop based on Completion |
189 // Ports so it is better suited for IO operations. | 149 // Ports so it is better suited for IO operations. |
190 // | 150 // |
191 class BASE_EXPORT MessagePumpForIO : public MessagePumpWin { | 151 class BASE_EXPORT MessagePumpForIO : public MessagePumpWin { |
192 public: | 152 public: |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 // This list will be empty almost always. It stores IO completions that have | 332 // This list will be empty almost always. It stores IO completions that have |
373 // not been delivered yet because somebody was doing cleanup. | 333 // not been delivered yet because somebody was doing cleanup. |
374 std::list<IOItem> completed_io_; | 334 std::list<IOItem> completed_io_; |
375 | 335 |
376 ObserverList<IOObserver> io_observers_; | 336 ObserverList<IOObserver> io_observers_; |
377 }; | 337 }; |
378 | 338 |
379 } // namespace base | 339 } // namespace base |
380 | 340 |
381 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_WIN_H_ | 341 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_WIN_H_ |
OLD | NEW |