Moved the calls to the MessageLoop destruction observers to after the pending tasks are deleted.

BUG=None
TEST=Unit-test provided, tests should pass and all hell should not break loose.


Review URL: http://codereview.chromium.org/5318003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67623 0039d316-1c4b-4281-b951-d872f2087c98


CrOS-Libchrome-Original-Commit: 582384779d93227fc44bb347947a094505080858
diff --git a/base/message_loop.cc b/base/message_loop.cc
index 57eda53..823670f 100644
--- a/base/message_loop.cc
+++ b/base/message_loop.cc
@@ -162,10 +162,6 @@
 MessageLoop::~MessageLoop() {
   DCHECK_EQ(this, current());
 
-  // Let interested parties have one last shot at accessing this.
-  FOR_EACH_OBSERVER(DestructionObserver, destruction_observers_,
-                    WillDestroyCurrentMessageLoop());
-
   DCHECK(!state_);
 
   // Clean up any unprocessed tasks, but take care: deleting a task could
@@ -185,6 +181,10 @@
   }
   DCHECK(!did_work);
 
+  // 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.
   lazy_tls_ptr.Pointer()->Set(NULL);
 }