Chromium Code Reviews| Index: net/test/embedded_test_server/embedded_test_server.cc |
| diff --git a/net/test/embedded_test_server/embedded_test_server.cc b/net/test/embedded_test_server/embedded_test_server.cc |
| index 3d246d1a820588adb19cb8698fc60a6e56aa7db8..794076d6f7d2840200f1fabf1812f5660feeea4c 100644 |
| --- a/net/test/embedded_test_server/embedded_test_server.cc |
| +++ b/net/test/embedded_test_server/embedded_test_server.cc |
| @@ -99,6 +99,10 @@ HttpListenSocket::~HttpListenSocket() { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| } |
| +void HttpListenSocket::DetachFromThread() { |
| + thread_checker_.DetachFromThread(); |
| +} |
| + |
| EmbeddedTestServer::EmbeddedTestServer() |
| : port_(-1), |
| weak_factory_(this) { |
| @@ -114,21 +118,30 @@ EmbeddedTestServer::~EmbeddedTestServer() { |
| } |
| bool EmbeddedTestServer::InitializeAndWaitUntilReady() { |
| - base::Thread::Options thread_options; |
| - thread_options.message_loop_type = base::MessageLoop::TYPE_IO; |
| - io_thread_.reset(new base::Thread("EmbeddedTestServer io thread")); |
| - CHECK(io_thread_->StartWithOptions(thread_options)); |
| - |
| + StartThread(); |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| - |
| if (!PostTaskToIOThreadAndWait(base::Bind( |
| &EmbeddedTestServer::InitializeOnIOThread, base::Unretained(this)))) { |
| return false; |
| } |
| - |
| return Started() && base_url_.is_valid(); |
| } |
| +void EmbeddedTestServer::StopThread() { |
| + io_thread_->Stop(); |
| + io_thread_.reset(); |
| + thread_checker_.DetachFromThread(); |
| + listen_socket_->DetachFromThread(); |
| +} |
| + |
| +void EmbeddedTestServer::RestartThreadAndListen() { |
| + StartThread(); |
| + if (!PostTaskToIOThreadAndWait(base::Bind( |
| + &EmbeddedTestServer::ListenOnIOThread, base::Unretained(this)))) { |
|
satorux1
2013/11/27 03:27:17
did you meant to add LOG(ERROR) here? Otherwise th
oshima
2013/11/27 07:41:54
changed to CHECK. This should never fail in tests
|
| + return; |
| + } |
| +} |
| + |
| bool EmbeddedTestServer::ShutdownAndWaitUntilComplete() { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| @@ -136,6 +149,14 @@ bool EmbeddedTestServer::ShutdownAndWaitUntilComplete() { |
| &EmbeddedTestServer::ShutdownOnIOThread, base::Unretained(this))); |
| } |
| +void EmbeddedTestServer::StartThread() { |
| + DCHECK(!io_thread_.get()); |
| + base::Thread::Options thread_options; |
| + thread_options.message_loop_type = base::MessageLoop::TYPE_IO; |
| + io_thread_.reset(new base::Thread("EmbeddedTestServer io thread")); |
| + CHECK(io_thread_->StartWithOptions(thread_options)); |
| +} |
| + |
| void EmbeddedTestServer::InitializeOnIOThread() { |
| DCHECK(io_thread_->message_loop_proxy()->BelongsToCurrentThread()); |
| DCHECK(!Started()); |
| @@ -157,6 +178,12 @@ void EmbeddedTestServer::InitializeOnIOThread() { |
| } |
| } |
| +void EmbeddedTestServer::ListenOnIOThread() { |
| + DCHECK(io_thread_->message_loop_proxy()->BelongsToCurrentThread()); |
| + DCHECK(Started()); |
| + listen_socket_->Listen(); |
| +} |
| + |
| void EmbeddedTestServer::ShutdownOnIOThread() { |
| DCHECK(io_thread_->message_loop_proxy()->BelongsToCurrentThread()); |