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

Unified Diff: net/http/bidirectional_stream.cc

Issue 2043863002: Use WeakPtrFactory in net::BidirectionalStream when posting task (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Matt's comments Created 4 years, 6 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/http/bidirectional_stream.h ('k') | net/http/bidirectional_stream_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « net/http/bidirectional_stream.h ('k') | net/http/bidirectional_stream_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698