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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "net/quic/chromium/bidirectional_stream_quic_impl.h" 5 #include "net/quic/chromium/bidirectional_stream_quic_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 has_received_headers_ = true; 239 has_received_headers_ = true;
240 connect_timing_ = session_->GetConnectTiming(); 240 connect_timing_ = session_->GetConnectTiming();
241 if (delegate_) 241 if (delegate_)
242 delegate_->OnHeadersReceived(headers); 242 delegate_->OnHeadersReceived(headers);
243 } else { 243 } else {
244 if (stream_->IsDoneReading()) { 244 if (stream_->IsDoneReading()) {
245 // If the write side is closed, OnFinRead() will call 245 // If the write side is closed, OnFinRead() will call
246 // BidirectionalStreamQuicImpl::OnClose(). 246 // BidirectionalStreamQuicImpl::OnClose().
247 stream_->OnFinRead(); 247 stream_->OnFinRead();
248 } 248 }
249 if (delegate_) 249 if (!delegate_)
250 delegate_->OnTrailersReceived(headers); 250 return;
251 // Complete any remaining read. The task is posted because
252 // |delegate_|->OnTrailersReceived() might destroy |this|.
253 base::ThreadTaskRunnerHandle::Get()->PostTask(
254 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.
255 weak_factory_.GetWeakPtr(), 0));
256 delegate_->OnTrailersReceived(headers);
257 // |this| can be destroyed after this point.
251 } 258 }
252 } 259 }
253 260
254 void BidirectionalStreamQuicImpl::OnDataAvailable() { 261 void BidirectionalStreamQuicImpl::OnDataAvailable() {
255 // Return early if ReadData has not been called. 262 // Return early if ReadData has not been called.
256 if (!read_buffer_) 263 if (!read_buffer_)
257 return; 264 return;
258 265
259 CHECK(read_buffer_); 266 DCHECK(read_buffer_);
260 CHECK_NE(0, read_buffer_len_); 267 DCHECK_NE(0, read_buffer_len_);
261 int rv = ReadData(read_buffer_.get(), read_buffer_len_); 268 int rv = ReadData(read_buffer_.get(), read_buffer_len_);
262 if (rv == ERR_IO_PENDING) { 269 if (rv == ERR_IO_PENDING) {
263 // Spurrious notification. Wait for the next one. 270 // Spurrious notification. Wait for the next one.
264 return; 271 return;
265 } 272 }
266 read_buffer_ = nullptr; 273 NotifyDataRead(rv);
267 read_buffer_len_ = 0;
268 if (delegate_)
269 delegate_->OnDataRead(rv);
270 } 274 }
271 275
272 void BidirectionalStreamQuicImpl::OnClose() { 276 void BidirectionalStreamQuicImpl::OnClose() {
273 DCHECK(stream_); 277 DCHECK(stream_);
274 278
275 if (stream_->connection_error() == QUIC_NO_ERROR && 279 if (stream_->connection_error() == QUIC_NO_ERROR &&
276 stream_->stream_error() == QUIC_STREAM_NO_ERROR) { 280 stream_->stream_error() == QUIC_STREAM_NO_ERROR) {
277 ResetStream(); 281 ResetStream();
278 return; 282 return;
279 } 283 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 } 349 }
346 350
347 void BidirectionalStreamQuicImpl::NotifyStreamReady() { 351 void BidirectionalStreamQuicImpl::NotifyStreamReady() {
348 if (send_request_headers_automatically_) { 352 if (send_request_headers_automatically_) {
349 SendRequestHeaders(); 353 SendRequestHeaders();
350 } 354 }
351 if (delegate_) 355 if (delegate_)
352 delegate_->OnStreamReady(has_sent_headers_); 356 delegate_->OnStreamReady(has_sent_headers_);
353 } 357 }
354 358
359 void BidirectionalStreamQuicImpl::NotifyDataRead(int bytes_read) {
360 if (!read_buffer_) {
361 return;
362 }
363 read_buffer_ = nullptr;
364 read_buffer_len_ = 0;
365 if (delegate_)
366 delegate_->OnDataRead(bytes_read);
367 }
368
355 void BidirectionalStreamQuicImpl::ResetStream() { 369 void BidirectionalStreamQuicImpl::ResetStream() {
356 if (!stream_) 370 if (!stream_)
357 return; 371 return;
358 closed_stream_received_bytes_ = stream_->stream_bytes_read(); 372 closed_stream_received_bytes_ = stream_->stream_bytes_read();
359 closed_stream_sent_bytes_ = stream_->stream_bytes_written(); 373 closed_stream_sent_bytes_ = stream_->stream_bytes_written();
360 closed_is_first_stream_ = stream_->IsFirstStream(); 374 closed_is_first_stream_ = stream_->IsFirstStream();
361 stream_->SetDelegate(nullptr); 375 stream_->SetDelegate(nullptr);
362 stream_ = nullptr; 376 stream_ = nullptr;
363 } 377 }
364 378
365 } // namespace net 379 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698