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.cc | |
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.cc')
-rw-r--r-- | base/message_loop.cc | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/base/message_loop.cc b/base/message_loop.cc index 7d2fbff..78f820c 100644 --- a/base/message_loop.cc +++ b/base/message_loop.cc @@ -140,9 +140,17 @@ MessageLoop::MessageLoop() : message_hwnd_(NULL), MessageLoop::~MessageLoop() { DCHECK(this == current()); + + // Let interested parties have one last shot at accessing this. + FOR_EACH_OBSERVER(DestructionObserver, destruction_observers_, + WillDestroyCurrentMessageLoop()); + + // OK, now make it so that no one can find us. ThreadLocalStorage::Set(tls_index_, NULL); + DCHECK(!dispatcher_); DCHECK(!quit_received_ && !quit_now_); + // Most tasks that have not been Run() are deleted in the |timer_manager_| // destructor after we remove our tls index. We delete the tasks in our // queues here so their destuction is similar to the tasks in the @@ -158,6 +166,16 @@ void MessageLoop::SetThreadName(const std::string& thread_name) { StartHistogrammer(); } +void MessageLoop::AddDestructionObserver(DestructionObserver *obs) { + DCHECK(this == current()); + destruction_observers_.AddObserver(obs); +} + +void MessageLoop::RemoveDestructionObserver(DestructionObserver *obs) { + DCHECK(this == current()); + destruction_observers_.RemoveObserver(obs); +} + void MessageLoop::AddObserver(Observer *obs) { DCHECK(this == current()); observers_.AddObserver(obs); |