Chromium Code Reviews| 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/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/message_loop/message_pump.h" | 14 #include "base/message_loop/message_pump.h" |
| 15 #include "base/message_loop/message_pump_dispatcher.h" | 15 #include "base/message_loop/message_pump_dispatcher.h" |
| 16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "base/win/scoped_handle.h" | 18 #include "base/win/scoped_handle.h" |
| 19 | 19 |
| 20 namespace base { | 20 namespace base { |
| 21 | 21 |
| 22 // MessagePumpWin serves as the base for specialized versions of the MessagePump | 22 // MessagePumpWin serves as the base for specialized versions of the MessagePump |
| 23 // for Windows. It provides basic functionality like handling of observers and | 23 // for Windows. It provides basic functionality like handling of observers and |
| 24 // controlling the lifetime of the message pump. | 24 // controlling the lifetime of the message pump. |
| 25 class BASE_EXPORT MessagePumpWin : public MessagePump { | 25 class BASE_EXPORT MessagePumpWin : public MessagePump { |
| 26 public: | 26 public: |
| 27 MessagePumpWin() : have_work_(0), state_(NULL) {} | 27 MessagePumpWin() : have_work_(0), state_(NULL) {} |
| 28 virtual ~MessagePumpWin() {} | |
|
dcheng
2015/04/16 21:03:26
How don't we don't need this? I guess the plugin o
Nico
2015/04/16 21:06:58
It complains "virtual methods shouldn't be inline"
| |
| 29 | 28 |
| 30 // Like MessagePump::Run, but MSG objects are routed through dispatcher. | 29 // Like MessagePump::Run, but MSG objects are routed through dispatcher. |
| 31 void RunWithDispatcher(Delegate* delegate, MessagePumpDispatcher* dispatcher); | 30 void RunWithDispatcher(Delegate* delegate, MessagePumpDispatcher* dispatcher); |
| 32 | 31 |
| 33 // MessagePump methods: | 32 // MessagePump methods: |
| 34 virtual void Run(Delegate* delegate) { RunWithDispatcher(delegate, NULL); } | 33 void Run(Delegate* delegate) override; |
| 35 virtual void Quit(); | 34 void Quit() override; |
| 36 | 35 |
| 37 protected: | 36 protected: |
| 38 struct RunState { | 37 struct RunState { |
| 39 Delegate* delegate; | 38 Delegate* delegate; |
| 40 MessagePumpDispatcher* dispatcher; | 39 MessagePumpDispatcher* dispatcher; |
| 41 | 40 |
| 42 // Used to flag that the current Run() invocation should return ASAP. | 41 // Used to flag that the current Run() invocation should return ASAP. |
| 43 bool should_quit; | 42 bool should_quit; |
| 44 | 43 |
| 45 // Used to count how many Run() invocations are on the stack. | 44 // Used to count how many Run() invocations are on the stack. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 // | 110 // |
| 112 class BASE_EXPORT MessagePumpForUI : public MessagePumpWin { | 111 class BASE_EXPORT MessagePumpForUI : public MessagePumpWin { |
| 113 public: | 112 public: |
| 114 // The application-defined code passed to the hook procedure. | 113 // The application-defined code passed to the hook procedure. |
| 115 static const int kMessageFilterCode = 0x5001; | 114 static const int kMessageFilterCode = 0x5001; |
| 116 | 115 |
| 117 MessagePumpForUI(); | 116 MessagePumpForUI(); |
| 118 virtual ~MessagePumpForUI(); | 117 virtual ~MessagePumpForUI(); |
| 119 | 118 |
| 120 // MessagePump methods: | 119 // MessagePump methods: |
| 121 virtual void ScheduleWork(); | 120 void ScheduleWork() override; |
| 122 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time); | 121 void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override; |
| 123 | 122 |
| 124 private: | 123 private: |
| 125 static LRESULT CALLBACK WndProcThunk(HWND window_handle, | 124 static LRESULT CALLBACK WndProcThunk(HWND window_handle, |
| 126 UINT message, | 125 UINT message, |
| 127 WPARAM wparam, | 126 WPARAM wparam, |
| 128 LPARAM lparam); | 127 LPARAM lparam); |
| 129 virtual void DoRunLoop(); | 128 void DoRunLoop() override; |
| 130 void InitMessageWnd(); | 129 void InitMessageWnd(); |
| 131 void WaitForWork(); | 130 void WaitForWork(); |
| 132 void HandleWorkMessage(); | 131 void HandleWorkMessage(); |
| 133 void HandleTimerMessage(); | 132 void HandleTimerMessage(); |
| 134 bool ProcessNextWindowsMessage(); | 133 bool ProcessNextWindowsMessage(); |
| 135 bool ProcessMessageHelper(const MSG& msg); | 134 bool ProcessMessageHelper(const MSG& msg); |
| 136 bool ProcessPumpReplacementMessage(); | 135 bool ProcessPumpReplacementMessage(); |
| 137 | 136 |
| 138 // Atom representing the registered window class. | 137 // Atom representing the registered window class. |
| 139 ATOM atom_; | 138 ATOM atom_; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 // notifies the completion of this operation. Please remember that any buffers | 259 // notifies the completion of this operation. Please remember that any buffers |
| 261 // involved with an IO operation should be around until the callback is | 260 // involved with an IO operation should be around until the callback is |
| 262 // received, so this technique can only be used for IO that do not involve | 261 // received, so this technique can only be used for IO that do not involve |
| 263 // additional buffers (other than the overlapped structure itself). | 262 // additional buffers (other than the overlapped structure itself). |
| 264 struct IOContext { | 263 struct IOContext { |
| 265 OVERLAPPED overlapped; | 264 OVERLAPPED overlapped; |
| 266 IOHandler* handler; | 265 IOHandler* handler; |
| 267 }; | 266 }; |
| 268 | 267 |
| 269 MessagePumpForIO(); | 268 MessagePumpForIO(); |
| 270 virtual ~MessagePumpForIO() {} | 269 ~MessagePumpForIO() override; |
| 271 | 270 |
| 272 // MessagePump methods: | 271 // MessagePump methods: |
| 273 virtual void ScheduleWork(); | 272 void ScheduleWork() override; |
| 274 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time); | 273 void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override; |
| 275 | 274 |
| 276 // Register the handler to be used when asynchronous IO for the given file | 275 // Register the handler to be used when asynchronous IO for the given file |
| 277 // completes. The registration persists as long as |file_handle| is valid, so | 276 // completes. The registration persists as long as |file_handle| is valid, so |
| 278 // |handler| must be valid as long as there is pending IO for the given file. | 277 // |handler| must be valid as long as there is pending IO for the given file. |
| 279 void RegisterIOHandler(HANDLE file_handle, IOHandler* handler); | 278 void RegisterIOHandler(HANDLE file_handle, IOHandler* handler); |
| 280 | 279 |
| 281 // Register the handler to be used to process job events. The registration | 280 // Register the handler to be used to process job events. The registration |
| 282 // persists as long as the job object is live, so |handler| must be valid | 281 // persists as long as the job object is live, so |handler| must be valid |
| 283 // until the job object is destroyed. Returns true if the registration | 282 // until the job object is destroyed. Returns true if the registration |
| 284 // succeeded, and false otherwise. | 283 // succeeded, and false otherwise. |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 304 IOContext* context; | 303 IOContext* context; |
| 305 DWORD bytes_transfered; | 304 DWORD bytes_transfered; |
| 306 DWORD error; | 305 DWORD error; |
| 307 | 306 |
| 308 // In some cases |context| can be a non-pointer value casted to a pointer. | 307 // In some cases |context| can be a non-pointer value casted to a pointer. |
| 309 // |has_valid_io_context| is true if |context| is a valid IOContext | 308 // |has_valid_io_context| is true if |context| is a valid IOContext |
| 310 // pointer, and false otherwise. | 309 // pointer, and false otherwise. |
| 311 bool has_valid_io_context; | 310 bool has_valid_io_context; |
| 312 }; | 311 }; |
| 313 | 312 |
| 314 virtual void DoRunLoop(); | 313 void DoRunLoop() override; |
| 315 void WaitForWork(); | 314 void WaitForWork(); |
| 316 bool MatchCompletedIOItem(IOHandler* filter, IOItem* item); | 315 bool MatchCompletedIOItem(IOHandler* filter, IOItem* item); |
| 317 bool GetIOItem(DWORD timeout, IOItem* item); | 316 bool GetIOItem(DWORD timeout, IOItem* item); |
| 318 bool ProcessInternalIOItem(const IOItem& item); | 317 bool ProcessInternalIOItem(const IOItem& item); |
| 319 void WillProcessIOEvent(); | 318 void WillProcessIOEvent(); |
| 320 void DidProcessIOEvent(); | 319 void DidProcessIOEvent(); |
| 321 | 320 |
| 322 // Converts an IOHandler pointer to a completion port key. | 321 // Converts an IOHandler pointer to a completion port key. |
| 323 // |has_valid_io_context| specifies whether completion packets posted to | 322 // |has_valid_io_context| specifies whether completion packets posted to |
| 324 // |handler| will have valid OVERLAPPED pointers. | 323 // |handler| will have valid OVERLAPPED pointers. |
| 325 static ULONG_PTR HandlerToKey(IOHandler* handler, bool has_valid_io_context); | 324 static ULONG_PTR HandlerToKey(IOHandler* handler, bool has_valid_io_context); |
| 326 | 325 |
| 327 // Converts a completion port key to an IOHandler pointer. | 326 // Converts a completion port key to an IOHandler pointer. |
| 328 static IOHandler* KeyToHandler(ULONG_PTR key, bool* has_valid_io_context); | 327 static IOHandler* KeyToHandler(ULONG_PTR key, bool* has_valid_io_context); |
| 329 | 328 |
| 330 // The completion port associated with this thread. | 329 // The completion port associated with this thread. |
| 331 win::ScopedHandle port_; | 330 win::ScopedHandle port_; |
| 332 // This list will be empty almost always. It stores IO completions that have | 331 // This list will be empty almost always. It stores IO completions that have |
| 333 // not been delivered yet because somebody was doing cleanup. | 332 // not been delivered yet because somebody was doing cleanup. |
| 334 std::list<IOItem> completed_io_; | 333 std::list<IOItem> completed_io_; |
| 335 | 334 |
| 336 ObserverList<IOObserver> io_observers_; | 335 ObserverList<IOObserver> io_observers_; |
| 337 }; | 336 }; |
| 338 | 337 |
| 339 } // namespace base | 338 } // namespace base |
| 340 | 339 |
| 341 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_WIN_H_ | 340 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_WIN_H_ |
| OLD | NEW |