1 // Copyright 2014 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.
5 // A server specific QuicSession subclass.
7 #ifndef NET_QUIC_QUIC_SERVER_SESSION_H_
8 #define NET_QUIC_QUIC_SERVER_SESSION_H_
13 #include "base/basictypes.h"
14 #include "base/containers/hash_tables.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "net/quic/quic_crypto_server_stream.h"
17 #include "net/quic/quic_per_connection_packet_writer.h"
18 #include "net/quic/quic_protocol.h"
19 #include "net/quic/quic_session.h"
23 class QuicBlockedWriterInterface
;
26 class QuicCryptoServerConfig
;
27 class ReliableQuicStream
;
30 class QuicServerSessionPeer
;
33 // An interface from the session to the entity owning the session.
34 // This lets the session notify its owner (the Dispatcher) when the connection
35 // is closed or blocked.
36 class QuicServerSessionVisitor
{
38 virtual ~QuicServerSessionVisitor() {}
40 virtual void OnConnectionClosed(QuicConnectionId connection_id
,
41 QuicErrorCode error
) = 0;
42 virtual void OnWriteBlocked(QuicBlockedWriterInterface
* blocked_writer
) = 0;
45 class QuicServerSession
: public QuicSession
{
47 // Takes ownership of connection_packet_writer
48 QuicServerSession(const QuicConfig
& config
,
49 QuicConnection
* connection
,
50 QuicPerConnectionPacketWriter
* connection_packet_writer
,
51 QuicServerSessionVisitor
* visitor
);
53 // Override the base class to notify the owner of the connection close.
54 virtual void OnConnectionClosed(QuicErrorCode error
, bool from_peer
) OVERRIDE
;
55 virtual void OnWriteBlocked() OVERRIDE
;
57 virtual ~QuicServerSession();
59 virtual void InitializeSession(const QuicCryptoServerConfig
& crypto_config
);
61 const QuicCryptoServerStream
* crypto_stream() const {
62 return crypto_stream_
.get();
65 // Override base class to process FEC config received from client.
66 virtual void OnConfigNegotiated() OVERRIDE
;
69 // QuicSession methods:
70 virtual QuicDataStream
* CreateIncomingDataStream(QuicStreamId id
) OVERRIDE
;
71 virtual QuicDataStream
* CreateOutgoingDataStream() OVERRIDE
;
72 virtual QuicCryptoServerStream
* GetCryptoStream() OVERRIDE
;
74 // If we should create an incoming stream, returns true. Otherwise
75 // does error handling, including communicating the error to the client and
76 // possibly closing the connection, and returns false.
77 virtual bool ShouldCreateIncomingDataStream(QuicStreamId id
);
79 virtual QuicCryptoServerStream
* CreateQuicCryptoServerStream(
80 const QuicCryptoServerConfig
& crypto_config
);
83 friend class test::QuicServerSessionPeer
;
85 scoped_ptr
<QuicCryptoServerStream
> crypto_stream_
;
86 scoped_ptr
<QuicPerConnectionPacketWriter
> connection_packet_writer_
;
87 QuicServerSessionVisitor
* visitor_
;
89 DISALLOW_COPY_AND_ASSIGN(QuicServerSession
);
94 #endif // NET_QUIC_QUIC_SERVER_SESSION_H_