Enables compositing support for webview.
[chromium-blink-merge.git] / net / spdy / spdy_session.h
bloba51daae507bbe2b9b40de3108b154e242db6ed85
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 #ifndef NET_SPDY_SPDY_SESSION_H_
6 #define NET_SPDY_SPDY_SESSION_H_
8 #include <algorithm>
9 #include <list>
10 #include <map>
11 #include <queue>
12 #include <string>
14 #include "base/gtest_prod_util.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/memory/weak_ptr.h"
17 #include "base/time.h"
18 #include "net/base/io_buffer.h"
19 #include "net/base/load_states.h"
20 #include "net/base/net_errors.h"
21 #include "net/base/request_priority.h"
22 #include "net/base/ssl_client_cert_type.h"
23 #include "net/base/ssl_config_service.h"
24 #include "net/socket/client_socket_handle.h"
25 #include "net/socket/ssl_client_socket.h"
26 #include "net/socket/stream_socket.h"
27 #include "net/spdy/buffered_spdy_framer.h"
28 #include "net/spdy/spdy_credential_state.h"
29 #include "net/spdy/spdy_header_block.h"
30 #include "net/spdy/spdy_io_buffer.h"
31 #include "net/spdy/spdy_protocol.h"
32 #include "net/spdy/spdy_session_pool.h"
34 namespace net {
36 // This is somewhat arbitrary and not really fixed, but it will always work
37 // reasonably with ethernet. Chop the world into 2-packet chunks. This is
38 // somewhat arbitrary, but is reasonably small and ensures that we elicit
39 // ACKs quickly from TCP (because TCP tries to only ACK every other packet).
40 const int kMss = 1430;
41 const int kMaxSpdyFrameChunkSize = (2 * kMss) - SpdyFrame::kHeaderSize;
43 // Specifies the maxiumum concurrent streams server could send (via push).
44 const int kMaxConcurrentPushedStreams = 1000;
46 class BoundNetLog;
47 class SpdyStream;
48 class SSLInfo;
50 enum SpdyProtocolErrorDetails {
51 // SpdyFramer::SpdyErrors
52 SPDY_ERROR_NO_ERROR,
53 SPDY_ERROR_INVALID_CONTROL_FRAME,
54 SPDY_ERROR_CONTROL_PAYLOAD_TOO_LARGE,
55 SPDY_ERROR_ZLIB_INIT_FAILURE,
56 SPDY_ERROR_UNSUPPORTED_VERSION,
57 SPDY_ERROR_DECOMPRESS_FAILURE,
58 SPDY_ERROR_COMPRESS_FAILURE,
59 SPDY_ERROR_CREDENTIAL_FRAME_CORRUPT,
60 SPDY_ERROR_INVALID_DATA_FRAME_FLAGS,
62 // SpdyStatusCodes
63 STATUS_CODE_INVALID,
64 STATUS_CODE_PROTOCOL_ERROR,
65 STATUS_CODE_INVALID_STREAM,
66 STATUS_CODE_REFUSED_STREAM,
67 STATUS_CODE_UNSUPPORTED_VERSION,
68 STATUS_CODE_CANCEL,
69 STATUS_CODE_INTERNAL_ERROR,
70 STATUS_CODE_FLOW_CONTROL_ERROR,
71 STATUS_CODE_STREAM_IN_USE,
72 STATUS_CODE_STREAM_ALREADY_CLOSED,
73 STATUS_CODE_INVALID_CREDENTIALS,
74 STATUS_CODE_FRAME_TOO_LARGE,
76 // SpdySession errors
77 PROTOCOL_ERROR_UNEXPECTED_PING,
78 PROTOCOL_ERROR_RST_STREAM_FOR_NON_ACTIVE_STREAM,
79 PROTOCOL_ERROR_SPDY_COMPRESSION_FAILURE,
80 PROTOCOL_ERROR_REQUEST_FOR_SECURE_CONTENT_OVER_INSECURE_SESSION,
81 PROTOCOL_ERROR_SYN_REPLY_NOT_RECEIVED,
82 NUM_SPDY_PROTOCOL_ERROR_DETAILS
85 COMPILE_ASSERT(STATUS_CODE_INVALID ==
86 static_cast<SpdyProtocolErrorDetails>(SpdyFramer::LAST_ERROR),
87 SpdyProtocolErrorDetails_SpdyErrors_mismatch);
89 COMPILE_ASSERT(PROTOCOL_ERROR_UNEXPECTED_PING ==
90 static_cast<SpdyProtocolErrorDetails>(NUM_STATUS_CODES +
91 STATUS_CODE_INVALID),
92 SpdyProtocolErrorDetails_SpdyErrors_mismatch);
94 class NET_EXPORT SpdySession : public base::RefCounted<SpdySession>,
95 public BufferedSpdyFramerVisitorInterface {
96 public:
97 typedef base::TimeTicks (*TimeFunc)(void);
99 // Defines an interface for producing SpdyIOBuffers.
100 class NET_EXPORT_PRIVATE SpdyIOBufferProducer {
101 public:
102 SpdyIOBufferProducer() {}
104 // Returns a newly created SpdyIOBuffer, owned by the caller, or NULL
105 // if not buffer is ready to be produced.
106 virtual SpdyIOBuffer* ProduceNextBuffer(SpdySession* session) = 0;
108 virtual RequestPriority GetPriority() const = 0;
110 virtual ~SpdyIOBufferProducer() {}
112 protected:
113 // Activates |spdy_stream| in |spdy_session|.
114 static void ActivateStream(SpdySession* spdy_session,
115 SpdyStream* spdy_stream);
117 static SpdyIOBuffer* CreateIOBuffer(SpdyFrame* frame,
118 RequestPriority priority,
119 SpdyStream* spdy_stream);
121 private:
122 DISALLOW_COPY_AND_ASSIGN(SpdyIOBufferProducer);
125 // Create a new SpdySession.
126 // |host_port_proxy_pair| is the host/port that this session connects to, and
127 // the proxy configuration settings that it's using.
128 // |spdy_session_pool| is the SpdySessionPool that owns us. Its lifetime must
129 // strictly be greater than |this|.
130 // |session| is the HttpNetworkSession. |net_log| is the NetLog that we log
131 // network events to.
132 SpdySession(const HostPortProxyPair& host_port_proxy_pair,
133 SpdySessionPool* spdy_session_pool,
134 HttpServerProperties* http_server_properties,
135 bool verify_domain_authentication,
136 bool enable_sending_initial_settings,
137 bool enable_credential_frames,
138 bool enable_compression,
139 bool enable_ping_based_connection_checking,
140 NextProto default_protocol_,
141 size_t initial_recv_window_size,
142 size_t initial_max_concurrent_streams,
143 size_t max_concurrent_streams_limit,
144 TimeFunc time_func,
145 const HostPortPair& trusted_spdy_proxy,
146 NetLog* net_log);
148 const HostPortPair& host_port_pair() const {
149 return host_port_proxy_pair_.first;
151 const HostPortProxyPair& host_port_proxy_pair() const {
152 return host_port_proxy_pair_;
155 // Get a pushed stream for a given |url|.
156 // If the server initiates a stream, it might already exist for a given path.
157 // The server might also not have initiated the stream yet, but indicated it
158 // will via X-Associated-Content. Writes the stream out to |spdy_stream|.
159 // Returns a net error code.
160 int GetPushStream(
161 const GURL& url,
162 scoped_refptr<SpdyStream>* spdy_stream,
163 const BoundNetLog& stream_net_log);
165 // Create a new stream for a given |url|. Writes it out to |spdy_stream|.
166 // Returns a net error code, possibly ERR_IO_PENDING.
167 int CreateStream(
168 const GURL& url,
169 RequestPriority priority,
170 scoped_refptr<SpdyStream>* spdy_stream,
171 const BoundNetLog& stream_net_log,
172 const CompletionCallback& callback);
174 // Remove PendingCreateStream objects on transaction deletion
175 void CancelPendingCreateStreams(const scoped_refptr<SpdyStream>* spdy_stream);
177 // Used by SpdySessionPool to initialize with a pre-existing SSL socket. For
178 // testing, setting is_secure to false allows initialization with a
179 // pre-existing TCP socket.
180 // Returns OK on success, or an error on failure.
181 net::Error InitializeWithSocket(ClientSocketHandle* connection,
182 bool is_secure,
183 int certificate_error_code);
185 // Check to see if this SPDY session can support an additional domain.
186 // If the session is un-authenticated, then this call always returns true.
187 // For SSL-based sessions, verifies that the server certificate in use by
188 // this session provides authentication for the domain and no client
189 // certificate or channel ID was sent to the original server during the SSL
190 // handshake. NOTE: This function can have false negatives on some
191 // platforms.
192 // TODO(wtc): rename this function and the Net.SpdyIPPoolDomainMatch
193 // histogram because this function does more than verifying domain
194 // authentication now.
195 bool VerifyDomainAuthentication(const std::string& domain);
197 // Records that |stream| has a write available from |producer|.
198 // |producer| will be owned by this SpdySession.
199 void SetStreamHasWriteAvailable(SpdyStream* stream,
200 SpdyIOBufferProducer* producer);
202 // Send the SYN frame for |stream_id|. This also sends PING message to check
203 // the status of the connection.
204 SpdySynStreamControlFrame* CreateSynStream(
205 SpdyStreamId stream_id,
206 RequestPriority priority,
207 uint8 credential_slot,
208 SpdyControlFlags flags,
209 const SpdyHeaderBlock& headers);
211 // Write a CREDENTIAL frame to the session.
212 SpdyCredentialControlFrame* CreateCredentialFrame(const std::string& origin,
213 SSLClientCertType type,
214 const std::string& key,
215 const std::string& cert,
216 RequestPriority priority);
218 // Write a HEADERS frame to the stream.
219 SpdyHeadersControlFrame* CreateHeadersFrame(SpdyStreamId stream_id,
220 const SpdyHeaderBlock& headers,
221 SpdyControlFlags flags);
223 // Write a data frame to the stream.
224 // Used to create and queue a data frame for the given stream.
225 SpdyDataFrame* CreateDataFrame(SpdyStreamId stream_id,
226 net::IOBuffer* data, int len,
227 SpdyDataFlags flags);
229 // Close a stream.
230 void CloseStream(SpdyStreamId stream_id, int status);
232 // Close a stream that has been created but is not yet active.
233 void CloseCreatedStream(SpdyStream* stream, int status);
235 // Reset a stream by sending a RST_STREAM frame with given status code.
236 // Also closes the stream. Was not piggybacked to CloseStream since not
237 // all of the calls to CloseStream necessitate sending a RST_STREAM.
238 void ResetStream(SpdyStreamId stream_id,
239 SpdyStatusCodes status,
240 const std::string& description);
242 // Check if a stream is active.
243 bool IsStreamActive(SpdyStreamId stream_id) const;
245 // The LoadState is used for informing the user of the current network
246 // status, such as "resolving host", "connecting", etc.
247 LoadState GetLoadState() const;
249 // Fills SSL info in |ssl_info| and returns true when SSL is in use.
250 bool GetSSLInfo(SSLInfo* ssl_info,
251 bool* was_npn_negotiated,
252 NextProto* protocol_negotiated);
254 // Fills SSL Certificate Request info |cert_request_info| and returns
255 // true when SSL is in use.
256 bool GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info);
258 // Returns the ServerBoundCertService used by this Socket, or NULL
259 // if server bound certs are not supported in this session.
260 ServerBoundCertService* GetServerBoundCertService() const;
262 // Send WINDOW_UPDATE frame, called by a stream whenever receive window
263 // size is increased.
264 void SendWindowUpdate(SpdyStreamId stream_id, int32 delta_window_size);
266 // If session is closed, no new streams/transactions should be created.
267 bool IsClosed() const { return state_ == CLOSED; }
269 // Closes this session. This will close all active streams and mark
270 // the session as permanently closed.
271 // |err| should not be OK; this function is intended to be called on
272 // error.
273 // |remove_from_pool| indicates whether to also remove the session from the
274 // session pool.
275 // |description| indicates the reason for the error.
276 void CloseSessionOnError(net::Error err,
277 bool remove_from_pool,
278 const std::string& description);
280 // Retrieves information on the current state of the SPDY session as a
281 // Value. Caller takes possession of the returned value.
282 base::Value* GetInfoAsValue() const;
284 // Indicates whether the session is being reused after having successfully
285 // used to send/receive data in the past.
286 bool IsReused() const;
288 // Returns true if the underlying transport socket ever had any reads or
289 // writes.
290 bool WasEverUsed() const {
291 return connection_->socket()->WasEverUsed();
294 void set_spdy_session_pool(SpdySessionPool* pool) {
295 spdy_session_pool_ = NULL;
298 // Returns true if session is not currently active
299 bool is_active() const {
300 return !active_streams_.empty() || !created_streams_.empty();
303 // Access to the number of active and pending streams. These are primarily
304 // available for testing and diagnostics.
305 size_t num_active_streams() const { return active_streams_.size(); }
306 size_t num_unclaimed_pushed_streams() const {
307 return unclaimed_pushed_streams_.size();
309 size_t num_created_streams() const { return created_streams_.size(); }
311 // Returns true if flow control is enabled for the session.
312 bool is_flow_control_enabled() const {
313 return flow_control_;
316 // Returns the current |initial_send_window_size_|.
317 int32 initial_send_window_size() const {
318 return initial_send_window_size_;
321 // Returns the current |initial_recv_window_size_|.
322 int32 initial_recv_window_size() const { return initial_recv_window_size_; }
324 // Sets |initial_recv_window_size_| used by unittests.
325 void set_initial_recv_window_size(int32 window_size) {
326 initial_recv_window_size_ = window_size;
329 const BoundNetLog& net_log() const { return net_log_; }
331 int GetPeerAddress(IPEndPoint* address) const;
332 int GetLocalAddress(IPEndPoint* address) const;
334 // Returns true if requests on this session require credentials.
335 bool NeedsCredentials() const;
337 SpdyCredentialState* credential_state() { return &credential_state_; }
339 // Adds |alias| to set of aliases associated with this session.
340 void AddPooledAlias(const HostPortProxyPair& alias);
342 // Returns the set of aliases associated with this session.
343 const std::set<HostPortProxyPair>& pooled_aliases() const {
344 return pooled_aliases_;
347 int GetProtocolVersion() const;
349 private:
350 friend class base::RefCounted<SpdySession>;
352 // Allow tests to access our innards for testing purposes.
353 FRIEND_TEST_ALL_PREFIXES(SpdySessionSpdy2Test, ClientPing);
354 FRIEND_TEST_ALL_PREFIXES(SpdySessionSpdy2Test, FailedPing);
355 FRIEND_TEST_ALL_PREFIXES(SpdySessionSpdy2Test, GetActivePushStream);
356 FRIEND_TEST_ALL_PREFIXES(SpdySessionSpdy2Test, DeleteExpiredPushStreams);
357 FRIEND_TEST_ALL_PREFIXES(SpdySessionSpdy3Test, ClientPing);
358 FRIEND_TEST_ALL_PREFIXES(SpdySessionSpdy3Test, FailedPing);
359 FRIEND_TEST_ALL_PREFIXES(SpdySessionSpdy3Test, GetActivePushStream);
360 FRIEND_TEST_ALL_PREFIXES(SpdySessionSpdy3Test, DeleteExpiredPushStreams);
362 struct PendingCreateStream {
363 PendingCreateStream(const GURL& url, RequestPriority priority,
364 scoped_refptr<SpdyStream>* spdy_stream,
365 const BoundNetLog& stream_net_log,
366 const CompletionCallback& callback);
368 ~PendingCreateStream();
370 const GURL* url;
371 RequestPriority priority;
372 scoped_refptr<SpdyStream>* spdy_stream;
373 const BoundNetLog* stream_net_log;
374 CompletionCallback callback;
376 typedef std::queue<PendingCreateStream, std::list<PendingCreateStream> >
377 PendingCreateStreamQueue;
378 typedef std::map<int, scoped_refptr<SpdyStream> > ActiveStreamMap;
379 typedef std::map<std::string,
380 std::pair<scoped_refptr<SpdyStream>, base::TimeTicks> > PushedStreamMap;
381 typedef std::priority_queue<SpdyIOBuffer> OutputQueue;
383 typedef std::set<scoped_refptr<SpdyStream> > CreatedStreamSet;
384 typedef std::map<SpdyIOBufferProducer*, SpdyStream*> StreamProducerMap;
385 class SpdyIOBufferProducerCompare {
386 public:
387 bool operator() (const SpdyIOBufferProducer* lhs,
388 const SpdyIOBufferProducer* rhs) const {
389 return lhs->GetPriority() < rhs->GetPriority();
392 typedef std::priority_queue<SpdyIOBufferProducer*,
393 std::vector<SpdyIOBufferProducer*>,
394 SpdyIOBufferProducerCompare> WriteQueue;
396 struct CallbackResultPair {
397 CallbackResultPair(const CompletionCallback& callback_in, int result_in);
398 ~CallbackResultPair();
400 CompletionCallback callback;
401 int result;
404 typedef std::map<const scoped_refptr<SpdyStream>*, CallbackResultPair>
405 PendingCallbackMap;
407 enum State {
408 IDLE,
409 CONNECTING,
410 CONNECTED,
411 CLOSED
414 virtual ~SpdySession();
416 void ProcessPendingCreateStreams();
417 int CreateStreamImpl(
418 const GURL& url,
419 RequestPriority priority,
420 scoped_refptr<SpdyStream>* spdy_stream,
421 const BoundNetLog& stream_net_log);
423 // IO Callbacks
424 void OnReadComplete(int result);
425 void OnWriteComplete(int result);
427 // Send relevant SETTINGS. This is generally called on connection setup.
428 void SendInitialSettings();
430 // Helper method to send SETTINGS a frame.
431 void SendSettings(const SettingsMap& settings);
433 // Handle SETTING. Either when we send settings, or when we receive a
434 // SETTINGS control frame, update our SpdySession accordingly.
435 void HandleSetting(uint32 id, uint32 value);
437 // Adjust the send window size of all ActiveStreams and PendingCreateStreams.
438 void UpdateStreamsSendWindowSize(int32 delta_window_size);
440 // Send the PING (preface-PING) frame.
441 void SendPrefacePingIfNoneInFlight();
443 // Send PING if there are no PINGs in flight and we haven't heard from server.
444 void SendPrefacePing();
446 // Send the PING frame.
447 void WritePingFrame(uint32 unique_id);
449 // Post a CheckPingStatus call after delay. Don't post if there is already
450 // CheckPingStatus running.
451 void PlanToCheckPingStatus();
453 // Check the status of the connection. It calls |CloseSessionOnError| if we
454 // haven't received any data in |kHungInterval| time period.
455 void CheckPingStatus(base::TimeTicks last_check_time);
457 // Start reading from the socket.
458 // Returns OK on success, or an error on failure.
459 net::Error ReadSocket();
461 // Write current data to the socket.
462 void WriteSocketLater();
463 void WriteSocket();
465 // Get a new stream id.
466 int GetNewStreamId();
468 // Queue a frame for sending.
469 // |frame| is the frame to send.
470 // |priority| is the priority for insertion into the queue.
471 void QueueFrame(SpdyFrame* frame, RequestPriority priority);
473 // Track active streams in the active stream list.
474 void ActivateStream(SpdyStream* stream);
475 void DeleteStream(SpdyStreamId id, int status);
477 // Removes this session from the session pool.
478 void RemoveFromPool();
480 // Check if we have a pending pushed-stream for this url
481 // Returns the stream if found (and returns it from the pending
482 // list), returns NULL otherwise.
483 scoped_refptr<SpdyStream> GetActivePushStream(const std::string& url);
485 // Calls OnResponseReceived().
486 // Returns true if successful.
487 bool Respond(const SpdyHeaderBlock& headers,
488 const scoped_refptr<SpdyStream> stream);
490 void RecordPingRTTHistogram(base::TimeDelta duration);
491 void RecordHistograms();
492 void RecordProtocolErrorHistogram(SpdyProtocolErrorDetails details);
494 // Closes all streams. Used as part of shutdown.
495 void CloseAllStreams(net::Error status);
497 void LogAbandonedStream(const scoped_refptr<SpdyStream>& stream,
498 net::Error status);
500 // Invokes a user callback for stream creation. We provide this method so it
501 // can be deferred to the MessageLoop, so we avoid re-entrancy problems.
502 void InvokeUserStreamCreationCallback(scoped_refptr<SpdyStream>* stream);
504 // Remove old unclaimed pushed streams.
505 void DeleteExpiredPushedStreams();
507 // BufferedSpdyFramerVisitorInterface:
508 virtual void OnError(SpdyFramer::SpdyError error_code) OVERRIDE;
509 virtual void OnStreamError(SpdyStreamId stream_id,
510 const std::string& description) OVERRIDE;
511 virtual void OnPing(uint32 unique_id) OVERRIDE;
512 virtual void OnRstStream(SpdyStreamId stream_id,
513 SpdyStatusCodes status) OVERRIDE;
514 virtual void OnGoAway(SpdyStreamId last_accepted_stream_id,
515 SpdyGoAwayStatus status) OVERRIDE;
516 virtual void OnStreamFrameData(SpdyStreamId stream_id,
517 const char* data,
518 size_t len,
519 SpdyDataFlags flags) OVERRIDE;
520 virtual void OnSetting(
521 SpdySettingsIds id, uint8 flags, uint32 value) OVERRIDE;
522 virtual void OnWindowUpdate(SpdyStreamId stream_id,
523 int delta_window_size) OVERRIDE;
524 virtual void OnControlFrameCompressed(
525 const SpdyControlFrame& uncompressed_frame,
526 const SpdyControlFrame& compressed_frame) OVERRIDE;
527 virtual void OnSynStream(SpdyStreamId stream_id,
528 SpdyStreamId associated_stream_id,
529 SpdyPriority priority,
530 uint8 credential_slot,
531 bool fin,
532 bool unidirectional,
533 const SpdyHeaderBlock& headers) OVERRIDE;
534 virtual void OnSynReply(
535 SpdyStreamId stream_id,
536 bool fin,
537 const SpdyHeaderBlock& headers) OVERRIDE;
538 virtual void OnHeaders(
539 SpdyStreamId stream_id,
540 bool fin,
541 const SpdyHeaderBlock& headers) OVERRIDE;
543 // --------------------------
544 // Helper methods for testing
545 // --------------------------
547 void set_connection_at_risk_of_loss_time(base::TimeDelta duration) {
548 connection_at_risk_of_loss_time_ = duration;
551 void set_hung_interval(base::TimeDelta duration) {
552 hung_interval_ = duration;
555 int64 pings_in_flight() const { return pings_in_flight_; }
557 uint32 next_ping_id() const { return next_ping_id_; }
559 base::TimeTicks last_activity_time() const { return last_activity_time_; }
561 bool check_ping_status_pending() const { return check_ping_status_pending_; }
563 // Returns the SSLClientSocket that this SPDY session sits on top of,
564 // or NULL, if the transport is not SSL.
565 SSLClientSocket* GetSSLClientSocket() const;
567 // Used for posting asynchronous IO tasks. We use this even though
568 // SpdySession is refcounted because we don't need to keep the SpdySession
569 // alive if the last reference is within a RunnableMethod. Just revoke the
570 // method.
571 base::WeakPtrFactory<SpdySession> weak_factory_;
573 // Map of the SpdyStreams for which we have a pending Task to invoke a
574 // callback. This is necessary since, before we invoke said callback, it's
575 // possible that the request is cancelled.
576 PendingCallbackMap pending_callback_map_;
578 // The domain this session is connected to.
579 const HostPortProxyPair host_port_proxy_pair_;
581 // Set set of HostPortProxyPairs for which this session has serviced
582 // requests.
583 std::set<HostPortProxyPair> pooled_aliases_;
585 // |spdy_session_pool_| owns us, therefore its lifetime must exceed ours. We
586 // set this to NULL after we are removed from the pool.
587 SpdySessionPool* spdy_session_pool_;
588 HttpServerProperties* const http_server_properties_;
590 // The socket handle for this session.
591 scoped_ptr<ClientSocketHandle> connection_;
593 // The read buffer used to read data from the socket.
594 scoped_refptr<IOBuffer> read_buffer_;
595 bool read_pending_;
597 int stream_hi_water_mark_; // The next stream id to use.
599 // Queue, for each priority, of pending Create Streams that have not
600 // yet been satisfied
601 PendingCreateStreamQueue create_stream_queues_[NUM_PRIORITIES];
603 // Map from stream id to all active streams. Streams are active in the sense
604 // that they have a consumer (typically SpdyNetworkTransaction and regardless
605 // of whether or not there is currently any ongoing IO [might be waiting for
606 // the server to start pushing the stream]) or there are still network events
607 // incoming even though the consumer has already gone away (cancellation).
608 // TODO(willchan): Perhaps we should separate out cancelled streams and move
609 // them into a separate ActiveStreamMap, and not deliver network events to
610 // them?
611 ActiveStreamMap active_streams_;
612 // Map of all the streams that have already started to be pushed by the
613 // server, but do not have consumers yet.
614 PushedStreamMap unclaimed_pushed_streams_;
616 // Set of all created streams but that have not yet sent any frames.
617 CreatedStreamSet created_streams_;
619 // As streams have data to be sent, we put them into the write queue.
620 WriteQueue write_queue_;
622 // Mapping from SpdyIOBufferProducers to their corresponding SpdyStream
623 // so that when a stream is destroyed, we can remove the corresponding
624 // producer from |write_queue_|.
625 StreamProducerMap stream_producers_;
627 // The packet we are currently sending.
628 bool write_pending_; // Will be true when a write is in progress.
629 SpdyIOBuffer in_flight_write_; // This is the write buffer in progress.
631 // Flag if we have a pending message scheduled for WriteSocket.
632 bool delayed_write_pending_;
634 // Flag if we're using an SSL connection for this SpdySession.
635 bool is_secure_;
637 // Certificate error code when using a secure connection.
638 int certificate_error_code_;
640 // Spdy Frame state.
641 scoped_ptr<BufferedSpdyFramer> buffered_spdy_framer_;
643 // If an error has occurred on the session, the session is effectively
644 // dead. Record this error here. When no error has occurred, |error_| will
645 // be OK.
646 net::Error error_;
647 State state_;
649 // Limits
650 size_t max_concurrent_streams_; // 0 if no limit
651 size_t max_concurrent_streams_limit_;
653 // Some statistics counters for the session.
654 int streams_initiated_count_;
655 int streams_pushed_count_;
656 int streams_pushed_and_claimed_count_;
657 int streams_abandoned_count_;
658 int bytes_received_;
659 bool sent_settings_; // Did this session send settings when it started.
660 bool received_settings_; // Did this session receive at least one settings
661 // frame.
662 int stalled_streams_; // Count of streams that were ever stalled.
664 // Count of all pings on the wire, for which we have not gotten a response.
665 int64 pings_in_flight_;
667 // This is the next ping_id (unique_id) to be sent in PING frame.
668 uint32 next_ping_id_;
670 // This is the last time we have sent a PING.
671 base::TimeTicks last_ping_sent_time_;
673 // This is the last time we had activity in the session.
674 base::TimeTicks last_activity_time_;
676 // This is the next time that unclaimed push streams should be checked for
677 // expirations.
678 base::TimeTicks next_unclaimed_push_stream_sweep_time_;
680 // Indicate if we have already scheduled a delayed task to check the ping
681 // status.
682 bool check_ping_status_pending_;
684 // Indicate if flow control is enabled or not.
685 bool flow_control_;
687 // Initial send window size for the session; can be changed by an
688 // arriving SETTINGS frame; newly created streams use this value for the
689 // initial send window size.
690 int32 initial_send_window_size_;
692 // Initial receive window size for the session; there are plans to add a
693 // command line switch that would cause a SETTINGS frame with window size
694 // announcement to be sent on startup; newly created streams will use
695 // this value for the initial receive window size.
696 int32 initial_recv_window_size_;
698 BoundNetLog net_log_;
700 // Outside of tests, these should always be true.
701 bool verify_domain_authentication_;
702 bool enable_sending_initial_settings_;
703 bool enable_credential_frames_;
704 bool enable_compression_;
705 bool enable_ping_based_connection_checking_;
706 NextProto default_protocol_;
708 SpdyCredentialState credential_state_;
710 // |connection_at_risk_of_loss_time_| is an optimization to avoid sending
711 // wasteful preface pings (when we just got some data).
713 // If it is zero (the most conservative figure), then we always send the
714 // preface ping (when none are in flight).
716 // It is common for TCP/IP sessions to time out in about 3-5 minutes.
717 // Certainly if it has been more than 3 minutes, we do want to send a preface
718 // ping.
720 // We don't think any connection will time out in under about 10 seconds. So
721 // this might as well be set to something conservative like 10 seconds. Later,
722 // we could adjust it to send fewer pings perhaps.
723 base::TimeDelta connection_at_risk_of_loss_time_;
725 // The amount of time that we are willing to tolerate with no activity (of any
726 // form), while there is a ping in flight, before we declare the connection to
727 // be hung. TODO(rtenneti): When hung, instead of resetting connection, race
728 // to build a new connection, and see if that completes before we (finally)
729 // get a PING response (http://crbug.com/127812).
730 base::TimeDelta hung_interval_;
732 // This SPDY proxy is allowed to push resources from origins that are
733 // different from those of their associated streams.
734 HostPortPair trusted_spdy_proxy_;
736 TimeFunc time_func_;
739 } // namespace net
741 #endif // NET_SPDY_SPDY_SESSION_H_