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 "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/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
11 #include "net/base/io_buffer.h" | 12 #include "net/base/io_buffer.h" |
12 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
13 #include "net/http/http_network_session.h" | 14 #include "net/http/http_network_session.h" |
14 #include "net/socket/client_socket_handle.h" | 15 #include "net/socket/client_socket_handle.h" |
15 #include "net/socket/client_socket_pool_manager.h" | 16 #include "net/socket/client_socket_pool_manager.h" |
16 #include "net/url_request/url_request_context.h" | 17 #include "net/url_request/url_request_context.h" |
17 #include "net/url_request/url_request_context_getter.h" | 18 #include "net/url_request/url_request_context_getter.h" |
(...skipping 10 matching lines...) Expand all Loading... |
28 connect_callback_(ALLOW_THIS_IN_INITIALIZER_LIST(this), | 29 connect_callback_(ALLOW_THIS_IN_INITIALIZER_LIST(this), |
29 &ProxyResolvingClientSocket::ProcessConnectDone), | 30 &ProxyResolvingClientSocket::ProcessConnectDone), |
30 ssl_config_(ssl_config), | 31 ssl_config_(ssl_config), |
31 pac_request_(NULL), | 32 pac_request_(NULL), |
32 dest_host_port_pair_(dest_host_port_pair), | 33 dest_host_port_pair_(dest_host_port_pair), |
33 tried_direct_connect_fallback_(false), | 34 tried_direct_connect_fallback_(false), |
34 bound_net_log_( | 35 bound_net_log_( |
35 net::BoundNetLog::Make( | 36 net::BoundNetLog::Make( |
36 request_context_getter->GetURLRequestContext()->net_log(), | 37 request_context_getter->GetURLRequestContext()->net_log(), |
37 net::NetLog::SOURCE_SOCKET)), | 38 net::NetLog::SOURCE_SOCKET)), |
38 scoped_runnable_method_factory_( | 39 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
39 ALLOW_THIS_IN_INITIALIZER_LIST(this)), | |
40 user_connect_callback_(NULL) { | 40 user_connect_callback_(NULL) { |
41 DCHECK(request_context_getter); | 41 DCHECK(request_context_getter); |
42 net::URLRequestContext* request_context = | 42 net::URLRequestContext* request_context = |
43 request_context_getter->GetURLRequestContext(); | 43 request_context_getter->GetURLRequestContext(); |
44 DCHECK(request_context); | 44 DCHECK(request_context); |
45 net::HttpNetworkSession::Params session_params; | 45 net::HttpNetworkSession::Params session_params; |
46 session_params.client_socket_factory = socket_factory; | 46 session_params.client_socket_factory = socket_factory; |
47 session_params.host_resolver = request_context->host_resolver(); | 47 session_params.host_resolver = request_context->host_resolver(); |
48 session_params.cert_verifier = request_context->cert_verifier(); | 48 session_params.cert_verifier = request_context->cert_verifier(); |
49 // TODO(rkn): This is NULL because OriginBoundCertService is not thread safe. | 49 // TODO(rkn): This is NULL because OriginBoundCertService is not thread safe. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 &pac_request_, | 110 &pac_request_, |
111 bound_net_log_); | 111 bound_net_log_); |
112 if (status != net::ERR_IO_PENDING) { | 112 if (status != net::ERR_IO_PENDING) { |
113 // We defer execution of ProcessProxyResolveDone instead of calling it | 113 // We defer execution of ProcessProxyResolveDone instead of calling it |
114 // directly here for simplicity. From the caller's point of view, | 114 // directly here for simplicity. From the caller's point of view, |
115 // the connect always happens asynchronously. | 115 // the connect always happens asynchronously. |
116 MessageLoop* message_loop = MessageLoop::current(); | 116 MessageLoop* message_loop = MessageLoop::current(); |
117 CHECK(message_loop); | 117 CHECK(message_loop); |
118 message_loop->PostTask( | 118 message_loop->PostTask( |
119 FROM_HERE, | 119 FROM_HERE, |
120 scoped_runnable_method_factory_.NewRunnableMethod( | 120 base::Bind(&ProxyResolvingClientSocket::ProcessProxyResolveDone, |
121 &ProxyResolvingClientSocket::ProcessProxyResolveDone, status)); | 121 weak_factory_.GetWeakPtr(), status)); |
122 } | 122 } |
123 user_connect_callback_ = callback; | 123 user_connect_callback_ = callback; |
124 return net::ERR_IO_PENDING; | 124 return net::ERR_IO_PENDING; |
125 } | 125 } |
126 | 126 |
127 void ProxyResolvingClientSocket::RunUserConnectCallback(int status) { | 127 void ProxyResolvingClientSocket::RunUserConnectCallback(int status) { |
128 DCHECK_LE(status, net::OK); | 128 DCHECK_LE(status, net::OK); |
129 net::OldCompletionCallback* user_connect_callback = user_connect_callback_; | 129 net::OldCompletionCallback* user_connect_callback = user_connect_callback_; |
130 user_connect_callback_ = NULL; | 130 user_connect_callback_ = NULL; |
131 user_connect_callback->Run(status); | 131 user_connect_callback->Run(status); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 } | 263 } |
264 | 264 |
265 // We either have new proxy info or there was an error in falling back. | 265 // We either have new proxy info or there was an error in falling back. |
266 // In both cases we want to post ProcessProxyResolveDone (in the error case | 266 // In both cases we want to post ProcessProxyResolveDone (in the error case |
267 // we might still want to fall back a direct connection). | 267 // we might still want to fall back a direct connection). |
268 if (rv != net::ERR_IO_PENDING) { | 268 if (rv != net::ERR_IO_PENDING) { |
269 MessageLoop* message_loop = MessageLoop::current(); | 269 MessageLoop* message_loop = MessageLoop::current(); |
270 CHECK(message_loop); | 270 CHECK(message_loop); |
271 message_loop->PostTask( | 271 message_loop->PostTask( |
272 FROM_HERE, | 272 FROM_HERE, |
273 scoped_runnable_method_factory_.NewRunnableMethod( | 273 base::Bind(&ProxyResolvingClientSocket::ProcessProxyResolveDone, |
274 &ProxyResolvingClientSocket::ProcessProxyResolveDone, rv)); | 274 weak_factory_.GetWeakPtr(), rv)); |
275 // Since we potentially have another try to go (trying the direct connect) | 275 // Since we potentially have another try to go (trying the direct connect) |
276 // set the return code code to ERR_IO_PENDING. | 276 // set the return code code to ERR_IO_PENDING. |
277 rv = net::ERR_IO_PENDING; | 277 rv = net::ERR_IO_PENDING; |
278 } | 278 } |
279 return rv; | 279 return rv; |
280 } | 280 } |
281 | 281 |
282 void ProxyResolvingClientSocket::ReportSuccessfulProxyConnection() { | 282 void ProxyResolvingClientSocket::ReportSuccessfulProxyConnection() { |
283 network_session_->proxy_service()->ReportSuccess(proxy_info_); | 283 network_session_->proxy_service()->ReportSuccess(proxy_info_); |
284 } | 284 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 return base::TimeDelta::FromMicroseconds(-1); | 367 return base::TimeDelta::FromMicroseconds(-1); |
368 } | 368 } |
369 | 369 |
370 void ProxyResolvingClientSocket::CloseTransportSocket() { | 370 void ProxyResolvingClientSocket::CloseTransportSocket() { |
371 if (transport_.get() && transport_->socket()) | 371 if (transport_.get() && transport_->socket()) |
372 transport_->socket()->Disconnect(); | 372 transport_->socket()->Disconnect(); |
373 transport_.reset(); | 373 transport_.reset(); |
374 } | 374 } |
375 | 375 |
376 } // namespace notifier | 376 } // namespace notifier |
OLD | NEW |