| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_PUMP_WIN_H_ | 5 #ifndef BASE_MESSAGE_PUMP_WIN_H_ |
| 6 #define BASE_MESSAGE_PUMP_WIN_H_ | 6 #define BASE_MESSAGE_PUMP_WIN_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 | 10 |
| 11 #include <list> | 11 #include <list> |
| 12 | 12 |
| 13 #include "base/base_export.h" | 13 #include "base/base_export.h" |
| 14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "base/message_pump.h" | 15 #include "base/message_pump.h" |
| 16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
| 17 #include "base/time.h" | 17 #include "base/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 typedef MSG NativeEvent; |
| 23 |
| 24 enum EventStatus { |
| 25 EVENT_CONTINUE, // The event should be dispatched as normal. |
| 26 }; |
| 27 |
| 22 // MessagePumpWin serves as the base for specialized versions of the MessagePump | 28 // MessagePumpWin serves as the base for specialized versions of the MessagePump |
| 23 // for Windows. It provides basic functionality like handling of observers and | 29 // for Windows. It provides basic functionality like handling of observers and |
| 24 // controlling the lifetime of the message pump. | 30 // controlling the lifetime of the message pump. |
| 25 class BASE_EXPORT MessagePumpWin : public MessagePump { | 31 class BASE_EXPORT MessagePumpWin : public MessagePump { |
| 26 public: | 32 public: |
| 27 // An Observer is an object that receives global notifications from the | 33 // An Observer is an object that receives global notifications from the |
| 28 // UI MessageLoop. | 34 // UI MessageLoop. |
| 29 // | 35 // |
| 30 // NOTE: An Observer implementation should be extremely fast! | 36 // NOTE: An Observer implementation should be extremely fast! |
| 31 // | 37 // |
| 32 class BASE_EXPORT Observer { | 38 class BASE_EXPORT Observer { |
| 33 public: | 39 public: |
| 34 virtual ~Observer() {} | 40 virtual ~Observer() {} |
| 35 | 41 |
| 36 // This method is called before processing a message. | 42 // This method is called before processing a message. |
| 37 // The message may be undefined in which case msg.message is 0 | 43 // The message may be undefined in which case msg.message is 0 |
| 38 virtual void WillProcessMessage(const MSG& msg) = 0; | 44 virtual EventStatus WillProcessEvent(const NativeEvent& msg) = 0; |
| 39 | 45 |
| 40 // This method is called when control returns from processing a UI message. | 46 // This method is called when control returns from processing a UI message. |
| 41 // The message may be undefined in which case msg.message is 0 | 47 // The message may be undefined in which case msg.message is 0 |
| 42 virtual void DidProcessMessage(const MSG& msg) = 0; | 48 virtual void DidProcessEvent(const NativeEvent& msg) = 0; |
| 43 }; | 49 }; |
| 44 | 50 |
| 45 // Dispatcher is used during a nested invocation of Run to dispatch events. | 51 // Dispatcher is used during a nested invocation of Run to dispatch events. |
| 46 // If Run is invoked with a non-NULL Dispatcher, MessageLoop does not | 52 // If Run is invoked with a non-NULL Dispatcher, MessageLoop does not |
| 47 // dispatch events (or invoke TranslateMessage), rather every message is | 53 // dispatch events (or invoke TranslateMessage), rather every message is |
| 48 // passed to Dispatcher's Dispatch method for dispatch. It is up to the | 54 // passed to Dispatcher's Dispatch method for dispatch. It is up to the |
| 49 // Dispatcher to dispatch, or not, the event. | 55 // Dispatcher to dispatch, or not, the event. |
| 50 // | 56 // |
| 51 // The nested loop is exited by either posting a quit, or returning false | 57 // The nested loop is exited by either posting a quit, or returning false |
| 52 // from Dispatch. | 58 // from Dispatch. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 63 | 69 |
| 64 // Add an Observer, which will start receiving notifications immediately. | 70 // Add an Observer, which will start receiving notifications immediately. |
| 65 void AddObserver(Observer* observer); | 71 void AddObserver(Observer* observer); |
| 66 | 72 |
| 67 // Remove an Observer. It is safe to call this method while an Observer is | 73 // Remove an Observer. It is safe to call this method while an Observer is |
| 68 // receiving a notification callback. | 74 // receiving a notification callback. |
| 69 void RemoveObserver(Observer* observer); | 75 void RemoveObserver(Observer* observer); |
| 70 | 76 |
| 71 // Give a chance to code processing additional messages to notify the | 77 // Give a chance to code processing additional messages to notify the |
| 72 // message loop observers that another message has been processed. | 78 // message loop observers that another message has been processed. |
| 73 void WillProcessMessage(const MSG& msg); | 79 void WillProcessEvent(const MSG& msg); |
| 74 void DidProcessMessage(const MSG& msg); | 80 void DidProcessEvent(const MSG& msg); |
| 75 | 81 |
| 76 // Like MessagePump::Run, but MSG objects are routed through dispatcher. | 82 // Like MessagePump::Run, but MSG objects are routed through dispatcher. |
| 77 void RunWithDispatcher(Delegate* delegate, Dispatcher* dispatcher); | 83 void RunWithDispatcher(Delegate* delegate, Dispatcher* dispatcher); |
| 78 | 84 |
| 79 // MessagePump methods: | 85 // MessagePump methods: |
| 80 virtual void Run(Delegate* delegate) { RunWithDispatcher(delegate, NULL); } | 86 virtual void Run(Delegate* delegate) { RunWithDispatcher(delegate, NULL); } |
| 81 virtual void Quit(); | 87 virtual void Quit(); |
| 82 | 88 |
| 83 protected: | 89 protected: |
| 84 struct RunState { | 90 struct RunState { |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 // This list will be empty almost always. It stores IO completions that have | 367 // This list will be empty almost always. It stores IO completions that have |
| 362 // not been delivered yet because somebody was doing cleanup. | 368 // not been delivered yet because somebody was doing cleanup. |
| 363 std::list<IOItem> completed_io_; | 369 std::list<IOItem> completed_io_; |
| 364 | 370 |
| 365 ObserverList<IOObserver> io_observers_; | 371 ObserverList<IOObserver> io_observers_; |
| 366 }; | 372 }; |
| 367 | 373 |
| 368 } // namespace base | 374 } // namespace base |
| 369 | 375 |
| 370 #endif // BASE_MESSAGE_PUMP_WIN_H_ | 376 #endif // BASE_MESSAGE_PUMP_WIN_H_ |
| OLD | NEW |