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

Side by Side Diff: net/test/embedded_test_server/embedded_test_server.cc

Issue 1129953004: Reland: Lazily initialize MessageLoop for faster thread startup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: build fix.. Created 5 years, 7 months 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 unified diff | Download patch
« no previous file with comments | « net/android/network_change_notifier_android.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/test/embedded_test_server/embedded_test_server.h" 5 #include "net/test/embedded_test_server/embedded_test_server.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 return PostTaskToIOThreadAndWait(base::Bind( 183 return PostTaskToIOThreadAndWait(base::Bind(
184 &EmbeddedTestServer::ShutdownOnIOThread, base::Unretained(this))); 184 &EmbeddedTestServer::ShutdownOnIOThread, base::Unretained(this)));
185 } 185 }
186 186
187 void EmbeddedTestServer::StartThread() { 187 void EmbeddedTestServer::StartThread() {
188 DCHECK(!io_thread_.get()); 188 DCHECK(!io_thread_.get());
189 base::Thread::Options thread_options; 189 base::Thread::Options thread_options;
190 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; 190 thread_options.message_loop_type = base::MessageLoop::TYPE_IO;
191 io_thread_.reset(new base::Thread("EmbeddedTestServer io thread")); 191 io_thread_.reset(new base::Thread("EmbeddedTestServer io thread"));
192 CHECK(io_thread_->StartWithOptions(thread_options)); 192 CHECK(io_thread_->StartWithOptions(thread_options));
193 CHECK(io_thread_->WaitUntilThreadStarted());
193 } 194 }
194 195
195 void EmbeddedTestServer::InitializeOnIOThread() { 196 void EmbeddedTestServer::InitializeOnIOThread() {
196 DCHECK(io_thread_->message_loop_proxy()->BelongsToCurrentThread()); 197 DCHECK(io_thread_->message_loop_proxy()->BelongsToCurrentThread());
197 DCHECK(!Started()); 198 DCHECK(!Started());
198 199
199 SocketDescriptor socket_descriptor = 200 SocketDescriptor socket_descriptor =
200 TCPListenSocket::CreateAndBindAnyPort("127.0.0.1", &port_); 201 TCPListenSocket::CreateAndBindAnyPort("127.0.0.1", &port_);
201 if (socket_descriptor == kInvalidSocket) 202 if (socket_descriptor == kInvalidSocket)
202 return; 203 return;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 FROM_HERE, closure, run_loop.QuitClosure())) { 354 FROM_HERE, closure, run_loop.QuitClosure())) {
354 return false; 355 return false;
355 } 356 }
356 run_loop.Run(); 357 run_loop.Run();
357 358
358 return true; 359 return true;
359 } 360 }
360 361
361 } // namespace test_server 362 } // namespace test_server
362 } // namespace net 363 } // namespace net
OLDNEW
« no previous file with comments | « net/android/network_change_notifier_android.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698