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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 | 92 |
93 if (rv == OK) { | 93 if (rv == OK) { |
94 stream_ = stream_request_.ReleaseStream(); | 94 stream_ = stream_request_.ReleaseStream(); |
95 InitializeStreamHelper(); | 95 InitializeStreamHelper(); |
96 } | 96 } |
97 | 97 |
98 return rv; | 98 return rv; |
99 } | 99 } |
100 | 100 |
101 UploadProgress SpdyHttpStream::GetUploadProgress() const { | 101 UploadProgress SpdyHttpStream::GetUploadProgress() const { |
102 if (!request_info_ || !HasUploadData()) | 102 if (!request_info_) |
103 return upload_progress_; | |
mmenke
2016/08/31 21:57:59
Hrm...I wonder about all this UploadProgress plumb
shivanisha
2016/09/01 20:30:59
Why do we even need to go to the URLRequestJob, Ht
shivanisha
2016/09/01 20:32:12
Ah ok, I see your concerns about rewinding the str
shivanisha
2016/09/08 20:43:54
Removed all the plumbing for getting upload progre
| |
104 | |
105 if (!HasUploadData()) | |
103 return UploadProgress(); | 106 return UploadProgress(); |
104 | 107 |
105 return UploadProgress(request_info_->upload_data_stream->position(), | 108 return UploadProgress(request_info_->upload_data_stream->position(), |
106 request_info_->upload_data_stream->size()); | 109 request_info_->upload_data_stream->size()); |
107 } | 110 } |
108 | 111 |
109 int SpdyHttpStream::ReadResponseHeaders(const CompletionCallback& callback) { | 112 int SpdyHttpStream::ReadResponseHeaders(const CompletionCallback& callback) { |
110 CHECK(!callback.is_null()); | 113 CHECK(!callback.is_null()); |
111 if (stream_closed_) | 114 if (stream_closed_) |
112 return closed_stream_status_; | 115 return closed_stream_status_; |
113 | 116 |
114 CHECK(stream_.get()); | 117 CHECK(stream_.get()); |
115 | 118 |
116 // Check if we already have the response headers. If so, return synchronously. | 119 // Check if we already have the response headers. If so, return synchronously. |
117 if (response_headers_status_ == RESPONSE_HEADERS_ARE_COMPLETE) { | 120 if (response_headers_status_ == RESPONSE_HEADERS_ARE_COMPLETE) { |
118 CHECK(!stream_->IsIdle()); | 121 CHECK(!stream_->IsIdle()); |
119 return OK; | 122 return OK; |
120 } | 123 } |
121 | 124 |
122 // Still waiting for the response, return IO_PENDING. | 125 // Still waiting for the response, return IO_PENDING. |
123 CHECK(response_callback_.is_null()); | 126 CHECK(response_callback_.is_null()); |
124 response_callback_ = callback; | 127 response_callback_ = callback; |
125 return ERR_IO_PENDING; | 128 return ERR_IO_PENDING; |
126 } | 129 } |
127 | 130 |
128 int SpdyHttpStream::ReadResponseBody( | 131 int SpdyHttpStream::ReadResponseBody( |
129 IOBuffer* buf, int buf_len, const CompletionCallback& callback) { | 132 IOBuffer* buf, int buf_len, const CompletionCallback& callback) { |
133 // Invalidate HttpRequestInfo pointer. This is to allow the stream to be | |
134 // shared across multiple HttpCache::Transactions which might require this | |
135 // stream to outlive the request_'s owner URLRequestHttpJob. | |
136 if (request_info_) | |
137 ResetRequestInfo(); | |
138 | |
130 if (stream_.get()) | 139 if (stream_.get()) |
131 CHECK(!stream_->IsIdle()); | 140 CHECK(!stream_->IsIdle()); |
132 | 141 |
133 CHECK(buf); | 142 CHECK(buf); |
134 CHECK(buf_len); | 143 CHECK(buf_len); |
135 CHECK(!callback.is_null()); | 144 CHECK(!callback.is_null()); |
136 | 145 |
137 // If we have data buffered, complete the IO immediately. | 146 // If we have data buffered, complete the IO immediately. |
138 if (!response_body_queue_.IsEmpty()) { | 147 if (!response_body_queue_.IsEmpty()) { |
139 return response_body_queue_.Dequeue(buf->data(), buf_len); | 148 return response_body_queue_.Dequeue(buf->data(), buf_len); |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
367 void SpdyHttpStream::OnDataSent() { | 376 void SpdyHttpStream::OnDataSent() { |
368 request_body_buf_size_ = 0; | 377 request_body_buf_size_ = 0; |
369 ReadAndSendRequestBodyData(); | 378 ReadAndSendRequestBodyData(); |
370 } | 379 } |
371 | 380 |
372 // TODO(xunjieli): Maybe do something with the trailers. crbug.com/422958. | 381 // TODO(xunjieli): Maybe do something with the trailers. crbug.com/422958. |
373 void SpdyHttpStream::OnTrailers(const SpdyHeaderBlock& trailers) {} | 382 void SpdyHttpStream::OnTrailers(const SpdyHeaderBlock& trailers) {} |
374 | 383 |
375 void SpdyHttpStream::OnClose(int status) { | 384 void SpdyHttpStream::OnClose(int status) { |
376 // Cancel any pending reads from the upload data stream. | 385 // Cancel any pending reads from the upload data stream. |
377 if (request_info_->upload_data_stream) | 386 if (request_info_ && request_info_->upload_data_stream) |
378 request_info_->upload_data_stream->Reset(); | 387 request_info_->upload_data_stream->Reset(); |
379 | 388 |
380 if (stream_.get()) { | 389 if (stream_.get()) { |
381 stream_closed_ = true; | 390 stream_closed_ = true; |
382 closed_stream_status_ = status; | 391 closed_stream_status_ = status; |
383 closed_stream_id_ = stream_->stream_id(); | 392 closed_stream_id_ = stream_->stream_id(); |
384 closed_stream_has_load_timing_info_ = | 393 closed_stream_has_load_timing_info_ = |
385 stream_->GetLoadTimingInfo(&closed_stream_load_timing_info_); | 394 stream_->GetLoadTimingInfo(&closed_stream_load_timing_info_); |
386 closed_stream_received_bytes_ = stream_->raw_received_bytes(); | 395 closed_stream_received_bytes_ = stream_->raw_received_bytes(); |
387 closed_stream_sent_bytes_ = stream_->raw_sent_bytes(); | 396 closed_stream_sent_bytes_ = stream_->raw_sent_bytes(); |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
612 void SpdyHttpStream::PopulateNetErrorDetails(NetErrorDetails* details) { | 621 void SpdyHttpStream::PopulateNetErrorDetails(NetErrorDetails* details) { |
613 details->connection_info = HttpResponseInfo::CONNECTION_INFO_HTTP2; | 622 details->connection_info = HttpResponseInfo::CONNECTION_INFO_HTTP2; |
614 return; | 623 return; |
615 } | 624 } |
616 | 625 |
617 void SpdyHttpStream::SetPriority(RequestPriority priority) { | 626 void SpdyHttpStream::SetPriority(RequestPriority priority) { |
618 // TODO(akalin): Plumb this through to |stream_request_| and | 627 // TODO(akalin): Plumb this through to |stream_request_| and |
619 // |stream_|. | 628 // |stream_|. |
620 } | 629 } |
621 | 630 |
631 void SpdyHttpStream::ResetRequestInfo() { | |
632 // Only allowed when Reading of response body starts. It is safe to reset it | |
633 // at this point since request_->upload_data_stream is also not needed | |
634 // anymore. | |
635 | |
636 // Save upload progress if any. | |
637 upload_progress_ = GetUploadProgress(); | |
638 | |
639 request_info_ = nullptr; | |
640 } | |
641 | |
622 } // namespace net | 642 } // namespace net |
OLD | NEW |