OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_SPDY_SPDY_SESSION_H_ | 5 #ifndef NET_SPDY_SPDY_SESSION_H_ |
6 #define NET_SPDY_SPDY_SESSION_H_ | 6 #define NET_SPDY_SPDY_SESSION_H_ |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <list> | 9 #include <list> |
10 #include <map> | 10 #include <map> |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 SpdyProtocolErrorDetails_SpdyErrors_mismatch); | 87 SpdyProtocolErrorDetails_SpdyErrors_mismatch); |
88 | 88 |
89 COMPILE_ASSERT(PROTOCOL_ERROR_UNEXPECTED_PING == | 89 COMPILE_ASSERT(PROTOCOL_ERROR_UNEXPECTED_PING == |
90 static_cast<SpdyProtocolErrorDetails>(NUM_STATUS_CODES + | 90 static_cast<SpdyProtocolErrorDetails>(NUM_STATUS_CODES + |
91 STATUS_CODE_INVALID), | 91 STATUS_CODE_INVALID), |
92 SpdyProtocolErrorDetails_SpdyErrors_mismatch); | 92 SpdyProtocolErrorDetails_SpdyErrors_mismatch); |
93 | 93 |
94 class NET_EXPORT SpdySession : public base::RefCounted<SpdySession>, | 94 class NET_EXPORT SpdySession : public base::RefCounted<SpdySession>, |
95 public BufferedSpdyFramerVisitorInterface { | 95 public BufferedSpdyFramerVisitorInterface { |
96 public: | 96 public: |
| 97 typedef base::TimeTicks (*TimeFunc)(void); |
| 98 |
97 // Defines an interface for producing SpdyIOBuffers. | 99 // Defines an interface for producing SpdyIOBuffers. |
98 class NET_EXPORT_PRIVATE SpdyIOBufferProducer { | 100 class NET_EXPORT_PRIVATE SpdyIOBufferProducer { |
99 public: | 101 public: |
100 SpdyIOBufferProducer() {} | 102 SpdyIOBufferProducer() {} |
101 | 103 |
102 // Returns a newly created SpdyIOBuffer, owned by the caller, or NULL | 104 // Returns a newly created SpdyIOBuffer, owned by the caller, or NULL |
103 // if not buffer is ready to be produced. | 105 // if not buffer is ready to be produced. |
104 virtual SpdyIOBuffer* ProduceNextBuffer(SpdySession* session) = 0; | 106 virtual SpdyIOBuffer* ProduceNextBuffer(SpdySession* session) = 0; |
105 | 107 |
106 virtual RequestPriority GetPriority() const = 0; | 108 virtual RequestPriority GetPriority() const = 0; |
(...skipping 18 matching lines...) Expand all Loading... |
125 // the proxy configuration settings that it's using. | 127 // the proxy configuration settings that it's using. |
126 // |spdy_session_pool| is the SpdySessionPool that owns us. Its lifetime must | 128 // |spdy_session_pool| is the SpdySessionPool that owns us. Its lifetime must |
127 // strictly be greater than |this|. | 129 // strictly be greater than |this|. |
128 // |session| is the HttpNetworkSession. |net_log| is the NetLog that we log | 130 // |session| is the HttpNetworkSession. |net_log| is the NetLog that we log |
129 // network events to. | 131 // network events to. |
130 SpdySession(const HostPortProxyPair& host_port_proxy_pair, | 132 SpdySession(const HostPortProxyPair& host_port_proxy_pair, |
131 SpdySessionPool* spdy_session_pool, | 133 SpdySessionPool* spdy_session_pool, |
132 HttpServerProperties* http_server_properties, | 134 HttpServerProperties* http_server_properties, |
133 bool verify_domain_authentication, | 135 bool verify_domain_authentication, |
134 bool enable_sending_initial_settings, | 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, |
135 const HostPortPair& trusted_spdy_proxy, | 145 const HostPortPair& trusted_spdy_proxy, |
136 NetLog* net_log); | 146 NetLog* net_log); |
137 | 147 |
138 const HostPortPair& host_port_pair() const { | 148 const HostPortPair& host_port_pair() const { |
139 return host_port_proxy_pair_.first; | 149 return host_port_proxy_pair_.first; |
140 } | 150 } |
141 const HostPortProxyPair& host_port_proxy_pair() const { | 151 const HostPortProxyPair& host_port_proxy_pair() const { |
142 return host_port_proxy_pair_; | 152 return host_port_proxy_pair_; |
143 } | 153 } |
144 | 154 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 NextProto* protocol_negotiated); | 252 NextProto* protocol_negotiated); |
243 | 253 |
244 // Fills SSL Certificate Request info |cert_request_info| and returns | 254 // Fills SSL Certificate Request info |cert_request_info| and returns |
245 // true when SSL is in use. | 255 // true when SSL is in use. |
246 bool GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info); | 256 bool GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info); |
247 | 257 |
248 // Returns the ServerBoundCertService used by this Socket, or NULL | 258 // Returns the ServerBoundCertService used by this Socket, or NULL |
249 // if server bound certs are not supported in this session. | 259 // if server bound certs are not supported in this session. |
250 ServerBoundCertService* GetServerBoundCertService() const; | 260 ServerBoundCertService* GetServerBoundCertService() const; |
251 | 261 |
252 // Reset all static settings to initialized values. Used to init test suite. | |
253 static void ResetStaticSettingsToInit(); | |
254 | |
255 // Specify the SPDY protocol to be used for SPDY session which do not use NPN | |
256 // to negotiate a particular protocol. | |
257 static void set_default_protocol(NextProto default_protocol); | |
258 | |
259 // Sets the max concurrent streams per session, as a ceiling on any server | |
260 // specific SETTINGS value. | |
261 static void set_max_concurrent_streams(size_t value); | |
262 | |
263 // Enable sending of PING frame with each request. | |
264 static void set_enable_ping_based_connection_checking(bool enable); | |
265 | |
266 // Enable the sending of CREDENTIAL frames. | |
267 static void set_enable_credential_frames(bool enable); | |
268 | |
269 // The initial max concurrent streams per session, can be overridden by the | |
270 // server via SETTINGS. | |
271 static void set_init_max_concurrent_streams(size_t value); | |
272 | |
273 // Sets the initial receive window size for newly created sessions. | |
274 static void set_default_initial_recv_window_size(size_t value); | |
275 | |
276 // Send WINDOW_UPDATE frame, called by a stream whenever receive window | 262 // Send WINDOW_UPDATE frame, called by a stream whenever receive window |
277 // size is increased. | 263 // size is increased. |
278 void SendWindowUpdate(SpdyStreamId stream_id, int32 delta_window_size); | 264 void SendWindowUpdate(SpdyStreamId stream_id, int32 delta_window_size); |
279 | 265 |
280 // If session is closed, no new streams/transactions should be created. | 266 // If session is closed, no new streams/transactions should be created. |
281 bool IsClosed() const { return state_ == CLOSED; } | 267 bool IsClosed() const { return state_ == CLOSED; } |
282 | 268 |
283 // Closes this session. This will close all active streams and mark | 269 // Closes this session. This will close all active streams and mark |
284 // the session as permanently closed. | 270 // the session as permanently closed. |
285 // |err| should not be OK; this function is intended to be called on | 271 // |err| should not be OK; this function is intended to be called on |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 typedef std::map<const scoped_refptr<SpdyStream>*, CallbackResultPair> | 404 typedef std::map<const scoped_refptr<SpdyStream>*, CallbackResultPair> |
419 PendingCallbackMap; | 405 PendingCallbackMap; |
420 | 406 |
421 enum State { | 407 enum State { |
422 IDLE, | 408 IDLE, |
423 CONNECTING, | 409 CONNECTING, |
424 CONNECTED, | 410 CONNECTED, |
425 CLOSED | 411 CLOSED |
426 }; | 412 }; |
427 | 413 |
428 typedef base::TimeTicks (*TimeFunc)(void); | |
429 | |
430 virtual ~SpdySession(); | 414 virtual ~SpdySession(); |
431 | 415 |
432 void ProcessPendingCreateStreams(); | 416 void ProcessPendingCreateStreams(); |
433 int CreateStreamImpl( | 417 int CreateStreamImpl( |
434 const GURL& url, | 418 const GURL& url, |
435 RequestPriority priority, | 419 RequestPriority priority, |
436 scoped_refptr<SpdyStream>* spdy_stream, | 420 scoped_refptr<SpdyStream>* spdy_stream, |
437 const BoundNetLog& stream_net_log); | 421 const BoundNetLog& stream_net_log); |
438 | 422 |
439 // IO Callbacks | 423 // IO Callbacks |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 const SpdyHeaderBlock& headers) OVERRIDE; | 537 const SpdyHeaderBlock& headers) OVERRIDE; |
554 virtual void OnHeaders( | 538 virtual void OnHeaders( |
555 SpdyStreamId stream_id, | 539 SpdyStreamId stream_id, |
556 bool fin, | 540 bool fin, |
557 const SpdyHeaderBlock& headers) OVERRIDE; | 541 const SpdyHeaderBlock& headers) OVERRIDE; |
558 | 542 |
559 // -------------------------- | 543 // -------------------------- |
560 // Helper methods for testing | 544 // Helper methods for testing |
561 // -------------------------- | 545 // -------------------------- |
562 | 546 |
563 static TimeFunc set_time_func(TimeFunc new_time_func); | |
564 | |
565 void set_connection_at_risk_of_loss_time(base::TimeDelta duration) { | 547 void set_connection_at_risk_of_loss_time(base::TimeDelta duration) { |
566 connection_at_risk_of_loss_time_ = duration; | 548 connection_at_risk_of_loss_time_ = duration; |
567 } | 549 } |
568 | 550 |
569 void set_hung_interval(base::TimeDelta duration) { | 551 void set_hung_interval(base::TimeDelta duration) { |
570 hung_interval_ = duration; | 552 hung_interval_ = duration; |
571 } | 553 } |
572 | 554 |
573 int64 pings_in_flight() const { return pings_in_flight_; } | 555 int64 pings_in_flight() const { return pings_in_flight_; } |
574 | 556 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 scoped_ptr<BufferedSpdyFramer> buffered_spdy_framer_; | 641 scoped_ptr<BufferedSpdyFramer> buffered_spdy_framer_; |
660 | 642 |
661 // If an error has occurred on the session, the session is effectively | 643 // If an error has occurred on the session, the session is effectively |
662 // dead. Record this error here. When no error has occurred, |error_| will | 644 // dead. Record this error here. When no error has occurred, |error_| will |
663 // be OK. | 645 // be OK. |
664 net::Error error_; | 646 net::Error error_; |
665 State state_; | 647 State state_; |
666 | 648 |
667 // Limits | 649 // Limits |
668 size_t max_concurrent_streams_; // 0 if no limit | 650 size_t max_concurrent_streams_; // 0 if no limit |
| 651 size_t max_concurrent_streams_limit_; |
669 | 652 |
670 // Some statistics counters for the session. | 653 // Some statistics counters for the session. |
671 int streams_initiated_count_; | 654 int streams_initiated_count_; |
672 int streams_pushed_count_; | 655 int streams_pushed_count_; |
673 int streams_pushed_and_claimed_count_; | 656 int streams_pushed_and_claimed_count_; |
674 int streams_abandoned_count_; | 657 int streams_abandoned_count_; |
675 int bytes_received_; | 658 int bytes_received_; |
676 bool sent_settings_; // Did this session send settings when it started. | 659 bool sent_settings_; // Did this session send settings when it started. |
677 bool received_settings_; // Did this session receive at least one settings | 660 bool received_settings_; // Did this session receive at least one settings |
678 // frame. | 661 // frame. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 // command line switch that would cause a SETTINGS frame with window size | 693 // command line switch that would cause a SETTINGS frame with window size |
711 // announcement to be sent on startup; newly created streams will use | 694 // announcement to be sent on startup; newly created streams will use |
712 // this value for the initial receive window size. | 695 // this value for the initial receive window size. |
713 int32 initial_recv_window_size_; | 696 int32 initial_recv_window_size_; |
714 | 697 |
715 BoundNetLog net_log_; | 698 BoundNetLog net_log_; |
716 | 699 |
717 // Outside of tests, these should always be true. | 700 // Outside of tests, these should always be true. |
718 bool verify_domain_authentication_; | 701 bool verify_domain_authentication_; |
719 bool enable_sending_initial_settings_; | 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_; |
720 | 707 |
721 SpdyCredentialState credential_state_; | 708 SpdyCredentialState credential_state_; |
722 | 709 |
723 // |connection_at_risk_of_loss_time_| is an optimization to avoid sending | 710 // |connection_at_risk_of_loss_time_| is an optimization to avoid sending |
724 // wasteful preface pings (when we just got some data). | 711 // wasteful preface pings (when we just got some data). |
725 // | 712 // |
726 // If it is zero (the most conservative figure), then we always send the | 713 // If it is zero (the most conservative figure), then we always send the |
727 // preface ping (when none are in flight). | 714 // preface ping (when none are in flight). |
728 // | 715 // |
729 // It is common for TCP/IP sessions to time out in about 3-5 minutes. | 716 // It is common for TCP/IP sessions to time out in about 3-5 minutes. |
730 // Certainly if it has been more than 3 minutes, we do want to send a preface | 717 // Certainly if it has been more than 3 minutes, we do want to send a preface |
731 // ping. | 718 // ping. |
732 // | 719 // |
733 // We don't think any connection will time out in under about 10 seconds. So | 720 // We don't think any connection will time out in under about 10 seconds. So |
734 // this might as well be set to something conservative like 10 seconds. Later, | 721 // this might as well be set to something conservative like 10 seconds. Later, |
735 // we could adjust it to send fewer pings perhaps. | 722 // we could adjust it to send fewer pings perhaps. |
736 base::TimeDelta connection_at_risk_of_loss_time_; | 723 base::TimeDelta connection_at_risk_of_loss_time_; |
737 | 724 |
738 // The amount of time that we are willing to tolerate with no activity (of any | 725 // The amount of time that we are willing to tolerate with no activity (of any |
739 // form), while there is a ping in flight, before we declare the connection to | 726 // form), while there is a ping in flight, before we declare the connection to |
740 // be hung. TODO(rtenneti): When hung, instead of resetting connection, race | 727 // be hung. TODO(rtenneti): When hung, instead of resetting connection, race |
741 // to build a new connection, and see if that completes before we (finally) | 728 // to build a new connection, and see if that completes before we (finally) |
742 // get a PING response (http://crbug.com/127812). | 729 // get a PING response (http://crbug.com/127812). |
743 base::TimeDelta hung_interval_; | 730 base::TimeDelta hung_interval_; |
744 | 731 |
745 // This SPDY proxy is allowed to push resources from origins that are | 732 // This SPDY proxy is allowed to push resources from origins that are |
746 // different from those of their associated streams. | 733 // different from those of their associated streams. |
747 HostPortPair trusted_spdy_proxy_; | 734 HostPortPair trusted_spdy_proxy_; |
| 735 |
| 736 TimeFunc time_func_; |
748 }; | 737 }; |
749 | 738 |
750 } // namespace net | 739 } // namespace net |
751 | 740 |
752 #endif // NET_SPDY_SPDY_SESSION_H_ | 741 #endif // NET_SPDY_SPDY_SESSION_H_ |
OLD | NEW |