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 <list> | |
10 #include <map> | 9 #include <map> |
11 #include <queue> | |
12 #include <set> | 10 #include <set> |
13 #include <string> | 11 #include <string> |
14 | 12 |
15 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
16 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
17 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/memory/scoped_ptr.h" | |
18 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
19 #include "base/time.h" | 18 #include "base/time.h" |
20 #include "net/base/io_buffer.h" | 19 #include "net/base/io_buffer.h" |
21 #include "net/base/load_states.h" | 20 #include "net/base/load_states.h" |
22 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
22 #include "net/base/net_export.h" | |
23 #include "net/base/request_priority.h" | 23 #include "net/base/request_priority.h" |
24 #include "net/socket/client_socket_handle.h" | 24 #include "net/socket/client_socket_handle.h" |
25 #include "net/socket/ssl_client_socket.h" | 25 #include "net/socket/ssl_client_socket.h" |
26 #include "net/socket/stream_socket.h" | 26 #include "net/socket/stream_socket.h" |
27 #include "net/spdy/buffered_spdy_framer.h" | 27 #include "net/spdy/buffered_spdy_framer.h" |
28 #include "net/spdy/spdy_credential_state.h" | 28 #include "net/spdy/spdy_credential_state.h" |
29 #include "net/spdy/spdy_header_block.h" | 29 #include "net/spdy/spdy_header_block.h" |
30 #include "net/spdy/spdy_io_buffer.h" | 30 #include "net/spdy/spdy_io_buffer.h" |
31 #include "net/spdy/spdy_protocol.h" | 31 #include "net/spdy/spdy_protocol.h" |
32 #include "net/spdy/spdy_session_pool.h" | 32 #include "net/spdy/spdy_session_pool.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 scoped_refptr<SpdySession> session_; | 157 scoped_refptr<SpdySession> session_; |
158 scoped_refptr<SpdyStream> stream_; | 158 scoped_refptr<SpdyStream> stream_; |
159 GURL url_; | 159 GURL url_; |
160 RequestPriority priority_; | 160 RequestPriority priority_; |
161 BoundNetLog net_log_; | 161 BoundNetLog net_log_; |
162 CompletionCallback callback_; | 162 CompletionCallback callback_; |
163 | 163 |
164 DISALLOW_COPY_AND_ASSIGN(SpdyStreamRequest); | 164 DISALLOW_COPY_AND_ASSIGN(SpdyStreamRequest); |
165 }; | 165 }; |
166 | 166 |
167 // The interface for something which provides a SpdyFrame for writing. | |
168 class NET_EXPORT_PRIVATE SpdyFrameProducer { | |
169 public: | |
170 // Returns the SpdyStream associated with the frame to be produced, | |
171 // or NULL if the frame is associated with the session itself. | |
172 virtual SpdyStream* GetStream() = 0; | |
Ryan Hamilton
2013/03/24 15:22:54
See this comment on the CL which landed SpdyIOBuff
akalin
2013/03/24 18:24:14
Hmm I looked at the comment but willchan didn't st
willchan no longer on Chromium
2013/03/24 18:58:22
Layering. This is at the frame level, which is low
| |
173 | |
174 // Produces the frame to be written. Will be called at most once. | |
175 virtual scoped_ptr<SpdyFrame> ProduceFrame() = 0; | |
176 | |
177 virtual ~SpdyFrameProducer() {} | |
178 }; | |
179 | |
167 class NET_EXPORT SpdySession : public base::RefCounted<SpdySession>, | 180 class NET_EXPORT SpdySession : public base::RefCounted<SpdySession>, |
168 public BufferedSpdyFramerVisitorInterface { | 181 public BufferedSpdyFramerVisitorInterface { |
169 public: | 182 public: |
170 // TODO(akalin): Use base::TickClock when it becomes available. | 183 // TODO(akalin): Use base::TickClock when it becomes available. |
171 typedef base::TimeTicks (*TimeFunc)(void); | 184 typedef base::TimeTicks (*TimeFunc)(void); |
172 | 185 |
173 // How we handle flow control (version-dependent). | 186 // How we handle flow control (version-dependent). |
174 enum FlowControlState { | 187 enum FlowControlState { |
175 FLOW_CONTROL_NONE, | 188 FLOW_CONTROL_NONE, |
176 FLOW_CONTROL_STREAM, | 189 FLOW_CONTROL_STREAM, |
177 FLOW_CONTROL_STREAM_AND_SESSION | 190 FLOW_CONTROL_STREAM_AND_SESSION |
178 }; | 191 }; |
179 | 192 |
180 // Defines an interface for producing SpdyIOBuffers. | |
181 class NET_EXPORT_PRIVATE SpdyIOBufferProducer { | |
182 public: | |
183 SpdyIOBufferProducer() {} | |
184 | |
185 // Returns a newly created SpdyIOBuffer, owned by the caller, or NULL | |
186 // if not buffer is ready to be produced. | |
187 virtual SpdyIOBuffer* ProduceNextBuffer(SpdySession* session) = 0; | |
188 | |
189 virtual RequestPriority GetPriority() const = 0; | |
190 | |
191 virtual ~SpdyIOBufferProducer() {} | |
192 | |
193 protected: | |
194 // Activates |spdy_stream| in |spdy_session|. | |
195 static void ActivateStream(SpdySession* spdy_session, | |
196 SpdyStream* spdy_stream); | |
197 | |
198 static SpdyIOBuffer* CreateIOBuffer(SpdyFrame* frame, | |
199 RequestPriority priority, | |
200 SpdyStream* spdy_stream); | |
201 }; | |
202 | |
203 // Create a new SpdySession. | 193 // Create a new SpdySession. |
204 // |host_port_proxy_pair| is the host/port that this session connects to, and | 194 // |host_port_proxy_pair| is the host/port that this session connects to, and |
205 // the proxy configuration settings that it's using. | 195 // the proxy configuration settings that it's using. |
206 // |spdy_session_pool| is the SpdySessionPool that owns us. Its lifetime must | 196 // |spdy_session_pool| is the SpdySessionPool that owns us. Its lifetime must |
207 // strictly be greater than |this|. | 197 // strictly be greater than |this|. |
208 // |session| is the HttpNetworkSession. |net_log| is the NetLog that we log | 198 // |session| is the HttpNetworkSession. |net_log| is the NetLog that we log |
209 // network events to. | 199 // network events to. |
210 SpdySession(const HostPortProxyPair& host_port_proxy_pair, | 200 SpdySession(const HostPortProxyPair& host_port_proxy_pair, |
211 SpdySessionPool* spdy_session_pool, | 201 SpdySessionPool* spdy_session_pool, |
212 HttpServerProperties* http_server_properties, | 202 HttpServerProperties* http_server_properties, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
256 // this session provides authentication for the domain and no client | 246 // this session provides authentication for the domain and no client |
257 // certificate or channel ID was sent to the original server during the SSL | 247 // certificate or channel ID was sent to the original server during the SSL |
258 // handshake. NOTE: This function can have false negatives on some | 248 // handshake. NOTE: This function can have false negatives on some |
259 // platforms. | 249 // platforms. |
260 // TODO(wtc): rename this function and the Net.SpdyIPPoolDomainMatch | 250 // TODO(wtc): rename this function and the Net.SpdyIPPoolDomainMatch |
261 // histogram because this function does more than verifying domain | 251 // histogram because this function does more than verifying domain |
262 // authentication now. | 252 // authentication now. |
263 bool VerifyDomainAuthentication(const std::string& domain); | 253 bool VerifyDomainAuthentication(const std::string& domain); |
264 | 254 |
265 // Records that |stream| has a write available from |producer|. | 255 // Records that |stream| has a write available from |producer|. |
266 // |producer| will be owned by this SpdySession. | |
267 void SetStreamHasWriteAvailable(SpdyStream* stream, | 256 void SetStreamHasWriteAvailable(SpdyStream* stream, |
268 SpdyIOBufferProducer* producer); | 257 scoped_ptr<SpdyFrameProducer> producer); |
269 | 258 |
270 // Send the SYN frame for |stream_id|. This also sends PING message to check | 259 // Send the SYN frame for |stream_id|. This also sends PING message to check |
271 // the status of the connection. | 260 // the status of the connection. |
272 SpdyFrame* CreateSynStream( | 261 SpdyFrame* CreateSynStream( |
273 SpdyStreamId stream_id, | 262 SpdyStreamId stream_id, |
274 RequestPriority priority, | 263 RequestPriority priority, |
275 uint8 credential_slot, | 264 uint8 credential_slot, |
276 SpdyControlFlags flags, | 265 SpdyControlFlags flags, |
277 const SpdyHeaderBlock& headers); | 266 const SpdyHeaderBlock& headers); |
278 | 267 |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
468 FRIEND_TEST_ALL_PREFIXES(SpdySessionSpdy3Test, SessionFlowControlEndToEnd31); | 457 FRIEND_TEST_ALL_PREFIXES(SpdySessionSpdy3Test, SessionFlowControlEndToEnd31); |
469 | 458 |
470 typedef std::deque<SpdyStreamRequest*> PendingStreamRequestQueue; | 459 typedef std::deque<SpdyStreamRequest*> PendingStreamRequestQueue; |
471 typedef std::set<SpdyStreamRequest*> PendingStreamRequestCompletionSet; | 460 typedef std::set<SpdyStreamRequest*> PendingStreamRequestCompletionSet; |
472 | 461 |
473 typedef std::map<int, scoped_refptr<SpdyStream> > ActiveStreamMap; | 462 typedef std::map<int, scoped_refptr<SpdyStream> > ActiveStreamMap; |
474 typedef std::map<std::string, | 463 typedef std::map<std::string, |
475 std::pair<scoped_refptr<SpdyStream>, base::TimeTicks> > PushedStreamMap; | 464 std::pair<scoped_refptr<SpdyStream>, base::TimeTicks> > PushedStreamMap; |
476 | 465 |
477 typedef std::set<scoped_refptr<SpdyStream> > CreatedStreamSet; | 466 typedef std::set<scoped_refptr<SpdyStream> > CreatedStreamSet; |
478 typedef std::map<SpdyIOBufferProducer*, SpdyStream*> StreamProducerMap; | |
479 | |
480 class SpdyIOBufferProducerCompare { | |
481 public: | |
482 bool operator() (const SpdyIOBufferProducer* lhs, | |
483 const SpdyIOBufferProducer* rhs) const { | |
484 return lhs->GetPriority() < rhs->GetPriority(); | |
485 } | |
486 }; | |
487 | |
488 typedef std::priority_queue<SpdyIOBufferProducer*, | |
489 std::vector<SpdyIOBufferProducer*>, | |
490 SpdyIOBufferProducerCompare> WriteQueue; | |
491 | 467 |
492 enum State { | 468 enum State { |
493 STATE_IDLE, | 469 STATE_IDLE, |
494 STATE_CONNECTING, | 470 STATE_CONNECTING, |
495 STATE_DO_READ, | 471 STATE_DO_READ, |
496 STATE_DO_READ_COMPLETE, | 472 STATE_DO_READ_COMPLETE, |
497 STATE_CLOSED | 473 STATE_CLOSED |
498 }; | 474 }; |
499 | 475 |
500 virtual ~SpdySession(); | 476 virtual ~SpdySession(); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
575 // haven't received any data in |kHungInterval| time period. | 551 // haven't received any data in |kHungInterval| time period. |
576 void CheckPingStatus(base::TimeTicks last_check_time); | 552 void CheckPingStatus(base::TimeTicks last_check_time); |
577 | 553 |
578 // Write current data to the socket. | 554 // Write current data to the socket. |
579 void WriteSocketLater(); | 555 void WriteSocketLater(); |
580 void WriteSocket(); | 556 void WriteSocket(); |
581 | 557 |
582 // Get a new stream id. | 558 // Get a new stream id. |
583 int GetNewStreamId(); | 559 int GetNewStreamId(); |
584 | 560 |
585 // Queue a frame for sending. | 561 // Delegates to QueueFrameProducerForWriting to put the given frame |
562 // associated with the session on the write queue. | |
563 // | |
586 // |frame| is the frame to send. | 564 // |frame| is the frame to send. |
587 // |priority| is the priority for insertion into the queue. | 565 // |priority| is the priority for insertion into the queue. |
588 void QueueFrame(SpdyFrame* frame, RequestPriority priority); | 566 void QueueSessionFrameForWriting(scoped_ptr<SpdyFrame> frame, |
567 RequestPriority priority); | |
568 | |
569 // Puts |producer| onto the write queue with the given priority. | |
570 void QueueFrameProducerForWriting(scoped_ptr<SpdyFrameProducer> producer, | |
571 RequestPriority priority); | |
572 | |
573 // Pops the next frame producer to send from the write queue, or | |
574 // NULL if there isn't one. | |
575 scoped_ptr<SpdyFrameProducer> PopNextFrameProducerToWrite(); | |
576 | |
577 // Remove all frame producers associated with the given stream from | |
578 // the write queue. | |
579 void RemoveStreamFromWriteQueue(const scoped_refptr<SpdyStream>& stream); | |
580 | |
581 // Remove everything from the write queue. | |
582 void ClearWriteQueue(); | |
589 | 583 |
590 // Track active streams in the active stream list. | 584 // Track active streams in the active stream list. |
591 void ActivateStream(SpdyStream* stream); | 585 void ActivateStream(SpdyStream* stream); |
592 void DeleteStream(SpdyStreamId id, int status); | 586 void DeleteStream(SpdyStreamId id, int status); |
593 | 587 |
594 // Removes this session from the session pool. | 588 // Removes this session from the session pool. |
595 void RemoveFromPool(); | 589 void RemoveFromPool(); |
596 | 590 |
597 // Check if we have a pending pushed-stream for this url | 591 // Check if we have a pending pushed-stream for this url |
598 // Returns the stream if found (and returns it from the pending | 592 // Returns the stream if found (and returns it from the pending |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
761 // them? | 755 // them? |
762 ActiveStreamMap active_streams_; | 756 ActiveStreamMap active_streams_; |
763 | 757 |
764 // Map of all the streams that have already started to be pushed by the | 758 // Map of all the streams that have already started to be pushed by the |
765 // server, but do not have consumers yet. | 759 // server, but do not have consumers yet. |
766 PushedStreamMap unclaimed_pushed_streams_; | 760 PushedStreamMap unclaimed_pushed_streams_; |
767 | 761 |
768 // Set of all created streams but that have not yet sent any frames. | 762 // Set of all created streams but that have not yet sent any frames. |
769 CreatedStreamSet created_streams_; | 763 CreatedStreamSet created_streams_; |
770 | 764 |
771 // As streams have data to be sent, we put them into the write queue. | 765 // A FIFO queue of data to be sent, binned by priority. |
772 WriteQueue write_queue_; | 766 std::deque<SpdyFrameProducer*> write_queue_[NUM_PRIORITIES]; |
773 | |
774 // Mapping from SpdyIOBufferProducers to their corresponding SpdyStream | |
775 // so that when a stream is destroyed, we can remove the corresponding | |
776 // producer from |write_queue_|. | |
777 StreamProducerMap stream_producers_; | |
778 | 767 |
779 // The packet we are currently sending. | 768 // The packet we are currently sending. |
780 bool write_pending_; // Will be true when a write is in progress. | 769 bool write_pending_; // Will be true when a write is in progress. |
781 SpdyIOBuffer in_flight_write_; // This is the write buffer in progress. | 770 SpdyIOBuffer in_flight_write_; // This is the write buffer in progress. |
782 | 771 |
783 // Flag if we have a pending message scheduled for WriteSocket. | 772 // Flag if we have a pending message scheduled for WriteSocket. |
784 bool delayed_write_pending_; | 773 bool delayed_write_pending_; |
785 | 774 |
786 // Flag if we're using an SSL connection for this SpdySession. | 775 // Flag if we're using an SSL connection for this SpdySession. |
787 bool is_secure_; | 776 bool is_secure_; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
903 // This SPDY proxy is allowed to push resources from origins that are | 892 // This SPDY proxy is allowed to push resources from origins that are |
904 // different from those of their associated streams. | 893 // different from those of their associated streams. |
905 HostPortPair trusted_spdy_proxy_; | 894 HostPortPair trusted_spdy_proxy_; |
906 | 895 |
907 TimeFunc time_func_; | 896 TimeFunc time_func_; |
908 }; | 897 }; |
909 | 898 |
910 } // namespace net | 899 } // namespace net |
911 | 900 |
912 #endif // NET_SPDY_SPDY_SESSION_H_ | 901 #endif // NET_SPDY_SPDY_SESSION_H_ |
OLD | NEW |