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 #include "base/message_loop/message_pump_win.h" | 5 #include "base/message_loop/message_pump_win.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 delay_msec, NULL); | 165 delay_msec, NULL); |
166 if (ret) | 166 if (ret) |
167 return; | 167 return; |
168 // If we can't set timers, we are in big trouble... but cross our fingers for | 168 // If we can't set timers, we are in big trouble... but cross our fingers for |
169 // now. | 169 // now. |
170 // TODO(jar): If we don't see this error, use a CHECK() here instead. | 170 // TODO(jar): If we don't see this error, use a CHECK() here instead. |
171 UMA_HISTOGRAM_ENUMERATION("Chrome.MessageLoopProblem", SET_TIMER_ERROR, | 171 UMA_HISTOGRAM_ENUMERATION("Chrome.MessageLoopProblem", SET_TIMER_ERROR, |
172 MESSAGE_LOOP_PROBLEM_MAX); | 172 MESSAGE_LOOP_PROBLEM_MAX); |
173 } | 173 } |
174 | 174 |
175 void MessagePumpForUI::PumpOutPendingPaintMessages() { | |
176 // If we are being called outside of the context of Run, then don't try to do | |
177 // any work. | |
178 if (!state_) | |
179 return; | |
180 | |
181 // Create a mini-message-pump to force immediate processing of only Windows | |
182 // WM_PAINT messages. Don't provide an infinite loop, but do enough peeking | |
183 // to get the job done. Actual common max is 4 peeks, but we'll be a little | |
184 // safe here. | |
185 const int kMaxPeekCount = 20; | |
186 int peek_count; | |
187 for (peek_count = 0; peek_count < kMaxPeekCount; ++peek_count) { | |
188 MSG msg; | |
189 if (!PeekMessage(&msg, NULL, 0, 0, PM_REMOVE | PM_QS_PAINT)) | |
190 break; | |
191 ProcessMessageHelper(msg); | |
192 if (state_->should_quit) // Handle WM_QUIT. | |
193 break; | |
194 } | |
195 // Histogram what was really being used, to help to adjust kMaxPeekCount. | |
196 DHISTOGRAM_COUNTS("Loop.PumpOutPendingPaintMessages Peeks", peek_count); | |
197 } | |
198 | |
199 //----------------------------------------------------------------------------- | 175 //----------------------------------------------------------------------------- |
200 // MessagePumpForUI private: | 176 // MessagePumpForUI private: |
201 | 177 |
202 // static | 178 // static |
203 LRESULT CALLBACK MessagePumpForUI::WndProcThunk( | 179 LRESULT CALLBACK MessagePumpForUI::WndProcThunk( |
204 HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { | 180 HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { |
205 switch (message) { | 181 switch (message) { |
206 case kMsgHaveWork: | 182 case kMsgHaveWork: |
207 reinterpret_cast<MessagePumpForUI*>(wparam)->HandleWorkMessage(); | 183 reinterpret_cast<MessagePumpForUI*>(wparam)->HandleWorkMessage(); |
208 break; | 184 break; |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 | 653 |
678 // static | 654 // static |
679 MessagePumpForIO::IOHandler* MessagePumpForIO::KeyToHandler( | 655 MessagePumpForIO::IOHandler* MessagePumpForIO::KeyToHandler( |
680 ULONG_PTR key, | 656 ULONG_PTR key, |
681 bool* has_valid_io_context) { | 657 bool* has_valid_io_context) { |
682 *has_valid_io_context = ((key & 1) == 0); | 658 *has_valid_io_context = ((key & 1) == 0); |
683 return reinterpret_cast<IOHandler*>(key & ~static_cast<ULONG_PTR>(1)); | 659 return reinterpret_cast<IOHandler*>(key & ~static_cast<ULONG_PTR>(1)); |
684 } | 660 } |
685 | 661 |
686 } // namespace base | 662 } // namespace base |
OLD | NEW |