Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / net / quic / quic_server_session.h
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.
4 //
5 // A server specific QuicSession subclass.
6
7 #ifndef NET_QUIC_QUIC_SERVER_SESSION_H_
8 #define NET_QUIC_QUIC_SERVER_SESSION_H_
9
10 #include <set>
11 #include <vector>
12
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"
20
21 namespace net {
22
23 class QuicBlockedWriterInterface;
24 class QuicConfig;
25 class QuicConnection;
26 class QuicCryptoServerConfig;
27 class ReliableQuicStream;
28
29 namespace test {
30 class QuicServerSessionPeer;
31 }  // namespace test
32
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 {
37  public:
38   virtual ~QuicServerSessionVisitor() {}
39
40   virtual void OnConnectionClosed(QuicConnectionId connection_id,
41                                   QuicErrorCode error) = 0;
42   virtual void OnWriteBlocked(QuicBlockedWriterInterface* blocked_writer) = 0;
43 };
44
45 class QuicServerSession : public QuicSession {
46  public:
47   // Takes ownership of connection_packet_writer
48   QuicServerSession(const QuicConfig& config,
49                     QuicConnection* connection,
50                     QuicPerConnectionPacketWriter* connection_packet_writer,
51                     QuicServerSessionVisitor* visitor);
52
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;
56
57   virtual ~QuicServerSession();
58
59   virtual void InitializeSession(const QuicCryptoServerConfig& crypto_config);
60
61   const QuicCryptoServerStream* crypto_stream() const {
62     return crypto_stream_.get();
63   }
64
65   // Override base class to process FEC config received from client.
66   virtual void OnConfigNegotiated() OVERRIDE;
67
68  protected:
69   // QuicSession methods:
70   virtual QuicDataStream* CreateIncomingDataStream(QuicStreamId id) OVERRIDE;
71   virtual QuicDataStream* CreateOutgoingDataStream() OVERRIDE;
72   virtual QuicCryptoServerStream* GetCryptoStream() OVERRIDE;
73
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);
78
79   virtual QuicCryptoServerStream* CreateQuicCryptoServerStream(
80       const QuicCryptoServerConfig& crypto_config);
81
82  private:
83   friend class test::QuicServerSessionPeer;
84
85   scoped_ptr<QuicCryptoServerStream> crypto_stream_;
86   scoped_ptr<QuicPerConnectionPacketWriter> connection_packet_writer_;
87   QuicServerSessionVisitor* visitor_;
88
89   DISALLOW_COPY_AND_ASSIGN(QuicServerSession);
90 };
91
92 }  // namespace net
93
94 #endif  // NET_QUIC_QUIC_SERVER_SESSION_H_