Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: base/message_loop/message_pump_win.h

Issue 1156503005: Don't peek messages in the MessagePumpForUI class when we receive our kMsgHaveWork message. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use an autoreset event to signal the worker that we have tasks to process Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
18 #include "base/synchronization/waitable_event.h"
17 #include "base/time/time.h" 19 #include "base/time/time.h"
18 #include "base/win/scoped_handle.h" 20 #include "base/win/scoped_handle.h"
19 21
20 namespace base { 22 namespace base {
21 23
24 class Thread;
25
22 // MessagePumpWin serves as the base for specialized versions of the MessagePump 26 // MessagePumpWin serves as the base for specialized versions of the MessagePump
23 // for Windows. It provides basic functionality like handling of observers and 27 // for Windows. It provides basic functionality like handling of observers and
24 // controlling the lifetime of the message pump. 28 // controlling the lifetime of the message pump.
25 class BASE_EXPORT MessagePumpWin : public MessagePump { 29 class BASE_EXPORT MessagePumpWin : public MessagePump {
26 public: 30 public:
27 MessagePumpWin() : have_work_(0), state_(NULL) {} 31 MessagePumpWin() : have_work_(0), state_(NULL) {}
28 32
29 // Like MessagePump::Run, but MSG objects are routed through dispatcher. 33 // Like MessagePump::Run, but MSG objects are routed through dispatcher.
30 void RunWithDispatcher(Delegate* delegate, MessagePumpDispatcher* dispatcher); 34 void RunWithDispatcher(Delegate* delegate, MessagePumpDispatcher* dispatcher);
31 35
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 void DoRunLoop() override; 132 void DoRunLoop() override;
129 void InitMessageWnd(); 133 void InitMessageWnd();
130 void WaitForWork(); 134 void WaitForWork();
131 void HandleWorkMessage(); 135 void HandleWorkMessage();
132 void HandleTimerMessage(); 136 void HandleTimerMessage();
133 void RescheduleTimer(); 137 void RescheduleTimer();
134 bool ProcessNextWindowsMessage(); 138 bool ProcessNextWindowsMessage();
135 bool ProcessMessageHelper(const MSG& msg); 139 bool ProcessMessageHelper(const MSG& msg);
136 bool ProcessPumpReplacementMessage(); 140 bool ProcessPumpReplacementMessage();
137 141
142 // We spawn a worker thread to periodically post (3 ms) the kMsgHaveWork
143 // message to the UI message pump. This is to ensure that the main thread
144 // gets to process tasks and delayed tasks when there is no activity in the
145 // Windows message pump or when there is a nested modal loop (sizing/moving/
146 // drag drop/message boxes) etc.
147 void DoWorkerThreadRunLoop();
148
149 // This function is posted as part of a user mode APC to shutdown the worker
150 // thread when the main message pump is shutting down.
151 static void CALLBACK ShutdownWorkerThread(ULONG_PTR param);
152
138 // Atom representing the registered window class. 153 // Atom representing the registered window class.
139 ATOM atom_; 154 ATOM atom_;
140 155
141 // A hidden message-only window. 156 // A hidden message-only window.
142 HWND message_hwnd_; 157 HWND message_hwnd_;
158
159 // This thread is used to periodically wake up the main thread to process
160 // tasks.
161 scoped_ptr<base::Thread> ui_worker_thread_;
162
163 // This event is signaled when we have tasks to be processed. The worker
164 // thread waits on this event and starts posting the kMsgHaveWork message
165 // to the UI message pump.
166 WaitableEvent ui_worker_thread_signal_;
143 }; 167 };
144 168
145 //----------------------------------------------------------------------------- 169 //-----------------------------------------------------------------------------
146 // MessagePumpForIO extends MessagePumpWin with methods that are particular to a 170 // MessagePumpForIO extends MessagePumpWin with methods that are particular to a
147 // MessageLoop instantiated with TYPE_IO. This version of MessagePump does not 171 // 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 172 // deal with Windows mesagges, and instead has a Run loop based on Completion
149 // Ports so it is better suited for IO operations. 173 // Ports so it is better suited for IO operations.
150 // 174 //
151 class BASE_EXPORT MessagePumpForIO : public MessagePumpWin { 175 class BASE_EXPORT MessagePumpForIO : public MessagePumpWin {
152 public: 176 public:
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 // This list will be empty almost always. It stores IO completions that have 356 // This list will be empty almost always. It stores IO completions that have
333 // not been delivered yet because somebody was doing cleanup. 357 // not been delivered yet because somebody was doing cleanup.
334 std::list<IOItem> completed_io_; 358 std::list<IOItem> completed_io_;
335 359
336 ObserverList<IOObserver> io_observers_; 360 ObserverList<IOObserver> io_observers_;
337 }; 361 };
338 362
339 } // namespace base 363 } // namespace base
340 364
341 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_WIN_H_ 365 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_WIN_H_
OLDNEW
« no previous file with comments | « no previous file | base/message_loop/message_pump_win.cc » ('j') | base/message_loop/message_pump_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698