| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/quic_spdy_stream.h" | 5 #include "net/quic/quic_spdy_stream.h" |
| 6 | 6 |
| 7 // TODO(rtenneti): Temporary while investigating crbug.com/585591. | 7 // TODO(rtenneti): Temporary while investigating crbug.com/585591. |
| 8 #include "base/debug/alias.h" | 8 #include "base/debug/alias.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 // TODO(rch): Add test to ensure fin_sent_ is set whenever a fin is sent. | 89 // TODO(rch): Add test to ensure fin_sent_ is set whenever a fin is sent. |
| 90 set_fin_sent(true); | 90 set_fin_sent(true); |
| 91 CloseWriteSide(); | 91 CloseWriteSide(); |
| 92 } | 92 } |
| 93 return bytes_written; | 93 return bytes_written; |
| 94 } | 94 } |
| 95 | 95 |
| 96 size_t QuicSpdyStream::WriteTrailers( | 96 size_t QuicSpdyStream::WriteTrailers( |
| 97 SpdyHeaderBlock trailer_block, | 97 SpdyHeaderBlock trailer_block, |
| 98 QuicAckListenerInterface* ack_notifier_delegate) { | 98 QuicAckListenerInterface* ack_notifier_delegate) { |
| 99 if (!FLAGS_quic_supports_trailers) { | |
| 100 return 0; | |
| 101 } | |
| 102 if (fin_sent()) { | 99 if (fin_sent()) { |
| 103 QUIC_BUG << "Trailers cannot be sent after a FIN."; | 100 QUIC_BUG << "Trailers cannot be sent after a FIN."; |
| 104 return 0; | 101 return 0; |
| 105 } | 102 } |
| 106 | 103 |
| 107 // The header block must contain the final offset for this stream, as the | 104 // The header block must contain the final offset for this stream, as the |
| 108 // trailers may be processed out of order at the peer. | 105 // trailers may be processed out of order at the peer. |
| 109 trailer_block.insert(std::make_pair( | 106 trailer_block.insert(std::make_pair( |
| 110 kFinalOffsetHeaderKey, | 107 kFinalOffsetHeaderKey, |
| 111 base::IntToString(stream_bytes_written() + queued_data_bytes()))); | 108 base::IntToString(stream_bytes_written() + queued_data_bytes()))); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 bool QuicSpdyStream::IsDoneReading() const { | 141 bool QuicSpdyStream::IsDoneReading() const { |
| 145 bool done_reading_headers = FinishedReadingHeaders(); | 142 bool done_reading_headers = FinishedReadingHeaders(); |
| 146 bool done_reading_body = sequencer()->IsClosed(); | 143 bool done_reading_body = sequencer()->IsClosed(); |
| 147 bool done_reading_trailers = FinishedReadingTrailers(); | 144 bool done_reading_trailers = FinishedReadingTrailers(); |
| 148 return done_reading_headers && done_reading_body && done_reading_trailers; | 145 return done_reading_headers && done_reading_body && done_reading_trailers; |
| 149 } | 146 } |
| 150 | 147 |
| 151 bool QuicSpdyStream::HasBytesToRead() const { | 148 bool QuicSpdyStream::HasBytesToRead() const { |
| 152 bool headers_to_read = !decompressed_headers_.empty(); | 149 bool headers_to_read = !decompressed_headers_.empty(); |
| 153 bool body_to_read = sequencer()->HasBytesToRead(); | 150 bool body_to_read = sequencer()->HasBytesToRead(); |
| 154 bool trailers_to_read = | 151 bool trailers_to_read = !decompressed_trailers_.empty(); |
| 155 (FLAGS_quic_supports_trailers && !decompressed_trailers_.empty()); | |
| 156 return headers_to_read || body_to_read || trailers_to_read; | 152 return headers_to_read || body_to_read || trailers_to_read; |
| 157 } | 153 } |
| 158 | 154 |
| 159 void QuicSpdyStream::MarkHeadersConsumed(size_t bytes_consumed) { | 155 void QuicSpdyStream::MarkHeadersConsumed(size_t bytes_consumed) { |
| 160 decompressed_headers_.erase(0, bytes_consumed); | 156 decompressed_headers_.erase(0, bytes_consumed); |
| 161 if (FinishedReadingHeaders()) { | 157 if (FinishedReadingHeaders()) { |
| 162 sequencer()->SetUnblocked(); | 158 sequencer()->SetUnblocked(); |
| 163 } | 159 } |
| 164 } | 160 } |
| 165 | 161 |
| 166 void QuicSpdyStream::MarkTrailersConsumed(size_t bytes_consumed) { | 162 void QuicSpdyStream::MarkTrailersConsumed(size_t bytes_consumed) { |
| 167 decompressed_trailers_.erase(0, bytes_consumed); | 163 decompressed_trailers_.erase(0, bytes_consumed); |
| 168 } | 164 } |
| 169 | 165 |
| 170 void QuicSpdyStream::SetPriority(SpdyPriority priority) { | 166 void QuicSpdyStream::SetPriority(SpdyPriority priority) { |
| 171 DCHECK_EQ(0u, stream_bytes_written()); | 167 DCHECK_EQ(0u, stream_bytes_written()); |
| 172 spdy_session_->UpdateStreamPriority(id(), priority); | 168 spdy_session_->UpdateStreamPriority(id(), priority); |
| 173 priority_ = priority; | 169 priority_ = priority; |
| 174 } | 170 } |
| 175 | 171 |
| 176 void QuicSpdyStream::OnStreamHeaders(StringPiece headers_data) { | 172 void QuicSpdyStream::OnStreamHeaders(StringPiece headers_data) { |
| 177 if (!FLAGS_quic_supports_trailers || !headers_decompressed_) { | 173 if (!headers_decompressed_) { |
| 178 headers_data.AppendToString(&decompressed_headers_); | 174 headers_data.AppendToString(&decompressed_headers_); |
| 179 } else { | 175 } else { |
| 180 DCHECK(!trailers_decompressed_); | 176 DCHECK(!trailers_decompressed_); |
| 181 headers_data.AppendToString(&decompressed_trailers_); | 177 headers_data.AppendToString(&decompressed_trailers_); |
| 182 } | 178 } |
| 183 } | 179 } |
| 184 | 180 |
| 185 void QuicSpdyStream::OnStreamHeadersPriority(SpdyPriority priority) { | 181 void QuicSpdyStream::OnStreamHeadersPriority(SpdyPriority priority) { |
| 186 DCHECK_EQ(Perspective::IS_SERVER, session()->connection()->perspective()); | 182 DCHECK_EQ(Perspective::IS_SERVER, session()->connection()->perspective()); |
| 187 SetPriority(priority); | 183 SetPriority(priority); |
| 188 } | 184 } |
| 189 | 185 |
| 190 void QuicSpdyStream::OnStreamHeadersComplete(bool fin, size_t frame_len) { | 186 void QuicSpdyStream::OnStreamHeadersComplete(bool fin, size_t frame_len) { |
| 191 if (!FLAGS_quic_supports_trailers || !headers_decompressed_) { | 187 if (!headers_decompressed_) { |
| 192 OnInitialHeadersComplete(fin, frame_len); | 188 OnInitialHeadersComplete(fin, frame_len); |
| 193 } else { | 189 } else { |
| 194 OnTrailingHeadersComplete(fin, frame_len); | 190 OnTrailingHeadersComplete(fin, frame_len); |
| 195 } | 191 } |
| 196 } | 192 } |
| 197 | 193 |
| 198 void QuicSpdyStream::OnInitialHeadersComplete(bool fin, size_t /*frame_len*/) { | 194 void QuicSpdyStream::OnInitialHeadersComplete(bool fin, size_t /*frame_len*/) { |
| 199 headers_decompressed_ = true; | 195 headers_decompressed_ = true; |
| 200 if (fin) { | 196 if (fin) { |
| 201 OnStreamFrame(QuicStreamFrame(id(), fin, 0, StringPiece())); | 197 OnStreamFrame(QuicStreamFrame(id(), fin, 0, StringPiece())); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 visitor_ = nullptr; | 255 visitor_ = nullptr; |
| 260 visitor->OnClose(this); | 256 visitor->OnClose(this); |
| 261 } | 257 } |
| 262 } | 258 } |
| 263 | 259 |
| 264 bool QuicSpdyStream::FinishedReadingHeaders() const { | 260 bool QuicSpdyStream::FinishedReadingHeaders() const { |
| 265 return headers_decompressed_ && decompressed_headers_.empty(); | 261 return headers_decompressed_ && decompressed_headers_.empty(); |
| 266 } | 262 } |
| 267 | 263 |
| 268 bool QuicSpdyStream::FinishedReadingTrailers() const { | 264 bool QuicSpdyStream::FinishedReadingTrailers() const { |
| 269 if (!FLAGS_quic_supports_trailers) { | |
| 270 return true; | |
| 271 } | |
| 272 // If no further trailing headers are expected, and the decompressed trailers | 265 // If no further trailing headers are expected, and the decompressed trailers |
| 273 // (if any) have been consumed, then reading of trailers is finished. | 266 // (if any) have been consumed, then reading of trailers is finished. |
| 274 bool no_more_trailers = fin_received() || trailers_decompressed_; | 267 bool no_more_trailers = fin_received() || trailers_decompressed_; |
| 275 return no_more_trailers && decompressed_trailers_.empty(); | 268 return no_more_trailers && decompressed_trailers_.empty(); |
| 276 } | 269 } |
| 277 | 270 |
| 278 SpdyPriority QuicSpdyStream::priority() const { | 271 SpdyPriority QuicSpdyStream::priority() const { |
| 279 return priority_; | 272 return priority_; |
| 280 } | 273 } |
| 281 } // namespace net | 274 } // namespace net |
| OLD | NEW |