Index: net/http/bidirectional_stream.cc |
diff --git a/net/http/bidirectional_stream.cc b/net/http/bidirectional_stream.cc |
index 9bf1c4886321494a00d05b97739a43b53de6f2c5..12aa0f63fe1587411d9efff1680c93d38588cc1e 100644 |
--- a/net/http/bidirectional_stream.cc |
+++ b/net/http/bidirectional_stream.cc |
@@ -85,7 +85,8 @@ BidirectionalStream::BidirectionalStream( |
send_request_headers_automatically_(send_request_headers_automatically), |
request_headers_sent_(false), |
delegate_(delegate), |
- timer_(std::move(timer)) { |
+ timer_(std::move(timer)), |
+ weak_factory_(this) { |
DCHECK(delegate_); |
DCHECK(request_info_); |
@@ -104,8 +105,8 @@ BidirectionalStream::BidirectionalStream( |
if (!request_info_->url.SchemeIs(url::kHttpsScheme)) { |
base::ThreadTaskRunnerHandle::Get()->PostTask( |
FROM_HERE, |
- base::Bind(&BidirectionalStream::Delegate::OnFailed, |
- base::Unretained(delegate_), ERR_DISALLOWED_URL_SCHEME)); |
+ base::Bind(&BidirectionalStream::NotifyFailed, |
+ weak_factory_.GetWeakPtr(), ERR_DISALLOWED_URL_SCHEME)); |
return; |
} |
@@ -220,7 +221,7 @@ void BidirectionalStream::OnHeadersReceived( |
HttpResponseInfo response_info; |
if (!SpdyHeadersToHttpResponse(response_headers, HTTP2, &response_info)) { |
DLOG(WARNING) << "Invalid headers"; |
- delegate_->OnFailed(ERR_FAILED); |
+ NotifyFailed(ERR_FAILED); |
return; |
} |
if (net_log_.IsCapturing()) { |
@@ -270,7 +271,7 @@ void BidirectionalStream::OnTrailersReceived(const SpdyHeaderBlock& trailers) { |
} |
void BidirectionalStream::OnFailed(int status) { |
- delegate_->OnFailed(status); |
+ NotifyFailed(status); |
} |
void BidirectionalStream::OnStreamReady(const SSLConfig& used_ssl_config, |
@@ -306,7 +307,7 @@ void BidirectionalStream::OnStreamFailed(int result, |
DCHECK_NE(result, ERR_IO_PENDING); |
DCHECK(stream_request_); |
- delegate_->OnFailed(result); |
+ NotifyFailed(result); |
} |
void BidirectionalStream::OnCertificateError(int result, |
@@ -316,7 +317,7 @@ void BidirectionalStream::OnCertificateError(int result, |
DCHECK_NE(result, ERR_IO_PENDING); |
DCHECK(stream_request_); |
- delegate_->OnFailed(result); |
+ NotifyFailed(result); |
} |
void BidirectionalStream::OnNeedsProxyAuth( |
@@ -326,14 +327,14 @@ void BidirectionalStream::OnNeedsProxyAuth( |
HttpAuthController* auth_controller) { |
DCHECK(stream_request_); |
- delegate_->OnFailed(ERR_PROXY_AUTH_REQUESTED); |
+ NotifyFailed(ERR_PROXY_AUTH_REQUESTED); |
} |
void BidirectionalStream::OnNeedsClientAuth(const SSLConfig& used_ssl_config, |
SSLCertRequestInfo* cert_info) { |
DCHECK(stream_request_); |
- delegate_->OnFailed(ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
+ NotifyFailed(ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
} |
void BidirectionalStream::OnHttpsProxyTunnelResponse( |
@@ -343,9 +344,13 @@ void BidirectionalStream::OnHttpsProxyTunnelResponse( |
HttpStream* stream) { |
DCHECK(stream_request_); |
- delegate_->OnFailed(ERR_HTTPS_PROXY_TUNNEL_RESPONSE); |
+ NotifyFailed(ERR_HTTPS_PROXY_TUNNEL_RESPONSE); |
} |
void BidirectionalStream::OnQuicBroken() {} |
+void BidirectionalStream::NotifyFailed(int error) { |
+ delegate_->OnFailed(error); |
+} |
+ |
} // namespace net |