| 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..aacecd23548994eb20614d80ecac4bd9cfa92134 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,28 @@ 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();
|
| + CHECK(PostTaskToIOThreadAndWait(base::Bind(
|
| + &EmbeddedTestServer::ListenOnIOThread, base::Unretained(this))));
|
| +}
|
| +
|
| bool EmbeddedTestServer::ShutdownAndWaitUntilComplete() {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
| @@ -136,6 +147,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 +176,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());
|
|
|
|
|