| 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 <utility> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 9 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 10 #include "base/values.h" | 12 #include "base/values.h" |
| 11 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 12 #include "net/socket/client_socket_factory.h" | 14 #include "net/socket/client_socket_factory.h" |
| 13 #include "net/socket/client_socket_handle.h" | 15 #include "net/socket/client_socket_handle.h" |
| 14 #include "net/socket/client_socket_pool_base.h" | 16 #include "net/socket/client_socket_pool_base.h" |
| 15 #include "net/socket/socks5_client_socket.h" | 17 #include "net/socket/socks5_client_socket.h" |
| 16 #include "net/socket/socks_client_socket.h" | 18 #include "net/socket/socks_client_socket.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 ResetTimer(base::TimeDelta::FromSeconds(kSOCKSConnectJobTimeoutInSeconds)); | 136 ResetTimer(base::TimeDelta::FromSeconds(kSOCKSConnectJobTimeoutInSeconds)); |
| 135 next_state_ = STATE_SOCKS_CONNECT; | 137 next_state_ = STATE_SOCKS_CONNECT; |
| 136 return result; | 138 return result; |
| 137 } | 139 } |
| 138 | 140 |
| 139 int SOCKSConnectJob::DoSOCKSConnect() { | 141 int SOCKSConnectJob::DoSOCKSConnect() { |
| 140 next_state_ = STATE_SOCKS_CONNECT_COMPLETE; | 142 next_state_ = STATE_SOCKS_CONNECT_COMPLETE; |
| 141 | 143 |
| 142 // Add a SOCKS connection on top of the tcp socket. | 144 // Add a SOCKS connection on top of the tcp socket. |
| 143 if (socks_params_->is_socks_v5()) { | 145 if (socks_params_->is_socks_v5()) { |
| 144 socket_.reset(new SOCKS5ClientSocket(transport_socket_handle_.Pass(), | 146 socket_.reset(new SOCKS5ClientSocket(std::move(transport_socket_handle_), |
| 145 socks_params_->destination())); | 147 socks_params_->destination())); |
| 146 } else { | 148 } else { |
| 147 socket_.reset(new SOCKSClientSocket(transport_socket_handle_.Pass(), | 149 socket_.reset(new SOCKSClientSocket(std::move(transport_socket_handle_), |
| 148 socks_params_->destination(), | 150 socks_params_->destination(), |
| 149 priority(), | 151 priority(), resolver_)); |
| 150 resolver_)); | |
| 151 } | 152 } |
| 152 return socket_->Connect( | 153 return socket_->Connect( |
| 153 base::Bind(&SOCKSConnectJob::OnIOComplete, base::Unretained(this))); | 154 base::Bind(&SOCKSConnectJob::OnIOComplete, base::Unretained(this))); |
| 154 } | 155 } |
| 155 | 156 |
| 156 int SOCKSConnectJob::DoSOCKSConnectComplete(int result) { | 157 int SOCKSConnectJob::DoSOCKSConnectComplete(int result) { |
| 157 if (result != OK) { | 158 if (result != OK) { |
| 158 socket_->Disconnect(); | 159 socket_->Disconnect(); |
| 159 return result; | 160 return result; |
| 160 } | 161 } |
| 161 | 162 |
| 162 SetSocket(socket_.Pass()); | 163 SetSocket(std::move(socket_)); |
| 163 return result; | 164 return result; |
| 164 } | 165 } |
| 165 | 166 |
| 166 int SOCKSConnectJob::ConnectInternal() { | 167 int SOCKSConnectJob::ConnectInternal() { |
| 167 next_state_ = STATE_TRANSPORT_CONNECT; | 168 next_state_ = STATE_TRANSPORT_CONNECT; |
| 168 return DoLoop(OK); | 169 return DoLoop(OK); |
| 169 } | 170 } |
| 170 | 171 |
| 171 scoped_ptr<ConnectJob> | 172 scoped_ptr<ConnectJob> |
| 172 SOCKSClientSocketPool::SOCKSConnectJobFactory::NewConnectJob( | 173 SOCKSClientSocketPool::SOCKSConnectJobFactory::NewConnectJob( |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 } | 235 } |
| 235 | 236 |
| 236 void SOCKSClientSocketPool::CancelRequest(const std::string& group_name, | 237 void SOCKSClientSocketPool::CancelRequest(const std::string& group_name, |
| 237 ClientSocketHandle* handle) { | 238 ClientSocketHandle* handle) { |
| 238 base_.CancelRequest(group_name, handle); | 239 base_.CancelRequest(group_name, handle); |
| 239 } | 240 } |
| 240 | 241 |
| 241 void SOCKSClientSocketPool::ReleaseSocket(const std::string& group_name, | 242 void SOCKSClientSocketPool::ReleaseSocket(const std::string& group_name, |
| 242 scoped_ptr<StreamSocket> socket, | 243 scoped_ptr<StreamSocket> socket, |
| 243 int id) { | 244 int id) { |
| 244 base_.ReleaseSocket(group_name, socket.Pass(), id); | 245 base_.ReleaseSocket(group_name, std::move(socket), id); |
| 245 } | 246 } |
| 246 | 247 |
| 247 void SOCKSClientSocketPool::FlushWithError(int error) { | 248 void SOCKSClientSocketPool::FlushWithError(int error) { |
| 248 base_.FlushWithError(error); | 249 base_.FlushWithError(error); |
| 249 } | 250 } |
| 250 | 251 |
| 251 void SOCKSClientSocketPool::CloseIdleSockets() { | 252 void SOCKSClientSocketPool::CloseIdleSockets() { |
| 252 base_.CloseIdleSockets(); | 253 base_.CloseIdleSockets(); |
| 253 } | 254 } |
| 254 | 255 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 269 scoped_ptr<base::DictionaryValue> SOCKSClientSocketPool::GetInfoAsValue( | 270 scoped_ptr<base::DictionaryValue> SOCKSClientSocketPool::GetInfoAsValue( |
| 270 const std::string& name, | 271 const std::string& name, |
| 271 const std::string& type, | 272 const std::string& type, |
| 272 bool include_nested_pools) const { | 273 bool include_nested_pools) const { |
| 273 scoped_ptr<base::DictionaryValue> dict(base_.GetInfoAsValue(name, type)); | 274 scoped_ptr<base::DictionaryValue> dict(base_.GetInfoAsValue(name, type)); |
| 274 if (include_nested_pools) { | 275 if (include_nested_pools) { |
| 275 scoped_ptr<base::ListValue> list(new base::ListValue()); | 276 scoped_ptr<base::ListValue> list(new base::ListValue()); |
| 276 list->Append(transport_pool_->GetInfoAsValue("transport_socket_pool", | 277 list->Append(transport_pool_->GetInfoAsValue("transport_socket_pool", |
| 277 "transport_socket_pool", | 278 "transport_socket_pool", |
| 278 false)); | 279 false)); |
| 279 dict->Set("nested_pools", list.Pass()); | 280 dict->Set("nested_pools", std::move(list)); |
| 280 } | 281 } |
| 281 return dict.Pass(); | 282 return dict; |
| 282 } | 283 } |
| 283 | 284 |
| 284 base::TimeDelta SOCKSClientSocketPool::ConnectionTimeout() const { | 285 base::TimeDelta SOCKSClientSocketPool::ConnectionTimeout() const { |
| 285 return base_.ConnectionTimeout(); | 286 return base_.ConnectionTimeout(); |
| 286 } | 287 } |
| 287 | 288 |
| 288 bool SOCKSClientSocketPool::IsStalled() const { | 289 bool SOCKSClientSocketPool::IsStalled() const { |
| 289 return base_.IsStalled(); | 290 return base_.IsStalled(); |
| 290 } | 291 } |
| 291 | 292 |
| 292 void SOCKSClientSocketPool::AddHigherLayeredPool( | 293 void SOCKSClientSocketPool::AddHigherLayeredPool( |
| 293 HigherLayeredPool* higher_pool) { | 294 HigherLayeredPool* higher_pool) { |
| 294 base_.AddHigherLayeredPool(higher_pool); | 295 base_.AddHigherLayeredPool(higher_pool); |
| 295 } | 296 } |
| 296 | 297 |
| 297 void SOCKSClientSocketPool::RemoveHigherLayeredPool( | 298 void SOCKSClientSocketPool::RemoveHigherLayeredPool( |
| 298 HigherLayeredPool* higher_pool) { | 299 HigherLayeredPool* higher_pool) { |
| 299 base_.RemoveHigherLayeredPool(higher_pool); | 300 base_.RemoveHigherLayeredPool(higher_pool); |
| 300 } | 301 } |
| 301 | 302 |
| 302 bool SOCKSClientSocketPool::CloseOneIdleConnection() { | 303 bool SOCKSClientSocketPool::CloseOneIdleConnection() { |
| 303 if (base_.CloseOneIdleSocket()) | 304 if (base_.CloseOneIdleSocket()) |
| 304 return true; | 305 return true; |
| 305 return base_.CloseOneIdleConnectionInHigherLayeredPool(); | 306 return base_.CloseOneIdleConnectionInHigherLayeredPool(); |
| 306 } | 307 } |
| 307 | 308 |
| 308 } // namespace net | 309 } // namespace net |
| OLD | NEW |