- add sources.
[platform/framework/web/crosswalk.git] / src / net / tools / quic / quic_server_session.h
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.
4 //
5 // A server specific QuicSession subclass.
6
7 #ifndef NET_TOOLS_QUIC_QUIC_SERVER_SESSION_H_
8 #define NET_TOOLS_QUIC_QUIC_SERVER_SESSION_H_
9
10 #include <set>
11 #include <vector>
12
13 #include "base/containers/hash_tables.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "net/quic/quic_crypto_server_stream.h"
16 #include "net/quic/quic_protocol.h"
17 #include "net/quic/quic_session.h"
18
19 namespace net {
20
21 class QuicConfig;
22 class QuicConnection;
23 class QuicCryptoServerConfig;
24 class ReliableQuicStream;
25
26 namespace tools {
27
28 namespace test {
29 class QuicServerSessionPeer;
30 }  // namespace test
31
32 // An interface from the session to the entity owning the session.
33 // This lets the session notify its owner (the Dispatcher) when the connection
34 // is closed.
35 class QuicSessionOwner {
36  public:
37   virtual ~QuicSessionOwner() {}
38
39   virtual void OnConnectionClosed(QuicGuid guid, QuicErrorCode error) = 0;
40 };
41
42 class QuicServerSession : public QuicSession {
43  public:
44   QuicServerSession(const QuicConfig& config,
45                     QuicConnection *connection,
46                     QuicSessionOwner* owner);
47
48   // Override the base class to notify the owner of the connection close.
49   virtual void OnConnectionClosed(QuicErrorCode error, bool from_peer) OVERRIDE;
50
51   virtual ~QuicServerSession();
52
53   virtual void InitializeSession(const QuicCryptoServerConfig& crypto_config);
54
55   const QuicCryptoServerStream* crypto_stream() { return crypto_stream_.get(); }
56
57  protected:
58   // QuicSession methods:
59   virtual ReliableQuicStream* CreateIncomingReliableStream(
60       QuicStreamId id) OVERRIDE;
61   virtual ReliableQuicStream* CreateOutgoingReliableStream() OVERRIDE;
62   virtual QuicCryptoServerStream* GetCryptoStream() OVERRIDE;
63
64   // If we should create an incoming stream, returns true. Otherwise
65   // does error handling, including communicating the error to the client and
66   // possibly closing the connection, and returns false.
67   virtual bool ShouldCreateIncomingReliableStream(QuicStreamId id);
68
69   virtual QuicCryptoServerStream* CreateQuicCryptoServerStream(
70     const QuicCryptoServerConfig& crypto_config);
71
72  private:
73   friend class test::QuicServerSessionPeer;
74
75   scoped_ptr<QuicCryptoServerStream> crypto_stream_;
76   QuicSessionOwner* owner_;
77
78   DISALLOW_COPY_AND_ASSIGN(QuicServerSession);
79 };
80
81 }  // namespace tools
82 }  // namespace net
83
84 #endif  // NET_TOOLS_QUIC_QUIC_SERVER_SESSION_H_