Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: jingle/notifier/base/proxy_resolving_client_socket.cc

Issue 8898036: base::Bind: Convert proxy_resolving_client_socket.[cc,h] and deps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Possible test fix. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "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/compiler_specific.h" 10 #include "base/compiler_specific.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "googleurl/src/gurl.h" 12 #include "googleurl/src/gurl.h"
12 #include "net/base/io_buffer.h" 13 #include "net/base/io_buffer.h"
13 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
14 #include "net/http/http_network_session.h" 15 #include "net/http/http_network_session.h"
15 #include "net/socket/client_socket_handle.h" 16 #include "net/socket/client_socket_handle.h"
16 #include "net/socket/client_socket_pool_manager.h" 17 #include "net/socket/client_socket_pool_manager.h"
17 #include "net/url_request/url_request_context.h" 18 #include "net/url_request/url_request_context.h"
18 #include "net/url_request/url_request_context_getter.h" 19 #include "net/url_request/url_request_context_getter.h"
19 20
20 namespace notifier { 21 namespace notifier {
21 22
22 ProxyResolvingClientSocket::ProxyResolvingClientSocket( 23 ProxyResolvingClientSocket::ProxyResolvingClientSocket(
23 net::ClientSocketFactory* socket_factory, 24 net::ClientSocketFactory* socket_factory,
24 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, 25 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
25 const net::SSLConfig& ssl_config, 26 const net::SSLConfig& ssl_config,
26 const net::HostPortPair& dest_host_port_pair) 27 const net::HostPortPair& dest_host_port_pair)
27 : proxy_resolve_callback_(ALLOW_THIS_IN_INITIALIZER_LIST(this), 28 : ALLOW_THIS_IN_INITIALIZER_LIST(proxy_resolve_callback_(
28 &ProxyResolvingClientSocket::ProcessProxyResolveDone), 29 base::Bind(&ProxyResolvingClientSocket::ProcessProxyResolveDone,
29 connect_callback_(ALLOW_THIS_IN_INITIALIZER_LIST(this), 30 base::Unretained(this)))),
30 &ProxyResolvingClientSocket::ProcessConnectDone), 31 ALLOW_THIS_IN_INITIALIZER_LIST(connect_callback_(
32 base::Bind(&ProxyResolvingClientSocket::ProcessConnectDone,
33 base::Unretained(this)))),
31 ssl_config_(ssl_config), 34 ssl_config_(ssl_config),
32 pac_request_(NULL), 35 pac_request_(NULL),
33 dest_host_port_pair_(dest_host_port_pair), 36 dest_host_port_pair_(dest_host_port_pair),
34 tried_direct_connect_fallback_(false), 37 tried_direct_connect_fallback_(false),
35 bound_net_log_( 38 bound_net_log_(
36 net::BoundNetLog::Make( 39 net::BoundNetLog::Make(
37 request_context_getter->GetURLRequestContext()->net_log(), 40 request_context_getter->GetURLRequestContext()->net_log(),
38 net::NetLog::SOURCE_SOCKET)), 41 net::NetLog::SOURCE_SOCKET)),
39 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 42 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
40 DCHECK(request_context_getter); 43 DCHECK(request_context_getter);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 const net::CompletionCallback& callback) { 105 const net::CompletionCallback& callback) {
103 DCHECK(user_connect_callback_.is_null()); 106 DCHECK(user_connect_callback_.is_null());
104 107
105 tried_direct_connect_fallback_ = false; 108 tried_direct_connect_fallback_ = false;
106 109
107 // First we try and resolve the proxy. 110 // First we try and resolve the proxy.
108 GURL url("http://" + dest_host_port_pair_.ToString()); 111 GURL url("http://" + dest_host_port_pair_.ToString());
109 int status = network_session_->proxy_service()->ResolveProxy( 112 int status = network_session_->proxy_service()->ResolveProxy(
110 url, 113 url,
111 &proxy_info_, 114 &proxy_info_,
112 &proxy_resolve_callback_, 115 proxy_resolve_callback_,
113 &pac_request_, 116 &pac_request_,
114 bound_net_log_); 117 bound_net_log_);
115 if (status != net::ERR_IO_PENDING) { 118 if (status != net::ERR_IO_PENDING) {
116 // We defer execution of ProcessProxyResolveDone instead of calling it 119 // We defer execution of ProcessProxyResolveDone instead of calling it
117 // directly here for simplicity. From the caller's point of view, 120 // directly here for simplicity. From the caller's point of view,
118 // the connect always happens asynchronously. 121 // the connect always happens asynchronously.
119 MessageLoop* message_loop = MessageLoop::current(); 122 MessageLoop* message_loop = MessageLoop::current();
120 CHECK(message_loop); 123 CHECK(message_loop);
121 message_loop->PostTask( 124 message_loop->PostTask(
122 FROM_HERE, 125 FROM_HERE,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 } else { 165 } else {
163 CloseTransportSocket(); 166 CloseTransportSocket();
164 RunUserConnectCallback(status); 167 RunUserConnectCallback(status);
165 return; 168 return;
166 } 169 }
167 } 170 }
168 171
169 transport_.reset(new net::ClientSocketHandle); 172 transport_.reset(new net::ClientSocketHandle);
170 // Now that we have resolved the proxy, we need to connect. 173 // Now that we have resolved the proxy, we need to connect.
171 status = net::InitSocketHandleForRawConnect( 174 status = net::InitSocketHandleForRawConnect(
172 dest_host_port_pair_, 175 dest_host_port_pair_, network_session_.get(), proxy_info_, ssl_config_,
173 network_session_.get(), 176 ssl_config_, bound_net_log_, transport_.get(), connect_callback_);
174 proxy_info_,
175 ssl_config_,
176 ssl_config_,
177 bound_net_log_,
178 transport_.get(),
179 &connect_callback_);
180 if (status != net::ERR_IO_PENDING) { 177 if (status != net::ERR_IO_PENDING) {
181 // Since this method is always called asynchronously. it is OK to call 178 // Since this method is always called asynchronously. it is OK to call
182 // ProcessConnectDone synchronously. 179 // ProcessConnectDone synchronously.
183 ProcessConnectDone(status); 180 ProcessConnectDone(status);
184 } 181 }
185 } 182 }
186 183
187 void ProxyResolvingClientSocket::ProcessConnectDone(int status) { 184 void ProxyResolvingClientSocket::ProcessConnectDone(int status) {
188 if (status != net::OK) { 185 if (status != net::OK) {
189 // If the connection fails, try another proxy. 186 // If the connection fails, try another proxy.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 return error; 244 return error;
248 } 245 }
249 246
250 if (proxy_info_.is_https() && ssl_config_.send_client_cert) { 247 if (proxy_info_.is_https() && ssl_config_.send_client_cert) {
251 network_session_->ssl_client_auth_cache()->Remove( 248 network_session_->ssl_client_auth_cache()->Remove(
252 proxy_info_.proxy_server().host_port_pair().ToString()); 249 proxy_info_.proxy_server().host_port_pair().ToString());
253 } 250 }
254 251
255 GURL url("http://" + dest_host_port_pair_.ToString()); 252 GURL url("http://" + dest_host_port_pair_.ToString());
256 int rv = network_session_->proxy_service()->ReconsiderProxyAfterError( 253 int rv = network_session_->proxy_service()->ReconsiderProxyAfterError(
257 url, &proxy_info_, &proxy_resolve_callback_, &pac_request_, 254 url, &proxy_info_, proxy_resolve_callback_, &pac_request_,
258 bound_net_log_); 255 bound_net_log_);
259 if (rv == net::OK || rv == net::ERR_IO_PENDING) { 256 if (rv == net::OK || rv == net::ERR_IO_PENDING) {
260 CloseTransportSocket(); 257 CloseTransportSocket();
261 } else { 258 } else {
262 // If ReconsiderProxyAfterError() failed synchronously, it means 259 // If ReconsiderProxyAfterError() failed synchronously, it means
263 // there was nothing left to fall-back to, so fail the transaction 260 // there was nothing left to fall-back to, so fail the transaction
264 // with the last connection error we got. 261 // with the last connection error we got.
265 rv = error; 262 rv = error;
266 } 263 }
267 264
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 return base::TimeDelta::FromMicroseconds(-1); 367 return base::TimeDelta::FromMicroseconds(-1);
371 } 368 }
372 369
373 void ProxyResolvingClientSocket::CloseTransportSocket() { 370 void ProxyResolvingClientSocket::CloseTransportSocket() {
374 if (transport_.get() && transport_->socket()) 371 if (transport_.get() && transport_->socket())
375 transport_->socket()->Disconnect(); 372 transport_->socket()->Disconnect();
376 transport_.reset(); 373 transport_.reset();
377 } 374 }
378 375
379 } // namespace notifier 376 } // namespace notifier
OLDNEW
« no previous file with comments | « jingle/notifier/base/proxy_resolving_client_socket.h ('k') | net/base/test_completion_callback.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698