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 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <limits> | 10 #include <limits> |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 // task (a series of such messages creates a continuous task pump). | 115 // task (a series of such messages creates a continuous task pump). |
116 static const int kMsgHaveWork = WM_USER + 1; | 116 static const int kMsgHaveWork = WM_USER + 1; |
117 | 117 |
118 // The application-defined code passed to the hook procedure. | 118 // The application-defined code passed to the hook procedure. |
119 static const int kMessageFilterCode = 0x5001; | 119 static const int kMessageFilterCode = 0x5001; |
120 | 120 |
121 //----------------------------------------------------------------------------- | 121 //----------------------------------------------------------------------------- |
122 // MessagePumpWin public: | 122 // MessagePumpWin public: |
123 | 123 |
124 MessagePumpWin::MessagePumpWin() { | 124 MessagePumpWin::MessagePumpWin() { |
125 InitUser32APIs(); | |
126 } | 125 } |
127 | 126 |
128 void MessagePumpWin::Run(Delegate* delegate) { | 127 void MessagePumpWin::Run(Delegate* delegate) { |
129 RunState s; | 128 RunState s; |
130 s.delegate = delegate; | 129 s.delegate = delegate; |
131 s.should_quit = false; | 130 s.should_quit = false; |
132 s.run_depth = state_ ? state_->run_depth + 1 : 1; | 131 s.run_depth = state_ ? state_->run_depth + 1 : 1; |
133 | 132 |
134 // TODO(stanisc): crbug.com/596190: Remove this code once the bug is fixed. | 133 // TODO(stanisc): crbug.com/596190: Remove this code once the bug is fixed. |
135 s.schedule_work_error_count = 0; | 134 s.schedule_work_error_count = 0; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 return timeout < 0 ? 0 : | 167 return timeout < 0 ? 0 : |
169 (timeout > std::numeric_limits<int>::max() ? | 168 (timeout > std::numeric_limits<int>::max() ? |
170 std::numeric_limits<int>::max() : static_cast<int>(timeout)); | 169 std::numeric_limits<int>::max() : static_cast<int>(timeout)); |
171 } | 170 } |
172 | 171 |
173 //----------------------------------------------------------------------------- | 172 //----------------------------------------------------------------------------- |
174 // MessagePumpForUI public: | 173 // MessagePumpForUI public: |
175 | 174 |
176 MessagePumpForUI::MessagePumpForUI() | 175 MessagePumpForUI::MessagePumpForUI() |
177 : atom_(0) { | 176 : atom_(0) { |
| 177 InitUser32APIs(); |
178 InitMessageWnd(); | 178 InitMessageWnd(); |
179 } | 179 } |
180 | 180 |
181 MessagePumpForUI::~MessagePumpForUI() { | 181 MessagePumpForUI::~MessagePumpForUI() { |
182 g_destroy_window(message_hwnd_); | 182 g_destroy_window(message_hwnd_); |
183 g_unregister_class(MAKEINTATOM(atom_), CURRENT_MODULE()); | 183 g_unregister_class(MAKEINTATOM(atom_), CURRENT_MODULE()); |
184 } | 184 } |
185 | 185 |
186 void MessagePumpForUI::ScheduleWork() { | 186 void MessagePumpForUI::ScheduleWork() { |
187 if (InterlockedExchange(&work_state_, HAVE_WORK) != READY) | 187 if (InterlockedExchange(&work_state_, HAVE_WORK) != READY) |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 // tasks appear very infrequently, but when the event queue is busy, the | 504 // tasks appear very infrequently, but when the event queue is busy, the |
505 // kMsgHaveWork events get (percentage wise) rarer and rarer. | 505 // kMsgHaveWork events get (percentage wise) rarer and rarer. |
506 ScheduleWork(); | 506 ScheduleWork(); |
507 return ProcessMessageHelper(msg); | 507 return ProcessMessageHelper(msg); |
508 } | 508 } |
509 | 509 |
510 //----------------------------------------------------------------------------- | 510 //----------------------------------------------------------------------------- |
511 // MessagePumpForGpu public: | 511 // MessagePumpForGpu public: |
512 | 512 |
513 MessagePumpForGpu::MessagePumpForGpu() | 513 MessagePumpForGpu::MessagePumpForGpu() |
514 : event_(CreateEvent(nullptr, FALSE, FALSE, nullptr)) {} | 514 : event_(CreateEvent(nullptr, FALSE, FALSE, nullptr)) { |
| 515 InitUser32APIs(); |
| 516 } |
515 | 517 |
516 MessagePumpForGpu::~MessagePumpForGpu() { | 518 MessagePumpForGpu::~MessagePumpForGpu() { |
517 CloseHandle(event_); | 519 CloseHandle(event_); |
518 } | 520 } |
519 | 521 |
520 // static | 522 // static |
521 void MessagePumpForGpu::InitFactory() { | 523 void MessagePumpForGpu::InitFactory() { |
522 bool init_result = MessageLoop::InitMessagePumpForUIFactory( | 524 bool init_result = MessageLoop::InitMessagePumpForUIFactory( |
523 &MessagePumpForGpu::CreateMessagePumpForGpu); | 525 &MessagePumpForGpu::CreateMessagePumpForGpu); |
524 DCHECK(init_result); | 526 DCHECK(init_result); |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 if (!filter || it->handler == filter) { | 824 if (!filter || it->handler == filter) { |
823 *item = *it; | 825 *item = *it; |
824 completed_io_.erase(it); | 826 completed_io_.erase(it); |
825 return true; | 827 return true; |
826 } | 828 } |
827 } | 829 } |
828 return false; | 830 return false; |
829 } | 831 } |
830 | 832 |
831 } // namespace base | 833 } // namespace base |
OLD | NEW |