1 // Copyright (c) 2012 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_TOOLS_QUIC_QUIC_SERVER_SESSION_H_
8 #define NET_TOOLS_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_protocol.h"
18 #include "net/quic/quic_session.h"
22 class QuicBlockedWriterInterface
;
25 class QuicCryptoServerConfig
;
26 class ReliableQuicStream
;
31 class QuicServerSessionPeer
;
34 // An interface from the session to the entity owning the session.
35 // This lets the session notify its owner (the Dispatcher) when the connection
36 // is closed or blocked.
37 class QuicServerSessionVisitor
{
39 virtual ~QuicServerSessionVisitor() {}
41 virtual void OnConnectionClosed(QuicGuid guid
, QuicErrorCode error
) = 0;
42 virtual void OnWriteBlocked(QuicBlockedWriterInterface
* writer
) = 0;
45 class QuicServerSession
: public QuicSession
{
47 QuicServerSession(const QuicConfig
& config
,
48 QuicConnection
*connection
,
49 QuicServerSessionVisitor
* visitor
);
51 // Override the base class to notify the owner of the connection close.
52 virtual void OnConnectionClosed(QuicErrorCode error
, bool from_peer
) OVERRIDE
;
53 virtual void OnWriteBlocked() OVERRIDE
;
55 virtual ~QuicServerSession();
57 virtual void InitializeSession(const QuicCryptoServerConfig
& crypto_config
);
59 const QuicCryptoServerStream
* crypto_stream() const {
60 return crypto_stream_
.get();
64 // QuicSession methods:
65 virtual QuicDataStream
* CreateIncomingDataStream(QuicStreamId id
) OVERRIDE
;
66 virtual QuicDataStream
* CreateOutgoingDataStream() OVERRIDE
;
67 virtual QuicCryptoServerStream
* GetCryptoStream() OVERRIDE
;
69 // If we should create an incoming stream, returns true. Otherwise
70 // does error handling, including communicating the error to the client and
71 // possibly closing the connection, and returns false.
72 virtual bool ShouldCreateIncomingDataStream(QuicStreamId id
);
74 virtual QuicCryptoServerStream
* CreateQuicCryptoServerStream(
75 const QuicCryptoServerConfig
& crypto_config
);
78 friend class test::QuicServerSessionPeer
;
80 scoped_ptr
<QuicCryptoServerStream
> crypto_stream_
;
81 QuicServerSessionVisitor
* visitor_
;
83 DISALLOW_COPY_AND_ASSIGN(QuicServerSession
);
89 #endif // NET_TOOLS_QUIC_QUIC_SERVER_SESSION_H_