OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/spdy/spdy_http_stream.h" | 5 #include "net/spdy/spdy_http_stream.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <list> | 8 #include <list> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 void SpdyHttpStream::Cancel() { | 295 void SpdyHttpStream::Cancel() { |
296 request_callback_.Reset(); | 296 request_callback_.Reset(); |
297 response_callback_.Reset(); | 297 response_callback_.Reset(); |
298 if (stream_.get()) { | 298 if (stream_.get()) { |
299 stream_->Cancel(); | 299 stream_->Cancel(); |
300 DCHECK(!stream_.get()); | 300 DCHECK(!stream_.get()); |
301 } | 301 } |
302 } | 302 } |
303 | 303 |
304 void SpdyHttpStream::OnRequestHeadersSent() { | 304 void SpdyHttpStream::OnRequestHeadersSent() { |
305 if (!request_callback_.is_null()) | 305 if (!request_callback_.is_null()) { |
306 // Avoid reseting the callback as long as it is used on errors in | |
307 // OnRequestBodyReadCompleted() method. | |
mmenke
2016/06/01 17:24:07
We should not be invoking the callback twice, unde
maksims (do not use this acc)
2016/06/03 11:39:08
Done.
| |
308 const CompletionCallback cb = request_callback_; | |
306 DoRequestCallback(OK); | 309 DoRequestCallback(OK); |
310 request_callback_ = cb; | |
311 } | |
307 | 312 |
308 // TODO(akalin): Do this immediately after sending the request | 313 // TODO(akalin): Do this immediately after sending the request |
309 // headers. | 314 // headers. |
310 if (HasUploadData()) | 315 if (HasUploadData()) |
311 ReadAndSendRequestBodyData(); | 316 ReadAndSendRequestBodyData(); |
312 } | 317 } |
313 | 318 |
314 SpdyResponseHeadersStatus SpdyHttpStream::OnResponseHeadersUpdated( | 319 SpdyResponseHeadersStatus SpdyHttpStream::OnResponseHeadersUpdated( |
315 const SpdyHeaderBlock& response_headers) { | 320 const SpdyHeaderBlock& response_headers) { |
316 CHECK_EQ(response_headers_status_, RESPONSE_HEADERS_ARE_INCOMPLETE); | 321 CHECK_EQ(response_headers_status_, RESPONSE_HEADERS_ARE_INCOMPLETE); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
441 return; | 446 return; |
442 | 447 |
443 // Read the data from the request body stream. | 448 // Read the data from the request body stream. |
444 const int rv = request_info_->upload_data_stream | 449 const int rv = request_info_->upload_data_stream |
445 ->Read(request_body_buf_.get(), | 450 ->Read(request_body_buf_.get(), |
446 request_body_buf_->size(), | 451 request_body_buf_->size(), |
447 base::Bind(&SpdyHttpStream::OnRequestBodyReadCompleted, | 452 base::Bind(&SpdyHttpStream::OnRequestBodyReadCompleted, |
448 weak_factory_.GetWeakPtr())); | 453 weak_factory_.GetWeakPtr())); |
449 | 454 |
450 if (rv != ERR_IO_PENDING) { | 455 if (rv != ERR_IO_PENDING) { |
451 // ERR_IO_PENDING is the only possible error. | 456 // UploadDataStream::Read() can fail reading data |
452 CHECK_GE(rv, 0); | |
453 OnRequestBodyReadCompleted(rv); | 457 OnRequestBodyReadCompleted(rv); |
454 } | 458 } |
455 } | 459 } |
456 | 460 |
461 void SpdyHttpStream::ResetStreamInternal() { | |
462 spdy_session_->ResetStream(stream()->stream_id(), RST_STREAM_INTERNAL_ERROR, | |
463 std::string()); | |
464 } | |
465 | |
457 void SpdyHttpStream::OnRequestBodyReadCompleted(int status) { | 466 void SpdyHttpStream::OnRequestBodyReadCompleted(int status) { |
467 if (status < 0) { | |
468 DCHECK_NE(ERR_IO_PENDING, status); | |
469 if (!request_callback_.is_null()) { | |
470 DoRequestCallback(status); | |
471 } | |
472 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
473 FROM_HERE, base::Bind(&SpdyHttpStream::ResetStreamInternal, | |
474 weak_factory_.GetWeakPtr())); | |
mmenke
2016/06/01 17:24:07
Should do this first - invoking |request_callback_
maksims (do not use this acc)
2016/06/02 12:43:12
Do you mean -
base::WeakPtr<SpdyHttpStream> weak_p
mmenke
2016/06/02 15:02:10
No, I mean do the PostTask to reset the stream, an
maksims (do not use this acc)
2016/06/03 11:39:08
Done.
| |
475 return; | |
476 } | |
477 | |
458 CHECK_GE(status, 0); | 478 CHECK_GE(status, 0); |
459 request_body_buf_size_ = status; | 479 request_body_buf_size_ = status; |
460 const bool eof = request_info_->upload_data_stream->IsEOF(); | 480 const bool eof = request_info_->upload_data_stream->IsEOF(); |
461 // Only the final fame may have a length of 0. | 481 // Only the final fame may have a length of 0. |
462 if (eof) { | 482 if (eof) { |
463 CHECK_GE(request_body_buf_size_, 0); | 483 CHECK_GE(request_body_buf_size_, 0); |
464 } else { | 484 } else { |
465 CHECK_GT(request_body_buf_size_, 0); | 485 CHECK_GT(request_body_buf_size_, 0); |
466 } | 486 } |
467 stream_->SendData(request_body_buf_.get(), | 487 stream_->SendData(request_body_buf_.get(), |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
584 details->connection_info = HttpResponseInfo::CONNECTION_INFO_HTTP2; | 604 details->connection_info = HttpResponseInfo::CONNECTION_INFO_HTTP2; |
585 return; | 605 return; |
586 } | 606 } |
587 | 607 |
588 void SpdyHttpStream::SetPriority(RequestPriority priority) { | 608 void SpdyHttpStream::SetPriority(RequestPriority priority) { |
589 // TODO(akalin): Plumb this through to |stream_request_| and | 609 // TODO(akalin): Plumb this through to |stream_request_| and |
590 // |stream_|. | 610 // |stream_|. |
591 } | 611 } |
592 | 612 |
593 } // namespace net | 613 } // namespace net |
OLD | NEW |