Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: base/message_pump_win.h

Issue 8021009: Consolidate message observer API for win and aura (and touch). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/message_pump_observer.h"
16 #include "base/observer_list.h" 17 #include "base/observer_list.h"
17 #include "base/time.h" 18 #include "base/time.h"
18 #include "base/win/scoped_handle.h" 19 #include "base/win/scoped_handle.h"
19 20
20 namespace base { 21 namespace base {
21 22
22 // MessagePumpWin serves as the base for specialized versions of the MessagePump 23 // MessagePumpWin serves as the base for specialized versions of the MessagePump
23 // for Windows. It provides basic functionality like handling of observers and 24 // for Windows. It provides basic functionality like handling of observers and
24 // controlling the lifetime of the message pump. 25 // controlling the lifetime of the message pump.
25 class BASE_EXPORT MessagePumpWin : public MessagePump { 26 class BASE_EXPORT MessagePumpWin : public MessagePump {
26 public: 27 public:
27 // An Observer is an object that receives global notifications from the
28 // UI MessageLoop.
29 //
30 // NOTE: An Observer implementation should be extremely fast!
31 //
32 class BASE_EXPORT Observer {
33 public:
34 virtual ~Observer() {}
35
36 // This method is called before processing a message.
37 // The message may be undefined in which case msg.message is 0
38 virtual void WillProcessMessage(const MSG& msg) = 0;
39
40 // 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
42 virtual void DidProcessMessage(const MSG& msg) = 0;
43 };
44 28
45 // Dispatcher is used during a nested invocation of Run to dispatch events. 29 // 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 30 // If Run is invoked with a non-NULL Dispatcher, MessageLoop does not
47 // dispatch events (or invoke TranslateMessage), rather every message is 31 // dispatch events (or invoke TranslateMessage), rather every message is
48 // passed to Dispatcher's Dispatch method for dispatch. It is up to the 32 // passed to Dispatcher's Dispatch method for dispatch. It is up to the
49 // Dispatcher to dispatch, or not, the event. 33 // Dispatcher to dispatch, or not, the event.
50 // 34 //
51 // The nested loop is exited by either posting a quit, or returning false 35 // The nested loop is exited by either posting a quit, or returning false
52 // from Dispatch. 36 // from Dispatch.
53 class BASE_EXPORT Dispatcher { 37 class BASE_EXPORT Dispatcher {
54 public: 38 public:
55 virtual ~Dispatcher() {} 39 virtual ~Dispatcher() {}
56 // Dispatches the event. If true is returned processing continues as 40 // Dispatches the event. If true is returned processing continues as
57 // normal. If false is returned, the nested loop exits immediately. 41 // normal. If false is returned, the nested loop exits immediately.
58 virtual bool Dispatch(const MSG& msg) = 0; 42 virtual bool Dispatch(const MSG& msg) = 0;
59 }; 43 };
60 44
61 MessagePumpWin() : have_work_(0), state_(NULL) {} 45 MessagePumpWin() : have_work_(0), state_(NULL) {}
62 virtual ~MessagePumpWin() {} 46 virtual ~MessagePumpWin() {}
63 47
64 // Add an Observer, which will start receiving notifications immediately. 48 // Add an Observer, which will start receiving notifications immediately.
65 void AddObserver(Observer* observer); 49 void AddObserver(MessagePumpObserver* observer);
66 50
67 // Remove an Observer. It is safe to call this method while an Observer is 51 // Remove an Observer. It is safe to call this method while an Observer is
68 // receiving a notification callback. 52 // receiving a notification callback.
69 void RemoveObserver(Observer* observer); 53 void RemoveObserver(MessagePumpObserver* observer);
70 54
71 // Give a chance to code processing additional messages to notify the 55 // Give a chance to code processing additional messages to notify the
72 // message loop observers that another message has been processed. 56 // message loop observers that another message has been processed.
73 void WillProcessMessage(const MSG& msg); 57 void WillProcessMessage(const MSG& msg);
74 void DidProcessMessage(const MSG& msg); 58 void DidProcessMessage(const MSG& msg);
75 59
76 // Like MessagePump::Run, but MSG objects are routed through dispatcher. 60 // Like MessagePump::Run, but MSG objects are routed through dispatcher.
77 void RunWithDispatcher(Delegate* delegate, Dispatcher* dispatcher); 61 void RunWithDispatcher(Delegate* delegate, Dispatcher* dispatcher);
78 62
79 // MessagePump methods: 63 // MessagePump methods:
80 virtual void Run(Delegate* delegate) { RunWithDispatcher(delegate, NULL); } 64 virtual void Run(Delegate* delegate) { RunWithDispatcher(delegate, NULL); }
81 virtual void Quit(); 65 virtual void Quit();
82 66
83 protected: 67 protected:
84 struct RunState { 68 struct RunState {
85 Delegate* delegate; 69 Delegate* delegate;
86 Dispatcher* dispatcher; 70 Dispatcher* dispatcher;
87 71
88 // Used to flag that the current Run() invocation should return ASAP. 72 // Used to flag that the current Run() invocation should return ASAP.
89 bool should_quit; 73 bool should_quit;
90 74
91 // Used to count how many Run() invocations are on the stack. 75 // Used to count how many Run() invocations are on the stack.
92 int run_depth; 76 int run_depth;
93 }; 77 };
94 78
95 virtual void DoRunLoop() = 0; 79 virtual void DoRunLoop() = 0;
96 int GetCurrentDelay() const; 80 int GetCurrentDelay() const;
97 81
98 ObserverList<Observer> observers_; 82 ObserverList<MessagePumpObserver> observers_;
99 83
100 // The time at which delayed work should run. 84 // The time at which delayed work should run.
101 TimeTicks delayed_work_time_; 85 TimeTicks delayed_work_time_;
102 86
103 // A boolean value used to indicate if there is a kMsgDoWork message pending 87 // A boolean value used to indicate if there is a kMsgDoWork message pending
104 // in the Windows Message queue. There is at most one such message, and it 88 // in the Windows Message queue. There is at most one such message, and it
105 // can drive execution of tasks when a native message pump is running. 89 // can drive execution of tasks when a native message pump is running.
106 LONG have_work_; 90 LONG have_work_;
107 91
108 // State for the current invocation of Run. 92 // State for the current invocation of Run.
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 // This list will be empty almost always. It stores IO completions that have 345 // This list will be empty almost always. It stores IO completions that have
362 // not been delivered yet because somebody was doing cleanup. 346 // not been delivered yet because somebody was doing cleanup.
363 std::list<IOItem> completed_io_; 347 std::list<IOItem> completed_io_;
364 348
365 ObserverList<IOObserver> io_observers_; 349 ObserverList<IOObserver> io_observers_;
366 }; 350 };
367 351
368 } // namespace base 352 } // namespace base
369 353
370 #endif // BASE_MESSAGE_PUMP_WIN_H_ 354 #endif // BASE_MESSAGE_PUMP_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698