Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Unified Diff: net/test/embedded_test_server/embedded_test_server.cc

Issue 83633004: Do not spawn a thread in browser/interactive ui tests before spawning sandbox host process (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..c7cf1efa7fff34c4b822fcb0d68ff6cb3a2d10dc 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,31 @@ 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::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::StopThread() {
+ io_thread_->Stop();
+ io_thread_.reset();
+ thread_checker_.DetachFromThread();
+ listen_socket_->DetachFromThread();
+}
+
bool EmbeddedTestServer::ShutdownAndWaitUntilComplete() {
DCHECK(thread_checker_.CalledOnValidThread());

Powered by Google App Engine
This is Rietveld 408576698