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/message_loop/message_pump.h" | 13 #include "base/message_loop/message_pump.h" |
14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "base/win/scoped_handle.h" | 16 #include "base/win/scoped_handle.h" |
17 | 17 |
18 namespace base { | 18 namespace base { |
19 | 19 |
20 // MessagePumpWin serves as the base for specialized versions of the MessagePump | 20 // MessagePumpWin serves as the base for specialized versions of the MessagePump |
21 // for Windows. It provides basic functionality like handling of observers and | 21 // for Windows. It provides basic functionality like handling of observers and |
22 // controlling the lifetime of the message pump. | 22 // controlling the lifetime of the message pump. |
23 class BASE_EXPORT MessagePumpWin : public MessagePump { | 23 class BASE_EXPORT MessagePumpWin : public MessagePump { |
24 public: | 24 public: |
25 MessagePumpWin() : have_work_(0), state_(NULL) {} | 25 MessagePumpWin() : work_state_(READY), state_(NULL) {} |
26 | 26 |
27 // MessagePump methods: | 27 // MessagePump methods: |
28 void Run(Delegate* delegate) override; | 28 void Run(Delegate* delegate) override; |
29 void Quit() override; | 29 void Quit() override; |
30 | 30 |
31 protected: | 31 protected: |
32 struct RunState { | 32 struct RunState { |
33 Delegate* delegate; | 33 Delegate* delegate; |
34 | 34 |
35 // Used to flag that the current Run() invocation should return ASAP. | 35 // Used to flag that the current Run() invocation should return ASAP. |
36 bool should_quit; | 36 bool should_quit; |
37 | 37 |
38 // Used to count how many Run() invocations are on the stack. | 38 // Used to count how many Run() invocations are on the stack. |
39 int run_depth; | 39 int run_depth; |
40 }; | 40 }; |
41 | 41 |
| 42 // State used with |work_state_| variable. |
| 43 enum WorkState { |
| 44 READY = 0, // Ready to accept new work. |
| 45 HAVE_WORK = 1, // New work has been signalled. |
| 46 WORKING = 2 // Handling the work. |
| 47 }; |
| 48 |
42 virtual void DoRunLoop() = 0; | 49 virtual void DoRunLoop() = 0; |
43 int GetCurrentDelay() const; | 50 int GetCurrentDelay() const; |
44 | 51 |
45 // The time at which delayed work should run. | 52 // The time at which delayed work should run. |
46 TimeTicks delayed_work_time_; | 53 TimeTicks delayed_work_time_; |
47 | 54 |
48 // A boolean value used to indicate if there is a kMsgDoWork message pending | 55 // A value used to indicate if there is a kMsgDoWork message pending |
49 // in the Windows Message queue. There is at most one such message, and it | 56 // in the Windows Message queue. There is at most one such message, and it |
50 // can drive execution of tasks when a native message pump is running. | 57 // can drive execution of tasks when a native message pump is running. |
51 LONG have_work_; | 58 LONG work_state_; |
52 | 59 |
53 // State for the current invocation of Run. | 60 // State for the current invocation of Run. |
54 RunState* state_; | 61 RunState* state_; |
55 }; | 62 }; |
56 | 63 |
57 //----------------------------------------------------------------------------- | 64 //----------------------------------------------------------------------------- |
58 // MessagePumpForUI extends MessagePumpWin with methods that are particular to a | 65 // MessagePumpForUI extends MessagePumpWin with methods that are particular to a |
59 // MessageLoop instantiated with TYPE_UI. | 66 // MessageLoop instantiated with TYPE_UI. |
60 // | 67 // |
61 // MessagePumpForUI implements a "traditional" Windows message pump. It contains | 68 // MessagePumpForUI implements a "traditional" Windows message pump. It contains |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 bool ProcessPumpReplacementMessage(); | 137 bool ProcessPumpReplacementMessage(); |
131 | 138 |
132 // Atom representing the registered window class. | 139 // Atom representing the registered window class. |
133 ATOM atom_; | 140 ATOM atom_; |
134 | 141 |
135 // A hidden message-only window. | 142 // A hidden message-only window. |
136 HWND message_hwnd_; | 143 HWND message_hwnd_; |
137 }; | 144 }; |
138 | 145 |
139 //----------------------------------------------------------------------------- | 146 //----------------------------------------------------------------------------- |
| 147 // MessagePumpForGpu is a simplified version of UI message pump that is |
| 148 // optimized for the GPU process. Unlike MessagePumpForUI it doesn't have a |
| 149 // hidden window and doesn't handle a situation where a native message pump |
| 150 // might take over message processing. |
| 151 // |
| 152 class BASE_EXPORT MessagePumpForGpu : public MessagePumpWin { |
| 153 public: |
| 154 MessagePumpForGpu(); |
| 155 ~MessagePumpForGpu() override; |
| 156 |
| 157 // Factory methods. |
| 158 static void InitFactory(); |
| 159 static std::unique_ptr<MessagePump> CreateMessagePumpForGpu(); |
| 160 |
| 161 // MessagePump methods: |
| 162 void ScheduleWork() override; |
| 163 void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override; |
| 164 |
| 165 private: |
| 166 // MessagePumpWin methods: |
| 167 void DoRunLoop() override; |
| 168 |
| 169 void WaitForWork(); |
| 170 bool ProcessMessages(); |
| 171 |
| 172 const DWORD thread_id_; |
| 173 }; |
| 174 |
| 175 //----------------------------------------------------------------------------- |
140 // MessagePumpForIO extends MessagePumpWin with methods that are particular to a | 176 // MessagePumpForIO extends MessagePumpWin with methods that are particular to a |
141 // MessageLoop instantiated with TYPE_IO. This version of MessagePump does not | 177 // MessageLoop instantiated with TYPE_IO. This version of MessagePump does not |
142 // 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 |
143 // Ports so it is better suited for IO operations. | 179 // Ports so it is better suited for IO operations. |
144 // | 180 // |
145 class BASE_EXPORT MessagePumpForIO : public MessagePumpWin { | 181 class BASE_EXPORT MessagePumpForIO : public MessagePumpWin { |
146 public: | 182 public: |
147 struct IOContext; | 183 struct IOContext; |
148 | 184 |
149 // Clients interested in receiving OS notifications when asynchronous IO | 185 // Clients interested in receiving OS notifications when asynchronous IO |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 // 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 |
327 // not been delivered yet because somebody was doing cleanup. | 363 // not been delivered yet because somebody was doing cleanup. |
328 std::list<IOItem> completed_io_; | 364 std::list<IOItem> completed_io_; |
329 | 365 |
330 ObserverList<IOObserver> io_observers_; | 366 ObserverList<IOObserver> io_observers_; |
331 }; | 367 }; |
332 | 368 |
333 } // namespace base | 369 } // namespace base |
334 | 370 |
335 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_WIN_H_ | 371 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_WIN_H_ |
OLD | NEW |