Chromium Code Reviews| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <list> | 10 #include <list> |
| (...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 // Defines an interface for producing SpdyIOBuffers. | |
| 98 class NET_EXPORT_PRIVATE SpdyIOBufferProducer { | |
| 99 public: | |
| 100 SpdyIOBufferProducer() {} | |
| 101 | |
| 102 // Returns a newly created SpdyIOBuffer, owned by the caller, or NULL | |
| 103 // if not buffer is ready to be produced. | |
| 104 virtual SpdyIOBuffer* ProduceNextBuffer(SpdySession* session) = 0; | |
| 105 | |
| 106 virtual RequestPriority GetPriority() const = 0; | |
| 107 | |
| 108 virtual ~SpdyIOBufferProducer() {} | |
| 109 | |
| 110 protected: | |
| 111 // Activates |spdy_stream| in |spdy_session|. | |
| 112 static void ActivateStream(SpdySession* spdy_session, | |
| 113 SpdyStream* spdy_stream); | |
| 114 | |
| 115 static SpdyIOBuffer* CreateIOBuffer(SpdyFrame* frame, | |
| 116 RequestPriority priority, | |
| 117 SpdyStream* spdy_stream); | |
| 118 | |
| 119 private: | |
| 120 DISALLOW_COPY_AND_ASSIGN(SpdyIOBufferProducer); | |
| 121 }; | |
| 122 | |
| 97 // Create a new SpdySession. | 123 // Create a new SpdySession. |
| 98 // |host_port_proxy_pair| is the host/port that this session connects to, and | 124 // |host_port_proxy_pair| is the host/port that this session connects to, and |
| 99 // the proxy configuration settings that it's using. | 125 // the proxy configuration settings that it's using. |
| 100 // |spdy_session_pool| is the SpdySessionPool that owns us. Its lifetime must | 126 // |spdy_session_pool| is the SpdySessionPool that owns us. Its lifetime must |
| 101 // strictly be greater than |this|. | 127 // strictly be greater than |this|. |
| 102 // |session| is the HttpNetworkSession. |net_log| is the NetLog that we log | 128 // |session| is the HttpNetworkSession. |net_log| is the NetLog that we log |
| 103 // network events to. | 129 // network events to. |
| 104 SpdySession(const HostPortProxyPair& host_port_proxy_pair, | 130 SpdySession(const HostPortProxyPair& host_port_proxy_pair, |
| 105 SpdySessionPool* spdy_session_pool, | 131 SpdySessionPool* spdy_session_pool, |
| 106 HttpServerProperties* http_server_properties, | 132 HttpServerProperties* http_server_properties, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 // If the session is un-authenticated, then this call always returns true. | 176 // If the session is un-authenticated, then this call always returns true. |
| 151 // For SSL-based sessions, verifies that the server certificate in use by | 177 // For SSL-based sessions, verifies that the server certificate in use by |
| 152 // this session provides authentication for the domain and no client | 178 // this session provides authentication for the domain and no client |
| 153 // certificate was sent to the original server during the SSL handshake. | 179 // certificate was sent to the original server during the SSL handshake. |
| 154 // NOTE: This function can have false negatives on some platforms. | 180 // NOTE: This function can have false negatives on some platforms. |
| 155 // TODO(wtc): rename this function and the Net.SpdyIPPoolDomainMatch | 181 // TODO(wtc): rename this function and the Net.SpdyIPPoolDomainMatch |
| 156 // histogram because this function does more than verifying domain | 182 // histogram because this function does more than verifying domain |
| 157 // authentication now. | 183 // authentication now. |
| 158 bool VerifyDomainAuthentication(const std::string& domain); | 184 bool VerifyDomainAuthentication(const std::string& domain); |
| 159 | 185 |
| 186 // Records that |stream| has a write available from |producer|. | |
| 187 // |producer| will be owned by this SpdySession. | |
| 188 void SetStreamHasWriteAvailable(SpdyStream* stream, | |
| 189 SpdyIOBufferProducer* producer); | |
| 190 | |
| 160 // Send the SYN frame for |stream_id|. This also sends PING message to check | 191 // Send the SYN frame for |stream_id|. This also sends PING message to check |
| 161 // the status of the connection. | 192 // the status of the connection. |
| 162 int WriteSynStream( | 193 SpdySynStreamControlFrame* CreateSynStream( |
| 163 SpdyStreamId stream_id, | 194 SpdyStreamId stream_id, |
| 164 RequestPriority priority, | 195 RequestPriority priority, |
| 165 uint8 credential_slot, | 196 uint8 credential_slot, |
| 166 SpdyControlFlags flags, | 197 SpdyControlFlags flags, |
| 167 const linked_ptr<SpdyHeaderBlock>& headers); | 198 const linked_ptr<SpdyHeaderBlock>& headers); |
| 168 | 199 |
| 169 // Write a CREDENTIAL frame to the session. | 200 // Write a CREDENTIAL frame to the session. |
| 170 int WriteCredentialFrame(const std::string& origin, | 201 SpdyCredentialControlFrame* CreateCredentialFrame(const std::string& origin, |
| 171 SSLClientCertType type, | 202 SSLClientCertType type, |
| 172 const std::string& key, | 203 const std::string& key, |
| 173 const std::string& cert, | 204 const std::string& cert, |
| 174 RequestPriority priority); | 205 RequestPriority priority); |
| 175 | 206 |
| 176 // Write a data frame to the stream. | 207 // Write a data frame to the stream. |
| 177 // Used to create and queue a data frame for the given stream. | 208 // Used to create and queue a data frame for the given stream. |
| 178 int WriteStreamData(SpdyStreamId stream_id, net::IOBuffer* data, | 209 SpdyDataFrame* CreateDataFrame(SpdyStreamId stream_id, |
| 179 int len, | 210 net::IOBuffer* data, int len, |
| 180 SpdyDataFlags flags); | 211 SpdyDataFlags flags); |
| 181 | 212 |
| 182 // Close a stream. | 213 // Close a stream. |
| 183 void CloseStream(SpdyStreamId stream_id, int status); | 214 void CloseStream(SpdyStreamId stream_id, int status); |
| 184 | 215 |
| 216 // Close a stream that has been created but is not yet active. | |
| 217 void CloseCreatedStream(SpdyStream* stream, int status); | |
| 218 | |
| 185 // Reset a stream by sending a RST_STREAM frame with given status code. | 219 // Reset a stream by sending a RST_STREAM frame with given status code. |
| 186 // Also closes the stream. Was not piggybacked to CloseStream since not | 220 // Also closes the stream. Was not piggybacked to CloseStream since not |
| 187 // all of the calls to CloseStream necessitate sending a RST_STREAM. | 221 // all of the calls to CloseStream necessitate sending a RST_STREAM. |
| 188 void ResetStream(SpdyStreamId stream_id, | 222 void ResetStream(SpdyStreamId stream_id, |
| 189 SpdyStatusCodes status, | 223 SpdyStatusCodes status, |
| 190 const std::string& description); | 224 const std::string& description); |
| 191 | 225 |
| 192 // Check if a stream is active. | 226 // Check if a stream is active. |
| 193 bool IsStreamActive(SpdyStreamId stream_id) const; | 227 bool IsStreamActive(SpdyStreamId stream_id) const; |
| 194 | 228 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 bool WasEverUsed() const { | 299 bool WasEverUsed() const { |
| 266 return connection_->socket()->WasEverUsed(); | 300 return connection_->socket()->WasEverUsed(); |
| 267 } | 301 } |
| 268 | 302 |
| 269 void set_spdy_session_pool(SpdySessionPool* pool) { | 303 void set_spdy_session_pool(SpdySessionPool* pool) { |
| 270 spdy_session_pool_ = NULL; | 304 spdy_session_pool_ = NULL; |
| 271 } | 305 } |
| 272 | 306 |
| 273 // Returns true if session is not currently active | 307 // Returns true if session is not currently active |
| 274 bool is_active() const { | 308 bool is_active() const { |
| 275 return !active_streams_.empty(); | 309 return !active_streams_.empty() || !created_streams_.empty(); |
| 276 } | 310 } |
| 277 | 311 |
| 278 // Access to the number of active and pending streams. These are primarily | 312 // Access to the number of active and pending streams. These are primarily |
| 279 // available for testing and diagnostics. | 313 // available for testing and diagnostics. |
| 280 size_t num_active_streams() const { return active_streams_.size(); } | 314 size_t num_active_streams() const { return active_streams_.size(); } |
| 281 size_t num_unclaimed_pushed_streams() const { | 315 size_t num_unclaimed_pushed_streams() const { |
| 282 return unclaimed_pushed_streams_.size(); | 316 return unclaimed_pushed_streams_.size(); |
| 283 } | 317 } |
| 318 size_t num_created_streams() const { return created_streams_.size(); } | |
| 284 | 319 |
| 285 // Returns true if flow control is enabled for the session. | 320 // Returns true if flow control is enabled for the session. |
| 286 bool is_flow_control_enabled() const { | 321 bool is_flow_control_enabled() const { |
| 287 return flow_control_; | 322 return flow_control_; |
| 288 } | 323 } |
| 289 | 324 |
| 290 // Returns the current |initial_send_window_size_|. | 325 // Returns the current |initial_send_window_size_|. |
| 291 int32 initial_send_window_size() const { | 326 int32 initial_send_window_size() const { |
| 292 return initial_send_window_size_; | 327 return initial_send_window_size_; |
| 293 } | 328 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 349 RequestPriority priority; | 384 RequestPriority priority; |
| 350 scoped_refptr<SpdyStream>* spdy_stream; | 385 scoped_refptr<SpdyStream>* spdy_stream; |
| 351 const BoundNetLog* stream_net_log; | 386 const BoundNetLog* stream_net_log; |
| 352 CompletionCallback callback; | 387 CompletionCallback callback; |
| 353 }; | 388 }; |
| 354 typedef std::queue<PendingCreateStream, std::list< PendingCreateStream> > | 389 typedef std::queue<PendingCreateStream, std::list< PendingCreateStream> > |
| 355 PendingCreateStreamQueue; | 390 PendingCreateStreamQueue; |
| 356 typedef std::map<int, scoped_refptr<SpdyStream> > ActiveStreamMap; | 391 typedef std::map<int, scoped_refptr<SpdyStream> > ActiveStreamMap; |
| 357 // Only HTTP push a stream. | 392 // Only HTTP push a stream. |
| 358 typedef std::map<std::string, scoped_refptr<SpdyStream> > PushedStreamMap; | 393 typedef std::map<std::string, scoped_refptr<SpdyStream> > PushedStreamMap; |
| 359 typedef std::priority_queue<SpdyIOBuffer> OutputQueue; | 394 typedef std::set<scoped_refptr<SpdyStream> > CreatedStreamSet; |
| 395 typedef std::map<SpdyIOBufferProducer*, SpdyStream*> StreamProducerMap; | |
| 396 class SpdyIOBufferProducerCompare { | |
| 397 public: | |
| 398 bool operator() (const SpdyIOBufferProducer* lhs, | |
| 399 const SpdyIOBufferProducer* rhs) const { | |
| 400 return lhs->GetPriority() < rhs->GetPriority(); | |
| 401 } | |
| 402 }; | |
| 403 typedef std::priority_queue<SpdyIOBufferProducer*, | |
| 404 std::vector<SpdyIOBufferProducer*>, | |
| 405 SpdyIOBufferProducerCompare> WriteQueue; | |
| 360 | 406 |
| 361 struct CallbackResultPair { | 407 struct CallbackResultPair { |
| 362 CallbackResultPair(const CompletionCallback& callback_in, int result_in) | 408 CallbackResultPair(const CompletionCallback& callback_in, int result_in) |
| 363 : callback(callback_in), result(result_in) {} | 409 : callback(callback_in), result(result_in) {} |
| 364 ~CallbackResultPair(); | 410 ~CallbackResultPair(); |
| 365 | 411 |
| 366 CompletionCallback callback; | 412 CompletionCallback callback; |
| 367 int result; | 413 int result; |
| 368 }; | 414 }; |
| 369 | 415 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 427 // Write current data to the socket. | 473 // Write current data to the socket. |
| 428 void WriteSocketLater(); | 474 void WriteSocketLater(); |
| 429 void WriteSocket(); | 475 void WriteSocket(); |
| 430 | 476 |
| 431 // Get a new stream id. | 477 // Get a new stream id. |
| 432 int GetNewStreamId(); | 478 int GetNewStreamId(); |
| 433 | 479 |
| 434 // Queue a frame for sending. | 480 // Queue a frame for sending. |
| 435 // |frame| is the frame to send. | 481 // |frame| is the frame to send. |
| 436 // |priority| is the priority for insertion into the queue. | 482 // |priority| is the priority for insertion into the queue. |
| 437 // |stream| is the stream which this IO is associated with (or NULL). | 483 void QueueFrame(SpdyFrame* frame, RequestPriority priority); |
| 438 void QueueFrame(SpdyFrame* frame, RequestPriority priority, | |
| 439 SpdyStream* stream); | |
| 440 | 484 |
| 441 // Track active streams in the active stream list. | 485 // Track active streams in the active stream list. |
| 442 void ActivateStream(SpdyStream* stream); | 486 void ActivateStream(SpdyStream* stream); |
| 443 void DeleteStream(SpdyStreamId id, int status); | 487 void DeleteStream(SpdyStreamId id, int status); |
| 444 | 488 |
| 445 // Removes this session from the session pool. | 489 // Removes this session from the session pool. |
| 446 void RemoveFromPool(); | 490 void RemoveFromPool(); |
| 447 | 491 |
| 448 // Check if we have a pending pushed-stream for this url | 492 // Check if we have a pending pushed-stream for this url |
| 449 // Returns the stream if found (and returns it from the pending | 493 // Returns the stream if found (and returns it from the pending |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 474 const SpdyRstStreamControlFrame& frame) OVERRIDE; | 518 const SpdyRstStreamControlFrame& frame) OVERRIDE; |
| 475 virtual void OnGoAway(const SpdyGoAwayControlFrame& frame) OVERRIDE; | 519 virtual void OnGoAway(const SpdyGoAwayControlFrame& frame) OVERRIDE; |
| 476 virtual void OnPing(const SpdyPingControlFrame& frame) OVERRIDE; | 520 virtual void OnPing(const SpdyPingControlFrame& frame) OVERRIDE; |
| 477 virtual void OnWindowUpdate( | 521 virtual void OnWindowUpdate( |
| 478 const SpdyWindowUpdateControlFrame& frame) OVERRIDE; | 522 const SpdyWindowUpdateControlFrame& frame) OVERRIDE; |
| 479 virtual void OnStreamFrameData(SpdyStreamId stream_id, | 523 virtual void OnStreamFrameData(SpdyStreamId stream_id, |
| 480 const char* data, | 524 const char* data, |
| 481 size_t len) OVERRIDE; | 525 size_t len) OVERRIDE; |
| 482 virtual void OnSetting( | 526 virtual void OnSetting( |
| 483 SpdySettingsIds id, uint8 flags, uint32 value) OVERRIDE; | 527 SpdySettingsIds id, uint8 flags, uint32 value) OVERRIDE; |
| 528 virtual void OnControlFrameCompressed( | |
| 529 const SpdyControlFrame& uncompressed_frame, | |
| 530 const SpdyControlFrame& compressed_frame) OVERRIDE; | |
| 484 virtual void OnSynStream( | 531 virtual void OnSynStream( |
| 485 const SpdySynStreamControlFrame& frame, | 532 const SpdySynStreamControlFrame& frame, |
| 486 const linked_ptr<SpdyHeaderBlock>& headers) OVERRIDE; | 533 const linked_ptr<SpdyHeaderBlock>& headers) OVERRIDE; |
| 487 virtual void OnSynReply( | 534 virtual void OnSynReply( |
| 488 const SpdySynReplyControlFrame& frame, | 535 const SpdySynReplyControlFrame& frame, |
| 489 const linked_ptr<SpdyHeaderBlock>& headers) OVERRIDE; | 536 const linked_ptr<SpdyHeaderBlock>& headers) OVERRIDE; |
| 490 virtual void OnHeaders( | 537 virtual void OnHeaders( |
| 491 const SpdyHeadersControlFrame& frame, | 538 const SpdyHeadersControlFrame& frame, |
| 492 const linked_ptr<SpdyHeaderBlock>& headers) OVERRIDE; | 539 const linked_ptr<SpdyHeaderBlock>& headers) OVERRIDE; |
| 493 | 540 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 556 // the server to start pushing the stream]) or there are still network events | 603 // the server to start pushing the stream]) or there are still network events |
| 557 // incoming even though the consumer has already gone away (cancellation). | 604 // incoming even though the consumer has already gone away (cancellation). |
| 558 // TODO(willchan): Perhaps we should separate out cancelled streams and move | 605 // TODO(willchan): Perhaps we should separate out cancelled streams and move |
| 559 // them into a separate ActiveStreamMap, and not deliver network events to | 606 // them into a separate ActiveStreamMap, and not deliver network events to |
| 560 // them? | 607 // them? |
| 561 ActiveStreamMap active_streams_; | 608 ActiveStreamMap active_streams_; |
| 562 // Map of all the streams that have already started to be pushed by the | 609 // Map of all the streams that have already started to be pushed by the |
| 563 // server, but do not have consumers yet. | 610 // server, but do not have consumers yet. |
| 564 PushedStreamMap unclaimed_pushed_streams_; | 611 PushedStreamMap unclaimed_pushed_streams_; |
| 565 | 612 |
| 566 // As we gather data to be sent, we put it into the output queue. | 613 // Set of all created streams but that have not yet sent any frames. |
| 567 OutputQueue queue_; | 614 CreatedStreamSet created_streams_; |
| 615 | |
| 616 // As streams have data to be sent, we put them into the write queue. | |
| 617 WriteQueue write_queue_; | |
| 618 | |
| 619 // Mapping from SpdyIOBufferProducers to their corresponding SpdyStream | |
| 620 // so that when a stream is destroyed, we can remove the corresponding | |
| 621 // producer from |write_queue_| | |
|
ramant (doing other things)
2012/06/26 23:30:25
overly nit: punctuation at the end of "|write_queu
Ryan Hamilton
2012/06/27 16:58:28
Done.
| |
| 622 StreamProducerMap stream_producers_; | |
| 568 | 623 |
| 569 // The packet we are currently sending. | 624 // The packet we are currently sending. |
| 570 bool write_pending_; // Will be true when a write is in progress. | 625 bool write_pending_; // Will be true when a write is in progress. |
| 571 SpdyIOBuffer in_flight_write_; // This is the write buffer in progress. | 626 SpdyIOBuffer in_flight_write_; // This is the write buffer in progress. |
| 572 | 627 |
| 573 // Flag if we have a pending message scheduled for WriteSocket. | 628 // Flag if we have a pending message scheduled for WriteSocket. |
| 574 bool delayed_write_pending_; | 629 bool delayed_write_pending_; |
| 575 | 630 |
| 576 // Flag if we're using an SSL connection for this SpdySession. | 631 // Flag if we're using an SSL connection for this SpdySession. |
| 577 bool is_secure_; | 632 bool is_secure_; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 663 base::TimeDelta hung_interval_; | 718 base::TimeDelta hung_interval_; |
| 664 | 719 |
| 665 // This SPDY proxy is allowed to push resources from origins that are | 720 // This SPDY proxy is allowed to push resources from origins that are |
| 666 // different from those of their associated streams. | 721 // different from those of their associated streams. |
| 667 HostPortPair trusted_spdy_proxy_; | 722 HostPortPair trusted_spdy_proxy_; |
| 668 }; | 723 }; |
| 669 | 724 |
| 670 } // namespace net | 725 } // namespace net |
| 671 | 726 |
| 672 #endif // NET_SPDY_SPDY_SESSION_H_ | 727 #endif // NET_SPDY_SPDY_SESSION_H_ |
| OLD | NEW |