Chromium Code Reviews| 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/bind.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 &ProxyResolvingClientSocket::ProcessConnectDone), | 30 &ProxyResolvingClientSocket::ProcessConnectDone), |
| 31 ssl_config_(ssl_config), | 31 ssl_config_(ssl_config), |
| 32 pac_request_(NULL), | 32 pac_request_(NULL), |
| 33 dest_host_port_pair_(dest_host_port_pair), | 33 dest_host_port_pair_(dest_host_port_pair), |
| 34 tried_direct_connect_fallback_(false), | 34 tried_direct_connect_fallback_(false), |
| 35 bound_net_log_( | 35 bound_net_log_( |
| 36 net::BoundNetLog::Make( | 36 net::BoundNetLog::Make( |
| 37 request_context_getter->GetURLRequestContext()->net_log(), | 37 request_context_getter->GetURLRequestContext()->net_log(), |
| 38 net::NetLog::SOURCE_SOCKET)), | 38 net::NetLog::SOURCE_SOCKET)), |
| 39 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 39 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
| 40 user_connect_callback_(NULL) { | 40 old_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. |
| 50 session_params.origin_bound_cert_service = NULL; | 50 session_params.origin_bound_cert_service = NULL; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 } | 90 } |
| 91 | 91 |
| 92 bool ProxyResolvingClientSocket::SetSendBufferSize(int32 size) { | 92 bool ProxyResolvingClientSocket::SetSendBufferSize(int32 size) { |
| 93 if (transport_.get() && transport_->socket()) | 93 if (transport_.get() && transport_->socket()) |
| 94 return transport_->socket()->SetSendBufferSize(size); | 94 return transport_->socket()->SetSendBufferSize(size); |
| 95 NOTREACHED(); | 95 NOTREACHED(); |
| 96 return false; | 96 return false; |
| 97 } | 97 } |
| 98 | 98 |
| 99 int ProxyResolvingClientSocket::Connect(net::OldCompletionCallback* callback) { | 99 int ProxyResolvingClientSocket::Connect(net::OldCompletionCallback* callback) { |
| 100 DCHECK(!user_connect_callback_); | 100 DCHECK(!old_user_connect_callback_); |
|
csilv
2011/12/06 21:03:18
Perhaps this DCHECK should be the same as the one
James Hawkins
2011/12/06 22:19:30
Done.
| |
| 101 | 101 |
| 102 tried_direct_connect_fallback_ = false; | 102 tried_direct_connect_fallback_ = false; |
| 103 | 103 |
| 104 // First we try and resolve the proxy. | |
| 105 GURL url("http://" + dest_host_port_pair_.ToString()); | |
| 106 int status = network_session_->proxy_service()->ResolveProxy( | |
| 107 url, | |
| 108 &proxy_info_, | |
| 109 &proxy_resolve_callback_, | |
| 110 &pac_request_, | |
| 111 bound_net_log_); | |
| 112 if (status != net::ERR_IO_PENDING) { | |
| 113 // We defer execution of ProcessProxyResolveDone instead of calling it | |
| 114 // directly here for simplicity. From the caller's point of view, | |
| 115 // the connect always happens asynchronously. | |
| 116 MessageLoop* message_loop = MessageLoop::current(); | |
| 117 CHECK(message_loop); | |
| 118 message_loop->PostTask( | |
| 119 FROM_HERE, | |
| 120 base::Bind(&ProxyResolvingClientSocket::ProcessProxyResolveDone, | |
| 121 weak_factory_.GetWeakPtr(), status)); | |
| 122 } | |
| 123 old_user_connect_callback_ = callback; | |
| 124 return net::ERR_IO_PENDING; | |
| 125 } | |
| 126 int ProxyResolvingClientSocket::Connect( | |
| 127 const net::CompletionCallback& callback) { | |
| 128 DCHECK(!old_user_connect_callback_ && user_connect_callback_.is_null()); | |
| 129 | |
| 130 tried_direct_connect_fallback_ = false; | |
| 131 | |
| 104 // First we try and resolve the proxy. | 132 // First we try and resolve the proxy. |
| 105 GURL url("http://" + dest_host_port_pair_.ToString()); | 133 GURL url("http://" + dest_host_port_pair_.ToString()); |
| 106 int status = network_session_->proxy_service()->ResolveProxy( | 134 int status = network_session_->proxy_service()->ResolveProxy( |
| 107 url, | 135 url, |
| 108 &proxy_info_, | 136 &proxy_info_, |
| 109 &proxy_resolve_callback_, | 137 &proxy_resolve_callback_, |
| 110 &pac_request_, | 138 &pac_request_, |
| 111 bound_net_log_); | 139 bound_net_log_); |
| 112 if (status != net::ERR_IO_PENDING) { | 140 if (status != net::ERR_IO_PENDING) { |
| 113 // We defer execution of ProcessProxyResolveDone instead of calling it | 141 // We defer execution of ProcessProxyResolveDone instead of calling it |
| 114 // directly here for simplicity. From the caller's point of view, | 142 // directly here for simplicity. From the caller's point of view, |
| 115 // the connect always happens asynchronously. | 143 // the connect always happens asynchronously. |
| 116 MessageLoop* message_loop = MessageLoop::current(); | 144 MessageLoop* message_loop = MessageLoop::current(); |
| 117 CHECK(message_loop); | 145 CHECK(message_loop); |
| 118 message_loop->PostTask( | 146 message_loop->PostTask( |
| 119 FROM_HERE, | 147 FROM_HERE, |
| 120 base::Bind(&ProxyResolvingClientSocket::ProcessProxyResolveDone, | 148 base::Bind(&ProxyResolvingClientSocket::ProcessProxyResolveDone, |
| 121 weak_factory_.GetWeakPtr(), status)); | 149 weak_factory_.GetWeakPtr(), status)); |
| 122 } | 150 } |
| 123 user_connect_callback_ = callback; | 151 user_connect_callback_ = callback; |
| 124 return net::ERR_IO_PENDING; | 152 return net::ERR_IO_PENDING; |
| 125 } | 153 } |
| 126 | 154 |
| 127 void ProxyResolvingClientSocket::RunUserConnectCallback(int status) { | 155 void ProxyResolvingClientSocket::RunUserConnectCallback(int status) { |
| 128 DCHECK_LE(status, net::OK); | 156 DCHECK_LE(status, net::OK); |
| 129 net::OldCompletionCallback* user_connect_callback = user_connect_callback_; | 157 if (old_user_connect_callback_) { |
| 130 user_connect_callback_ = NULL; | 158 net::OldCompletionCallback* user_connect_callback = |
| 131 user_connect_callback->Run(status); | 159 old_user_connect_callback_; |
| 160 old_user_connect_callback_ = NULL; | |
| 161 user_connect_callback->Run(status); | |
| 162 } else { | |
| 163 net::CompletionCallback user_connect_callback = user_connect_callback_; | |
| 164 user_connect_callback_.Reset(); | |
| 165 user_connect_callback.Run(status); | |
| 166 } | |
| 132 } | 167 } |
| 133 | 168 |
| 134 // Always runs asynchronously. | 169 // Always runs asynchronously. |
| 135 void ProxyResolvingClientSocket::ProcessProxyResolveDone(int status) { | 170 void ProxyResolvingClientSocket::ProcessProxyResolveDone(int status) { |
| 136 pac_request_ = NULL; | 171 pac_request_ = NULL; |
| 137 | 172 |
| 138 DCHECK_NE(status, net::ERR_IO_PENDING); | 173 DCHECK_NE(status, net::ERR_IO_PENDING); |
| 139 if (status == net::OK) { | 174 if (status == net::OK) { |
| 140 // Remove unsupported proxies from the list. | 175 // Remove unsupported proxies from the list. |
| 141 proxy_info_.RemoveProxiesWithoutScheme( | 176 proxy_info_.RemoveProxiesWithoutScheme( |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 } | 315 } |
| 281 | 316 |
| 282 void ProxyResolvingClientSocket::ReportSuccessfulProxyConnection() { | 317 void ProxyResolvingClientSocket::ReportSuccessfulProxyConnection() { |
| 283 network_session_->proxy_service()->ReportSuccess(proxy_info_); | 318 network_session_->proxy_service()->ReportSuccess(proxy_info_); |
| 284 } | 319 } |
| 285 | 320 |
| 286 void ProxyResolvingClientSocket::Disconnect() { | 321 void ProxyResolvingClientSocket::Disconnect() { |
| 287 CloseTransportSocket(); | 322 CloseTransportSocket(); |
| 288 if (pac_request_) | 323 if (pac_request_) |
| 289 network_session_->proxy_service()->CancelPacRequest(pac_request_); | 324 network_session_->proxy_service()->CancelPacRequest(pac_request_); |
| 290 user_connect_callback_ = NULL; | 325 old_user_connect_callback_ = NULL; |
| 326 user_connect_callback_.Reset(); | |
| 291 } | 327 } |
| 292 | 328 |
| 293 bool ProxyResolvingClientSocket::IsConnected() const { | 329 bool ProxyResolvingClientSocket::IsConnected() const { |
| 294 if (!transport_.get() || !transport_->socket()) | 330 if (!transport_.get() || !transport_->socket()) |
| 295 return false; | 331 return false; |
| 296 return transport_->socket()->IsConnected(); | 332 return transport_->socket()->IsConnected(); |
| 297 } | 333 } |
| 298 | 334 |
| 299 bool ProxyResolvingClientSocket::IsConnectedAndIdle() const { | 335 bool ProxyResolvingClientSocket::IsConnectedAndIdle() const { |
| 300 if (!transport_.get() || !transport_->socket()) | 336 if (!transport_.get() || !transport_->socket()) |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 return base::TimeDelta::FromMicroseconds(-1); | 403 return base::TimeDelta::FromMicroseconds(-1); |
| 368 } | 404 } |
| 369 | 405 |
| 370 void ProxyResolvingClientSocket::CloseTransportSocket() { | 406 void ProxyResolvingClientSocket::CloseTransportSocket() { |
| 371 if (transport_.get() && transport_->socket()) | 407 if (transport_.get() && transport_->socket()) |
| 372 transport_->socket()->Disconnect(); | 408 transport_->socket()->Disconnect(); |
| 373 transport_.reset(); | 409 transport_.reset(); |
| 374 } | 410 } |
| 375 | 411 |
| 376 } // namespace notifier | 412 } // namespace notifier |
| OLD | NEW |