| 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 // The base class for streams which deliver data to/from an application. | 5 // The base class for streams which deliver data to/from an application. |
| 6 // In each direction, the data on such a stream first contains compressed | 6 // In each direction, the data on such a stream first contains compressed |
| 7 // headers then body data. | 7 // headers then body data. |
| 8 | 8 |
| 9 #ifndef NET_QUIC_QUIC_DATA_STREAM_H_ | 9 #ifndef NET_QUIC_QUIC_DATA_STREAM_H_ |
| 10 #define NET_QUIC_QUIC_DATA_STREAM_H_ | 10 #define NET_QUIC_QUIC_DATA_STREAM_H_ |
| 11 | 11 |
| 12 #include <sys/types.h> | 12 #include <sys/types.h> |
| 13 | 13 |
| 14 #include <list> | 14 #include <list> |
| 15 | 15 |
| 16 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
| 17 #include "base/strings/string_piece.h" | 17 #include "base/strings/string_piece.h" |
| 18 #include "net/base/iovec.h" | 18 #include "net/base/iovec.h" |
| 19 #include "net/base/net_export.h" | 19 #include "net/base/net_export.h" |
| 20 #include "net/quic/quic_ack_notifier.h" | 20 #include "net/quic/quic_ack_notifier.h" |
| 21 #include "net/quic/quic_protocol.h" | 21 #include "net/quic/quic_protocol.h" |
| 22 #include "net/quic/quic_spdy_compressor.h" | |
| 23 #include "net/quic/quic_spdy_decompressor.h" | |
| 24 #include "net/quic/quic_stream_sequencer.h" | 22 #include "net/quic/quic_stream_sequencer.h" |
| 25 #include "net/quic/reliable_quic_stream.h" | 23 #include "net/quic/reliable_quic_stream.h" |
| 24 #include "net/spdy/spdy_framer.h" |
| 26 | 25 |
| 27 namespace net { | 26 namespace net { |
| 28 | 27 |
| 29 namespace test { | 28 namespace test { |
| 30 class QuicDataStreamPeer; | 29 class QuicDataStreamPeer; |
| 31 class ReliableQuicStreamPeer; | 30 class ReliableQuicStreamPeer; |
| 32 } // namespace test | 31 } // namespace test |
| 33 | 32 |
| 34 class IPEndPoint; | 33 class IPEndPoint; |
| 35 class QuicSession; | 34 class QuicSession; |
| 36 class SSLInfo; | 35 class SSLInfo; |
| 37 | 36 |
| 38 // All this does right now is send data to subclasses via the sequencer. | 37 // All this does right now is send data to subclasses via the sequencer. |
| 39 class NET_EXPORT_PRIVATE QuicDataStream : public ReliableQuicStream, | 38 class NET_EXPORT_PRIVATE QuicDataStream : public ReliableQuicStream { |
| 40 public QuicSpdyDecompressor::Visitor { | |
| 41 public: | 39 public: |
| 42 // Visitor receives callbacks from the stream. | 40 // Visitor receives callbacks from the stream. |
| 43 class Visitor { | 41 class Visitor { |
| 44 public: | 42 public: |
| 45 Visitor() {} | 43 Visitor() {} |
| 46 | 44 |
| 47 // Called when the stream is closed. | 45 // Called when the stream is closed. |
| 48 virtual void OnClose(QuicDataStream* stream) = 0; | 46 virtual void OnClose(QuicDataStream* stream) = 0; |
| 49 | 47 |
| 50 protected: | 48 protected: |
| 51 virtual ~Visitor() {} | 49 virtual ~Visitor() {} |
| 52 | 50 |
| 53 private: | 51 private: |
| 54 DISALLOW_COPY_AND_ASSIGN(Visitor); | 52 DISALLOW_COPY_AND_ASSIGN(Visitor); |
| 55 }; | 53 }; |
| 56 | 54 |
| 57 QuicDataStream(QuicStreamId id, QuicSession* session); | 55 QuicDataStream(QuicStreamId id, QuicSession* session); |
| 58 | 56 |
| 59 virtual ~QuicDataStream(); | 57 virtual ~QuicDataStream(); |
| 60 | 58 |
| 61 // ReliableQuicStream implementation | 59 // ReliableQuicStream implementation |
| 62 virtual void OnClose() OVERRIDE; | 60 virtual void OnClose() OVERRIDE; |
| 63 virtual uint32 ProcessRawData(const char* data, uint32 data_len) OVERRIDE; | 61 virtual uint32 ProcessRawData(const char* data, uint32 data_len) OVERRIDE; |
| 64 // By default, this is the same as priority(), however it allows streams | 62 // By default, this is the same as priority(), however it allows streams |
| 65 // to temporarily alter effective priority. For example if a SPDY stream has | 63 // to temporarily alter effective priority. For example if a SPDY stream has |
| 66 // compressed but not written headers it can write the headers with a higher | 64 // compressed but not written headers it can write the headers with a higher |
| 67 // priority. | 65 // priority. |
| 68 virtual QuicPriority EffectivePriority() const OVERRIDE; | 66 virtual QuicPriority EffectivePriority() const OVERRIDE; |
| 69 | 67 |
| 70 // QuicSpdyDecompressor::Visitor implementation. | 68 // Overridden by subclasses to process data. The headers will be delivered |
| 71 virtual bool OnDecompressedData(base::StringPiece data) OVERRIDE; | 69 // via OnStreamHeaders, so only data will be delivered through this method. |
| 72 virtual void OnDecompressionError() OVERRIDE; | |
| 73 | |
| 74 // Overridden by subclasses to process data. For QUIC_VERSION_12 or less, | |
| 75 // data will be delivered in order, first the decompressed headers, then | |
| 76 // the body. For later QUIC versions, the headers will be delivered via | |
| 77 // OnStreamHeaders, and only the data will be delivered through this method. | |
| 78 virtual uint32 ProcessData(const char* data, uint32 data_len) = 0; | 70 virtual uint32 ProcessData(const char* data, uint32 data_len) = 0; |
| 79 | 71 |
| 80 // Called by the session when decompressed headers data is received | 72 // Called by the session when decompressed headers data is received |
| 81 // for this stream. Only called for versions greater than QUIC_VERSION_12. | 73 // for this stream. |
| 82 // May be called multiple times, with each call providing additional headers | 74 // May be called multiple times, with each call providing additional headers |
| 83 // data until OnStreamHeadersComplete is called. | 75 // data until OnStreamHeadersComplete is called. |
| 84 virtual void OnStreamHeaders(base::StringPiece headers_data); | 76 virtual void OnStreamHeaders(base::StringPiece headers_data); |
| 85 | 77 |
| 86 // Called by the session when headers with a priority have been received | 78 // Called by the session when headers with a priority have been received |
| 87 // for this stream. This method will only be called for server streams. | 79 // for this stream. This method will only be called for server streams. |
| 88 virtual void OnStreamHeadersPriority(QuicPriority priority); | 80 virtual void OnStreamHeadersPriority(QuicPriority priority); |
| 89 | 81 |
| 90 // Called by the session when decompressed headers have been completely | 82 // Called by the session when decompressed headers have been completely |
| 91 // delilvered to this stream. If |fin| is true, then this stream | 83 // delilvered to this stream. If |fin| is true, then this stream |
| 92 // should be closed; no more data will be sent by the peer. | 84 // should be closed; no more data will be sent by the peer. |
| 93 // Only called for versions greater than QUIC_VERSION_12. | |
| 94 virtual void OnStreamHeadersComplete(bool fin, size_t frame_len); | 85 virtual void OnStreamHeadersComplete(bool fin, size_t frame_len); |
| 95 | 86 |
| 96 // Writes the headers contained in |header_block| to the dedicated | 87 // Writes the headers contained in |header_block| to the dedicated |
| 97 // headers stream. | 88 // headers stream. |
| 98 virtual size_t WriteHeaders(const SpdyHeaderBlock& header_block, | 89 virtual size_t WriteHeaders(const SpdyHeaderBlock& header_block, |
| 99 bool fin); | 90 bool fin); |
| 100 | 91 |
| 101 // This block of functions wraps the sequencer's functions of the same | 92 // This block of functions wraps the sequencer's functions of the same |
| 102 // name. These methods return uncompressed data until that has | 93 // name. These methods return uncompressed data until that has |
| 103 // been fully processed. Then they simply delegate to the sequencer. | 94 // been fully processed. Then they simply delegate to the sequencer. |
| 104 virtual size_t Readv(const struct iovec* iov, size_t iov_len); | 95 virtual size_t Readv(const struct iovec* iov, size_t iov_len); |
| 105 virtual int GetReadableRegions(iovec* iov, size_t iov_len); | 96 virtual int GetReadableRegions(iovec* iov, size_t iov_len); |
| 106 // Returns true when all data has been read from the peer, including the fin. | 97 // Returns true when all data has been read from the peer, including the fin. |
| 107 virtual bool IsDoneReading() const; | 98 virtual bool IsDoneReading() const; |
| 108 virtual bool HasBytesToRead() const; | 99 virtual bool HasBytesToRead() const; |
| 109 | 100 |
| 110 // Called by the session when a decompression blocked stream | |
| 111 // becomes unblocked. | |
| 112 virtual void OnDecompressorAvailable(); | |
| 113 | |
| 114 void set_visitor(Visitor* visitor) { visitor_ = visitor; } | 101 void set_visitor(Visitor* visitor) { visitor_ = visitor; } |
| 115 | 102 |
| 116 bool headers_decompressed() const { return headers_decompressed_; } | 103 bool headers_decompressed() const { return headers_decompressed_; } |
| 117 | 104 |
| 118 const IPEndPoint& GetPeerAddress(); | 105 const IPEndPoint& GetPeerAddress(); |
| 119 | 106 |
| 120 QuicSpdyCompressor* compressor(); | |
| 121 | |
| 122 // Gets the SSL connection information. | 107 // Gets the SSL connection information. |
| 123 bool GetSSLInfo(SSLInfo* ssl_info); | 108 bool GetSSLInfo(SSLInfo* ssl_info); |
| 124 | 109 |
| 125 // Adjust flow control windows according to new offset in |frame|. | 110 // Adjust flow control windows according to new offset in |frame|. |
| 126 void OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame); | 111 void OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame); |
| 127 | 112 |
| 128 protected: | 113 protected: |
| 129 // Sets priority_ to priority. This should only be called before bytes are | 114 // Sets priority_ to priority. This should only be called before bytes are |
| 130 // written to the server. | 115 // written to the server. |
| 131 void set_priority(QuicPriority priority); | 116 void set_priority(QuicPriority priority); |
| 132 // This is protected because external classes should use EffectivePriority | 117 // This is protected because external classes should use EffectivePriority |
| 133 // instead. | 118 // instead. |
| 134 QuicPriority priority() const { return priority_; } | 119 QuicPriority priority() const { return priority_; } |
| 135 | 120 |
| 136 private: | 121 private: |
| 137 friend class test::QuicDataStreamPeer; | 122 friend class test::QuicDataStreamPeer; |
| 138 friend class test::ReliableQuicStreamPeer; | 123 friend class test::ReliableQuicStreamPeer; |
| 139 friend class QuicStreamUtils; | 124 friend class QuicStreamUtils; |
| 140 | 125 |
| 141 // Processes raw stream data for QUIC_VERSION_12 and earlier. | |
| 142 uint32 ProcessRawData12(const char* data, uint32 data_len); | |
| 143 | |
| 144 uint32 ProcessHeaderData(); | 126 uint32 ProcessHeaderData(); |
| 145 | 127 |
| 146 uint32 StripPriorityAndHeaderId(const char* data, uint32 data_len); | |
| 147 | |
| 148 bool FinishedReadingHeaders(); | 128 bool FinishedReadingHeaders(); |
| 149 | 129 |
| 150 Visitor* visitor_; | 130 Visitor* visitor_; |
| 151 // True if the headers have been completely decompresssed. | 131 // True if the headers have been completely decompresssed. |
| 152 bool headers_decompressed_; | 132 bool headers_decompressed_; |
| 153 // The priority of the stream, once parsed. | 133 // The priority of the stream, once parsed. |
| 154 QuicPriority priority_; | 134 QuicPriority priority_; |
| 155 // ID of the header block sent by the peer, once parsed. | |
| 156 QuicHeaderId headers_id_; | |
| 157 // Buffer into which we write bytes from priority_ and headers_id_ | |
| 158 // until each is fully parsed. | |
| 159 string headers_id_and_priority_buffer_; | |
| 160 // Contains a copy of the decompressed headers until they are consumed | 135 // Contains a copy of the decompressed headers until they are consumed |
| 161 // via ProcessData or Readv. | 136 // via ProcessData or Readv. |
| 162 string decompressed_headers_; | 137 string decompressed_headers_; |
| 163 // True if an error was encountered during decompression. | 138 // True if an error was encountered during decompression. |
| 164 bool decompression_failed_; | 139 bool decompression_failed_; |
| 165 // True if the priority has been read, false otherwise. | 140 // True if the priority has been read, false otherwise. |
| 166 bool priority_parsed_; | 141 bool priority_parsed_; |
| 167 | 142 |
| 168 DISALLOW_COPY_AND_ASSIGN(QuicDataStream); | 143 DISALLOW_COPY_AND_ASSIGN(QuicDataStream); |
| 169 }; | 144 }; |
| 170 | 145 |
| 171 } // namespace net | 146 } // namespace net |
| 172 | 147 |
| 173 #endif // NET_QUIC_QUIC_DATA_STREAM_H_ | 148 #endif // NET_QUIC_QUIC_DATA_STREAM_H_ |
| OLD | NEW |