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/websocket_transport_client_socket_pool.h" | 5 #include "net/socket/websocket_transport_client_socket_pool.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 RequestPriority priority, | 33 RequestPriority priority, |
34 ClientSocketPool::RespectLimits respect_limits, | 34 ClientSocketPool::RespectLimits respect_limits, |
35 const scoped_refptr<TransportSocketParams>& params, | 35 const scoped_refptr<TransportSocketParams>& params, |
36 base::TimeDelta timeout_duration, | 36 base::TimeDelta timeout_duration, |
37 const CompletionCallback& callback, | 37 const CompletionCallback& callback, |
38 ClientSocketFactory* client_socket_factory, | 38 ClientSocketFactory* client_socket_factory, |
39 HostResolver* host_resolver, | 39 HostResolver* host_resolver, |
40 ClientSocketHandle* handle, | 40 ClientSocketHandle* handle, |
41 Delegate* delegate, | 41 Delegate* delegate, |
42 NetLog* pool_net_log, | 42 NetLog* pool_net_log, |
43 const BoundNetLog& request_net_log) | 43 const NetLogWithSource& request_net_log) |
44 : ConnectJob( | 44 : ConnectJob( |
45 group_name, | 45 group_name, |
46 timeout_duration, | 46 timeout_duration, |
47 priority, | 47 priority, |
48 respect_limits, | 48 respect_limits, |
49 delegate, | 49 delegate, |
50 BoundNetLog::Make(pool_net_log, NetLogSourceType::CONNECT_JOB)), | 50 NetLogWithSource::Make(pool_net_log, NetLogSourceType::CONNECT_JOB)), |
51 params_(params), | 51 params_(params), |
52 resolver_(host_resolver), | 52 resolver_(host_resolver), |
53 client_socket_factory_(client_socket_factory), | 53 client_socket_factory_(client_socket_factory), |
54 next_state_(STATE_NONE), | 54 next_state_(STATE_NONE), |
55 race_result_(TransportConnectJob::RACE_UNKNOWN), | 55 race_result_(TransportConnectJob::RACE_UNKNOWN), |
56 handle_(handle), | 56 handle_(handle), |
57 callback_(callback), | 57 callback_(callback), |
58 request_net_log_(request_net_log), | 58 request_net_log_(request_net_log), |
59 had_ipv4_(false), | 59 had_ipv4_(false), |
60 had_ipv6_(false) {} | 60 had_ipv6_(false) {} |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 WebSocketEndpointLockManager::GetInstance()->UnlockEndpoint(address); | 317 WebSocketEndpointLockManager::GetInstance()->UnlockEndpoint(address); |
318 } | 318 } |
319 | 319 |
320 int WebSocketTransportClientSocketPool::RequestSocket( | 320 int WebSocketTransportClientSocketPool::RequestSocket( |
321 const std::string& group_name, | 321 const std::string& group_name, |
322 const void* params, | 322 const void* params, |
323 RequestPriority priority, | 323 RequestPriority priority, |
324 RespectLimits respect_limits, | 324 RespectLimits respect_limits, |
325 ClientSocketHandle* handle, | 325 ClientSocketHandle* handle, |
326 const CompletionCallback& callback, | 326 const CompletionCallback& callback, |
327 const BoundNetLog& request_net_log) { | 327 const NetLogWithSource& request_net_log) { |
328 DCHECK(params); | 328 DCHECK(params); |
329 const scoped_refptr<TransportSocketParams>& casted_params = | 329 const scoped_refptr<TransportSocketParams>& casted_params = |
330 *static_cast<const scoped_refptr<TransportSocketParams>*>(params); | 330 *static_cast<const scoped_refptr<TransportSocketParams>*>(params); |
331 | 331 |
332 NetLogTcpClientSocketPoolRequestedSocket(request_net_log, &casted_params); | 332 NetLogTcpClientSocketPoolRequestedSocket(request_net_log, &casted_params); |
333 | 333 |
334 CHECK(!callback.is_null()); | 334 CHECK(!callback.is_null()); |
335 CHECK(handle); | 335 CHECK(handle); |
336 | 336 |
337 request_net_log.BeginEvent(NetLogEventType::SOCKET_POOL); | 337 request_net_log.BeginEvent(NetLogEventType::SOCKET_POOL); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 TryHandOutSocket(result, connect_job.get()); | 378 TryHandOutSocket(result, connect_job.get()); |
379 } | 379 } |
380 | 380 |
381 return result; | 381 return result; |
382 } | 382 } |
383 | 383 |
384 void WebSocketTransportClientSocketPool::RequestSockets( | 384 void WebSocketTransportClientSocketPool::RequestSockets( |
385 const std::string& group_name, | 385 const std::string& group_name, |
386 const void* params, | 386 const void* params, |
387 int num_sockets, | 387 int num_sockets, |
388 const BoundNetLog& net_log) { | 388 const NetLogWithSource& net_log) { |
389 NOTIMPLEMENTED(); | 389 NOTIMPLEMENTED(); |
390 } | 390 } |
391 | 391 |
392 void WebSocketTransportClientSocketPool::CancelRequest( | 392 void WebSocketTransportClientSocketPool::CancelRequest( |
393 const std::string& group_name, | 393 const std::string& group_name, |
394 ClientSocketHandle* handle) { | 394 ClientSocketHandle* handle) { |
395 DCHECK(!handle->is_initialized()); | 395 DCHECK(!handle->is_initialized()); |
396 if (DeleteStalledRequest(handle)) | 396 if (DeleteStalledRequest(handle)) |
397 return; | 397 return; |
398 std::unique_ptr<StreamSocket> socket = handle->PassSocket(); | 398 std::unique_ptr<StreamSocket> socket = handle->PassSocket(); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 return !stalled_request_queue_.empty(); | 494 return !stalled_request_queue_.empty(); |
495 } | 495 } |
496 | 496 |
497 bool WebSocketTransportClientSocketPool::TryHandOutSocket( | 497 bool WebSocketTransportClientSocketPool::TryHandOutSocket( |
498 int result, | 498 int result, |
499 WebSocketTransportConnectJob* job) { | 499 WebSocketTransportConnectJob* job) { |
500 DCHECK_NE(result, ERR_IO_PENDING); | 500 DCHECK_NE(result, ERR_IO_PENDING); |
501 | 501 |
502 std::unique_ptr<StreamSocket> socket = job->PassSocket(); | 502 std::unique_ptr<StreamSocket> socket = job->PassSocket(); |
503 ClientSocketHandle* const handle = job->handle(); | 503 ClientSocketHandle* const handle = job->handle(); |
504 BoundNetLog request_net_log = job->request_net_log(); | 504 NetLogWithSource request_net_log = job->request_net_log(); |
505 LoadTimingInfo::ConnectTiming connect_timing = job->connect_timing(); | 505 LoadTimingInfo::ConnectTiming connect_timing = job->connect_timing(); |
506 | 506 |
507 if (result == OK) { | 507 if (result == OK) { |
508 DCHECK(socket); | 508 DCHECK(socket); |
509 | 509 |
510 HandOutSocket(std::move(socket), connect_timing, handle, request_net_log); | 510 HandOutSocket(std::move(socket), connect_timing, handle, request_net_log); |
511 | 511 |
512 request_net_log.EndEvent(NetLogEventType::SOCKET_POOL); | 512 request_net_log.EndEvent(NetLogEventType::SOCKET_POOL); |
513 | 513 |
514 return true; | 514 return true; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 bool WebSocketTransportClientSocketPool::ReachedMaxSocketsLimit() const { | 582 bool WebSocketTransportClientSocketPool::ReachedMaxSocketsLimit() const { |
583 return handed_out_socket_count_ >= max_sockets_ || | 583 return handed_out_socket_count_ >= max_sockets_ || |
584 base::checked_cast<int>(pending_connects_.size()) >= | 584 base::checked_cast<int>(pending_connects_.size()) >= |
585 max_sockets_ - handed_out_socket_count_; | 585 max_sockets_ - handed_out_socket_count_; |
586 } | 586 } |
587 | 587 |
588 void WebSocketTransportClientSocketPool::HandOutSocket( | 588 void WebSocketTransportClientSocketPool::HandOutSocket( |
589 std::unique_ptr<StreamSocket> socket, | 589 std::unique_ptr<StreamSocket> socket, |
590 const LoadTimingInfo::ConnectTiming& connect_timing, | 590 const LoadTimingInfo::ConnectTiming& connect_timing, |
591 ClientSocketHandle* handle, | 591 ClientSocketHandle* handle, |
592 const BoundNetLog& net_log) { | 592 const NetLogWithSource& net_log) { |
593 DCHECK(socket); | 593 DCHECK(socket); |
594 DCHECK_EQ(ClientSocketHandle::UNUSED, handle->reuse_type()); | 594 DCHECK_EQ(ClientSocketHandle::UNUSED, handle->reuse_type()); |
595 DCHECK_EQ(0, handle->idle_time().InMicroseconds()); | 595 DCHECK_EQ(0, handle->idle_time().InMicroseconds()); |
596 | 596 |
597 handle->SetSocket(std::move(socket)); | 597 handle->SetSocket(std::move(socket)); |
598 handle->set_pool_id(0); | 598 handle->set_pool_id(0); |
599 handle->set_connect_timing(connect_timing); | 599 handle->set_connect_timing(connect_timing); |
600 | 600 |
601 net_log.AddEvent( | 601 net_log.AddEvent( |
602 NetLogEventType::SOCKET_POOL_BOUND_TO_SOCKET, | 602 NetLogEventType::SOCKET_POOL_BOUND_TO_SOCKET, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 ConnectJob* job) { | 681 ConnectJob* job) { |
682 owner_->OnConnectJobComplete(result, | 682 owner_->OnConnectJobComplete(result, |
683 static_cast<WebSocketTransportConnectJob*>(job)); | 683 static_cast<WebSocketTransportConnectJob*>(job)); |
684 } | 684 } |
685 | 685 |
686 WebSocketTransportClientSocketPool::StalledRequest::StalledRequest( | 686 WebSocketTransportClientSocketPool::StalledRequest::StalledRequest( |
687 const scoped_refptr<TransportSocketParams>& params, | 687 const scoped_refptr<TransportSocketParams>& params, |
688 RequestPriority priority, | 688 RequestPriority priority, |
689 ClientSocketHandle* handle, | 689 ClientSocketHandle* handle, |
690 const CompletionCallback& callback, | 690 const CompletionCallback& callback, |
691 const BoundNetLog& net_log) | 691 const NetLogWithSource& net_log) |
692 : params(params), | 692 : params(params), |
693 priority(priority), | 693 priority(priority), |
694 handle(handle), | 694 handle(handle), |
695 callback(callback), | 695 callback(callback), |
696 net_log(net_log) {} | 696 net_log(net_log) {} |
697 | 697 |
698 WebSocketTransportClientSocketPool::StalledRequest::StalledRequest( | 698 WebSocketTransportClientSocketPool::StalledRequest::StalledRequest( |
699 const StalledRequest& other) = default; | 699 const StalledRequest& other) = default; |
700 | 700 |
701 WebSocketTransportClientSocketPool::StalledRequest::~StalledRequest() {} | 701 WebSocketTransportClientSocketPool::StalledRequest::~StalledRequest() {} |
702 | 702 |
703 } // namespace net | 703 } // namespace net |
OLD | NEW |