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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 } | 190 } |
191 | 191 |
192 SOCKSClientSocketPool::SOCKSClientSocketPool( | 192 SOCKSClientSocketPool::SOCKSClientSocketPool( |
193 int max_sockets, | 193 int max_sockets, |
194 int max_sockets_per_group, | 194 int max_sockets_per_group, |
195 ClientSocketPoolHistograms* histograms, | 195 ClientSocketPoolHistograms* histograms, |
196 HostResolver* host_resolver, | 196 HostResolver* host_resolver, |
197 TransportClientSocketPool* transport_pool, | 197 TransportClientSocketPool* transport_pool, |
198 NetLog* net_log) | 198 NetLog* net_log) |
199 : transport_pool_(transport_pool), | 199 : transport_pool_(transport_pool), |
200 base_(max_sockets, max_sockets_per_group, histograms, | 200 base_(this, max_sockets, max_sockets_per_group, histograms, |
201 ClientSocketPool::unused_idle_socket_timeout(), | 201 ClientSocketPool::unused_idle_socket_timeout(), |
202 ClientSocketPool::used_idle_socket_timeout(), | 202 ClientSocketPool::used_idle_socket_timeout(), |
203 new SOCKSConnectJobFactory(transport_pool, | 203 new SOCKSConnectJobFactory(transport_pool, |
204 host_resolver, | 204 host_resolver, |
205 net_log)) { | 205 net_log)) { |
206 // We should always have a |transport_pool_| except in unit tests. | 206 // We should always have a |transport_pool_| except in unit tests. |
207 if (transport_pool_) | 207 if (transport_pool_) |
208 transport_pool_->AddLayeredPool(this); | 208 base_.AddLowerLayeredPool(transport_pool_); |
209 } | 209 } |
210 | 210 |
211 SOCKSClientSocketPool::~SOCKSClientSocketPool() { | 211 SOCKSClientSocketPool::~SOCKSClientSocketPool() { |
212 // We should always have a |transport_pool_| except in unit tests. | |
213 if (transport_pool_) | |
214 transport_pool_->RemoveLayeredPool(this); | |
215 } | 212 } |
216 | 213 |
217 int SOCKSClientSocketPool::RequestSocket( | 214 int SOCKSClientSocketPool::RequestSocket( |
218 const std::string& group_name, const void* socket_params, | 215 const std::string& group_name, const void* socket_params, |
219 RequestPriority priority, ClientSocketHandle* handle, | 216 RequestPriority priority, ClientSocketHandle* handle, |
220 const CompletionCallback& callback, const BoundNetLog& net_log) { | 217 const CompletionCallback& callback, const BoundNetLog& net_log) { |
221 const scoped_refptr<SOCKSSocketParams>* casted_socket_params = | 218 const scoped_refptr<SOCKSSocketParams>* casted_socket_params = |
222 static_cast<const scoped_refptr<SOCKSSocketParams>*>(socket_params); | 219 static_cast<const scoped_refptr<SOCKSSocketParams>*>(socket_params); |
223 | 220 |
224 return base_.RequestSocket(group_name, *casted_socket_params, priority, | 221 return base_.RequestSocket(group_name, *casted_socket_params, priority, |
(...skipping 19 matching lines...) Expand all Loading... |
244 void SOCKSClientSocketPool::ReleaseSocket(const std::string& group_name, | 241 void SOCKSClientSocketPool::ReleaseSocket(const std::string& group_name, |
245 scoped_ptr<StreamSocket> socket, | 242 scoped_ptr<StreamSocket> socket, |
246 int id) { | 243 int id) { |
247 base_.ReleaseSocket(group_name, socket.Pass(), id); | 244 base_.ReleaseSocket(group_name, socket.Pass(), id); |
248 } | 245 } |
249 | 246 |
250 void SOCKSClientSocketPool::FlushWithError(int error) { | 247 void SOCKSClientSocketPool::FlushWithError(int error) { |
251 base_.FlushWithError(error); | 248 base_.FlushWithError(error); |
252 } | 249 } |
253 | 250 |
254 bool SOCKSClientSocketPool::IsStalled() const { | |
255 return base_.IsStalled() || transport_pool_->IsStalled(); | |
256 } | |
257 | |
258 void SOCKSClientSocketPool::CloseIdleSockets() { | 251 void SOCKSClientSocketPool::CloseIdleSockets() { |
259 base_.CloseIdleSockets(); | 252 base_.CloseIdleSockets(); |
260 } | 253 } |
261 | 254 |
262 int SOCKSClientSocketPool::IdleSocketCount() const { | 255 int SOCKSClientSocketPool::IdleSocketCount() const { |
263 return base_.idle_socket_count(); | 256 return base_.idle_socket_count(); |
264 } | 257 } |
265 | 258 |
266 int SOCKSClientSocketPool::IdleSocketCountInGroup( | 259 int SOCKSClientSocketPool::IdleSocketCountInGroup( |
267 const std::string& group_name) const { | 260 const std::string& group_name) const { |
268 return base_.IdleSocketCountInGroup(group_name); | 261 return base_.IdleSocketCountInGroup(group_name); |
269 } | 262 } |
270 | 263 |
271 LoadState SOCKSClientSocketPool::GetLoadState( | 264 LoadState SOCKSClientSocketPool::GetLoadState( |
272 const std::string& group_name, const ClientSocketHandle* handle) const { | 265 const std::string& group_name, const ClientSocketHandle* handle) const { |
273 return base_.GetLoadState(group_name, handle); | 266 return base_.GetLoadState(group_name, handle); |
274 } | 267 } |
275 | 268 |
276 void SOCKSClientSocketPool::AddLayeredPool(LayeredPool* layered_pool) { | |
277 base_.AddLayeredPool(layered_pool); | |
278 } | |
279 | |
280 void SOCKSClientSocketPool::RemoveLayeredPool(LayeredPool* layered_pool) { | |
281 base_.RemoveLayeredPool(layered_pool); | |
282 } | |
283 | |
284 base::DictionaryValue* SOCKSClientSocketPool::GetInfoAsValue( | 269 base::DictionaryValue* SOCKSClientSocketPool::GetInfoAsValue( |
285 const std::string& name, | 270 const std::string& name, |
286 const std::string& type, | 271 const std::string& type, |
287 bool include_nested_pools) const { | 272 bool include_nested_pools) const { |
288 base::DictionaryValue* dict = base_.GetInfoAsValue(name, type); | 273 base::DictionaryValue* dict = base_.GetInfoAsValue(name, type); |
289 if (include_nested_pools) { | 274 if (include_nested_pools) { |
290 base::ListValue* list = new base::ListValue(); | 275 base::ListValue* list = new base::ListValue(); |
291 list->Append(transport_pool_->GetInfoAsValue("transport_socket_pool", | 276 list->Append(transport_pool_->GetInfoAsValue("transport_socket_pool", |
292 "transport_socket_pool", | 277 "transport_socket_pool", |
293 false)); | 278 false)); |
294 dict->Set("nested_pools", list); | 279 dict->Set("nested_pools", list); |
295 } | 280 } |
296 return dict; | 281 return dict; |
297 } | 282 } |
298 | 283 |
299 base::TimeDelta SOCKSClientSocketPool::ConnectionTimeout() const { | 284 base::TimeDelta SOCKSClientSocketPool::ConnectionTimeout() const { |
300 return base_.ConnectionTimeout(); | 285 return base_.ConnectionTimeout(); |
301 } | 286 } |
302 | 287 |
303 ClientSocketPoolHistograms* SOCKSClientSocketPool::histograms() const { | 288 ClientSocketPoolHistograms* SOCKSClientSocketPool::histograms() const { |
304 return base_.histograms(); | 289 return base_.histograms(); |
305 }; | 290 }; |
306 | 291 |
| 292 bool SOCKSClientSocketPool::IsStalled() const { |
| 293 return base_.IsStalled(); |
| 294 } |
| 295 |
| 296 void SOCKSClientSocketPool::AddHigherLayeredPool( |
| 297 HigherLayeredPool* higher_pool) { |
| 298 base_.AddHigherLayeredPool(higher_pool); |
| 299 } |
| 300 |
| 301 void SOCKSClientSocketPool::RemoveHigherLayeredPool( |
| 302 HigherLayeredPool* higher_pool) { |
| 303 base_.RemoveHigherLayeredPool(higher_pool); |
| 304 } |
| 305 |
307 bool SOCKSClientSocketPool::CloseOneIdleConnection() { | 306 bool SOCKSClientSocketPool::CloseOneIdleConnection() { |
308 if (base_.CloseOneIdleSocket()) | 307 if (base_.CloseOneIdleSocket()) |
309 return true; | 308 return true; |
310 return base_.CloseOneIdleConnectionInLayeredPool(); | 309 return base_.CloseOneIdleConnectionInHigherLayeredPool(); |
311 } | 310 } |
312 | 311 |
313 } // namespace net | 312 } // namespace net |
OLD | NEW |