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

Side by Side Diff: net/quic/chromium/bidirectional_stream_quic_impl.cc

Issue 2900533002: Add an async ReadTrailers method to QuicChromiumClientStream::Handle (Closed)
Patch Set: Fix comments Created 3 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 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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 is_first_stream = stream_->IsFirstStream(); 225 is_first_stream = stream_->IsFirstStream();
226 if (is_first_stream) { 226 if (is_first_stream) {
227 load_timing_info->socket_reused = false; 227 load_timing_info->socket_reused = false;
228 load_timing_info->connect_timing = connect_timing_; 228 load_timing_info->connect_timing = connect_timing_;
229 } else { 229 } else {
230 load_timing_info->socket_reused = true; 230 load_timing_info->socket_reused = true;
231 } 231 }
232 return true; 232 return true;
233 } 233 }
234 234
235 void BidirectionalStreamQuicImpl::OnTrailingHeadersAvailable(
236 const SpdyHeaderBlock& headers,
237 size_t frame_len) {
238 headers_bytes_received_ += frame_len;
239 if (delegate_)
240 delegate_->OnTrailersReceived(headers);
241 // |this| can be destroyed after this point.
242 }
243
244 void BidirectionalStreamQuicImpl::OnClose() { 235 void BidirectionalStreamQuicImpl::OnClose() {
245 DCHECK(stream_); 236 DCHECK(stream_);
246 237
247 if (stream_->connection_error() != QUIC_NO_ERROR || 238 if (stream_->connection_error() != QUIC_NO_ERROR ||
248 stream_->stream_error() != QUIC_STREAM_NO_ERROR) { 239 stream_->stream_error() != QUIC_STREAM_NO_ERROR) {
249 NotifyError(session_->IsCryptoHandshakeConfirmed() 240 NotifyError(session_->IsCryptoHandshakeConfirmed()
250 ? ERR_QUIC_PROTOCOL_ERROR 241 ? ERR_QUIC_PROTOCOL_ERROR
251 : ERR_QUIC_HANDSHAKE_FAILED); 242 : ERR_QUIC_HANDSHAKE_FAILED);
252 return; 243 return;
253 } 244 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 void BidirectionalStreamQuicImpl::OnReadInitialHeadersComplete(int rv) { 292 void BidirectionalStreamQuicImpl::OnReadInitialHeadersComplete(int rv) {
302 DCHECK_NE(ERR_IO_PENDING, rv); 293 DCHECK_NE(ERR_IO_PENDING, rv);
303 if (rv < 0) { 294 if (rv < 0) {
304 NotifyError(rv); 295 NotifyError(rv);
305 return; 296 return;
306 } 297 }
307 298
308 headers_bytes_received_ += rv; 299 headers_bytes_received_ += rv;
309 negotiated_protocol_ = kProtoQUIC; 300 negotiated_protocol_ = kProtoQUIC;
310 connect_timing_ = session_->GetConnectTiming(); 301 connect_timing_ = session_->GetConnectTiming();
302 base::ThreadTaskRunnerHandle::Get()->PostTask(
303 FROM_HERE, base::Bind(&BidirectionalStreamQuicImpl::ReadTrailingHeaders,
304 weak_factory_.GetWeakPtr()));
311 if (delegate_) 305 if (delegate_)
312 delegate_->OnHeadersReceived(initial_headers_); 306 delegate_->OnHeadersReceived(initial_headers_);
313 } 307 }
314 308
309 void BidirectionalStreamQuicImpl::ReadTrailingHeaders() {
310 int rv = stream_->ReadTrailingHeaders(
311 &trailing_headers_,
312 base::Bind(&BidirectionalStreamQuicImpl::OnReadTrailingHeadersComplete,
313 weak_factory_.GetWeakPtr()));
314
315 if (rv != ERR_IO_PENDING)
316 OnReadTrailingHeadersComplete(rv);
317 }
318
319 void BidirectionalStreamQuicImpl::OnReadTrailingHeadersComplete(int rv) {
320 DCHECK_NE(ERR_IO_PENDING, rv);
321 if (rv < 0) {
322 NotifyError(rv);
323 return;
324 }
325
326 headers_bytes_received_ += rv;
327
328 if (delegate_)
329 delegate_->OnTrailersReceived(trailing_headers_);
330 }
331
315 void BidirectionalStreamQuicImpl::OnReadDataComplete(int rv) { 332 void BidirectionalStreamQuicImpl::OnReadDataComplete(int rv) {
316 DCHECK_GE(rv, 0); 333 DCHECK_GE(rv, 0);
317 read_buffer_ = nullptr; 334 read_buffer_ = nullptr;
318 read_buffer_len_ = 0; 335 read_buffer_len_ = 0;
319 336
320 if (stream_->IsDoneReading()) { 337 if (stream_->IsDoneReading()) {
321 // If the write side is closed, OnFinRead() will call 338 // If the write side is closed, OnFinRead() will call
322 // BidirectionalStreamQuicImpl::OnClose(). 339 // BidirectionalStreamQuicImpl::OnClose().
323 stream_->OnFinRead(); 340 stream_->OnFinRead();
324 } 341 }
(...skipping 30 matching lines...) Expand all
355 if (!stream_) 372 if (!stream_)
356 return; 373 return;
357 closed_stream_received_bytes_ = stream_->stream_bytes_read(); 374 closed_stream_received_bytes_ = stream_->stream_bytes_read();
358 closed_stream_sent_bytes_ = stream_->stream_bytes_written(); 375 closed_stream_sent_bytes_ = stream_->stream_bytes_written();
359 closed_is_first_stream_ = stream_->IsFirstStream(); 376 closed_is_first_stream_ = stream_->IsFirstStream();
360 stream_->ClearDelegate(); 377 stream_->ClearDelegate();
361 stream_ = nullptr; 378 stream_ = nullptr;
362 } 379 }
363 380
364 } // namespace net 381 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/chromium/bidirectional_stream_quic_impl.h ('k') | net/quic/chromium/bidirectional_stream_quic_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698