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" 18f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "base/time/time.h" 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "net/base/completion_callback.h" 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "net/proxy/proxy_server.h" 21effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "net/quic/quic_client_session_base.h" 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "net/quic/quic_connection_logger.h" 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/quic/quic_crypto_client_stream.h" 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "net/quic/quic_protocol.h" 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/quic/quic_reliable_client_stream.h" 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace net { 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2923730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)class CertVerifyResult; 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class DatagramClientSocket; 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class QuicConnectionHelper; 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class QuicCryptoClientStreamFactory; 33e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochclass QuicServerId; 3423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)class QuicServerInfo; 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class QuicStreamFactory; 367dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochclass SSLInfo; 3703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)class TransportSecurityState; 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace test { 4090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class QuicClientSessionPeer; 4190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} // namespace test 4290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 43effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochclass NET_EXPORT_PRIVATE QuicClientSession : public QuicClientSessionBase { 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 458bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // An interface for observing events on a session. 468bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) class NET_EXPORT_PRIVATE Observer { 478bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) public: 488bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual ~Observer() {} 498bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual void OnCryptoHandshakeConfirmed() = 0; 508bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual void OnSessionClosed(int error) = 0; 518bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) }; 528bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 53a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // A helper class used to manage a request to create a stream. 54a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) class NET_EXPORT_PRIVATE StreamRequest { 55a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) public: 56a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) StreamRequest(); 57a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) ~StreamRequest(); 58a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 59a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // Starts a request to create a stream. If OK is returned, then 60a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // |stream| will be updated with the newly created stream. If 61a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // ERR_IO_PENDING is returned, then when the request is eventuallly 62a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // complete |callback| will be called. 638bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) int StartRequest(const base::WeakPtr<QuicClientSession>& session, 64a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) QuicReliableClientStream** stream, 65a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const CompletionCallback& callback); 66a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 67a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // Cancels any pending stream creation request. May be called 68a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // repeatedly. 69a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) void CancelRequest(); 70a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 71a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) private: 72a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) friend class QuicClientSession; 73a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 74a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // Called by |session_| for an asynchronous request when the stream 75a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // request has finished successfully. 76a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) void OnRequestCompleteSuccess(QuicReliableClientStream* stream); 77a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 78a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // Called by |session_| for an asynchronous request when the stream 79a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // request has finished with an error. Also called with ERR_ABORTED 80a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // if |session_| is destroyed while the stream request is still pending. 81a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) void OnRequestCompleteFailure(int rv); 82a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 83a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) base::WeakPtr<QuicClientSession> session_; 84a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) CompletionCallback callback_; 85a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) QuicReliableClientStream** stream_; 86a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 87a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(StreamRequest); 88a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) }; 89a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 901320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Constructs a new session which will own |connection|, but not 911320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // |stream_factory|, which must outlive this session. 922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // TODO(rch): decouple the factory from the session via a Delegate interface. 932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) QuicClientSession(QuicConnection* connection, 943551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) scoped_ptr<DatagramClientSocket> socket, 952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) QuicStreamFactory* stream_factory, 9603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) TransportSecurityState* transport_security_state, 9723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) scoped_ptr<QuicServerInfo> server_info, 9890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const QuicConfig& config, 9946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) base::TaskRunner* task_runner, 1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NetLog* net_log); 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~QuicClientSession(); 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1031320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Initialize session's connection to |server_id|. 1041320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci void InitializeSession( 1051320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci const QuicServerId& server_id, 1061320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci QuicCryptoClientConfig* config, 1071320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci QuicCryptoClientStreamFactory* crypto_client_stream_factory); 1081320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 1098bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) void AddObserver(Observer* observer); 1108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) void RemoveObserver(Observer* observer); 1118bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 112a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // Attempts to create a new stream. If the stream can be 113a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // created immediately, returns OK. If the open stream limit 114a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // has been reached, returns ERR_IO_PENDING, and |request| 115a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // will be added to the stream requets queue and will 116a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // be completed asynchronously. 117a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // TODO(rch): remove |stream| from this and use setter on |request| 118a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // and fix in spdy too. 119a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) int TryCreateStream(StreamRequest* request, 120a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) QuicReliableClientStream** stream); 121a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 122a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // Cancels the pending stream creation request. 123a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) void CancelRequest(StreamRequest* request); 124a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // QuicSession methods: 1265c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu virtual void OnStreamFrames( 12768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) const std::vector<QuicStreamFrame>& frames) OVERRIDE; 1285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual QuicReliableClientStream* CreateOutgoingDataStream() OVERRIDE; 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual QuicCryptoClientStream* GetCryptoStream() OVERRIDE; 1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void CloseStream(QuicStreamId stream_id) OVERRIDE; 131424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) virtual void SendRstStream(QuicStreamId id, 1325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) QuicRstStreamErrorCode error, 1335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) QuicStreamOffset bytes_written) OVERRIDE; 134c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void OnCryptoHandshakeEvent(CryptoHandshakeEvent event) OVERRIDE; 1353551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual void OnCryptoHandshakeMessageSent( 1363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const CryptoHandshakeMessage& message) OVERRIDE; 1373551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual void OnCryptoHandshakeMessageReceived( 1383551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const CryptoHandshakeMessage& message) OVERRIDE; 13923730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) virtual bool GetSSLInfo(SSLInfo* ssl_info) const OVERRIDE; 14023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) 141effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // QuicClientSessionBase methods: 14223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) virtual void OnProofValid( 14323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) const QuicCryptoClientConfig::CachedState& cached) OVERRIDE; 14423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) virtual void OnProofVerifyDetailsAvailable( 14523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) const ProofVerifyDetails& verify_details) OVERRIDE; 146c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 147c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // QuicConnectionVisitorInterface methods: 1481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual void OnConnectionClosed(QuicErrorCode error, bool from_peer) OVERRIDE; 149d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) virtual void OnSuccessfulVersionNegotiation( 150d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) const QuicVersion& version) OVERRIDE; 1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Performs a crypto handshake with the server. 1533551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) int CryptoConnect(bool require_confirmation, 1543551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const CompletionCallback& callback); 1552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 15646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // Resumes a crypto handshake with the server after a timeout. 15746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) int ResumeCryptoConnect(const CompletionCallback& callback); 15846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Causes the QuicConnectionHelper to start reading from the socket 1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // and passing the data along to the QuicConnection. 1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void StartReading(); 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 163eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Close the session because of |error| and notifies the factory 164eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // that this session has been closed, which will delete the session. 1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void CloseSessionOnError(int error); 1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 167cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::Value* GetInfoAsValue(const std::set<HostPortPair>& aliases); 1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const BoundNetLog& net_log() const { return net_log_; } 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 171a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) base::WeakPtr<QuicClientSession> GetWeakPtr(); 172a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 17358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // Returns the number of client hello messages that have been sent on the 17458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // crypto stream. If the handshake has completed then this is one greater 17558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // than the number of round-trips needed for the handshake. 17658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) int GetNumSentClientHellos() const; 17758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 1785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Returns true if |hostname| may be pooled onto this session. If this 1795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // is a secure QUIC session, then |hostname| must match the certificate 1805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // presented during the handshake. 1815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool CanPool(const std::string& hostname) const; 1825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // QuicSession methods: 1855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual QuicDataStream* CreateIncomingDataStream(QuicStreamId id) OVERRIDE; 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 18890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) friend class test::QuicClientSessionPeer; 189a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 1908bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) typedef std::set<Observer*> ObserverSet; 191a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) typedef std::list<StreamRequest*> StreamRequestQueue; 192a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 193a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) QuicReliableClientStream* CreateOutgoingReliableStreamImpl(); 1942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // A completion callback invoked when a read completes. 1952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void OnReadComplete(int result); 1962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 197424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) void OnClosedStream(); 198424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 1998bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // A Session may be closed via any of three methods: 2008bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // OnConnectionClosed - called by the connection when the connection has been 2018bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // closed, perhaps due to a timeout or a protocol error. 2028bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // CloseSessionOnError - called from the owner of the session, 2038bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // the QuicStreamFactory, when there is an error. 2048bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // OnReadComplete - when there is a read error. 2058bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // This method closes all stream and performs any necessary cleanup. 20658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) void CloseSessionOnErrorInner(int net_error, QuicErrorCode quic_error); 207eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 2088bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) void CloseAllStreams(int net_error); 2098bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) void CloseAllObservers(int net_error); 2108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 2118bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Notifies the factory that this session is going away and no more streams 2128bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // should be created from it. This needs to be called before closing any 2138bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // streams, because closing a stream may cause a new stream to be created. 2148bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) void NotifyFactoryOfSessionGoingAway(); 2158bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 216eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Posts a task to notify the factory that this session has been closed. 2178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) void NotifyFactoryOfSessionClosedLater(); 218eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 219eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Notifies the factory that this session has been closed which will 220eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // delete |this|. 2218bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) void NotifyFactoryOfSessionClosed(); 222eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 22346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) void OnConnectTimeout(); 22446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 2251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci HostPortPair server_host_port_; 2263551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) bool require_confirmation_; 2272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<QuicCryptoClientStream> crypto_stream_; 2282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) QuicStreamFactory* stream_factory_; 2292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<DatagramClientSocket> socket_; 2302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<IOBufferWithSize> read_buffer_; 23103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) TransportSecurityState* transport_security_state_; 23223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) scoped_ptr<QuicServerInfo> server_info_; 23323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) scoped_ptr<CertVerifyResult> cert_verify_result_; 2345f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) std::string pinning_failure_log_; 2358bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ObserverSet observers_; 236a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) StreamRequestQueue stream_requests_; 2372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool read_pending_; 2382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CompletionCallback callback_; 2392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) size_t num_total_streams_; 24046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) base::TaskRunner* task_runner_; 2412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BoundNetLog net_log_; 242f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) base::TimeTicks handshake_start_; // Time the handshake was started. 2435f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) QuicConnectionLogger* logger_; // Owned by |connection_|. 2441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Number of packets read in the current read loop. 2451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) size_t num_packets_read_; 246effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // True when the session is going away, and streams may no longer be created 247effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // on this session. Existing stream will continue to be processed. 248effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch bool going_away_; 2493551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) base::WeakPtrFactory<QuicClientSession> weak_factory_; 2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(QuicClientSession); 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace net 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // NET_QUIC_QUIC_CLIENT_SESSION_H_ 257