| OLD | NEW |
| 1 // Copyright (c) 2011 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_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/message_pump_dispatcher.h" |
| 16 #include "base/message_pump_observer.h" | 17 #include "base/message_pump_observer.h" |
| 17 #include "base/observer_list.h" | 18 #include "base/observer_list.h" |
| 18 #include "base/time.h" | 19 #include "base/time.h" |
| 19 #include "base/win/scoped_handle.h" | 20 #include "base/win/scoped_handle.h" |
| 20 | 21 |
| 21 namespace base { | 22 namespace base { |
| 22 | 23 |
| 23 // MessagePumpWin serves as the base for specialized versions of the MessagePump | 24 // MessagePumpWin serves as the base for specialized versions of the MessagePump |
| 24 // for Windows. It provides basic functionality like handling of observers and | 25 // for Windows. It provides basic functionality like handling of observers and |
| 25 // controlling the lifetime of the message pump. | 26 // controlling the lifetime of the message pump. |
| 26 class BASE_EXPORT MessagePumpWin : public MessagePump { | 27 class BASE_EXPORT MessagePumpWin : public MessagePump { |
| 27 public: | 28 public: |
| 28 | |
| 29 // Dispatcher is used during a nested invocation of Run to dispatch events. | |
| 30 // If Run is invoked with a non-NULL Dispatcher, MessageLoop does not | |
| 31 // dispatch events (or invoke TranslateMessage), rather every message is | |
| 32 // passed to Dispatcher's Dispatch method for dispatch. It is up to the | |
| 33 // Dispatcher to dispatch, or not, the event. | |
| 34 // | |
| 35 // The nested loop is exited by either posting a quit, or returning false | |
| 36 // from Dispatch. | |
| 37 class BASE_EXPORT Dispatcher { | |
| 38 public: | |
| 39 virtual ~Dispatcher() {} | |
| 40 // Dispatches the event. If true is returned processing continues as | |
| 41 // normal. If false is returned, the nested loop exits immediately. | |
| 42 virtual bool Dispatch(const MSG& msg) = 0; | |
| 43 }; | |
| 44 | |
| 45 MessagePumpWin() : have_work_(0), state_(NULL) {} | 29 MessagePumpWin() : have_work_(0), state_(NULL) {} |
| 46 virtual ~MessagePumpWin() {} | 30 virtual ~MessagePumpWin() {} |
| 47 | 31 |
| 48 // Add an Observer, which will start receiving notifications immediately. | 32 // Add an Observer, which will start receiving notifications immediately. |
| 49 void AddObserver(MessagePumpObserver* observer); | 33 void AddObserver(MessagePumpObserver* observer); |
| 50 | 34 |
| 51 // Remove an Observer. It is safe to call this method while an Observer is | 35 // Remove an Observer. It is safe to call this method while an Observer is |
| 52 // receiving a notification callback. | 36 // receiving a notification callback. |
| 53 void RemoveObserver(MessagePumpObserver* observer); | 37 void RemoveObserver(MessagePumpObserver* observer); |
| 54 | 38 |
| 55 // Give a chance to code processing additional messages to notify the | 39 // Give a chance to code processing additional messages to notify the |
| 56 // message loop observers that another message has been processed. | 40 // message loop observers that another message has been processed. |
| 57 void WillProcessMessage(const MSG& msg); | 41 void WillProcessMessage(const MSG& msg); |
| 58 void DidProcessMessage(const MSG& msg); | 42 void DidProcessMessage(const MSG& msg); |
| 59 | 43 |
| 60 // Like MessagePump::Run, but MSG objects are routed through dispatcher. | 44 // Like MessagePump::Run, but MSG objects are routed through dispatcher. |
| 61 void RunWithDispatcher(Delegate* delegate, Dispatcher* dispatcher); | 45 void RunWithDispatcher(Delegate* delegate, MessagePumpDispatcher* dispatcher); |
| 62 | 46 |
| 63 // MessagePump methods: | 47 // MessagePump methods: |
| 64 virtual void Run(Delegate* delegate) { RunWithDispatcher(delegate, NULL); } | 48 virtual void Run(Delegate* delegate) { RunWithDispatcher(delegate, NULL); } |
| 65 virtual void Quit(); | 49 virtual void Quit(); |
| 66 | 50 |
| 67 protected: | 51 protected: |
| 68 struct RunState { | 52 struct RunState { |
| 69 Delegate* delegate; | 53 Delegate* delegate; |
| 70 Dispatcher* dispatcher; | 54 MessagePumpDispatcher* dispatcher; |
| 71 | 55 |
| 72 // Used to flag that the current Run() invocation should return ASAP. | 56 // Used to flag that the current Run() invocation should return ASAP. |
| 73 bool should_quit; | 57 bool should_quit; |
| 74 | 58 |
| 75 // Used to count how many Run() invocations are on the stack. | 59 // Used to count how many Run() invocations are on the stack. |
| 76 int run_depth; | 60 int run_depth; |
| 77 }; | 61 }; |
| 78 | 62 |
| 79 virtual void DoRunLoop() = 0; | 63 virtual void DoRunLoop() = 0; |
| 80 int GetCurrentDelay() const; | 64 int GetCurrentDelay() const; |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 // This list will be empty almost always. It stores IO completions that have | 329 // This list will be empty almost always. It stores IO completions that have |
| 346 // not been delivered yet because somebody was doing cleanup. | 330 // not been delivered yet because somebody was doing cleanup. |
| 347 std::list<IOItem> completed_io_; | 331 std::list<IOItem> completed_io_; |
| 348 | 332 |
| 349 ObserverList<IOObserver> io_observers_; | 333 ObserverList<IOObserver> io_observers_; |
| 350 }; | 334 }; |
| 351 | 335 |
| 352 } // namespace base | 336 } // namespace base |
| 353 | 337 |
| 354 #endif // BASE_MESSAGE_PUMP_WIN_H_ | 338 #endif // BASE_MESSAGE_PUMP_WIN_H_ |
| OLD | NEW |