| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/socks_client_socket_pool.h" | 5 #include "net/socket/socks_client_socket_pool.h" |
| 6 | 6 |
| 7 #include "base/time.h" | 7 #include "base/time.h" |
| 8 #include "googleurl/src/gurl.h" | 8 #include "googleurl/src/gurl.h" |
| 9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
| 10 #include "net/socket/client_socket_factory.h" | 10 #include "net/socket/client_socket_factory.h" |
| 11 #include "net/socket/client_socket_handle.h" | 11 #include "net/socket/client_socket_handle.h" |
| 12 #include "net/socket/client_socket_pool_base.h" | 12 #include "net/socket/client_socket_pool_base.h" |
| 13 #include "net/socket/socks5_client_socket.h" | 13 #include "net/socket/socks5_client_socket.h" |
| 14 #include "net/socket/socks_client_socket.h" | 14 #include "net/socket/socks_client_socket.h" |
| 15 | 15 |
| 16 namespace net { | 16 namespace net { |
| 17 | 17 |
| 18 // SOCKSConnectJobs will time out after this many seconds. Note this is on | 18 // SOCKSConnectJobs will time out after this many seconds. Note this is on |
| 19 // top of the timeout for the transport socket. | 19 // top of the timeout for the transport socket. |
| 20 static const int kSOCKSConnectJobTimeoutInSeconds = 30; | 20 static const int kSOCKSConnectJobTimeoutInSeconds = 30; |
| 21 | 21 |
| 22 SOCKSConnectJob::SOCKSConnectJob( | 22 SOCKSConnectJob::SOCKSConnectJob( |
| 23 const std::string& group_name, | 23 const std::string& group_name, |
| 24 const SOCKSSocketParams& socks_params, | 24 const SOCKSSocketParams& socks_params, |
| 25 const base::TimeDelta& timeout_duration, | 25 const base::TimeDelta& timeout_duration, |
| 26 const scoped_refptr<TCPClientSocketPool>& tcp_pool, | 26 const scoped_refptr<TCPClientSocketPool>& tcp_pool, |
| 27 const scoped_refptr<HostResolver>& host_resolver, | 27 const scoped_refptr<HostResolver>& host_resolver, |
| 28 Delegate* delegate, | 28 Delegate* delegate, |
| 29 const BoundNetLog& net_log) | 29 NetLog* net_log) |
| 30 : ConnectJob(group_name, timeout_duration, delegate, net_log), | 30 : ConnectJob(group_name, timeout_duration, delegate, |
| 31 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), |
| 31 socks_params_(socks_params), | 32 socks_params_(socks_params), |
| 32 tcp_pool_(tcp_pool), | 33 tcp_pool_(tcp_pool), |
| 33 resolver_(host_resolver), | 34 resolver_(host_resolver), |
| 34 ALLOW_THIS_IN_INITIALIZER_LIST( | 35 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 35 callback_(this, &SOCKSConnectJob::OnIOComplete)) {} | 36 callback_(this, &SOCKSConnectJob::OnIOComplete)) { |
| 37 } |
| 36 | 38 |
| 37 SOCKSConnectJob::~SOCKSConnectJob() { | 39 SOCKSConnectJob::~SOCKSConnectJob() { |
| 38 // We don't worry about cancelling the tcp socket since the destructor in | 40 // We don't worry about cancelling the tcp socket since the destructor in |
| 39 // scoped_ptr<ClientSocketHandle> tcp_socket_handle_ will take care of it. | 41 // scoped_ptr<ClientSocketHandle> tcp_socket_handle_ will take care of it. |
| 40 } | 42 } |
| 41 | 43 |
| 42 LoadState SOCKSConnectJob::GetLoadState() const { | 44 LoadState SOCKSConnectJob::GetLoadState() const { |
| 43 switch (next_state_) { | 45 switch (next_state_) { |
| 44 case kStateTCPConnect: | 46 case kStateTCPConnect: |
| 45 case kStateTCPConnectComplete: | 47 case kStateTCPConnectComplete: |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 return result; | 139 return result; |
| 138 } | 140 } |
| 139 | 141 |
| 140 set_socket(socket_.release()); | 142 set_socket(socket_.release()); |
| 141 return result; | 143 return result; |
| 142 } | 144 } |
| 143 | 145 |
| 144 ConnectJob* SOCKSClientSocketPool::SOCKSConnectJobFactory::NewConnectJob( | 146 ConnectJob* SOCKSClientSocketPool::SOCKSConnectJobFactory::NewConnectJob( |
| 145 const std::string& group_name, | 147 const std::string& group_name, |
| 146 const PoolBase::Request& request, | 148 const PoolBase::Request& request, |
| 147 ConnectJob::Delegate* delegate, | 149 ConnectJob::Delegate* delegate) const { |
| 148 const BoundNetLog& net_log) const { | |
| 149 return new SOCKSConnectJob(group_name, request.params(), ConnectionTimeout(), | 150 return new SOCKSConnectJob(group_name, request.params(), ConnectionTimeout(), |
| 150 tcp_pool_, host_resolver_, delegate, net_log); | 151 tcp_pool_, host_resolver_, delegate, net_log_); |
| 151 } | 152 } |
| 152 | 153 |
| 153 base::TimeDelta | 154 base::TimeDelta |
| 154 SOCKSClientSocketPool::SOCKSConnectJobFactory::ConnectionTimeout() const { | 155 SOCKSClientSocketPool::SOCKSConnectJobFactory::ConnectionTimeout() const { |
| 155 return tcp_pool_->ConnectionTimeout() + | 156 return tcp_pool_->ConnectionTimeout() + |
| 156 base::TimeDelta::FromSeconds(kSOCKSConnectJobTimeoutInSeconds); | 157 base::TimeDelta::FromSeconds(kSOCKSConnectJobTimeoutInSeconds); |
| 157 } | 158 } |
| 158 | 159 |
| 159 SOCKSClientSocketPool::SOCKSClientSocketPool( | 160 SOCKSClientSocketPool::SOCKSClientSocketPool( |
| 160 int max_sockets, | 161 int max_sockets, |
| 161 int max_sockets_per_group, | 162 int max_sockets_per_group, |
| 162 const scoped_refptr<ClientSocketPoolHistograms>& histograms, | 163 const scoped_refptr<ClientSocketPoolHistograms>& histograms, |
| 163 const scoped_refptr<HostResolver>& host_resolver, | 164 const scoped_refptr<HostResolver>& host_resolver, |
| 164 const scoped_refptr<TCPClientSocketPool>& tcp_pool, | 165 const scoped_refptr<TCPClientSocketPool>& tcp_pool, |
| 165 NetworkChangeNotifier* network_change_notifier) | 166 NetworkChangeNotifier* network_change_notifier, |
| 167 NetLog* net_log) |
| 166 : base_(max_sockets, max_sockets_per_group, histograms, | 168 : base_(max_sockets, max_sockets_per_group, histograms, |
| 167 base::TimeDelta::FromSeconds(kUnusedIdleSocketTimeout), | 169 base::TimeDelta::FromSeconds(kUnusedIdleSocketTimeout), |
| 168 base::TimeDelta::FromSeconds(kUsedIdleSocketTimeout), | 170 base::TimeDelta::FromSeconds(kUsedIdleSocketTimeout), |
| 169 new SOCKSConnectJobFactory(tcp_pool, host_resolver), | 171 new SOCKSConnectJobFactory(tcp_pool, host_resolver, net_log), |
| 170 network_change_notifier) {} | 172 network_change_notifier) {} |
| 171 | 173 |
| 172 SOCKSClientSocketPool::~SOCKSClientSocketPool() {} | 174 SOCKSClientSocketPool::~SOCKSClientSocketPool() {} |
| 173 | 175 |
| 174 int SOCKSClientSocketPool::RequestSocket( | 176 int SOCKSClientSocketPool::RequestSocket( |
| 175 const std::string& group_name, | 177 const std::string& group_name, |
| 176 const void* socket_params, | 178 const void* socket_params, |
| 177 RequestPriority priority, | 179 RequestPriority priority, |
| 178 ClientSocketHandle* handle, | 180 ClientSocketHandle* handle, |
| 179 CompletionCallback* callback, | 181 CompletionCallback* callback, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 205 const std::string& group_name) const { | 207 const std::string& group_name) const { |
| 206 return base_.IdleSocketCountInGroup(group_name); | 208 return base_.IdleSocketCountInGroup(group_name); |
| 207 } | 209 } |
| 208 | 210 |
| 209 LoadState SOCKSClientSocketPool::GetLoadState( | 211 LoadState SOCKSClientSocketPool::GetLoadState( |
| 210 const std::string& group_name, const ClientSocketHandle* handle) const { | 212 const std::string& group_name, const ClientSocketHandle* handle) const { |
| 211 return base_.GetLoadState(group_name, handle); | 213 return base_.GetLoadState(group_name, handle); |
| 212 } | 214 } |
| 213 | 215 |
| 214 } // namespace net | 216 } // namespace net |
| OLD | NEW |