| 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 // If the session is un-authenticated, then this call always returns true. | 151 // If the session is un-authenticated, then this call always returns true. |
| 152 // For SSL-based sessions, verifies that the server certificate in use by | 152 // For SSL-based sessions, verifies that the server certificate in use by |
| 153 // this session provides authentication for the domain and no client | 153 // this session provides authentication for the domain and no client |
| 154 // certificate was sent to the original server during the SSL handshake. | 154 // certificate was sent to the original server during the SSL handshake. |
| 155 // NOTE: This function can have false negatives on some platforms. | 155 // NOTE: This function can have false negatives on some platforms. |
| 156 // TODO(wtc): rename this function and the Net.SpdyIPPoolDomainMatch | 156 // TODO(wtc): rename this function and the Net.SpdyIPPoolDomainMatch |
| 157 // histogram because this function does more than verifying domain | 157 // histogram because this function does more than verifying domain |
| 158 // authentication now. | 158 // authentication now. |
| 159 bool VerifyDomainAuthentication(const std::string& domain); | 159 bool VerifyDomainAuthentication(const std::string& domain); |
| 160 | 160 |
| 161 // Records that |stream| has a write available. |
| 162 void SetStreamHasWriteAvailable(SpdyStream* stream); |
| 163 |
| 161 // Send the SYN frame for |stream_id|. This also sends PING message to check | 164 // Send the SYN frame for |stream_id|. This also sends PING message to check |
| 162 // the status of the connection. | 165 // the status of the connection. |
| 163 int WriteSynStream( | 166 SpdySynStreamControlFrame* CreateSynStream( |
| 164 SpdyStreamId stream_id, | 167 SpdyStreamId stream_id, |
| 165 RequestPriority priority, | 168 RequestPriority priority, |
| 166 uint8 credential_slot, | 169 uint8 credential_slot, |
| 167 SpdyControlFlags flags, | 170 SpdyControlFlags flags, |
| 168 const linked_ptr<SpdyHeaderBlock>& headers); | 171 const linked_ptr<SpdyHeaderBlock>& headers); |
| 169 | 172 |
| 170 // Write a CREDENTIAL frame to the session. | 173 // Write a CREDENTIAL frame to the session. |
| 171 int WriteCredentialFrame(const std::string& origin, | 174 SpdyCredentialControlFrame* CreateCredentialFrame(const std::string& origin, |
| 172 SSLClientCertType type, | 175 SSLClientCertType type, |
| 173 const std::string& key, | 176 const std::string& key, |
| 174 const std::string& cert, | 177 const std::string& cert, |
| 175 RequestPriority priority); | 178 RequestPriority priority); |
| 176 | 179 |
| 177 // Write a data frame to the stream. | 180 // Write a data frame to the stream. |
| 178 // Used to create and queue a data frame for the given stream. | 181 // Used to create and queue a data frame for the given stream. |
| 179 int WriteStreamData(SpdyStreamId stream_id, net::IOBuffer* data, | 182 SpdyDataFrame* CreateDataFrame(SpdyStreamId stream_id, |
| 180 int len, | 183 net::IOBuffer* data, int len, |
| 181 SpdyDataFlags flags); | 184 SpdyDataFlags flags); |
| 182 | 185 |
| 183 // Close a stream. | 186 // Close a stream. |
| 184 void CloseStream(SpdyStreamId stream_id, int status); | 187 void CloseStream(SpdyStreamId stream_id, int status); |
| 185 | 188 |
| 189 // Close a stream that has been created but is not yet active. |
| 190 void CloseCreatedStream(SpdyStream* stream, int status); |
| 191 |
| 186 // Reset a stream by sending a RST_STREAM frame with given status code. | 192 // Reset a stream by sending a RST_STREAM frame with given status code. |
| 187 // Also closes the stream. Was not piggybacked to CloseStream since not | 193 // Also closes the stream. Was not piggybacked to CloseStream since not |
| 188 // all of the calls to CloseStream necessitate sending a RST_STREAM. | 194 // all of the calls to CloseStream necessitate sending a RST_STREAM. |
| 189 void ResetStream(SpdyStreamId stream_id, | 195 void ResetStream(SpdyStreamId stream_id, |
| 190 SpdyStatusCodes status, | 196 SpdyStatusCodes status, |
| 191 const std::string& description); | 197 const std::string& description); |
| 192 | 198 |
| 193 // Check if a stream is active. | 199 // Check if a stream is active. |
| 194 bool IsStreamActive(SpdyStreamId stream_id) const; | 200 bool IsStreamActive(SpdyStreamId stream_id) const; |
| 195 | 201 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 bool WasEverUsed() const { | 269 bool WasEverUsed() const { |
| 264 return connection_->socket()->WasEverUsed(); | 270 return connection_->socket()->WasEverUsed(); |
| 265 } | 271 } |
| 266 | 272 |
| 267 void set_spdy_session_pool(SpdySessionPool* pool) { | 273 void set_spdy_session_pool(SpdySessionPool* pool) { |
| 268 spdy_session_pool_ = NULL; | 274 spdy_session_pool_ = NULL; |
| 269 } | 275 } |
| 270 | 276 |
| 271 // Returns true if session is not currently active | 277 // Returns true if session is not currently active |
| 272 bool is_active() const { | 278 bool is_active() const { |
| 273 return !active_streams_.empty(); | 279 return !active_streams_.empty() || !created_streams_.empty(); |
| 274 } | 280 } |
| 275 | 281 |
| 276 // Access to the number of active and pending streams. These are primarily | 282 // Access to the number of active and pending streams. These are primarily |
| 277 // available for testing and diagnostics. | 283 // available for testing and diagnostics. |
| 278 size_t num_active_streams() const { return active_streams_.size(); } | 284 size_t num_active_streams() const { return active_streams_.size(); } |
| 279 size_t num_unclaimed_pushed_streams() const { | 285 size_t num_unclaimed_pushed_streams() const { |
| 280 return unclaimed_pushed_streams_.size(); | 286 return unclaimed_pushed_streams_.size(); |
| 281 } | 287 } |
| 288 size_t num_created_streams() const { return created_streams_.size(); } |
| 282 | 289 |
| 283 // Returns true if flow control is enabled for the session. | 290 // Returns true if flow control is enabled for the session. |
| 284 bool is_flow_control_enabled() const { | 291 bool is_flow_control_enabled() const { |
| 285 return flow_control_; | 292 return flow_control_; |
| 286 } | 293 } |
| 287 | 294 |
| 288 // Returns the current |initial_send_window_size_|. | 295 // Returns the current |initial_send_window_size_|. |
| 289 int32 initial_send_window_size() const { | 296 int32 initial_send_window_size() const { |
| 290 return initial_send_window_size_; | 297 return initial_send_window_size_; |
| 291 } | 298 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 RequestPriority priority; | 354 RequestPriority priority; |
| 348 scoped_refptr<SpdyStream>* spdy_stream; | 355 scoped_refptr<SpdyStream>* spdy_stream; |
| 349 const BoundNetLog* stream_net_log; | 356 const BoundNetLog* stream_net_log; |
| 350 CompletionCallback callback; | 357 CompletionCallback callback; |
| 351 }; | 358 }; |
| 352 typedef std::queue<PendingCreateStream, std::list< PendingCreateStream> > | 359 typedef std::queue<PendingCreateStream, std::list< PendingCreateStream> > |
| 353 PendingCreateStreamQueue; | 360 PendingCreateStreamQueue; |
| 354 typedef std::map<int, scoped_refptr<SpdyStream> > ActiveStreamMap; | 361 typedef std::map<int, scoped_refptr<SpdyStream> > ActiveStreamMap; |
| 355 // Only HTTP push a stream. | 362 // Only HTTP push a stream. |
| 356 typedef std::map<std::string, scoped_refptr<SpdyStream> > PushedStreamMap; | 363 typedef std::map<std::string, scoped_refptr<SpdyStream> > PushedStreamMap; |
| 357 typedef std::priority_queue<SpdyIOBuffer> OutputQueue; | 364 typedef std::set<scoped_refptr<SpdyStream> > CreatedStreamSet; |
| 365 class SpdyFrameProducerCompare { |
| 366 public: |
| 367 bool operator() (const SpdyFrameProducer* lhs, |
| 368 const SpdyFrameProducer* rhs) const { |
| 369 return lhs->GetPriority() < rhs->GetPriority(); |
| 370 } |
| 371 }; |
| 372 typedef std::priority_queue<SpdyFrameProducer*, |
| 373 std::vector<SpdyFrameProducer*>, |
| 374 SpdyFrameProducerCompare> WriteQueue; |
| 358 | 375 |
| 359 struct CallbackResultPair { | 376 struct CallbackResultPair { |
| 360 CallbackResultPair(const CompletionCallback& callback_in, int result_in) | 377 CallbackResultPair(const CompletionCallback& callback_in, int result_in) |
| 361 : callback(callback_in), result(result_in) {} | 378 : callback(callback_in), result(result_in) {} |
| 362 ~CallbackResultPair(); | 379 ~CallbackResultPair(); |
| 363 | 380 |
| 364 CompletionCallback callback; | 381 CompletionCallback callback; |
| 365 int result; | 382 int result; |
| 366 }; | 383 }; |
| 367 | 384 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 // Write current data to the socket. | 439 // Write current data to the socket. |
| 423 void WriteSocketLater(); | 440 void WriteSocketLater(); |
| 424 void WriteSocket(); | 441 void WriteSocket(); |
| 425 | 442 |
| 426 // Get a new stream id. | 443 // Get a new stream id. |
| 427 int GetNewStreamId(); | 444 int GetNewStreamId(); |
| 428 | 445 |
| 429 // Queue a frame for sending. | 446 // Queue a frame for sending. |
| 430 // |frame| is the frame to send. | 447 // |frame| is the frame to send. |
| 431 // |priority| is the priority for insertion into the queue. | 448 // |priority| is the priority for insertion into the queue. |
| 432 // |stream| is the stream which this IO is associated with (or NULL). | 449 void QueueFrame(SpdyFrame* frame, RequestPriority priority); |
| 433 void QueueFrame(SpdyFrame* frame, RequestPriority priority, | |
| 434 SpdyStream* stream); | |
| 435 | 450 |
| 436 // Track active streams in the active stream list. | 451 // Track active streams in the active stream list. |
| 437 void ActivateStream(SpdyStream* stream); | 452 void ActivateStream(SpdyStream* stream); |
| 438 void DeleteStream(SpdyStreamId id, int status); | 453 void DeleteStream(SpdyStreamId id, int status); |
| 439 | 454 |
| 440 // Removes this session from the session pool. | 455 // Removes this session from the session pool. |
| 441 void RemoveFromPool(); | 456 void RemoveFromPool(); |
| 442 | 457 |
| 443 // Check if we have a pending pushed-stream for this url | 458 // Check if we have a pending pushed-stream for this url |
| 444 // Returns the stream if found (and returns it from the pending | 459 // Returns the stream if found (and returns it from the pending |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 // the server to start pushing the stream]) or there are still network events | 566 // the server to start pushing the stream]) or there are still network events |
| 552 // incoming even though the consumer has already gone away (cancellation). | 567 // incoming even though the consumer has already gone away (cancellation). |
| 553 // TODO(willchan): Perhaps we should separate out cancelled streams and move | 568 // TODO(willchan): Perhaps we should separate out cancelled streams and move |
| 554 // them into a separate ActiveStreamMap, and not deliver network events to | 569 // them into a separate ActiveStreamMap, and not deliver network events to |
| 555 // them? | 570 // them? |
| 556 ActiveStreamMap active_streams_; | 571 ActiveStreamMap active_streams_; |
| 557 // Map of all the streams that have already started to be pushed by the | 572 // Map of all the streams that have already started to be pushed by the |
| 558 // server, but do not have consumers yet. | 573 // server, but do not have consumers yet. |
| 559 PushedStreamMap unclaimed_pushed_streams_; | 574 PushedStreamMap unclaimed_pushed_streams_; |
| 560 | 575 |
| 561 // As we gather data to be sent, we put it into the output queue. | 576 // Set of all created streams but that have not yet sent any frames. |
| 562 OutputQueue queue_; | 577 CreatedStreamSet created_streams_; |
| 578 |
| 579 // As streams have data to be sent, we put them into the write queue. |
| 580 WriteQueue write_queue_; |
| 563 | 581 |
| 564 // The packet we are currently sending. | 582 // The packet we are currently sending. |
| 565 bool write_pending_; // Will be true when a write is in progress. | 583 bool write_pending_; // Will be true when a write is in progress. |
| 566 SpdyIOBuffer in_flight_write_; // This is the write buffer in progress. | 584 SpdyIOBuffer in_flight_write_; // This is the write buffer in progress. |
| 567 | 585 |
| 568 // Flag if we have a pending message scheduled for WriteSocket. | 586 // Flag if we have a pending message scheduled for WriteSocket. |
| 569 bool delayed_write_pending_; | 587 bool delayed_write_pending_; |
| 570 | 588 |
| 571 // Flag if we're using an SSL connection for this SpdySession. | 589 // Flag if we're using an SSL connection for this SpdySession. |
| 572 bool is_secure_; | 590 bool is_secure_; |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 private: | 734 private: |
| 717 const int status_; | 735 const int status_; |
| 718 const std::string description_; | 736 const std::string description_; |
| 719 | 737 |
| 720 DISALLOW_COPY_AND_ASSIGN(NetLogSpdySessionCloseParameter); | 738 DISALLOW_COPY_AND_ASSIGN(NetLogSpdySessionCloseParameter); |
| 721 }; | 739 }; |
| 722 | 740 |
| 723 } // namespace net | 741 } // namespace net |
| 724 | 742 |
| 725 #endif // NET_SPDY_SPDY_SESSION_H_ | 743 #endif // NET_SPDY_SPDY_SESSION_H_ |
| OLD | NEW |