Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: net/spdy/spdy_session.h

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

Powered by Google App Engine
This is Rietveld 408576698