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/socket/socks_client_socket_pool.h" | 5 #include "net/socket/socks_client_socket_pool.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 const HostPortPair& host_port_pair) | 24 const HostPortPair& host_port_pair) |
25 : transport_params_(proxy_server), | 25 : transport_params_(proxy_server), |
26 destination_(host_port_pair), | 26 destination_(host_port_pair), |
27 socks_v5_(socks_v5) { | 27 socks_v5_(socks_v5) { |
28 if (transport_params_.get()) | 28 if (transport_params_.get()) |
29 ignore_limits_ = transport_params_->ignore_limits(); | 29 ignore_limits_ = transport_params_->ignore_limits(); |
30 else | 30 else |
31 ignore_limits_ = false; | 31 ignore_limits_ = false; |
32 } | 32 } |
33 | 33 |
34 SOCKSSocketParams::~SOCKSSocketParams() {} | 34 SOCKSSocketParams::~SOCKSSocketParams() { |
| 35 } |
35 | 36 |
36 // SOCKSConnectJobs will time out after this many seconds. Note this is on | 37 // SOCKSConnectJobs will time out after this many seconds. Note this is on |
37 // top of the timeout for the transport socket. | 38 // top of the timeout for the transport socket. |
38 static const int kSOCKSConnectJobTimeoutInSeconds = 30; | 39 static const int kSOCKSConnectJobTimeoutInSeconds = 30; |
39 | 40 |
40 SOCKSConnectJob::SOCKSConnectJob( | 41 SOCKSConnectJob::SOCKSConnectJob( |
41 const std::string& group_name, | 42 const std::string& group_name, |
42 RequestPriority priority, | 43 RequestPriority priority, |
43 const scoped_refptr<SOCKSSocketParams>& socks_params, | 44 const scoped_refptr<SOCKSSocketParams>& socks_params, |
44 const base::TimeDelta& timeout_duration, | 45 const base::TimeDelta& timeout_duration, |
45 TransportClientSocketPool* transport_pool, | 46 TransportClientSocketPool* transport_pool, |
46 HostResolver* host_resolver, | 47 HostResolver* host_resolver, |
47 Delegate* delegate, | 48 Delegate* delegate, |
48 NetLog* net_log) | 49 NetLog* net_log) |
49 : ConnectJob(group_name, timeout_duration, priority, delegate, | 50 : ConnectJob(group_name, |
| 51 timeout_duration, |
| 52 priority, |
| 53 delegate, |
50 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), | 54 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), |
51 socks_params_(socks_params), | 55 socks_params_(socks_params), |
52 transport_pool_(transport_pool), | 56 transport_pool_(transport_pool), |
53 resolver_(host_resolver), | 57 resolver_(host_resolver), |
54 callback_(base::Bind(&SOCKSConnectJob::OnIOComplete, | 58 callback_( |
55 base::Unretained(this))) { | 59 base::Bind(&SOCKSConnectJob::OnIOComplete, base::Unretained(this))) { |
56 } | 60 } |
57 | 61 |
58 SOCKSConnectJob::~SOCKSConnectJob() { | 62 SOCKSConnectJob::~SOCKSConnectJob() { |
59 // We don't worry about cancelling the tcp socket since the destructor in | 63 // We don't worry about cancelling the tcp socket since the destructor in |
60 // scoped_ptr<ClientSocketHandle> transport_socket_handle_ will take care of | 64 // scoped_ptr<ClientSocketHandle> transport_socket_handle_ will take care of |
61 // it. | 65 // it. |
62 } | 66 } |
63 | 67 |
64 LoadState SOCKSConnectJob::GetLoadState() const { | 68 LoadState SOCKSConnectJob::GetLoadState() const { |
65 switch (next_state_) { | 69 switch (next_state_) { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 ConnectionTimeout(), | 183 ConnectionTimeout(), |
180 transport_pool_, | 184 transport_pool_, |
181 host_resolver_, | 185 host_resolver_, |
182 delegate, | 186 delegate, |
183 net_log_)); | 187 net_log_)); |
184 } | 188 } |
185 | 189 |
186 base::TimeDelta | 190 base::TimeDelta |
187 SOCKSClientSocketPool::SOCKSConnectJobFactory::ConnectionTimeout() const { | 191 SOCKSClientSocketPool::SOCKSConnectJobFactory::ConnectionTimeout() const { |
188 return transport_pool_->ConnectionTimeout() + | 192 return transport_pool_->ConnectionTimeout() + |
189 base::TimeDelta::FromSeconds(kSOCKSConnectJobTimeoutInSeconds); | 193 base::TimeDelta::FromSeconds(kSOCKSConnectJobTimeoutInSeconds); |
190 } | 194 } |
191 | 195 |
192 SOCKSClientSocketPool::SOCKSClientSocketPool( | 196 SOCKSClientSocketPool::SOCKSClientSocketPool( |
193 int max_sockets, | 197 int max_sockets, |
194 int max_sockets_per_group, | 198 int max_sockets_per_group, |
195 ClientSocketPoolHistograms* histograms, | 199 ClientSocketPoolHistograms* histograms, |
196 HostResolver* host_resolver, | 200 HostResolver* host_resolver, |
197 TransportClientSocketPool* transport_pool, | 201 TransportClientSocketPool* transport_pool, |
198 NetLog* net_log) | 202 NetLog* net_log) |
199 : transport_pool_(transport_pool), | 203 : transport_pool_(transport_pool), |
200 base_(this, max_sockets, max_sockets_per_group, histograms, | 204 base_( |
201 ClientSocketPool::unused_idle_socket_timeout(), | 205 this, |
202 ClientSocketPool::used_idle_socket_timeout(), | 206 max_sockets, |
203 new SOCKSConnectJobFactory(transport_pool, | 207 max_sockets_per_group, |
204 host_resolver, | 208 histograms, |
205 net_log)) { | 209 ClientSocketPool::unused_idle_socket_timeout(), |
| 210 ClientSocketPool::used_idle_socket_timeout(), |
| 211 new SOCKSConnectJobFactory(transport_pool, host_resolver, net_log)) { |
206 // We should always have a |transport_pool_| except in unit tests. | 212 // We should always have a |transport_pool_| except in unit tests. |
207 if (transport_pool_) | 213 if (transport_pool_) |
208 base_.AddLowerLayeredPool(transport_pool_); | 214 base_.AddLowerLayeredPool(transport_pool_); |
209 } | 215 } |
210 | 216 |
211 SOCKSClientSocketPool::~SOCKSClientSocketPool() { | 217 SOCKSClientSocketPool::~SOCKSClientSocketPool() { |
212 } | 218 } |
213 | 219 |
214 int SOCKSClientSocketPool::RequestSocket( | 220 int SOCKSClientSocketPool::RequestSocket(const std::string& group_name, |
215 const std::string& group_name, const void* socket_params, | 221 const void* socket_params, |
216 RequestPriority priority, ClientSocketHandle* handle, | 222 RequestPriority priority, |
217 const CompletionCallback& callback, const BoundNetLog& net_log) { | 223 ClientSocketHandle* handle, |
| 224 const CompletionCallback& callback, |
| 225 const BoundNetLog& net_log) { |
218 const scoped_refptr<SOCKSSocketParams>* casted_socket_params = | 226 const scoped_refptr<SOCKSSocketParams>* casted_socket_params = |
219 static_cast<const scoped_refptr<SOCKSSocketParams>*>(socket_params); | 227 static_cast<const scoped_refptr<SOCKSSocketParams>*>(socket_params); |
220 | 228 |
221 return base_.RequestSocket(group_name, *casted_socket_params, priority, | 229 return base_.RequestSocket( |
222 handle, callback, net_log); | 230 group_name, *casted_socket_params, priority, handle, callback, net_log); |
223 } | 231 } |
224 | 232 |
225 void SOCKSClientSocketPool::RequestSockets( | 233 void SOCKSClientSocketPool::RequestSockets(const std::string& group_name, |
226 const std::string& group_name, | 234 const void* params, |
227 const void* params, | 235 int num_sockets, |
228 int num_sockets, | 236 const BoundNetLog& net_log) { |
229 const BoundNetLog& net_log) { | |
230 const scoped_refptr<SOCKSSocketParams>* casted_params = | 237 const scoped_refptr<SOCKSSocketParams>* casted_params = |
231 static_cast<const scoped_refptr<SOCKSSocketParams>*>(params); | 238 static_cast<const scoped_refptr<SOCKSSocketParams>*>(params); |
232 | 239 |
233 base_.RequestSockets(group_name, *casted_params, num_sockets, net_log); | 240 base_.RequestSockets(group_name, *casted_params, num_sockets, net_log); |
234 } | 241 } |
235 | 242 |
236 void SOCKSClientSocketPool::CancelRequest(const std::string& group_name, | 243 void SOCKSClientSocketPool::CancelRequest(const std::string& group_name, |
237 ClientSocketHandle* handle) { | 244 ClientSocketHandle* handle) { |
238 base_.CancelRequest(group_name, handle); | 245 base_.CancelRequest(group_name, handle); |
239 } | 246 } |
(...skipping 15 matching lines...) Expand all Loading... |
255 int SOCKSClientSocketPool::IdleSocketCount() const { | 262 int SOCKSClientSocketPool::IdleSocketCount() const { |
256 return base_.idle_socket_count(); | 263 return base_.idle_socket_count(); |
257 } | 264 } |
258 | 265 |
259 int SOCKSClientSocketPool::IdleSocketCountInGroup( | 266 int SOCKSClientSocketPool::IdleSocketCountInGroup( |
260 const std::string& group_name) const { | 267 const std::string& group_name) const { |
261 return base_.IdleSocketCountInGroup(group_name); | 268 return base_.IdleSocketCountInGroup(group_name); |
262 } | 269 } |
263 | 270 |
264 LoadState SOCKSClientSocketPool::GetLoadState( | 271 LoadState SOCKSClientSocketPool::GetLoadState( |
265 const std::string& group_name, const ClientSocketHandle* handle) const { | 272 const std::string& group_name, |
| 273 const ClientSocketHandle* handle) const { |
266 return base_.GetLoadState(group_name, handle); | 274 return base_.GetLoadState(group_name, handle); |
267 } | 275 } |
268 | 276 |
269 base::DictionaryValue* SOCKSClientSocketPool::GetInfoAsValue( | 277 base::DictionaryValue* SOCKSClientSocketPool::GetInfoAsValue( |
270 const std::string& name, | 278 const std::string& name, |
271 const std::string& type, | 279 const std::string& type, |
272 bool include_nested_pools) const { | 280 bool include_nested_pools) const { |
273 base::DictionaryValue* dict = base_.GetInfoAsValue(name, type); | 281 base::DictionaryValue* dict = base_.GetInfoAsValue(name, type); |
274 if (include_nested_pools) { | 282 if (include_nested_pools) { |
275 base::ListValue* list = new base::ListValue(); | 283 base::ListValue* list = new base::ListValue(); |
276 list->Append(transport_pool_->GetInfoAsValue("transport_socket_pool", | 284 list->Append(transport_pool_->GetInfoAsValue( |
277 "transport_socket_pool", | 285 "transport_socket_pool", "transport_socket_pool", false)); |
278 false)); | |
279 dict->Set("nested_pools", list); | 286 dict->Set("nested_pools", list); |
280 } | 287 } |
281 return dict; | 288 return dict; |
282 } | 289 } |
283 | 290 |
284 base::TimeDelta SOCKSClientSocketPool::ConnectionTimeout() const { | 291 base::TimeDelta SOCKSClientSocketPool::ConnectionTimeout() const { |
285 return base_.ConnectionTimeout(); | 292 return base_.ConnectionTimeout(); |
286 } | 293 } |
287 | 294 |
288 ClientSocketPoolHistograms* SOCKSClientSocketPool::histograms() const { | 295 ClientSocketPoolHistograms* SOCKSClientSocketPool::histograms() const { |
(...skipping 14 matching lines...) Expand all Loading... |
303 base_.RemoveHigherLayeredPool(higher_pool); | 310 base_.RemoveHigherLayeredPool(higher_pool); |
304 } | 311 } |
305 | 312 |
306 bool SOCKSClientSocketPool::CloseOneIdleConnection() { | 313 bool SOCKSClientSocketPool::CloseOneIdleConnection() { |
307 if (base_.CloseOneIdleSocket()) | 314 if (base_.CloseOneIdleSocket()) |
308 return true; | 315 return true; |
309 return base_.CloseOneIdleConnectionInHigherLayeredPool(); | 316 return base_.CloseOneIdleConnectionInHigherLayeredPool(); |
310 } | 317 } |
311 | 318 |
312 } // namespace net | 319 } // namespace net |
OLD | NEW |