OLD | NEW |
---|---|
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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
17 #include "base/process/process_metrics.h" | 17 #include "base/process/process_metrics.h" |
18 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
21 #include "base/threading/thread_restrictions.h" | 21 #include "base/threading/thread_restrictions.h" |
22 #include "base/threading/thread_task_runner_handle.h" | 22 #include "base/threading/thread_task_runner_handle.h" |
23 #include "crypto/rsa_private_key.h" | 23 #include "crypto/rsa_private_key.h" |
24 #include "net/base/ip_endpoint.h" | 24 #include "net/base/ip_endpoint.h" |
25 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
26 #include "net/base/port_util.h" | |
26 #include "net/cert/pem_tokenizer.h" | 27 #include "net/cert/pem_tokenizer.h" |
27 #include "net/cert/test_root_certs.h" | 28 #include "net/cert/test_root_certs.h" |
28 #include "net/log/net_log_source.h" | 29 #include "net/log/net_log_source.h" |
29 #include "net/socket/ssl_server_socket.h" | 30 #include "net/socket/ssl_server_socket.h" |
30 #include "net/socket/stream_socket.h" | 31 #include "net/socket/stream_socket.h" |
31 #include "net/socket/tcp_server_socket.h" | 32 #include "net/socket/tcp_server_socket.h" |
32 #include "net/ssl/ssl_server_config.h" | 33 #include "net/ssl/ssl_server_config.h" |
33 #include "net/test/cert_test_util.h" | 34 #include "net/test/cert_test_util.h" |
34 #include "net/test/embedded_test_server/default_handlers.h" | 35 #include "net/test/embedded_test_server/default_handlers.h" |
35 #include "net/test/embedded_test_server/embedded_test_server_connection_listener .h" | 36 #include "net/test/embedded_test_server/embedded_test_server_connection_listener .h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 CHECK(io_thread_->WaitUntilThreadStarted()); | 157 CHECK(io_thread_->WaitUntilThreadStarted()); |
157 | 158 |
158 io_thread_->task_runner()->PostTask( | 159 io_thread_->task_runner()->PostTask( |
159 FROM_HERE, | 160 FROM_HERE, |
160 base::Bind(&EmbeddedTestServer::DoAcceptLoop, base::Unretained(this))); | 161 base::Bind(&EmbeddedTestServer::DoAcceptLoop, base::Unretained(this))); |
161 } | 162 } |
162 | 163 |
163 bool EmbeddedTestServer::ShutdownAndWaitUntilComplete() { | 164 bool EmbeddedTestServer::ShutdownAndWaitUntilComplete() { |
164 DCHECK(thread_checker_.CalledOnValidThread()); | 165 DCHECK(thread_checker_.CalledOnValidThread()); |
165 | 166 |
167 port_exception_ = nullptr; | |
166 return PostTaskToIOThreadAndWait(base::Bind( | 168 return PostTaskToIOThreadAndWait(base::Bind( |
167 &EmbeddedTestServer::ShutdownOnIOThread, base::Unretained(this))); | 169 &EmbeddedTestServer::ShutdownOnIOThread, base::Unretained(this))); |
168 } | 170 } |
169 | 171 |
170 void EmbeddedTestServer::ShutdownOnIOThread() { | 172 void EmbeddedTestServer::ShutdownOnIOThread() { |
171 DCHECK(io_thread_->task_runner()->BelongsToCurrentThread()); | 173 DCHECK(io_thread_->task_runner()->BelongsToCurrentThread()); |
172 weak_factory_.InvalidateWeakPtrs(); | 174 weak_factory_.InvalidateWeakPtrs(); |
173 listen_socket_.reset(); | 175 listen_socket_.reset(); |
174 connections_.clear(); | 176 connections_.clear(); |
175 } | 177 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 GURL::Replacements replace_host; | 229 GURL::Replacements replace_host; |
228 replace_host.SetHostStr(hostname); | 230 replace_host.SetHostStr(hostname); |
229 return local_url.ReplaceComponents(replace_host); | 231 return local_url.ReplaceComponents(replace_host); |
230 } | 232 } |
231 | 233 |
232 bool EmbeddedTestServer::GetAddressList(AddressList* address_list) const { | 234 bool EmbeddedTestServer::GetAddressList(AddressList* address_list) const { |
233 *address_list = AddressList(local_endpoint_); | 235 *address_list = AddressList(local_endpoint_); |
234 return true; | 236 return true; |
235 } | 237 } |
236 | 238 |
239 void EmbeddedTestServer::SetPortExceptionEnabled(bool enabled) { | |
svaldez
2016/12/09 15:26:53
Might as well default this to true and then remove
rohitrao (ping after 24h)
2016/12/09 16:08:53
Done.
| |
240 if (enabled) { | |
241 DCHECK(Started()); | |
242 port_exception_ = base::MakeUnique<ScopedPortException>(port_); | |
243 } else { | |
244 port_exception_ = nullptr; | |
245 } | |
246 } | |
247 | |
237 void EmbeddedTestServer::SetSSLConfig(ServerCertificate cert, | 248 void EmbeddedTestServer::SetSSLConfig(ServerCertificate cert, |
238 const SSLServerConfig& ssl_config) { | 249 const SSLServerConfig& ssl_config) { |
239 DCHECK(!Started()); | 250 DCHECK(!Started()); |
240 cert_ = cert; | 251 cert_ = cert; |
241 ssl_config_ = ssl_config; | 252 ssl_config_ = ssl_config; |
242 } | 253 } |
243 | 254 |
244 void EmbeddedTestServer::SetSSLConfig(ServerCertificate cert) { | 255 void EmbeddedTestServer::SetSSLConfig(ServerCertificate cert) { |
245 SetSSLConfig(cert, SSLServerConfig()); | 256 SetSSLConfig(cert, SSLServerConfig()); |
246 } | 257 } |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
461 run_loop.QuitClosure())) { | 472 run_loop.QuitClosure())) { |
462 return false; | 473 return false; |
463 } | 474 } |
464 run_loop.Run(); | 475 run_loop.Run(); |
465 | 476 |
466 return true; | 477 return true; |
467 } | 478 } |
468 | 479 |
469 } // namespace test_server | 480 } // namespace test_server |
470 } // namespace net | 481 } // namespace net |
OLD | NEW |