quic_client_session.h revision 5c02ac1a9c1b504631c0a3d2b6e737b5d738bae1
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// A client specific QuicSession subclass.  This class owns the underlying
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// QuicConnection and QuicConnectionHelper objects.  The connection stores
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// a non-owning pointer to the helper so this session needs to ensure that
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// the helper outlives the connection.
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef NET_QUIC_QUIC_CLIENT_SESSION_H_
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define NET_QUIC_QUIC_CLIENT_SESSION_H_
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <string>
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/basictypes.h"
167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/containers/hash_tables.h"
173551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "net/base/completion_callback.h"
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "net/proxy/proxy_server.h"
20effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "net/quic/quic_client_session_base.h"
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "net/quic/quic_connection_logger.h"
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/quic/quic_crypto_client_stream.h"
235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "net/quic/quic_protocol.h"
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/quic/quic_reliable_client_stream.h"
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace net {
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)class CertVerifyResult;
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class DatagramClientSocket;
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class QuicConnectionHelper;
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class QuicCryptoClientStreamFactory;
321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class QuicDefaultPacketWriter;
33e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochclass QuicServerId;
3423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)class QuicServerInfo;
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class QuicStreamFactory;
367dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochclass SSLInfo;
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace test {
3990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class QuicClientSessionPeer;
4090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}  // namespace test
4190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
42effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochclass NET_EXPORT_PRIVATE QuicClientSession : public QuicClientSessionBase {
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
448bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // An interface for observing events on a session.
458bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  class NET_EXPORT_PRIVATE Observer {
468bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)   public:
478bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    virtual ~Observer() {}
488bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    virtual void OnCryptoHandshakeConfirmed() = 0;
498bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    virtual void OnSessionClosed(int error) = 0;
508bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  };
518bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
52a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // A helper class used to manage a request to create a stream.
53a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  class NET_EXPORT_PRIVATE StreamRequest {
54a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)   public:
55a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    StreamRequest();
56a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    ~StreamRequest();
57a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
58a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    // Starts a request to create a stream.  If OK is returned, then
59a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    // |stream| will be updated with the newly created stream.  If
60a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    // ERR_IO_PENDING is returned, then when the request is eventuallly
61a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    // complete |callback| will be called.
628bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    int StartRequest(const base::WeakPtr<QuicClientSession>& session,
63a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)                     QuicReliableClientStream** stream,
64a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)                     const CompletionCallback& callback);
65a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
66a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    // Cancels any pending stream creation request. May be called
67a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    // repeatedly.
68a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    void CancelRequest();
69a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
70a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)   private:
71a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    friend class QuicClientSession;
72a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
73a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    // Called by |session_| for an asynchronous request when the stream
74a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    // request has finished successfully.
75a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    void OnRequestCompleteSuccess(QuicReliableClientStream* stream);
76a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
77a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    // Called by |session_| for an asynchronous request when the stream
78a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    // request has finished with an error. Also called with ERR_ABORTED
79a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    // if |session_| is destroyed while the stream request is still pending.
80a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    void OnRequestCompleteFailure(int rv);
81a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
82a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    base::WeakPtr<QuicClientSession> session_;
83a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    CompletionCallback callback_;
84a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    QuicReliableClientStream** stream_;
85a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
86a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    DISALLOW_COPY_AND_ASSIGN(StreamRequest);
87a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  };
88a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Constructs a new session which will own |connection| and |helper|, but
902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // not |stream_factory|, which must outlive this session.
912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // TODO(rch): decouple the factory from the session via a Delegate interface.
922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  QuicClientSession(QuicConnection* connection,
933551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)                    scoped_ptr<DatagramClientSocket> socket,
941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                    scoped_ptr<QuicDefaultPacketWriter> writer,
952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                    QuicStreamFactory* stream_factory,
962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                    QuicCryptoClientStreamFactory* crypto_client_stream_factory,
9723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)                    scoped_ptr<QuicServerInfo> server_info,
98e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch                    const QuicServerId& server_id,
9990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                    const QuicConfig& config,
100c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                    QuicCryptoClientConfig* crypto_config,
1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                    NetLog* net_log);
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~QuicClientSession();
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1058bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  void AddObserver(Observer* observer);
1068bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  void RemoveObserver(Observer* observer);
1078bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
108a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // Attempts to create a new stream.  If the stream can be
109a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // created immediately, returns OK.  If the open stream limit
110a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // has been reached, returns ERR_IO_PENDING, and |request|
111a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // will be added to the stream requets queue and will
112a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // be completed asynchronously.
113a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // TODO(rch): remove |stream| from this and use setter on |request|
114a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // and fix in spdy too.
115a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  int TryCreateStream(StreamRequest* request,
116a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)                      QuicReliableClientStream** stream);
117a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
118a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // Cancels the pending stream creation request.
119a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  void CancelRequest(StreamRequest* request);
120a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // QuicSession methods:
1225c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  virtual void OnStreamFrames(
12368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)      const std::vector<QuicStreamFrame>& frames) OVERRIDE;
1245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual QuicReliableClientStream* CreateOutgoingDataStream() OVERRIDE;
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual QuicCryptoClientStream* GetCryptoStream() OVERRIDE;
1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void CloseStream(QuicStreamId stream_id) OVERRIDE;
127424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  virtual void SendRstStream(QuicStreamId id,
1285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                             QuicRstStreamErrorCode error,
1295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                             QuicStreamOffset bytes_written) OVERRIDE;
130c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual void OnCryptoHandshakeEvent(CryptoHandshakeEvent event) OVERRIDE;
1313551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual void OnCryptoHandshakeMessageSent(
1323551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      const CryptoHandshakeMessage& message) OVERRIDE;
1333551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual void OnCryptoHandshakeMessageReceived(
1343551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      const CryptoHandshakeMessage& message) OVERRIDE;
13523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  virtual bool GetSSLInfo(SSLInfo* ssl_info) const OVERRIDE;
13623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)
137effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // QuicClientSessionBase methods:
13823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  virtual void OnProofValid(
13923730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)      const QuicCryptoClientConfig::CachedState& cached) OVERRIDE;
14023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  virtual void OnProofVerifyDetailsAvailable(
14123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)      const ProofVerifyDetails& verify_details) OVERRIDE;
142c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
143c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // QuicConnectionVisitorInterface methods:
1441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void OnConnectionClosed(QuicErrorCode error, bool from_peer) OVERRIDE;
145d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  virtual void OnSuccessfulVersionNegotiation(
146d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      const QuicVersion& version) OVERRIDE;
1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Performs a crypto handshake with the server.
1493551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  int CryptoConnect(bool require_confirmation,
1503551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)                    const CompletionCallback& callback);
1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Causes the QuicConnectionHelper to start reading from the socket
1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // and passing the data along to the QuicConnection.
1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void StartReading();
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
156eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Close the session because of |error| and notifies the factory
157eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // that this session has been closed, which will delete the session.
1582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void CloseSessionOnError(int error);
1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
160a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  base::Value* GetInfoAsValue(const std::set<HostPortPair>& aliases) const;
1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const BoundNetLog& net_log() const { return net_log_; }
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
164a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  base::WeakPtr<QuicClientSession> GetWeakPtr();
165a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
16658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Returns the number of client hello messages that have been sent on the
16758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // crypto stream. If the handshake has completed then this is one greater
16858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // than the number of round-trips needed for the handshake.
16958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  int GetNumSentClientHellos() const;
17058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
1715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Returns true if |hostname| may be pooled onto this session.  If this
1725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // is a secure QUIC session, then |hostname| must match the certificate
1735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // presented during the handshake.
1745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool CanPool(const std::string& hostname) const;
1755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // QuicSession methods:
1785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual QuicDataStream* CreateIncomingDataStream(QuicStreamId id) OVERRIDE;
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
18190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  friend class test::QuicClientSessionPeer;
182a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
1838bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  typedef std::set<Observer*> ObserverSet;
184a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  typedef std::list<StreamRequest*> StreamRequestQueue;
185a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
186a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  QuicReliableClientStream* CreateOutgoingReliableStreamImpl();
1872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // A completion callback invoked when a read completes.
1882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void OnReadComplete(int result);
1892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
190424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  void OnClosedStream();
191424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
1928bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // A Session may be closed via any of three methods:
1938bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // OnConnectionClosed - called by the connection when the connection has been
1948bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  //     closed, perhaps due to a timeout or a protocol error.
1958bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // CloseSessionOnError - called from the owner of the session,
1968bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  //     the QuicStreamFactory, when there is an error.
1978bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // OnReadComplete - when there is a read error.
1988bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // This method closes all stream and performs any necessary cleanup.
19958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  void CloseSessionOnErrorInner(int net_error, QuicErrorCode quic_error);
200eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
2018bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  void CloseAllStreams(int net_error);
2028bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  void CloseAllObservers(int net_error);
2038bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
2048bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // Notifies the factory that this session is going away and no more streams
2058bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // should be created from it.  This needs to be called before closing any
2068bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // streams, because closing a stream may cause a new stream to be created.
2078bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  void NotifyFactoryOfSessionGoingAway();
2088bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
209eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Posts a task to notify the factory that this session has been closed.
2108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  void NotifyFactoryOfSessionClosedLater();
211eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
212eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Notifies the factory that this session has been closed which will
213eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // delete |this|.
2148bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  void NotifyFactoryOfSessionClosed();
215eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
2163551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  bool require_confirmation_;
2172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_ptr<QuicCryptoClientStream> crypto_stream_;
2182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  QuicStreamFactory* stream_factory_;
2192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_ptr<DatagramClientSocket> socket_;
2201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  scoped_ptr<QuicDefaultPacketWriter> writer_;
2212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_refptr<IOBufferWithSize> read_buffer_;
22223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  scoped_ptr<QuicServerInfo> server_info_;
22323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  scoped_ptr<CertVerifyResult> cert_verify_result_;
2248bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  ObserverSet observers_;
225a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  StreamRequestQueue stream_requests_;
2262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool read_pending_;
2272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  CompletionCallback callback_;
2282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  size_t num_total_streams_;
2292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  BoundNetLog net_log_;
2302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  QuicConnectionLogger logger_;
2311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Number of packets read in the current read loop.
2321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  size_t num_packets_read_;
233effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // True when the session is going away, and streams may no longer be created
234effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // on this session. Existing stream will continue to be processed.
235effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  bool going_away_;
2363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  base::WeakPtrFactory<QuicClientSession> weak_factory_;
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(QuicClientSession);
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace net
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // NET_QUIC_QUIC_CLIENT_SESSION_H_
244