| 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 <deque> | 8 #include <deque> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 | 337 |
| 338 // Fills SSL Certificate Request info |cert_request_info| and returns | 338 // Fills SSL Certificate Request info |cert_request_info| and returns |
| 339 // true when SSL is in use. | 339 // true when SSL is in use. |
| 340 bool GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info); | 340 bool GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info); |
| 341 | 341 |
| 342 // Send a WINDOW_UPDATE frame for a stream. Called by a stream | 342 // Send a WINDOW_UPDATE frame for a stream. Called by a stream |
| 343 // whenever receive window size is increased. | 343 // whenever receive window size is increased. |
| 344 void SendStreamWindowUpdate(SpdyStreamId stream_id, | 344 void SendStreamWindowUpdate(SpdyStreamId stream_id, |
| 345 uint32 delta_window_size); | 345 uint32 delta_window_size); |
| 346 | 346 |
| 347 // Accessors for the session's availability state. | 347 // Whether the stream is closed, i.e. it has stopped processing data |
| 348 bool IsAvailable() const { return availability_state_ == STATE_AVAILABLE; } | 348 // and is about to be destroyed. |
| 349 bool IsGoingAway() const { return availability_state_ == STATE_GOING_AWAY; } | 349 // |
| 350 bool IsDraining() const { return availability_state_ == STATE_DRAINING; } | 350 // TODO(akalin): This is only used in tests. Remove this function |
| 351 // and have tests test the WeakPtr instead. |
| 352 bool IsClosed() const { return availability_state_ == STATE_CLOSED; } |
| 351 | 353 |
| 352 // Closes this session. This will close all active streams and mark | 354 // Closes this session. This will close all active streams and mark |
| 353 // the session as permanently closed. Callers must assume that the | 355 // the session as permanently closed. Callers must assume that the |
| 354 // session is destroyed after this is called. (However, it may not | 356 // session is destroyed after this is called. (However, it may not |
| 355 // be destroyed right away, e.g. when a SpdySession function is | 357 // be destroyed right away, e.g. when a SpdySession function is |
| 356 // present in the call stack.) | 358 // present in the call stack.) |
| 357 // | 359 // |
| 358 // |err| should be < ERR_IO_PENDING; this function is intended to be | 360 // |err| should be < ERR_IO_PENDING; this function is intended to be |
| 359 // called on error. | 361 // called on error. |
| 360 // |description| indicates the reason for the error. | 362 // |description| indicates the reason for the error. |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 | 526 |
| 525 typedef std::set<SpdyStream*> CreatedStreamSet; | 527 typedef std::set<SpdyStream*> CreatedStreamSet; |
| 526 | 528 |
| 527 enum AvailabilityState { | 529 enum AvailabilityState { |
| 528 // The session is available in its socket pool and can be used | 530 // The session is available in its socket pool and can be used |
| 529 // freely. | 531 // freely. |
| 530 STATE_AVAILABLE, | 532 STATE_AVAILABLE, |
| 531 // The session can process data on existing streams but will | 533 // The session can process data on existing streams but will |
| 532 // refuse to create new ones. | 534 // refuse to create new ones. |
| 533 STATE_GOING_AWAY, | 535 STATE_GOING_AWAY, |
| 534 // The session is draining its write queue in preparation of closing. | 536 // The session has been closed, is waiting to be deleted, and will |
| 535 // Further writes will not be queued, and further reads will be | 537 // refuse to process any more data. |
| 536 // neither issued nor processed. The session will be destroyed by its | 538 STATE_CLOSED |
| 537 // write loop once the write queue is drained. | |
| 538 STATE_DRAINING, | |
| 539 }; | 539 }; |
| 540 | 540 |
| 541 enum ReadState { | 541 enum ReadState { |
| 542 READ_STATE_DO_READ, | 542 READ_STATE_DO_READ, |
| 543 READ_STATE_DO_READ_COMPLETE, | 543 READ_STATE_DO_READ_COMPLETE, |
| 544 }; | 544 }; |
| 545 | 545 |
| 546 enum WriteState { | 546 enum WriteState { |
| 547 // There is no in-flight write and the write queue is empty. | 547 // There is no in-flight write and the write queue is empty. |
| 548 WRITE_STATE_IDLE, | 548 WRITE_STATE_IDLE, |
| 549 WRITE_STATE_DO_WRITE, | 549 WRITE_STATE_DO_WRITE, |
| 550 WRITE_STATE_DO_WRITE_COMPLETE, | 550 WRITE_STATE_DO_WRITE_COMPLETE, |
| 551 }; | 551 }; |
| 552 | 552 |
| 553 // The return value of DoCloseSession() describing what was done. |
| 554 enum CloseSessionResult { |
| 555 // The session was already closed so nothing was done. |
| 556 SESSION_ALREADY_CLOSED, |
| 557 // The session was moved into the closed state but was not removed |
| 558 // from |pool_| (because we're in an IO loop). |
| 559 SESSION_CLOSED_BUT_NOT_REMOVED, |
| 560 // The session was moved into the closed state and removed from |
| 561 // |pool_|. |
| 562 SESSION_CLOSED_AND_REMOVED, |
| 563 }; |
| 564 |
| 553 // Checks whether a stream for the given |url| can be created or | 565 // Checks whether a stream for the given |url| can be created or |
| 554 // retrieved from the set of unclaimed push streams. Returns OK if | 566 // retrieved from the set of unclaimed push streams. Returns OK if |
| 555 // so. Otherwise, the session is closed and an error < | 567 // so. Otherwise, the session is closed and an error < |
| 556 // ERR_IO_PENDING is returned. | 568 // ERR_IO_PENDING is returned. |
| 557 Error TryAccessStream(const GURL& url); | 569 Error TryAccessStream(const GURL& url); |
| 558 | 570 |
| 559 // Called by SpdyStreamRequest to start a request to create a | 571 // Called by SpdyStreamRequest to start a request to create a |
| 560 // stream. If OK is returned, then |stream| will be filled in with a | 572 // stream. If OK is returned, then |stream| will be filled in with a |
| 561 // valid stream. If ERR_IO_PENDING is returned, then | 573 // valid stream. If ERR_IO_PENDING is returned, then |
| 562 // |request->OnRequestComplete{Success,Failure}()| will be called | 574 // |request->OnRequestComplete{Success,Failure}()| will be called |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 // Send a RST_STREAM frame with the given parameters. There should | 612 // Send a RST_STREAM frame with the given parameters. There should |
| 601 // either be no active stream with the given ID, or that active | 613 // either be no active stream with the given ID, or that active |
| 602 // stream should be closed shortly after this function is called. | 614 // stream should be closed shortly after this function is called. |
| 603 // | 615 // |
| 604 // TODO(akalin): Rename this to EnqueueResetStreamFrame(). | 616 // TODO(akalin): Rename this to EnqueueResetStreamFrame(). |
| 605 void EnqueueResetStreamFrame(SpdyStreamId stream_id, | 617 void EnqueueResetStreamFrame(SpdyStreamId stream_id, |
| 606 RequestPriority priority, | 618 RequestPriority priority, |
| 607 SpdyRstStreamStatus status, | 619 SpdyRstStreamStatus status, |
| 608 const std::string& description); | 620 const std::string& description); |
| 609 | 621 |
| 610 // Calls DoReadLoop. Use this function instead of DoReadLoop when | 622 // Calls DoReadLoop and then if |availability_state_| is |
| 611 // posting a task to pump the read loop. | 623 // STATE_CLOSED, calls RemoveFromPool(). |
| 624 // |
| 625 // Use this function instead of DoReadLoop when posting a task to |
| 626 // pump the read loop. |
| 612 void PumpReadLoop(ReadState expected_read_state, int result); | 627 void PumpReadLoop(ReadState expected_read_state, int result); |
| 613 | 628 |
| 614 // Advance the ReadState state machine. |expected_read_state| is the | 629 // Advance the ReadState state machine. |expected_read_state| is the |
| 615 // expected starting read state. | 630 // expected starting read state. |
| 616 // | 631 // |
| 617 // This function must always be called via PumpReadLoop(). | 632 // This function must always be called via PumpReadLoop(). |
| 618 int DoReadLoop(ReadState expected_read_state, int result); | 633 int DoReadLoop(ReadState expected_read_state, int result); |
| 619 // The implementations of the states of the ReadState state machine. | 634 // The implementations of the states of the ReadState state machine. |
| 620 int DoRead(); | 635 int DoRead(); |
| 621 int DoReadComplete(int result); | 636 int DoReadComplete(int result); |
| 622 | 637 |
| 623 // Calls DoWriteLoop. If |availability_state_| is STATE_DRAINING and no | 638 // Calls DoWriteLoop and then if |availability_state_| is |
| 624 // writes remain, the session is removed from the session pool and | 639 // STATE_CLOSED, calls RemoveFromPool(). |
| 625 // destroyed. | |
| 626 // | 640 // |
| 627 // Use this function instead of DoWriteLoop when posting a task to | 641 // Use this function instead of DoWriteLoop when posting a task to |
| 628 // pump the write loop. | 642 // pump the write loop. |
| 629 void PumpWriteLoop(WriteState expected_write_state, int result); | 643 void PumpWriteLoop(WriteState expected_write_state, int result); |
| 630 | 644 |
| 631 // Iff the write loop is not currently active, posts a callback into | |
| 632 // PumpWriteLoop(). | |
| 633 void MaybePostWriteLoop(); | |
| 634 | |
| 635 // Advance the WriteState state machine. |expected_write_state| is | 645 // Advance the WriteState state machine. |expected_write_state| is |
| 636 // the expected starting write state. | 646 // the expected starting write state. |
| 637 // | 647 // |
| 638 // This function must always be called via PumpWriteLoop(). | 648 // This function must always be called via PumpWriteLoop(). |
| 639 int DoWriteLoop(WriteState expected_write_state, int result); | 649 int DoWriteLoop(WriteState expected_write_state, int result); |
| 640 // The implementations of the states of the WriteState state machine. | 650 // The implementations of the states of the WriteState state machine. |
| 641 int DoWrite(); | 651 int DoWrite(); |
| 642 int DoWriteComplete(int result); | 652 int DoWriteComplete(int result); |
| 643 | 653 |
| 644 // TODO(akalin): Rename the Send* and Write* functions below to | 654 // TODO(akalin): Rename the Send* and Write* functions below to |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 void RecordPingRTTHistogram(base::TimeDelta duration); | 737 void RecordPingRTTHistogram(base::TimeDelta duration); |
| 728 void RecordHistograms(); | 738 void RecordHistograms(); |
| 729 void RecordProtocolErrorHistogram(SpdyProtocolErrorDetails details); | 739 void RecordProtocolErrorHistogram(SpdyProtocolErrorDetails details); |
| 730 | 740 |
| 731 // DCHECKs that |availability_state_| >= STATE_GOING_AWAY, that | 741 // DCHECKs that |availability_state_| >= STATE_GOING_AWAY, that |
| 732 // there are no pending stream creation requests, and that there are | 742 // there are no pending stream creation requests, and that there are |
| 733 // no created streams. | 743 // no created streams. |
| 734 void DcheckGoingAway() const; | 744 void DcheckGoingAway() const; |
| 735 | 745 |
| 736 // Calls DcheckGoingAway(), then DCHECKs that |availability_state_| | 746 // Calls DcheckGoingAway(), then DCHECKs that |availability_state_| |
| 737 // == STATE_DRAINING, |error_on_close_| has a valid value, and that there | 747 // == STATE_CLOSED, |error_on_close_| has a valid value, that there |
| 738 // are no active streams or unclaimed pushed streams. | 748 // are no active streams or unclaimed pushed streams, and that the |
| 739 void DcheckDraining() const; | 749 // write queue is empty. |
| 750 void DcheckClosed() const; |
| 740 | 751 |
| 741 // Closes all active streams with stream id's greater than | 752 // Closes all active streams with stream id's greater than |
| 742 // |last_good_stream_id|, as well as any created or pending | 753 // |last_good_stream_id|, as well as any created or pending |
| 743 // streams. Must be called only when |availability_state_| >= | 754 // streams. Must be called only when |availability_state_| >= |
| 744 // STATE_GOING_AWAY. After this function, DcheckGoingAway() will | 755 // STATE_GOING_AWAY. After this function, DcheckGoingAway() will |
| 745 // pass. May be called multiple times. | 756 // pass. May be called multiple times. |
| 746 void StartGoingAway(SpdyStreamId last_good_stream_id, Error status); | 757 void StartGoingAway(SpdyStreamId last_good_stream_id, Error status); |
| 747 | 758 |
| 748 // Must be called only when going away (i.e., DcheckGoingAway() | 759 // Must be called only when going away (i.e., DcheckGoingAway() |
| 749 // passes). If there are no more active streams and the session | 760 // passes). If there are no more active streams and the session |
| 750 // isn't closed yet, close it. | 761 // isn't closed yet, close it. |
| 751 void MaybeFinishGoingAway(); | 762 void MaybeFinishGoingAway(); |
| 752 | 763 |
| 753 // If the session is already draining, does nothing. Otherwise, moves | 764 // If the stream is already closed, does nothing. Otherwise, moves |
| 754 // the session to the draining state. | 765 // the session to a closed state. Then, if we're in an IO loop, |
| 755 void DoDrainSession(Error err, const std::string& description); | 766 // returns (as the IO loop will do the pool removal itself when its |
| 767 // done). Otherwise, also removes |this| from |pool_|. The returned |
| 768 // result describes what was done. |
| 769 CloseSessionResult DoCloseSession(Error err, const std::string& description); |
| 770 |
| 771 // Remove this session from its pool, which must exist. Must be |
| 772 // called only when the session is closed. |
| 773 // |
| 774 // Must be called only via Pump{Read,Write}Loop() or |
| 775 // DoCloseSession(). |
| 776 void RemoveFromPool(); |
| 756 | 777 |
| 757 // Called right before closing a (possibly-inactive) stream for a | 778 // Called right before closing a (possibly-inactive) stream for a |
| 758 // reason other than being requested to by the stream. | 779 // reason other than being requested to by the stream. |
| 759 void LogAbandonedStream(SpdyStream* stream, Error status); | 780 void LogAbandonedStream(SpdyStream* stream, Error status); |
| 760 | 781 |
| 761 // Called right before closing an active stream for a reason other | 782 // Called right before closing an active stream for a reason other |
| 762 // than being requested to by the stream. | 783 // than being requested to by the stream. |
| 763 void LogAbandonedActiveStream(ActiveStreamMap::const_iterator it, | 784 void LogAbandonedActiveStream(ActiveStreamMap::const_iterator it, |
| 764 Error status); | 785 Error status); |
| 765 | 786 |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 985 int certificate_error_code_; | 1006 int certificate_error_code_; |
| 986 | 1007 |
| 987 // Spdy Frame state. | 1008 // Spdy Frame state. |
| 988 scoped_ptr<BufferedSpdyFramer> buffered_spdy_framer_; | 1009 scoped_ptr<BufferedSpdyFramer> buffered_spdy_framer_; |
| 989 | 1010 |
| 990 // The state variables. | 1011 // The state variables. |
| 991 AvailabilityState availability_state_; | 1012 AvailabilityState availability_state_; |
| 992 ReadState read_state_; | 1013 ReadState read_state_; |
| 993 WriteState write_state_; | 1014 WriteState write_state_; |
| 994 | 1015 |
| 995 // If the session is closing (i.e., |availability_state_| is STATE_DRAINING), | 1016 // If the session was closed (i.e., |availability_state_| is |
| 996 // then |error_on_close_| holds the error with which it was closed, which | 1017 // STATE_CLOSED), then |error_on_close_| holds the error with which |
| 997 // may be OK (upon a polite GOAWAY) or an error < ERR_IO_PENDING otherwise. | 1018 // it was closed, which is < ERR_IO_PENDING. Otherwise, it is set to |
| 998 // Initialized to OK. | 1019 // OK. |
| 999 Error error_on_close_; | 1020 Error error_on_close_; |
| 1000 | 1021 |
| 1001 // Limits | 1022 // Limits |
| 1002 size_t max_concurrent_streams_; // 0 if no limit | 1023 size_t max_concurrent_streams_; // 0 if no limit |
| 1003 size_t max_concurrent_streams_limit_; | 1024 size_t max_concurrent_streams_limit_; |
| 1004 | 1025 |
| 1005 // Some statistics counters for the session. | 1026 // Some statistics counters for the session. |
| 1006 int streams_initiated_count_; | 1027 int streams_initiated_count_; |
| 1007 int streams_pushed_count_; | 1028 int streams_pushed_count_; |
| 1008 int streams_pushed_and_claimed_count_; | 1029 int streams_pushed_and_claimed_count_; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1111 // Used for posting asynchronous IO tasks. We use this even though | 1132 // Used for posting asynchronous IO tasks. We use this even though |
| 1112 // SpdySession is refcounted because we don't need to keep the SpdySession | 1133 // SpdySession is refcounted because we don't need to keep the SpdySession |
| 1113 // alive if the last reference is within a RunnableMethod. Just revoke the | 1134 // alive if the last reference is within a RunnableMethod. Just revoke the |
| 1114 // method. | 1135 // method. |
| 1115 base::WeakPtrFactory<SpdySession> weak_factory_; | 1136 base::WeakPtrFactory<SpdySession> weak_factory_; |
| 1116 }; | 1137 }; |
| 1117 | 1138 |
| 1118 } // namespace net | 1139 } // namespace net |
| 1119 | 1140 |
| 1120 #endif // NET_SPDY_SPDY_SESSION_H_ | 1141 #endif // NET_SPDY_SPDY_SESSION_H_ |
| OLD | NEW |