| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/socket/transport_client_socket_pool_test_util.h" | 5 #include "net/socket/transport_client_socket_pool_test_util.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 } | 180 } |
| 181 | 181 |
| 182 static scoped_ptr<StreamSocket> MakeMockPendingClientSocket( | 182 static scoped_ptr<StreamSocket> MakeMockPendingClientSocket( |
| 183 const AddressList& addrlist, | 183 const AddressList& addrlist, |
| 184 bool should_connect, | 184 bool should_connect, |
| 185 net::NetLog* net_log) { | 185 net::NetLog* net_log) { |
| 186 scoped_ptr<MockTriggerableClientSocket> socket( | 186 scoped_ptr<MockTriggerableClientSocket> socket( |
| 187 new MockTriggerableClientSocket(addrlist, should_connect, net_log)); | 187 new MockTriggerableClientSocket(addrlist, should_connect, net_log)); |
| 188 base::MessageLoop::current()->PostTask(FROM_HERE, | 188 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 189 socket->GetConnectCallback()); | 189 socket->GetConnectCallback()); |
| 190 return socket.PassAs<StreamSocket>(); | 190 return socket.Pass(); |
| 191 } | 191 } |
| 192 | 192 |
| 193 static scoped_ptr<StreamSocket> MakeMockDelayedClientSocket( | 193 static scoped_ptr<StreamSocket> MakeMockDelayedClientSocket( |
| 194 const AddressList& addrlist, | 194 const AddressList& addrlist, |
| 195 bool should_connect, | 195 bool should_connect, |
| 196 const base::TimeDelta& delay, | 196 const base::TimeDelta& delay, |
| 197 net::NetLog* net_log) { | 197 net::NetLog* net_log) { |
| 198 scoped_ptr<MockTriggerableClientSocket> socket( | 198 scoped_ptr<MockTriggerableClientSocket> socket( |
| 199 new MockTriggerableClientSocket(addrlist, should_connect, net_log)); | 199 new MockTriggerableClientSocket(addrlist, should_connect, net_log)); |
| 200 base::MessageLoop::current()->PostDelayedTask( | 200 base::MessageLoop::current()->PostDelayedTask( |
| 201 FROM_HERE, socket->GetConnectCallback(), delay); | 201 FROM_HERE, socket->GetConnectCallback(), delay); |
| 202 return socket.PassAs<StreamSocket>(); | 202 return socket.Pass(); |
| 203 } | 203 } |
| 204 | 204 |
| 205 static scoped_ptr<StreamSocket> MakeMockStalledClientSocket( | 205 static scoped_ptr<StreamSocket> MakeMockStalledClientSocket( |
| 206 const AddressList& addrlist, | 206 const AddressList& addrlist, |
| 207 net::NetLog* net_log) { | 207 net::NetLog* net_log) { |
| 208 scoped_ptr<MockTriggerableClientSocket> socket( | 208 scoped_ptr<MockTriggerableClientSocket> socket( |
| 209 new MockTriggerableClientSocket(addrlist, true, net_log)); | 209 new MockTriggerableClientSocket(addrlist, true, net_log)); |
| 210 return socket.PassAs<StreamSocket>(); | 210 return socket.Pass(); |
| 211 } | 211 } |
| 212 | 212 |
| 213 // StreamSocket implementation. | 213 // StreamSocket implementation. |
| 214 virtual int Connect(const CompletionCallback& callback) override { | 214 virtual int Connect(const CompletionCallback& callback) override { |
| 215 DCHECK(callback_.is_null()); | 215 DCHECK(callback_.is_null()); |
| 216 callback_ = callback; | 216 callback_ = callback; |
| 217 return ERR_IO_PENDING; | 217 return ERR_IO_PENDING; |
| 218 } | 218 } |
| 219 | 219 |
| 220 virtual void Disconnect() override {} | 220 virtual void Disconnect() override {} |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 case MOCK_TRIGGERABLE_CLIENT_SOCKET: { | 381 case MOCK_TRIGGERABLE_CLIENT_SOCKET: { |
| 382 scoped_ptr<MockTriggerableClientSocket> rv( | 382 scoped_ptr<MockTriggerableClientSocket> rv( |
| 383 new MockTriggerableClientSocket(addresses, true, net_log_)); | 383 new MockTriggerableClientSocket(addresses, true, net_log_)); |
| 384 triggerable_sockets_.push(rv->GetConnectCallback()); | 384 triggerable_sockets_.push(rv->GetConnectCallback()); |
| 385 // run_loop_quit_closure_ behaves like a condition variable. It will | 385 // run_loop_quit_closure_ behaves like a condition variable. It will |
| 386 // wake up WaitForTriggerableSocketCreation() if it is sleeping. We | 386 // wake up WaitForTriggerableSocketCreation() if it is sleeping. We |
| 387 // don't need to worry about atomicity because this code is | 387 // don't need to worry about atomicity because this code is |
| 388 // single-threaded. | 388 // single-threaded. |
| 389 if (!run_loop_quit_closure_.is_null()) | 389 if (!run_loop_quit_closure_.is_null()) |
| 390 run_loop_quit_closure_.Run(); | 390 run_loop_quit_closure_.Run(); |
| 391 return rv.PassAs<StreamSocket>(); | 391 return rv.Pass(); |
| 392 } | 392 } |
| 393 default: | 393 default: |
| 394 NOTREACHED(); | 394 NOTREACHED(); |
| 395 return scoped_ptr<StreamSocket>( | 395 return scoped_ptr<StreamSocket>( |
| 396 new MockConnectClientSocket(addresses, net_log_)); | 396 new MockConnectClientSocket(addresses, net_log_)); |
| 397 } | 397 } |
| 398 } | 398 } |
| 399 | 399 |
| 400 scoped_ptr<SSLClientSocket> | 400 scoped_ptr<SSLClientSocket> |
| 401 MockTransportClientSocketFactory::CreateSSLClientSocket( | 401 MockTransportClientSocketFactory::CreateSSLClientSocket( |
| (...skipping 25 matching lines...) Expand all Loading... |
| 427 run_loop_quit_closure_ = run_loop.QuitClosure(); | 427 run_loop_quit_closure_ = run_loop.QuitClosure(); |
| 428 run_loop.Run(); | 428 run_loop.Run(); |
| 429 run_loop_quit_closure_.Reset(); | 429 run_loop_quit_closure_.Reset(); |
| 430 } | 430 } |
| 431 base::Closure trigger = triggerable_sockets_.front(); | 431 base::Closure trigger = triggerable_sockets_.front(); |
| 432 triggerable_sockets_.pop(); | 432 triggerable_sockets_.pop(); |
| 433 return trigger; | 433 return trigger; |
| 434 } | 434 } |
| 435 | 435 |
| 436 } // namespace net | 436 } // namespace net |
| OLD | NEW |