OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/values.h" | 8 #include "base/values.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" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 TransportClientSocketPool* transport_pool, | 44 TransportClientSocketPool* transport_pool, |
45 HostResolver* host_resolver, | 45 HostResolver* host_resolver, |
46 Delegate* delegate, | 46 Delegate* delegate, |
47 NetLog* net_log) | 47 NetLog* net_log) |
48 : ConnectJob(group_name, timeout_duration, delegate, | 48 : ConnectJob(group_name, timeout_duration, delegate, |
49 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), | 49 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), |
50 socks_params_(socks_params), | 50 socks_params_(socks_params), |
51 transport_pool_(transport_pool), | 51 transport_pool_(transport_pool), |
52 resolver_(host_resolver), | 52 resolver_(host_resolver), |
53 ALLOW_THIS_IN_INITIALIZER_LIST( | 53 ALLOW_THIS_IN_INITIALIZER_LIST( |
54 callback_(this, &SOCKSConnectJob::OnIOComplete)) { | 54 callback_old_(this, &SOCKSConnectJob::OnIOComplete)) { |
55 } | 55 } |
56 | 56 |
57 SOCKSConnectJob::~SOCKSConnectJob() { | 57 SOCKSConnectJob::~SOCKSConnectJob() { |
58 // We don't worry about cancelling the tcp socket since the destructor in | 58 // We don't worry about cancelling the tcp socket since the destructor in |
59 // scoped_ptr<ClientSocketHandle> transport_socket_handle_ will take care of | 59 // scoped_ptr<ClientSocketHandle> transport_socket_handle_ will take care of |
60 // it. | 60 // it. |
61 } | 61 } |
62 | 62 |
63 LoadState SOCKSConnectJob::GetLoadState() const { | 63 LoadState SOCKSConnectJob::GetLoadState() const { |
64 switch (next_state_) { | 64 switch (next_state_) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 | 111 |
112 return rv; | 112 return rv; |
113 } | 113 } |
114 | 114 |
115 int SOCKSConnectJob::DoTransportConnect() { | 115 int SOCKSConnectJob::DoTransportConnect() { |
116 next_state_ = STATE_TRANSPORT_CONNECT_COMPLETE; | 116 next_state_ = STATE_TRANSPORT_CONNECT_COMPLETE; |
117 transport_socket_handle_.reset(new ClientSocketHandle()); | 117 transport_socket_handle_.reset(new ClientSocketHandle()); |
118 return transport_socket_handle_->Init(group_name(), | 118 return transport_socket_handle_->Init(group_name(), |
119 socks_params_->transport_params(), | 119 socks_params_->transport_params(), |
120 socks_params_->destination().priority(), | 120 socks_params_->destination().priority(), |
121 &callback_, | 121 &callback_old_, |
122 transport_pool_, | 122 transport_pool_, |
123 net_log()); | 123 net_log()); |
124 } | 124 } |
125 | 125 |
126 int SOCKSConnectJob::DoTransportConnectComplete(int result) { | 126 int SOCKSConnectJob::DoTransportConnectComplete(int result) { |
127 if (result != OK) | 127 if (result != OK) |
128 return ERR_PROXY_CONNECTION_FAILED; | 128 return ERR_PROXY_CONNECTION_FAILED; |
129 | 129 |
130 // Reset the timer to just the length of time allowed for SOCKS handshake | 130 // Reset the timer to just the length of time allowed for SOCKS handshake |
131 // so that a fast TCP connection plus a slow SOCKS failure doesn't take | 131 // so that a fast TCP connection plus a slow SOCKS failure doesn't take |
132 // longer to timeout than it should. | 132 // longer to timeout than it should. |
133 ResetTimer(base::TimeDelta::FromSeconds(kSOCKSConnectJobTimeoutInSeconds)); | 133 ResetTimer(base::TimeDelta::FromSeconds(kSOCKSConnectJobTimeoutInSeconds)); |
134 next_state_ = STATE_SOCKS_CONNECT; | 134 next_state_ = STATE_SOCKS_CONNECT; |
135 return result; | 135 return result; |
136 } | 136 } |
137 | 137 |
138 int SOCKSConnectJob::DoSOCKSConnect() { | 138 int SOCKSConnectJob::DoSOCKSConnect() { |
139 next_state_ = STATE_SOCKS_CONNECT_COMPLETE; | 139 next_state_ = STATE_SOCKS_CONNECT_COMPLETE; |
140 | 140 |
141 // Add a SOCKS connection on top of the tcp socket. | 141 // Add a SOCKS connection on top of the tcp socket. |
142 if (socks_params_->is_socks_v5()) { | 142 if (socks_params_->is_socks_v5()) { |
143 socket_.reset(new SOCKS5ClientSocket(transport_socket_handle_.release(), | 143 socket_.reset(new SOCKS5ClientSocket(transport_socket_handle_.release(), |
144 socks_params_->destination())); | 144 socks_params_->destination())); |
145 } else { | 145 } else { |
146 socket_.reset(new SOCKSClientSocket(transport_socket_handle_.release(), | 146 socket_.reset(new SOCKSClientSocket(transport_socket_handle_.release(), |
147 socks_params_->destination(), | 147 socks_params_->destination(), |
148 resolver_)); | 148 resolver_)); |
149 } | 149 } |
150 return socket_->Connect(&callback_); | 150 return socket_->Connect( |
| 151 base::Bind(&SOCKSConnectJob::OnIOComplete, base::Unretained(this))); |
151 } | 152 } |
152 | 153 |
153 int SOCKSConnectJob::DoSOCKSConnectComplete(int result) { | 154 int SOCKSConnectJob::DoSOCKSConnectComplete(int result) { |
154 if (result != OK) { | 155 if (result != OK) { |
155 socket_->Disconnect(); | 156 socket_->Disconnect(); |
156 return result; | 157 return result; |
157 } | 158 } |
158 | 159 |
159 set_socket(socket_.release()); | 160 set_socket(socket_.release()); |
160 return result; | 161 return result; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 return base_.histograms(); | 301 return base_.histograms(); |
301 }; | 302 }; |
302 | 303 |
303 bool SOCKSClientSocketPool::CloseOneIdleConnection() { | 304 bool SOCKSClientSocketPool::CloseOneIdleConnection() { |
304 if (base_.CloseOneIdleSocket()) | 305 if (base_.CloseOneIdleSocket()) |
305 return true; | 306 return true; |
306 return base_.CloseOneIdleConnectionInLayeredPool(); | 307 return base_.CloseOneIdleConnectionInLayeredPool(); |
307 } | 308 } |
308 | 309 |
309 } // namespace net | 310 } // namespace net |
OLD | NEW |