OLD | NEW |
1 // Copyright (c) 2012 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 "jingle/notifier/base/proxy_resolving_client_socket.h" | 5 #include "jingle/notifier/base/proxy_resolving_client_socket.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
13 #include "net/base/io_buffer.h" | 13 #include "net/base/io_buffer.h" |
14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
15 #include "net/http/http_network_session.h" | 15 #include "net/http/http_network_session.h" |
16 #include "net/socket/client_socket_handle.h" | 16 #include "net/socket/client_socket_handle.h" |
17 #include "net/socket/client_socket_pool_manager.h" | 17 #include "net/socket/client_socket_pool_manager.h" |
18 #include "net/url_request/url_request_context.h" | 18 #include "net/url_request/url_request_context.h" |
19 #include "net/url_request/url_request_context_getter.h" | 19 #include "net/url_request/url_request_context_getter.h" |
20 | 20 |
21 namespace notifier { | 21 namespace notifier { |
22 | 22 |
23 namespace { | |
24 | |
25 void HandleProxyTunnelAuth(const net::HttpResponseInfo& response_info, | |
26 net::HttpAuthController* auth_controller, | |
27 net::CompletionCallback callback) { | |
28 // Since we have no way to respond, simply invoke the callback and the | |
29 // request will fail. | |
30 callback.Run(net::OK); | |
31 } | |
32 | |
33 } // namespace | |
34 | |
35 ProxyResolvingClientSocket::ProxyResolvingClientSocket( | 23 ProxyResolvingClientSocket::ProxyResolvingClientSocket( |
36 net::ClientSocketFactory* socket_factory, | 24 net::ClientSocketFactory* socket_factory, |
37 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, | 25 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, |
38 const net::SSLConfig& ssl_config, | 26 const net::SSLConfig& ssl_config, |
39 const net::HostPortPair& dest_host_port_pair) | 27 const net::HostPortPair& dest_host_port_pair) |
40 : ALLOW_THIS_IN_INITIALIZER_LIST(proxy_resolve_callback_( | 28 : ALLOW_THIS_IN_INITIALIZER_LIST(proxy_resolve_callback_( |
41 base::Bind(&ProxyResolvingClientSocket::ProcessProxyResolveDone, | 29 base::Bind(&ProxyResolvingClientSocket::ProcessProxyResolveDone, |
42 base::Unretained(this)))), | 30 base::Unretained(this)))), |
43 ALLOW_THIS_IN_INITIALIZER_LIST(connect_callback_( | 31 ALLOW_THIS_IN_INITIALIZER_LIST(connect_callback_( |
44 base::Bind(&ProxyResolvingClientSocket::ProcessConnectDone, | 32 base::Bind(&ProxyResolvingClientSocket::ProcessConnectDone, |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 CloseTransportSocket(); | 165 CloseTransportSocket(); |
178 RunUserConnectCallback(status); | 166 RunUserConnectCallback(status); |
179 return; | 167 return; |
180 } | 168 } |
181 } | 169 } |
182 | 170 |
183 transport_.reset(new net::ClientSocketHandle); | 171 transport_.reset(new net::ClientSocketHandle); |
184 // Now that we have resolved the proxy, we need to connect. | 172 // Now that we have resolved the proxy, we need to connect. |
185 status = net::InitSocketHandleForRawConnect( | 173 status = net::InitSocketHandleForRawConnect( |
186 dest_host_port_pair_, network_session_.get(), proxy_info_, ssl_config_, | 174 dest_host_port_pair_, network_session_.get(), proxy_info_, ssl_config_, |
187 ssl_config_, bound_net_log_, transport_.get(), | 175 ssl_config_, bound_net_log_, transport_.get(), connect_callback_); |
188 base::Bind(&HandleProxyTunnelAuth), connect_callback_); | |
189 | |
190 if (status != net::ERR_IO_PENDING) { | 176 if (status != net::ERR_IO_PENDING) { |
191 // Since this method is always called asynchronously. it is OK to call | 177 // Since this method is always called asynchronously. it is OK to call |
192 // ProcessConnectDone synchronously. | 178 // ProcessConnectDone synchronously. |
193 ProcessConnectDone(status); | 179 ProcessConnectDone(status); |
194 } | 180 } |
195 } | 181 } |
196 | 182 |
197 void ProxyResolvingClientSocket::ProcessConnectDone(int status) { | 183 void ProxyResolvingClientSocket::ProcessConnectDone(int status) { |
198 if (status != net::OK) { | 184 if (status != net::OK) { |
199 // If the connection fails, try another proxy. | 185 // If the connection fails, try another proxy. |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 return base::TimeDelta::FromMicroseconds(-1); | 366 return base::TimeDelta::FromMicroseconds(-1); |
381 } | 367 } |
382 | 368 |
383 void ProxyResolvingClientSocket::CloseTransportSocket() { | 369 void ProxyResolvingClientSocket::CloseTransportSocket() { |
384 if (transport_.get() && transport_->socket()) | 370 if (transport_.get() && transport_->socket()) |
385 transport_->socket()->Disconnect(); | 371 transport_->socket()->Disconnect(); |
386 transport_.reset(); | 372 transport_.reset(); |
387 } | 373 } |
388 | 374 |
389 } // namespace notifier | 375 } // namespace notifier |
OLD | NEW |