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

Unified Diff: net/quic/chromium/bidirectional_stream_quic_impl.cc

Issue 2393233002: Remove OnDataAvailable() notification when trailers are to be delivered (Closed)
Patch Set: self review Created 4 years, 2 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
Index: net/quic/chromium/bidirectional_stream_quic_impl.cc
diff --git a/net/quic/chromium/bidirectional_stream_quic_impl.cc b/net/quic/chromium/bidirectional_stream_quic_impl.cc
index 7645f8a36b0ed0071c90163eb8ae7e8fbdb5b85d..36e45b9c3a50024c0b3a5b3672ba765392423d91 100644
--- a/net/quic/chromium/bidirectional_stream_quic_impl.cc
+++ b/net/quic/chromium/bidirectional_stream_quic_impl.cc
@@ -246,8 +246,15 @@ void BidirectionalStreamQuicImpl::OnHeadersAvailable(
// BidirectionalStreamQuicImpl::OnClose().
stream_->OnFinRead();
}
- if (delegate_)
- delegate_->OnTrailersReceived(headers);
+ if (!delegate_)
+ return;
+ // Complete any remaining read. The task is posted because
+ // |delegate_|->OnTrailersReceived() might destroy |this|.
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(&BidirectionalStreamQuicImpl::NotifyDataRead,
mef 2016/10/05 17:58:42 Is this right thing to do? What if there is a lot
xunjieli 2016/10/05 18:10:30 Ah, that's right. Thanks for catching this! Done.
+ weak_factory_.GetWeakPtr(), 0));
+ delegate_->OnTrailersReceived(headers);
+ // |this| can be destroyed after this point.
}
}
@@ -256,17 +263,14 @@ void BidirectionalStreamQuicImpl::OnDataAvailable() {
if (!read_buffer_)
return;
- CHECK(read_buffer_);
- CHECK_NE(0, read_buffer_len_);
+ DCHECK(read_buffer_);
+ DCHECK_NE(0, read_buffer_len_);
int rv = ReadData(read_buffer_.get(), read_buffer_len_);
if (rv == ERR_IO_PENDING) {
// Spurrious notification. Wait for the next one.
return;
}
- read_buffer_ = nullptr;
- read_buffer_len_ = 0;
- if (delegate_)
- delegate_->OnDataRead(rv);
+ NotifyDataRead(rv);
}
void BidirectionalStreamQuicImpl::OnClose() {
@@ -352,6 +356,16 @@ void BidirectionalStreamQuicImpl::NotifyStreamReady() {
delegate_->OnStreamReady(has_sent_headers_);
}
+void BidirectionalStreamQuicImpl::NotifyDataRead(int bytes_read) {
+ if (!read_buffer_) {
+ return;
+ }
+ read_buffer_ = nullptr;
+ read_buffer_len_ = 0;
+ if (delegate_)
+ delegate_->OnDataRead(bytes_read);
+}
+
void BidirectionalStreamQuicImpl::ResetStream() {
if (!stream_)
return;

Powered by Google App Engine
This is Rietveld 408576698