summaryrefslogtreecommitdiffstats
path: root/base/message_loop.h
diff options
context:
space:
mode:
Diffstat (limited to 'base/message_loop.h')
-rw-r--r--base/message_loop.h95
1 files changed, 55 insertions, 40 deletions
diff --git a/base/message_loop.h b/base/message_loop.h
index cd7b1c5..9ce0b8a 100644
--- a/base/message_loop.h
+++ b/base/message_loop.h
@@ -30,7 +30,6 @@
#ifndef BASE_MESSAGE_LOOP_H__
#define BASE_MESSAGE_LOOP_H__
-#include <windows.h>
#include <deque>
#include <queue>
#include <string>
@@ -141,6 +140,7 @@ class MessageLoop {
static void SetStrategy(int strategy);
static void EnableHistogrammer(bool enable_histogrammer);
+#ifdef OS_WIN
// Used with WatchObject to asynchronously monitor the signaled state of a
// HANDLE object.
class Watcher {
@@ -154,6 +154,36 @@ class MessageLoop {
// Pass a null watcher to stop watching the object.
bool WatchObject(HANDLE, Watcher*);
+ // An Observer is an object that receives global notifications from the
+ // MessageLoop.
+ //
+ // NOTE: An Observer implementation should be extremely fast!
+ //
+ class Observer {
+ public:
+ virtual ~Observer() {}
+
+ // This method is called before processing a message.
+ // The message may be undefined in which case msg.message is 0
+ virtual void WillProcessMessage(const MSG& msg) = 0;
+
+ // This method is called when control returns from processing a UI message.
+ // The message may be undefined in which case msg.message is 0
+ virtual void DidProcessMessage(const MSG& msg) = 0;
+ };
+
+ // Add an Observer, which will start receiving notifications immediately.
+ void AddObserver(Observer* observer);
+
+ // Remove an Observer. It is safe to call this method while an Observer is
+ // receiving a notification callback.
+ void RemoveObserver(Observer* observer);
+
+ // Give a chance to code processing additional messages to notify the
+ // message loop observers that another message has been processed.
+ void WillProcessMessage(const MSG& msg);
+ void DidProcessMessage(const MSG& msg);
+
// Dispatcher is used during a nested invocation of Run to dispatch events.
// If Run is invoked with a non-NULL Dispatcher, MessageLoop does not
// dispatch events (or invoke TranslateMessage), rather every message is
@@ -175,6 +205,12 @@ class MessageLoop {
// normal. If false is returned, the nested loop exits immediately.
virtual bool Dispatch(const MSG& msg) = 0;
};
+#else // !OS_WIN
+ // On non-Windows platforms, the Dispatcher does not exist, but we allow the
+ // typename to exist for convenience. On non-Windows platforms, a Dispatcher
+ // pointer should always be NULL.
+ class Dispatcher;
+#endif // OS_*
// A DestructionObserver is notified when the current MessageLoop is being
// destroyed. These obsevers are notified prior to MessageLoop::current()
@@ -198,31 +234,6 @@ class MessageLoop {
// DestructionObserver is receiving a notification callback.
void RemoveDestructionObserver(DestructionObserver* destruction_observer);
- // An Observer is an object that receives global notifications from the
- // MessageLoop.
- //
- // NOTE: An Observer implementation should be extremely fast!
- //
- class Observer {
- public:
- virtual ~Observer() {}
-
- // This method is called before processing a message.
- // The message may be undefined in which case msg.message is 0
- virtual void WillProcessMessage(const MSG& msg) = 0;
-
- // This method is called when control returns from processing a UI message.
- // The message may be undefined in which case msg.message is 0
- virtual void DidProcessMessage(const MSG& msg) = 0;
- };
-
- // Add an Observer, which will start receiving notifications immediately.
- void AddObserver(Observer* observer);
-
- // Remove an Observer. It is safe to call this method while an Observer is
- // receiving a notification callback.
- void RemoveObserver(Observer* observer);
-
// Call the task's Run method asynchronously from within a message loop at
// some point in the future. With the PostTask variant, tasks are invoked in
// FIFO order, inter-mixed with normal UI event processing. With the
@@ -299,9 +310,6 @@ class MessageLoop {
}
};
- // Wnd Proc for message_hwnd_.
- LRESULT MessageWndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
-
// Normally, it is not necessary to instantiate a MessageLoop. Instead, it
// is typical to make use of the current thread's MessageLoop instance.
MessageLoop();
@@ -309,7 +317,7 @@ class MessageLoop {
// Optional call to connect the thread name with this loop.
void SetThreadName(const std::string& thread_name);
- std::string thread_name() const { return thread_name_; }
+ const std::string& thread_name() const { return thread_name_; }
// Returns the MessageLoop object for the current thread, or null if none.
static MessageLoop* current() {
@@ -319,11 +327,6 @@ class MessageLoop {
// Returns the TimerManager object for the current thread.
TimerManager* timer_manager() { return &timer_manager_; }
- // Give a chance to code processing additional messages to notify the
- // message loop delegates that another message has been processed.
- void WillProcessMessage(const MSG& msg);
- void DidProcessMessage(const MSG& msg);
-
// Enables or disables the recursive task processing. This happens in the case
// of recursive message loops. Some unwanted message loop may occurs when
// using common controls or printer functions. By default, recursive task
@@ -413,7 +416,7 @@ class MessageLoop {
: task_(task),
sequence_number_(sequence_number),
priority_(task->priority()) {}
- Task* task() { return task_; }
+ Task* task() const { return task_; }
bool operator < (PrioritizedTask const & right) const ;
private:
@@ -459,8 +462,15 @@ class MessageLoop {
DISALLOW_EVIL_CONSTRUCTORS(OptionallyPrioritizedTaskQueue);
};
+#ifdef OS_WIN
void InitMessageWnd();
+ // Windows procedure for message_hwnd_.
+ static LRESULT CALLBACK WndProcThunk(
+ HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
+ LRESULT WndProc(
+ HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
+#endif // OS_WIN
// A function to encapsulate all the exception handling capability in the
// stacks around the running of a main message loop.
@@ -490,8 +500,7 @@ class MessageLoop {
bool ProcessSomeTimers();
//----------------------------------------------------------------------------
- // Process some pending messages.
- // Returns true if a message was processed.
+ // Process some pending messages. Returns true if a message was processed.
bool ProcessNextWindowsMessage();
// Wait until either an object is signaled, a message is available, a timer
@@ -499,12 +508,14 @@ class MessageLoop {
// Handle (without returning) any APCs (only IO thread currently has APCs.)
void WaitForWork();
+#ifdef OS_WIN
// Helper function for processing window messages. This includes handling
// WM_QUIT, message translation and dispatch, etc.
//
// If dispatcher_ is non-NULL this method does NOT dispatch the event, instead
// it invokes Dispatch on the dispatcher_.
bool ProcessMessageHelper(const MSG& msg);
+#endif // OS_WIN
// When we encounter a kMsgPumpATask, the following helper can be called to
// peek and process a replacement message, such as a WM_PAINT or WM_TIMER.
@@ -566,7 +577,7 @@ class MessageLoop {
void EnsureMessageGetsPosted(int message) const;
// Post a task to our incomming queue.
- void MessageLoop::PostTaskInternal(Task* task);
+ void PostTaskInternal(Task* task);
// Start recording histogram info about events and action IF it was enabled
// and IF the statistics recorder can accept a registration of our histogram.
@@ -593,14 +604,18 @@ class MessageLoop {
// there was no real prioritization.
OptionallyPrioritizedTaskQueue work_queue_;
+#ifdef OS_WIN
+ HWND message_hwnd_;
+
// A vector of objects (and corresponding watchers) that are routinely
// serviced by this message loop's pump.
std::vector<HANDLE> objects_;
std::vector<Watcher*> watchers_;
ObserverList<Observer> observers_;
+#endif // OS_WIN
+
ObserverList<DestructionObserver> destruction_observers_;
- HWND message_hwnd_;
IDMap<Task> timed_tasks_;
// A recursion block that prevents accidentally running additonal tasks when
// insider a (accidentally induced?) nested message pump.