diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-17 21:39:16 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-17 21:39:16 +0000 |
commit | c5e7293b2ee5e90568ffa7ea67ba3ff361450659 (patch) | |
tree | 9874b3f5ef52c01cc9e5c62eb0786830a4a37014 /net/http/http_network_transaction.cc | |
parent | dd8ac359edca83603382f76c096b0cafbef93688 (diff) | |
download | chromium_src-c5e7293b2ee5e90568ffa7ea67ba3ff361450659.zip chromium_src-c5e7293b2ee5e90568ffa7ea67ba3ff361450659.tar.gz chromium_src-c5e7293b2ee5e90568ffa7ea67ba3ff361450659.tar.bz2 |
Revert "Revert "Add connected socket function to ClientSocketPool and ClientSocketHandle.""
This reverts commit c235c719f964cc8f7f9343177ae6d5af724be6c0.
Fixes a use of deleted memory by making a copy instead of keeping a reference to the deleted memory.
Review URL: http://codereview.chromium.org/113512
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16263 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_network_transaction.cc')
-rw-r--r-- | net/http/http_network_transaction.cc | 133 |
1 files changed, 30 insertions, 103 deletions
diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc index 99a02ba..159d07e 100644 --- a/net/http/http_network_transaction.cc +++ b/net/http/http_network_transaction.cc @@ -182,7 +182,7 @@ int HttpNetworkTransaction::RestartIgnoringLastError( if (connection_.socket()->IsConnected()) { next_state_ = STATE_WRITE_HEADERS; } else { - connection_.set_socket(NULL); + connection_.socket()->Disconnect(); connection_.Reset(); next_state_ = STATE_INIT_CONNECTION; } @@ -306,7 +306,7 @@ void HttpNetworkTransaction::DidDrainBodyForAuthRestart(bool keep_alive) { reused_socket_ = true; } else { next_state_ = STATE_INIT_CONNECTION; - connection_.set_socket(NULL); + connection_.socket()->Disconnect(); connection_.Reset(); } @@ -356,10 +356,8 @@ LoadState HttpNetworkTransaction::GetLoadState() const { switch (next_state_) { case STATE_RESOLVE_PROXY_COMPLETE: return LOAD_STATE_RESOLVING_PROXY_FOR_URL; - case STATE_RESOLVE_HOST_COMPLETE: - return LOAD_STATE_RESOLVING_HOST; - case STATE_TCP_CONNECT_COMPLETE: - return LOAD_STATE_CONNECTING; + case STATE_INIT_CONNECTION_COMPLETE: + return connection_.GetLoadState(); case STATE_WRITE_HEADERS_COMPLETE: case STATE_WRITE_BODY_COMPLETE: return LOAD_STATE_SENDING_REQUEST; @@ -380,10 +378,10 @@ uint64 HttpNetworkTransaction::GetUploadProgress() const { } HttpNetworkTransaction::~HttpNetworkTransaction() { - // If we still have an open socket, then make sure to close it so we don't - // try to reuse it later on. + // If we still have an open socket, then make sure to disconnect it so we + // don't try to reuse it later on. if (connection_.is_initialized()) - connection_.set_socket(NULL); + connection_.socket()->Disconnect(); if (pac_request_) session_->proxy_service()->CancelPacRequest(pac_request_); @@ -431,24 +429,6 @@ int HttpNetworkTransaction::DoLoop(int result) { rv = DoInitConnectionComplete(rv); TRACE_EVENT_END("http.init_conn", request_, request_->url.spec()); break; - case STATE_RESOLVE_HOST: - DCHECK_EQ(OK, rv); - TRACE_EVENT_BEGIN("http.resolve_host", request_, request_->url.spec()); - rv = DoResolveHost(); - break; - case STATE_RESOLVE_HOST_COMPLETE: - rv = DoResolveHostComplete(rv); - TRACE_EVENT_END("http.resolve_host", request_, request_->url.spec()); - break; - case STATE_TCP_CONNECT: - DCHECK_EQ(OK, rv); - TRACE_EVENT_BEGIN("http.connect", request_, request_->url.spec()); - rv = DoTCPConnect(); - break; - case STATE_TCP_CONNECT_COMPLETE: - rv = DoTCPConnectComplete(rv); - TRACE_EVENT_END("http.connect", request_, request_->url.spec()); - break; case STATE_SSL_CONNECT: DCHECK_EQ(OK, rv); TRACE_EVENT_BEGIN("http.ssl_connect", request_, request_->url.spec()); @@ -558,83 +538,41 @@ int HttpNetworkTransaction::DoInitConnection() { // Build the string used to uniquely identify connections of this type. std::string connection_group; - if (using_proxy_ || using_tunnel_) - connection_group = "proxy/" + proxy_info_.proxy_server().ToURI() + "/"; + std::string host; + int port; + if (using_proxy_ || using_tunnel_) { + ProxyServer proxy_server = proxy_info_.proxy_server(); + connection_group = "proxy/" + proxy_server.ToURI() + "/"; + host = proxy_server.HostNoBrackets(); + port = proxy_server.port(); + } else { + host = request_->url.HostNoBrackets(); + port = request_->url.EffectiveIntPort(); + } if (!using_proxy_) connection_group.append(request_->url.GetOrigin().spec()); DCHECK(!connection_group.empty()); - return connection_.Init(connection_group, request_->priority, &io_callback_); + int rv = connection_.Init(connection_group, host, port, request_->priority, + &io_callback_); + return rv; } int HttpNetworkTransaction::DoInitConnectionComplete(int result) { if (result < 0) - return result; + return ReconsiderProxyAfterError(result); DCHECK(connection_.is_initialized()); // Set the reused_socket_ flag to indicate that we are using a keep-alive // connection. This flag is used to handle errors that occur while we are // trying to reuse a keep-alive connection. - reused_socket_ = (connection_.socket() != NULL); + reused_socket_ = connection_.is_reused(); if (reused_socket_) { next_state_ = STATE_WRITE_HEADERS; } else { - next_state_ = STATE_RESOLVE_HOST; - } - return OK; -} - -int HttpNetworkTransaction::DoResolveHost() { - next_state_ = STATE_RESOLVE_HOST_COMPLETE; - - std::string host; - int port; - - // Determine the host and port to connect to. - if (using_proxy_ || using_tunnel_) { - ProxyServer proxy_server = proxy_info_.proxy_server(); - host = proxy_server.HostNoBrackets(); - port = proxy_server.port(); - } else { - // Direct connection - host = request_->url.HostNoBrackets(); - port = request_->url.EffectiveIntPort(); - } - - host_resolution_start_time_ = base::Time::Now(); - - DidStartDnsResolution(host, this); - return resolver_.Resolve(host, port, &addresses_, &io_callback_); -} - -int HttpNetworkTransaction::DoResolveHostComplete(int result) { - bool ok = (result == OK); - DidFinishDnsResolutionWithStatus(ok, request_->referrer, this); - if (ok) { - next_state_ = STATE_TCP_CONNECT; - } else { - result = ReconsiderProxyAfterError(result); - } - return result; -} - -int HttpNetworkTransaction::DoTCPConnect() { - next_state_ = STATE_TCP_CONNECT_COMPLETE; - - DCHECK(!connection_.socket()); - - connect_start_time_ = base::Time::Now(); - - ClientSocket* s = socket_factory_->CreateTCPClientSocket(addresses_); - connection_.set_socket(s); - return connection_.socket()->Connect(&io_callback_); -} - -int HttpNetworkTransaction::DoTCPConnectComplete(int result) { - // If we are using a direct SSL connection, then go ahead and establish the - // SSL connection, now. Otherwise, we need to first issue a CONNECT request. - if (result == OK) { + // Now we have a TCP connected socket. Perform other connection setup as + // needed. LogTCPConnectedMetrics(); if (using_ssl_ && !using_tunnel_) { next_state_ = STATE_SSL_CONNECT; @@ -643,10 +581,8 @@ int HttpNetworkTransaction::DoTCPConnectComplete(int result) { if (using_tunnel_) establishing_tunnel_ = true; } - } else { - result = ReconsiderProxyAfterError(result); } - return result; + return OK; } int HttpNetworkTransaction::DoSSLConnect() { @@ -947,7 +883,7 @@ int HttpNetworkTransaction::DoReadBodyComplete(int result) { if (done) { LogTransactionMetrics(); if (!keep_alive) - connection_.set_socket(NULL); + connection_.socket()->Disconnect(); connection_.Reset(); // The next Read call will return 0 (EOF). } @@ -1019,15 +955,6 @@ int HttpNetworkTransaction::DoDrainBodyForAuthRestartComplete(int result) { } void HttpNetworkTransaction::LogTCPConnectedMetrics() const { - DCHECK(connect_start_time_ != base::Time()); - base::TimeDelta connect_duration = - base::Time::Now() - connect_start_time_; - - UMA_HISTOGRAM_CLIPPED_TIMES(FieldTrial::MakeName( - "Net.TCP_Connection_Latency", "DnsImpact").data(), connect_duration, - base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromMinutes(10), - 100); - base::TimeDelta host_resolution_and_tcp_connection_latency = base::Time::Now() - host_resolution_start_time_; @@ -1300,7 +1227,7 @@ int HttpNetworkTransaction::HandleSSLHandshakeError(int error) { // This could be a TLS-intolerant server or an SSL 3.0 server that // chose a TLS-only cipher suite. Turn off TLS 1.0 and retry. ssl_config_.tls1_enabled = false; - connection_.set_socket(NULL); + connection_.socket()->Disconnect(); connection_.Reset(); next_state_ = STATE_INIT_CONNECTION; error = OK; @@ -1363,7 +1290,7 @@ bool HttpNetworkTransaction::ShouldResendRequest() const { } void HttpNetworkTransaction::ResetConnectionAndRequestForResend() { - connection_.set_socket(NULL); + connection_.socket()->Disconnect(); connection_.Reset(); // There are two reasons we need to clear request_headers_. 1) It contains // the real request headers, but we may need to resend the CONNECT request @@ -1408,7 +1335,7 @@ int HttpNetworkTransaction::ReconsiderProxyAfterError(int error) { int rv = session_->proxy_service()->ReconsiderProxyAfterError( request_->url, &proxy_info_, &io_callback_, &pac_request_); if (rv == OK || rv == ERR_IO_PENDING) { - connection_.set_socket(NULL); + connection_.socket()->Disconnect(); connection_.Reset(); DCHECK(!request_headers_bytes_sent_); next_state_ = STATE_RESOLVE_PROXY_COMPLETE; |