15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file.
45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#ifndef NET_QUIC_QUIC_HEADERS_STREAM_H_
65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#define NET_QUIC_QUIC_HEADERS_STREAM_H_
75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/basictypes.h"
95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "net/base/net_export.h"
115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "net/quic/quic_protocol.h"
125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "net/quic/reliable_quic_stream.h"
135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "net/spdy/spdy_framer.h"
145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace net {
165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Headers in QUIC are sent as SPDY SYN_STREAM or SYN_REPLY frames
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// over a reserved reliable stream with the id 2.  Each endpoint (client
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// and server) will allocate an instance of QuicHeadersStream to send
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// and receive headers.
215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class NET_EXPORT_PRIVATE QuicHeadersStream : public ReliableQuicStream {
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public:
235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  explicit QuicHeadersStream(QuicSession* session);
245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual ~QuicHeadersStream();
255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Writes |headers| for |stream_id| in a SYN_STREAM or SYN_REPLY
275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // frame to the peer.  If |fin| is true, the fin flag will be set on
285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // the SPDY frame.  Returns the size, in bytes, of the resulting
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // SPDY frame.
3023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  size_t WriteHeaders(
3123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)      QuicStreamId stream_id,
3223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)      const SpdyHeaderBlock& headers,
3323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)      bool fin,
3423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)      QuicAckNotifier::DelegateInterface* ack_notifier_delegate);
355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // ReliableQuicStream implementation
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual uint32 ProcessRawData(const char* data, uint32 data_len) OVERRIDE;
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual QuicPriority EffectivePriority() const OVERRIDE;
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private:
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  class SpdyFramerVisitor;
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // The following methods are called by the SimpleVisitor.
445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Called when a SYN_STREAM frame has been received.
465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void OnSynStream(SpdyStreamId stream_id,
475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                   SpdyPriority priority,
485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                   bool fin);
495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Called when a SYN_REPLY frame been received.
515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void OnSynReply(SpdyStreamId stream_id, bool fin);
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Called when a chunk of header data is available. This is called
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // after OnSynStream, or OnSynReply.
555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // |stream_id| The stream receiving the header data.
565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // |header_data| A buffer containing the header data chunk received.
575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // |len| The length of the header data buffer. A length of zero indicates
585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //       that the header data block has been completely sent.
595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void OnControlFrameHeaderData(SpdyStreamId stream_id,
605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                const char* header_data,
615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                size_t len);
625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Called when the size of the compressed frame payload is available.
645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void OnCompressedFrameSize(size_t frame_len);
655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Returns true if the session is still connected.
675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool IsConnected();
685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Data about the stream whose headers are being processed.
705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  QuicStreamId stream_id_;
715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool fin_;
725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  size_t frame_len_;
735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  SpdyFramer spdy_framer_;
755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  scoped_ptr<SpdyFramerVisitor> spdy_framer_visitor_;
765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(QuicHeadersStream);
785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}  // namespace net
815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif  // NET_QUIC_QUIC_HEADERS_STREAM_H_
83