Delete unused downloads page asset.
[chromium-blink-merge.git] / net / quic / quic_data_stream.h
blob1b66f9a64c3726be2ad8c5ade2791357516af72b
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
3 // found in the LICENSE file.
4 //
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
7 // headers then body data.
9 #ifndef NET_QUIC_QUIC_DATA_STREAM_H_
10 #define NET_QUIC_QUIC_DATA_STREAM_H_
12 #include <sys/types.h>
14 #include <list>
15 #include <string>
17 #include "base/basictypes.h"
18 #include "base/strings/string_piece.h"
19 #include "net/base/iovec.h"
20 #include "net/base/ip_endpoint.h"
21 #include "net/base/net_export.h"
22 #include "net/quic/quic_ack_notifier.h"
23 #include "net/quic/quic_protocol.h"
24 #include "net/quic/quic_stream_sequencer.h"
25 #include "net/quic/reliable_quic_stream.h"
26 #include "net/spdy/spdy_framer.h"
28 namespace net {
30 namespace test {
31 class QuicDataStreamPeer;
32 class ReliableQuicStreamPeer;
33 } // namespace test
35 class QuicSpdySession;
37 // A QUIC data stream that can also send and receive headers.
38 class NET_EXPORT_PRIVATE QuicDataStream : public ReliableQuicStream {
39 public:
40 // Visitor receives callbacks from the stream.
41 class NET_EXPORT_PRIVATE Visitor {
42 public:
43 Visitor() {}
45 // Called when the stream is closed.
46 virtual void OnClose(QuicDataStream* stream) = 0;
48 protected:
49 virtual ~Visitor() {}
51 private:
52 DISALLOW_COPY_AND_ASSIGN(Visitor);
55 QuicDataStream(QuicStreamId id, QuicSpdySession* spdy_session);
56 ~QuicDataStream() override;
58 // ReliableQuicStream implementation
59 void OnClose() override;
61 // By default, this is the same as priority(), however it allows streams
62 // to temporarily alter effective priority. For example if a SPDY stream has
63 // compressed but not written headers it can write the headers with a higher
64 // priority.
65 QuicPriority EffectivePriority() const override;
67 // Called by the session when decompressed headers data is received
68 // for this stream.
69 // May be called multiple times, with each call providing additional headers
70 // data until OnStreamHeadersComplete is called.
71 virtual void OnStreamHeaders(base::StringPiece headers_data);
73 // Called by the session when headers with a priority have been received
74 // for this stream. This method will only be called for server streams.
75 virtual void OnStreamHeadersPriority(QuicPriority priority);
77 // Called by the session when decompressed headers have been completely
78 // delilvered to this stream. If |fin| is true, then this stream
79 // should be closed; no more data will be sent by the peer.
80 virtual void OnStreamHeadersComplete(bool fin, size_t frame_len);
82 // Writes the headers contained in |header_block| to the dedicated
83 // headers stream.
84 virtual size_t WriteHeaders(
85 const SpdyHeaderBlock& header_block,
86 bool fin,
87 QuicAckNotifier::DelegateInterface* ack_notifier_delegate);
89 // Marks |bytes_consumed| of the headers data as consumed.
90 void MarkHeadersConsumed(size_t bytes_consumed);
92 // This block of functions wraps the sequencer's functions of the same
93 // name. These methods return uncompressed data until that has
94 // been fully processed. Then they simply delegate to the sequencer.
95 virtual size_t Readv(const struct iovec* iov, size_t iov_len);
96 virtual int GetReadableRegions(iovec* iov, size_t iov_len) const;
97 void MarkConsumed(size_t num_bytes);
99 // Returns true when all data has been read from the peer, including the fin.
100 bool IsDoneReading() const;
101 bool HasBytesToRead() const;
103 void set_visitor(Visitor* visitor) { visitor_ = visitor; }
105 bool headers_decompressed() const { return headers_decompressed_; }
107 const std::string& decompressed_headers() const {
108 return decompressed_headers_;
111 protected:
112 // Sets priority_ to priority. This should only be called before bytes are
113 // written to the server.
114 void set_priority(QuicPriority priority);
115 // This is protected because external classes should use EffectivePriority
116 // instead.
117 QuicPriority priority() const { return priority_; }
119 bool FinishedReadingHeaders() const;
121 private:
122 friend class test::QuicDataStreamPeer;
123 friend class test::ReliableQuicStreamPeer;
124 friend class QuicStreamUtils;
126 QuicSpdySession* spdy_session_;
128 Visitor* visitor_;
129 // True if the headers have been completely decompressed.
130 bool headers_decompressed_;
131 // The priority of the stream, once parsed.
132 QuicPriority priority_;
133 // Contains a copy of the decompressed headers until they are consumed
134 // via ProcessData or Readv.
135 std::string decompressed_headers_;
137 DISALLOW_COPY_AND_ASSIGN(QuicDataStream);
140 } // namespace net
142 #endif // NET_QUIC_QUIC_DATA_STREAM_H_