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