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" | |
14 #include "base/message_loop/message_pump.h" | 15 #include "base/message_loop/message_pump.h" |
15 #include "base/message_loop/message_pump_dispatcher.h" | 16 #include "base/message_loop/message_pump_dispatcher.h" |
16 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
18 #include "base/win/scoped_handle.h" | 19 #include "base/win/scoped_handle.h" |
19 | 20 |
20 namespace base { | 21 namespace base { |
21 | 22 |
23 class Thread; | |
24 | |
22 // MessagePumpWin serves as the base for specialized versions of the MessagePump | 25 // MessagePumpWin serves as the base for specialized versions of the MessagePump |
23 // for Windows. It provides basic functionality like handling of observers and | 26 // for Windows. It provides basic functionality like handling of observers and |
24 // controlling the lifetime of the message pump. | 27 // controlling the lifetime of the message pump. |
25 class BASE_EXPORT MessagePumpWin : public MessagePump { | 28 class BASE_EXPORT MessagePumpWin : public MessagePump { |
26 public: | 29 public: |
27 MessagePumpWin() : have_work_(0), state_(NULL) {} | 30 MessagePumpWin() : have_work_(0), state_(NULL) {} |
28 | 31 |
29 // Like MessagePump::Run, but MSG objects are routed through dispatcher. | 32 // Like MessagePump::Run, but MSG objects are routed through dispatcher. |
30 void RunWithDispatcher(Delegate* delegate, MessagePumpDispatcher* dispatcher); | 33 void RunWithDispatcher(Delegate* delegate, MessagePumpDispatcher* dispatcher); |
31 | 34 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 void DoRunLoop() override; | 131 void DoRunLoop() override; |
129 void InitMessageWnd(); | 132 void InitMessageWnd(); |
130 void WaitForWork(); | 133 void WaitForWork(); |
131 void HandleWorkMessage(); | 134 void HandleWorkMessage(); |
132 void HandleTimerMessage(); | 135 void HandleTimerMessage(); |
133 void RescheduleTimer(); | 136 void RescheduleTimer(); |
134 bool ProcessNextWindowsMessage(); | 137 bool ProcessNextWindowsMessage(); |
135 bool ProcessMessageHelper(const MSG& msg); | 138 bool ProcessMessageHelper(const MSG& msg); |
136 bool ProcessPumpReplacementMessage(); | 139 bool ProcessPumpReplacementMessage(); |
137 | 140 |
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 void SetWakeupTimer(int64 delay); | |
scottmg
2015/06/09 16:22:42
nit; "delay_ms" (and in the .cc) would be better s
ananta
2015/06/09 18:25:43
Done.
| |
159 | |
138 // Atom representing the registered window class. | 160 // Atom representing the registered window class. |
139 ATOM atom_; | 161 ATOM atom_; |
140 | 162 |
141 // A hidden message-only window. | 163 // A hidden message-only window. |
142 HWND message_hwnd_; | 164 HWND message_hwnd_; |
165 | |
166 // This thread is used to periodically wake up the main thread to process | |
167 // tasks. | |
168 scoped_ptr<base::Thread> ui_worker_thread_; | |
169 | |
170 // The UI worker thread waits on this timer indefinitely. When the main | |
171 // thread has tasks ready to be processed it sets the timer. | |
172 base::win::ScopedHandle ui_worker_thread_timer_; | |
143 }; | 173 }; |
144 | 174 |
145 //----------------------------------------------------------------------------- | 175 //----------------------------------------------------------------------------- |
146 // MessagePumpForIO extends MessagePumpWin with methods that are particular to a | 176 // MessagePumpForIO extends MessagePumpWin with methods that are particular to a |
147 // MessageLoop instantiated with TYPE_IO. This version of MessagePump does not | 177 // MessageLoop instantiated with TYPE_IO. This version of MessagePump does not |
148 // deal with Windows mesagges, and instead has a Run loop based on Completion | 178 // deal with Windows mesagges, and instead has a Run loop based on Completion |
149 // Ports so it is better suited for IO operations. | 179 // Ports so it is better suited for IO operations. |
150 // | 180 // |
151 class BASE_EXPORT MessagePumpForIO : public MessagePumpWin { | 181 class BASE_EXPORT MessagePumpForIO : public MessagePumpWin { |
152 public: | 182 public: |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 // This list will be empty almost always. It stores IO completions that have | 362 // This list will be empty almost always. It stores IO completions that have |
333 // not been delivered yet because somebody was doing cleanup. | 363 // not been delivered yet because somebody was doing cleanup. |
334 std::list<IOItem> completed_io_; | 364 std::list<IOItem> completed_io_; |
335 | 365 |
336 ObserverList<IOObserver> io_observers_; | 366 ObserverList<IOObserver> io_observers_; |
337 }; | 367 }; |
338 | 368 |
339 } // namespace base | 369 } // namespace base |
340 | 370 |
341 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_WIN_H_ | 371 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_WIN_H_ |
OLD | NEW |