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 client specific QuicSession subclass. This class owns the underlying
6 // QuicConnection and QuicConnectionHelper objects. The connection stores
7 // a non-owning pointer to the helper so this session needs to ensure that
8 // the helper outlives the connection.
10 #ifndef NET_QUIC_QUIC_CLIENT_SESSION_H_
11 #define NET_QUIC_QUIC_CLIENT_SESSION_H_
15 #include "base/hash_tables.h"
16 #include "net/base/completion_callback.h"
17 #include "net/quic/quic_connection_logger.h"
18 #include "net/quic/quic_crypto_client_stream.h"
19 #include "net/quic/quic_reliable_client_stream.h"
20 #include "net/quic/quic_session.h"
24 class DatagramClientSocket
;
25 class QuicConnectionHelper
;
26 class QuicCryptoClientStreamFactory
;
27 class QuicStreamFactory
;
29 class NET_EXPORT_PRIVATE QuicClientSession
: public QuicSession
{
31 // Constructs a new session which will own |connection| and |helper|, but
32 // not |stream_factory|, which must outlive this session.
33 // TODO(rch): decouple the factory from the session via a Delegate interface.
34 QuicClientSession(QuicConnection
* connection
,
35 DatagramClientSocket
* socket
,
36 QuicStreamFactory
* stream_factory
,
37 QuicCryptoClientStreamFactory
* crypto_client_stream_factory
,
38 const std::string
& server_hostname
,
39 QuicCryptoClientConfig
* crypto_config
,
42 virtual ~QuicClientSession();
44 // QuicSession methods:
45 virtual QuicReliableClientStream
* CreateOutgoingReliableStream() OVERRIDE
;
46 virtual QuicCryptoClientStream
* GetCryptoStream() OVERRIDE
;
47 virtual void CloseStream(QuicStreamId stream_id
) OVERRIDE
;
48 virtual void OnCryptoHandshakeComplete(QuicErrorCode error
) OVERRIDE
;
50 // Performs a crypto handshake with the server.
51 int CryptoConnect(const CompletionCallback
& callback
);
53 // Causes the QuicConnectionHelper to start reading from the socket
54 // and passing the data along to the QuicConnection.
57 // Close the session because of |error|.
58 void CloseSessionOnError(int error
);
60 base::Value
* GetInfoAsValue(const HostPortPair
& pair
) const;
62 const BoundNetLog
& net_log() const { return net_log_
; }
65 // QuicSession methods:
66 virtual ReliableQuicStream
* CreateIncomingReliableStream(
67 QuicStreamId id
) OVERRIDE
;
70 // A completion callback invoked when a read completes.
71 void OnReadComplete(int result
);
73 base::WeakPtrFactory
<QuicClientSession
> weak_factory_
;
74 // config_ contains non-crypto configuration options negotiated in the crypto
77 scoped_ptr
<QuicCryptoClientStream
> crypto_stream_
;
78 QuicStreamFactory
* stream_factory_
;
79 scoped_ptr
<DatagramClientSocket
> socket_
;
80 scoped_refptr
<IOBufferWithSize
> read_buffer_
;
82 CompletionCallback callback_
;
83 size_t num_total_streams_
;
85 QuicConnectionLogger logger_
;
87 DISALLOW_COPY_AND_ASSIGN(QuicClientSession
);
92 #endif // NET_QUIC_QUIC_CLIENT_SESSION_H_