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/memory/scoped_ptr.h" | |
Lei Zhang
2016/04/07 21:32:26
No new scoped_ptr please. use std::unique_ptr.
stanisc
2016/04/08 01:07:12
Done.
Lei Zhang
2016/04/08 19:10:21
#include <memory> instead.
stanisc
2016/04/11 21:52:59
Done.
| |
13 #include "base/message_loop/message_pump.h" | 14 #include "base/message_loop/message_pump.h" |
14 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
16 #include "base/win/scoped_handle.h" | 17 #include "base/win/scoped_handle.h" |
17 | 18 |
18 namespace base { | 19 namespace base { |
19 | 20 |
20 // MessagePumpWin serves as the base for specialized versions of the MessagePump | 21 // MessagePumpWin serves as the base for specialized versions of the MessagePump |
21 // for Windows. It provides basic functionality like handling of observers and | 22 // for Windows. It provides basic functionality like handling of observers and |
22 // controlling the lifetime of the message pump. | 23 // controlling the lifetime of the message pump. |
23 class BASE_EXPORT MessagePumpWin : public MessagePump { | 24 class BASE_EXPORT MessagePumpWin : public MessagePump { |
24 public: | 25 public: |
25 MessagePumpWin() : have_work_(0), state_(NULL) {} | 26 MessagePumpWin() : work_state_(READY), state_(NULL) {} |
26 | 27 |
27 // MessagePump methods: | 28 // MessagePump methods: |
28 void Run(Delegate* delegate) override; | 29 void Run(Delegate* delegate) override; |
29 void Quit() override; | 30 void Quit() override; |
30 | 31 |
31 protected: | 32 protected: |
32 struct RunState { | 33 struct RunState { |
33 Delegate* delegate; | 34 Delegate* delegate; |
34 | 35 |
35 // Used to flag that the current Run() invocation should return ASAP. | 36 // Used to flag that the current Run() invocation should return ASAP. |
36 bool should_quit; | 37 bool should_quit; |
37 | 38 |
38 // Used to count how many Run() invocations are on the stack. | 39 // Used to count how many Run() invocations are on the stack. |
39 int run_depth; | 40 int run_depth; |
40 }; | 41 }; |
41 | 42 |
43 // State used with work_state_ variable. | |
Lei Zhang
2016/04/07 21:32:26
nit: work_state_ variable -> |work_state_|
stanisc
2016/04/08 01:07:12
Done.
| |
44 enum WorkState { | |
45 READY = 0, // Ready to accept new work. | |
46 HAVE_WORK = 1, // New work has been signalled. | |
47 WORKING = 2 // Handling the work. | |
48 }; | |
49 | |
42 virtual void DoRunLoop() = 0; | 50 virtual void DoRunLoop() = 0; |
43 int GetCurrentDelay() const; | 51 int GetCurrentDelay() const; |
44 | 52 |
45 // The time at which delayed work should run. | 53 // The time at which delayed work should run. |
46 TimeTicks delayed_work_time_; | 54 TimeTicks delayed_work_time_; |
47 | 55 |
48 // A boolean value used to indicate if there is a kMsgDoWork message pending | 56 // 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 | 57 // 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. | 58 // can drive execution of tasks when a native message pump is running. |
51 LONG have_work_; | 59 LONG work_state_; |
52 | 60 |
53 // State for the current invocation of Run. | 61 // State for the current invocation of Run. |
54 RunState* state_; | 62 RunState* state_; |
55 }; | 63 }; |
56 | 64 |
57 //----------------------------------------------------------------------------- | 65 //----------------------------------------------------------------------------- |
58 // MessagePumpForUI extends MessagePumpWin with methods that are particular to a | 66 // MessagePumpForUI extends MessagePumpWin with methods that are particular to a |
59 // MessageLoop instantiated with TYPE_UI. | 67 // MessageLoop instantiated with TYPE_UI. |
60 // | 68 // |
61 // MessagePumpForUI implements a "traditional" Windows message pump. It contains | 69 // 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(); | 138 bool ProcessPumpReplacementMessage(); |
131 | 139 |
132 // Atom representing the registered window class. | 140 // Atom representing the registered window class. |
133 ATOM atom_; | 141 ATOM atom_; |
134 | 142 |
135 // A hidden message-only window. | 143 // A hidden message-only window. |
136 HWND message_hwnd_; | 144 HWND message_hwnd_; |
137 }; | 145 }; |
138 | 146 |
139 //----------------------------------------------------------------------------- | 147 //----------------------------------------------------------------------------- |
148 // MessagePumpForGpu is a simplified version of UI message pump that is | |
149 // optimized for the GPU process. Unlike MessagePumpForUI it doesn't have a | |
150 // hidden window and doesn't handle a situation where a native message pump | |
151 // might take over message processing. | |
152 // | |
153 class BASE_EXPORT MessagePumpForGpu : public MessagePumpWin { | |
154 public: | |
155 MessagePumpForGpu(); | |
156 ~MessagePumpForGpu() override; | |
157 | |
158 // Factory methods. | |
159 static void InitFactory(); | |
160 static scoped_ptr<MessagePump> CreateMessagePumpForGpu(); | |
161 | |
162 // MessagePump methods: | |
163 void ScheduleWork() override; | |
164 void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override; | |
165 | |
166 private: | |
167 // MessagePump methods: | |
Lei Zhang
2016/04/07 21:32:26
MessagePumpWin, actually.
stanisc
2016/04/08 01:07:12
Done.
| |
168 void DoRunLoop() override; | |
Lei Zhang
2016/04/07 21:32:26
Add a blank line below to separate this from Messa
stanisc
2016/04/08 01:07:12
Done.
| |
169 void WaitForWork(); | |
170 bool ProcessMessages(); | |
171 | |
172 DWORD thread_id_; | |
Lei Zhang
2016/04/07 21:32:26
const?
stanisc
2016/04/08 01:07:12
Done.
| |
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 |