The base unittests were succeeding for the isolated
tests, but failed when all tests were run because
some tests run without a message loop. The
observer_list_threadsafe allowed AddObserver to run
with null message loops. But, if you call Notify
after doing so, then the notify call would attempt
to use the registered "null" ptr to a message loop.
This crashed, of course.
Review URL: http://codereview.chromium.org/9045
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4459 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/base/observer_list_threadsafe.h b/base/observer_list_threadsafe.h
index f76f063..113805fa 100644
--- a/base/observer_list_threadsafe.h
+++ b/base/observer_list_threadsafe.h
@@ -64,6 +64,8 @@
void AddObserver(ObserverType* obs) {
ObserverList<ObserverType>* list = NULL;
MessageLoop* loop = MessageLoop::current();
+ if (!loop)
+ return; // Some unittests may access this without a message loop.
{
AutoLock lock(list_lock_);
if (observer_lists_.find(loop) == observer_lists_.end())