| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | |
| 9 #include <string> | 8 #include <string> |
| 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
| 18 #include "net/base/ip_endpoint.h" | 18 #include "net/base/ip_endpoint.h" |
| 19 #include "net/base/load_timing_info.h" | 19 #include "net/base/load_timing_info.h" |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 } | 198 } |
| 199 | 199 |
| 200 static scoped_ptr<StreamSocket> MakeMockPendingClientSocket( | 200 static scoped_ptr<StreamSocket> MakeMockPendingClientSocket( |
| 201 const AddressList& addrlist, | 201 const AddressList& addrlist, |
| 202 bool should_connect, | 202 bool should_connect, |
| 203 net::NetLog* net_log) { | 203 net::NetLog* net_log) { |
| 204 scoped_ptr<MockTriggerableClientSocket> socket( | 204 scoped_ptr<MockTriggerableClientSocket> socket( |
| 205 new MockTriggerableClientSocket(addrlist, should_connect, net_log)); | 205 new MockTriggerableClientSocket(addrlist, should_connect, net_log)); |
| 206 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 206 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 207 socket->GetConnectCallback()); | 207 socket->GetConnectCallback()); |
| 208 return socket.Pass(); | 208 return std::move(socket); |
| 209 } | 209 } |
| 210 | 210 |
| 211 static scoped_ptr<StreamSocket> MakeMockDelayedClientSocket( | 211 static scoped_ptr<StreamSocket> MakeMockDelayedClientSocket( |
| 212 const AddressList& addrlist, | 212 const AddressList& addrlist, |
| 213 bool should_connect, | 213 bool should_connect, |
| 214 const base::TimeDelta& delay, | 214 const base::TimeDelta& delay, |
| 215 net::NetLog* net_log) { | 215 net::NetLog* net_log) { |
| 216 scoped_ptr<MockTriggerableClientSocket> socket( | 216 scoped_ptr<MockTriggerableClientSocket> socket( |
| 217 new MockTriggerableClientSocket(addrlist, should_connect, net_log)); | 217 new MockTriggerableClientSocket(addrlist, should_connect, net_log)); |
| 218 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 218 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 219 FROM_HERE, socket->GetConnectCallback(), delay); | 219 FROM_HERE, socket->GetConnectCallback(), delay); |
| 220 return socket.Pass(); | 220 return std::move(socket); |
| 221 } | 221 } |
| 222 | 222 |
| 223 static scoped_ptr<StreamSocket> MakeMockStalledClientSocket( | 223 static scoped_ptr<StreamSocket> MakeMockStalledClientSocket( |
| 224 const AddressList& addrlist, | 224 const AddressList& addrlist, |
| 225 net::NetLog* net_log, | 225 net::NetLog* net_log, |
| 226 bool failing) { | 226 bool failing) { |
| 227 scoped_ptr<MockTriggerableClientSocket> socket( | 227 scoped_ptr<MockTriggerableClientSocket> socket( |
| 228 new MockTriggerableClientSocket(addrlist, true, net_log)); | 228 new MockTriggerableClientSocket(addrlist, true, net_log)); |
| 229 if (failing) { | 229 if (failing) { |
| 230 DCHECK_LE(1u, addrlist.size()); | 230 DCHECK_LE(1u, addrlist.size()); |
| 231 ConnectionAttempts attempts; | 231 ConnectionAttempts attempts; |
| 232 attempts.push_back(ConnectionAttempt(addrlist[0], ERR_CONNECTION_FAILED)); | 232 attempts.push_back(ConnectionAttempt(addrlist[0], ERR_CONNECTION_FAILED)); |
| 233 socket->AddConnectionAttempts(attempts); | 233 socket->AddConnectionAttempts(attempts); |
| 234 } | 234 } |
| 235 return socket.Pass(); | 235 return std::move(socket); |
| 236 } | 236 } |
| 237 | 237 |
| 238 // StreamSocket implementation. | 238 // StreamSocket implementation. |
| 239 int Connect(const CompletionCallback& callback) override { | 239 int Connect(const CompletionCallback& callback) override { |
| 240 DCHECK(callback_.is_null()); | 240 DCHECK(callback_.is_null()); |
| 241 callback_ = callback; | 241 callback_ = callback; |
| 242 return ERR_IO_PENDING; | 242 return ERR_IO_PENDING; |
| 243 } | 243 } |
| 244 | 244 |
| 245 void Disconnect() override {} | 245 void Disconnect() override {} |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 case MOCK_TRIGGERABLE_CLIENT_SOCKET: { | 418 case MOCK_TRIGGERABLE_CLIENT_SOCKET: { |
| 419 scoped_ptr<MockTriggerableClientSocket> rv( | 419 scoped_ptr<MockTriggerableClientSocket> rv( |
| 420 new MockTriggerableClientSocket(addresses, true, net_log_)); | 420 new MockTriggerableClientSocket(addresses, true, net_log_)); |
| 421 triggerable_sockets_.push(rv->GetConnectCallback()); | 421 triggerable_sockets_.push(rv->GetConnectCallback()); |
| 422 // run_loop_quit_closure_ behaves like a condition variable. It will | 422 // run_loop_quit_closure_ behaves like a condition variable. It will |
| 423 // wake up WaitForTriggerableSocketCreation() if it is sleeping. We | 423 // wake up WaitForTriggerableSocketCreation() if it is sleeping. We |
| 424 // don't need to worry about atomicity because this code is | 424 // don't need to worry about atomicity because this code is |
| 425 // single-threaded. | 425 // single-threaded. |
| 426 if (!run_loop_quit_closure_.is_null()) | 426 if (!run_loop_quit_closure_.is_null()) |
| 427 run_loop_quit_closure_.Run(); | 427 run_loop_quit_closure_.Run(); |
| 428 return rv.Pass(); | 428 return std::move(rv); |
| 429 } | 429 } |
| 430 default: | 430 default: |
| 431 NOTREACHED(); | 431 NOTREACHED(); |
| 432 return scoped_ptr<StreamSocket>( | 432 return scoped_ptr<StreamSocket>( |
| 433 new MockConnectClientSocket(addresses, net_log_)); | 433 new MockConnectClientSocket(addresses, net_log_)); |
| 434 } | 434 } |
| 435 } | 435 } |
| 436 | 436 |
| 437 scoped_ptr<SSLClientSocket> | 437 scoped_ptr<SSLClientSocket> |
| 438 MockTransportClientSocketFactory::CreateSSLClientSocket( | 438 MockTransportClientSocketFactory::CreateSSLClientSocket( |
| (...skipping 25 matching lines...) Expand all Loading... |
| 464 run_loop_quit_closure_ = run_loop.QuitClosure(); | 464 run_loop_quit_closure_ = run_loop.QuitClosure(); |
| 465 run_loop.Run(); | 465 run_loop.Run(); |
| 466 run_loop_quit_closure_.Reset(); | 466 run_loop_quit_closure_.Reset(); |
| 467 } | 467 } |
| 468 base::Closure trigger = triggerable_sockets_.front(); | 468 base::Closure trigger = triggerable_sockets_.front(); |
| 469 triggerable_sockets_.pop(); | 469 triggerable_sockets_.pop(); |
| 470 return trigger; | 470 return trigger; |
| 471 } | 471 } |
| 472 | 472 |
| 473 } // namespace net | 473 } // namespace net |
| OLD | NEW |