diff options
author | ananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-13 15:45:38 +0000 |
---|---|---|
committer | ananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-13 15:45:38 +0000 |
commit | bf64d1e5c95a7fa9e65395747d2d4da65de0040a (patch) | |
tree | c348ac9d116c26ab1c5de93d42f295a2f6611ee8 /base/thread_unittest.cc | |
parent | 42b15f33e277b41b5f0d90b1a07967528d0440e7 (diff) | |
download | chromium_src-bf64d1e5c95a7fa9e65395747d2d4da65de0040a.zip chromium_src-bf64d1e5c95a7fa9e65395747d2d4da65de0040a.tar.gz chromium_src-bf64d1e5c95a7fa9e65395747d2d4da65de0040a.tar.bz2 |
Reverting this CL as it causes chrome frame net tests to crash at exit. The crash happens because the IPC channel proxy
code relies on the listener threads message loop being around. This change destroys the message loop when it goes out
of scope leading to the crash.
Revert 44323 - Don't call Thread::CleanUp() before the MessageLoop destruction observers have run.
This is consistent with the comment for Thread::CleanUp(), which says it runs after the message loop has "stopped".
Certain consumers depend on this ordering to avoid accessing variables which are deleted by Thread::CleanUp().
BUG=39723
TEST=ThreadTest.CleanUp
Review URL: http://codereview.chromium.org/1540002
TBR=eroman@chromium.org
Review URL: http://codereview.chromium.org/1528034
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44357 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/thread_unittest.cc')
-rw-r--r-- | base/thread_unittest.cc | 110 |
1 files changed, 1 insertions, 109 deletions
diff --git a/base/thread_unittest.cc b/base/thread_unittest.cc index 193f7c1..90aec51 100644 --- a/base/thread_unittest.cc +++ b/base/thread_unittest.cc @@ -2,14 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/thread.h" - -#include <vector> - #include "base/dynamic_annotations.h" #include "base/lock.h" #include "base/message_loop.h" #include "base/string_util.h" +#include "base/thread.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" @@ -57,81 +54,6 @@ class SleepInsideInitThread : public Thread { bool init_called_; }; -enum ThreadEvent { - // Thread::Init() was called. - THREAD_EVENT_INIT, - - // The MessageLoop for the thread was deleted. - THREAD_EVENT_MESSAGE_LOOP_DESTROYED, - - // Thread::CleanUp() was called. - THREAD_EVENT_CLEANUP, -}; - -typedef std::vector<ThreadEvent> EventList; - -class CaptureToEventList : public Thread { - public: - // This Thread pushes events into the vector |event_list| to show - // the order they occured in. |event_list| must remain valid for the - // lifetime of this thread. - explicit CaptureToEventList(EventList* event_list) - : Thread("none"), event_list_(event_list) { - } - - virtual ~CaptureToEventList() { - // Must call Stop() manually to have our CleanUp() function called. - Stop(); - } - - virtual void Init() { - event_list_->push_back(THREAD_EVENT_INIT); - } - - virtual void CleanUp() { - event_list_->push_back(THREAD_EVENT_CLEANUP); - } - - private: - EventList* event_list_; -}; - -// Observer that writes a value into |event_list| when a message loop has been -// destroyed. -class CapturingDestructionObserver : public MessageLoop::DestructionObserver { - public: - // |event_list| must remain valid throughout the observer's lifetime. - explicit CapturingDestructionObserver(EventList* event_list) - : event_list_(event_list) { - } - - // DestructionObserver implementation: - virtual void WillDestroyCurrentMessageLoop() { - event_list_->push_back(THREAD_EVENT_MESSAGE_LOOP_DESTROYED); - event_list_ = NULL; - } - - private: - EventList* event_list_; -}; - -// Task that adds a destruction observer to the current message loop. -class RegisterDestructionObserver : public Task { - public: - explicit RegisterDestructionObserver( - MessageLoop::DestructionObserver* observer) - : observer_(observer) { - } - - virtual void Run() { - MessageLoop::current()->AddDestructionObserver(observer_); - observer_ = NULL; - } - - private: - MessageLoop::DestructionObserver* observer_; -}; - } // namespace TEST_F(ThreadTest, Restart) { @@ -219,33 +141,3 @@ TEST_F(ThreadTest, SleepInsideInit) { t.Start(); EXPECT_TRUE(t.InitCalled()); } - -// Make sure that MessageLoop::DestructionObserver is called before -// Thread::Cleanup. -TEST_F(ThreadTest, CleanUp) { - EventList captured_events; - CapturingDestructionObserver loop_destruction_observer(&captured_events); - - { - // Start a thread which writes its event into |captured_events|. - CaptureToEventList t(&captured_events); - EXPECT_TRUE(t.Start()); - EXPECT_TRUE(t.message_loop()); - EXPECT_TRUE(t.IsRunning()); - - // Register an observer that writes into |captured_events| once the - // thread's message loop is destroyed. - t.message_loop()->PostTask( - FROM_HERE, - new RegisterDestructionObserver(&loop_destruction_observer)); - - // Upon leaving this scope, the thread is deleted. - } - - // Check the order of events during shutdown. In particular, that the message - // loop destruction observer ran before Thread::CleanUp(). - ASSERT_EQ(3u, captured_events.size()); - EXPECT_EQ(THREAD_EVENT_INIT, captured_events[0]); - EXPECT_EQ(THREAD_EVENT_MESSAGE_LOOP_DESTROYED, captured_events[1]); - EXPECT_EQ(THREAD_EVENT_CLEANUP, captured_events[2]); -} |