Chromium Code Reviews| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 } // namespace | 85 } // namespace |
| 86 | 86 |
| 87 HttpListenSocket::HttpListenSocket(const SocketDescriptor socket_descriptor, | 87 HttpListenSocket::HttpListenSocket(const SocketDescriptor socket_descriptor, |
| 88 StreamListenSocket::Delegate* delegate) | 88 StreamListenSocket::Delegate* delegate) |
| 89 : TCPListenSocket(socket_descriptor, delegate) { | 89 : TCPListenSocket(socket_descriptor, delegate) { |
| 90 DCHECK(thread_checker_.CalledOnValidThread()); | 90 DCHECK(thread_checker_.CalledOnValidThread()); |
| 91 } | 91 } |
| 92 | 92 |
| 93 void HttpListenSocket::Listen() { | 93 void HttpListenSocket::Listen() { |
| 94 DCHECK(thread_checker_.CalledOnValidThread()); | 94 DCHECK(thread_checker_.CalledOnValidThread()); |
| 95 #if !defined(OS_POSIX) | |
| 96 // This method may be called after the IO thread is changed, thus we need to | |
| 97 // call |WatchSocket| again to make sure it listens on the current IO thread. | |
| 98 // Only needed for non POSIX platforms, since on POSIX platforms | |
| 99 // StreamListenSocket::Listen already calls WatchSocket inside the function. | |
| 100 WatchSocket(WAITING_ACCEPT); | |
| 101 #endif | |
| 95 TCPListenSocket::Listen(); | 102 TCPListenSocket::Listen(); |
| 96 } | 103 } |
| 97 | 104 |
| 105 void HttpListenSocket::ListenOnIOThread() { | |
|
xiyuan
2014/08/12 18:35:54
This looks the same as HttpListenSocket::Listen. I
guohui
2014/08/12 19:01:16
Sorry this patch is broken =(
the #if block shoul
| |
| 106 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 107 #if !defined(OS_POSIX) | |
| 108 // This method may be called after the IO thread is changed, thus we need to | |
| 109 // call |WatchSocket| again to make sure it listens on the current IO thread. | |
| 110 // Only needed for non POSIX platforms, since on POSIX platforms | |
| 111 // StreamListenSocket::Listen already calls WatchSocket inside the function. | |
| 112 WatchSocket(WAITING_ACCEPT); | |
| 113 #endif | |
| 114 Listen(); | |
| 115 } | |
| 116 | |
| 98 HttpListenSocket::~HttpListenSocket() { | 117 HttpListenSocket::~HttpListenSocket() { |
| 99 DCHECK(thread_checker_.CalledOnValidThread()); | 118 DCHECK(thread_checker_.CalledOnValidThread()); |
| 100 } | 119 } |
| 101 | 120 |
| 102 void HttpListenSocket::DetachFromThread() { | 121 void HttpListenSocket::DetachFromThread() { |
| 103 thread_checker_.DetachFromThread(); | 122 thread_checker_.DetachFromThread(); |
| 104 } | 123 } |
| 105 | 124 |
| 106 EmbeddedTestServer::EmbeddedTestServer() | 125 EmbeddedTestServer::EmbeddedTestServer() |
| 107 : port_(-1), | 126 : port_(-1), |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 if (result == OK) { | 210 if (result == OK) { |
| 192 base_url_ = GURL(std::string("http://") + address.ToString()); | 211 base_url_ = GURL(std::string("http://") + address.ToString()); |
| 193 } else { | 212 } else { |
| 194 LOG(ERROR) << "GetLocalAddress failed: " << ErrorToString(result); | 213 LOG(ERROR) << "GetLocalAddress failed: " << ErrorToString(result); |
| 195 } | 214 } |
| 196 } | 215 } |
| 197 | 216 |
| 198 void EmbeddedTestServer::ListenOnIOThread() { | 217 void EmbeddedTestServer::ListenOnIOThread() { |
| 199 DCHECK(io_thread_->message_loop_proxy()->BelongsToCurrentThread()); | 218 DCHECK(io_thread_->message_loop_proxy()->BelongsToCurrentThread()); |
| 200 DCHECK(Started()); | 219 DCHECK(Started()); |
| 201 listen_socket_->Listen(); | 220 listen_socket_->ListenOnIOThread(); |
| 202 } | 221 } |
| 203 | 222 |
| 204 void EmbeddedTestServer::ShutdownOnIOThread() { | 223 void EmbeddedTestServer::ShutdownOnIOThread() { |
| 205 DCHECK(io_thread_->message_loop_proxy()->BelongsToCurrentThread()); | 224 DCHECK(io_thread_->message_loop_proxy()->BelongsToCurrentThread()); |
| 206 | 225 |
| 207 listen_socket_.reset(); | 226 listen_socket_.reset(); |
| 208 STLDeleteContainerPairSecondPointers(connections_.begin(), | 227 STLDeleteContainerPairSecondPointers(connections_.begin(), |
| 209 connections_.end()); | 228 connections_.end()); |
| 210 connections_.clear(); | 229 connections_.clear(); |
| 211 } | 230 } |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 327 FROM_HERE, closure, run_loop.QuitClosure())) { | 346 FROM_HERE, closure, run_loop.QuitClosure())) { |
| 328 return false; | 347 return false; |
| 329 } | 348 } |
| 330 run_loop.Run(); | 349 run_loop.Run(); |
| 331 | 350 |
| 332 return true; | 351 return true; |
| 333 } | 352 } |
| 334 | 353 |
| 335 } // namespace test_server | 354 } // namespace test_server |
| 336 } // namespace net | 355 } // namespace net |
| OLD | NEW |