diff options
author | darin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-05 23:16:41 +0000 |
---|---|---|
committer | darin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-05 23:16:41 +0000 |
commit | 2a1272586d0ab6719820ea25ac596683b33d0676 (patch) | |
tree | 3f0203f0cc289e067d9668d73265832e5ecf6742 /base/message_loop.h | |
parent | 836dff30efbff95f2090a024da25debe4edd2f83 (diff) | |
download | chromium_src-2a1272586d0ab6719820ea25ac596683b33d0676.zip chromium_src-2a1272586d0ab6719820ea25ac596683b33d0676.tar.gz chromium_src-2a1272586d0ab6719820ea25ac596683b33d0676.tar.bz2 |
ObjectWatcher needs to know when the current thread's MessageLoop is being destroyed. This might also be generically useful, so I added a new API on ML to observe when the ML is being destroyed. The notification is sent to observers just prior to ML::current() being modified to return NULL.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@407 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/message_loop.h')
-rw-r--r-- | base/message_loop.h | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/base/message_loop.h b/base/message_loop.h index 1610d07..cd7b1c5 100644 --- a/base/message_loop.h +++ b/base/message_loop.h @@ -150,6 +150,10 @@ class MessageLoop { virtual void OnObjectSignaled(HANDLE object) = 0; }; + // Have the current thread's message loop watch for a signaled object. + // Pass a null watcher to stop watching the object. + bool WatchObject(HANDLE, Watcher*); + // 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 @@ -172,9 +176,27 @@ class MessageLoop { virtual bool Dispatch(const MSG& msg) = 0; }; - // Have the current thread's message loop watch for a signaled object. - // Pass a null watcher to stop watching the object. - bool WatchObject(HANDLE, Watcher*); + // A DestructionObserver is notified when the current MessageLoop is being + // destroyed. These obsevers are notified prior to MessageLoop::current() + // being changed to return NULL. This gives interested parties the chance to + // do final cleanup that depends on the MessageLoop. + // + // NOTE: Any tasks posted to the MessageLoop during this notification will + // not be run. Instead, they will be deleted. + // + class DestructionObserver { + public: + virtual ~DestructionObserver() {} + virtual void WillDestroyCurrentMessageLoop() = 0; + }; + + // Add a DestructionObserver, which will start receiving notifications + // immediately. + void AddDestructionObserver(DestructionObserver* destruction_observer); + + // Remove a DestructionObserver. It is safe to call this method while a + // DestructionObserver is receiving a notification callback. + void RemoveDestructionObserver(DestructionObserver* destruction_observer); // An Observer is an object that receives global notifications from the // MessageLoop. @@ -577,6 +599,7 @@ class MessageLoop { std::vector<Watcher*> watchers_; ObserverList<Observer> observers_; + ObserverList<DestructionObserver> destruction_observers_; HWND message_hwnd_; IDMap<Task> timed_tasks_; // A recursion block that prevents accidentally running additonal tasks when |