diff options
Diffstat (limited to 'net/spdy/spdy_stream.h')
-rw-r--r-- | net/spdy/spdy_stream.h | 137 |
1 files changed, 55 insertions, 82 deletions
diff --git a/net/spdy/spdy_stream.h b/net/spdy/spdy_stream.h index 919bca8..1792cf1 100644 --- a/net/spdy/spdy_stream.h +++ b/net/spdy/spdy_stream.h @@ -6,25 +6,25 @@ #define NET_SPDY_SPDY_STREAM_H_ #include <string> -#include <vector> #include "base/basictypes.h" -#include "base/linked_ptr.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" #include "net/base/bandwidth_metrics.h" #include "net/base/io_buffer.h" #include "net/base/net_log.h" -#include "net/spdy/spdy_framer.h" +#include "net/http/http_request_info.h" #include "net/spdy/spdy_protocol.h" namespace net { +class HttpResponseInfo; class SpdySession; -class SSLInfo; +class UploadDataStream; // The SpdyStream is used by the SpdySession to represent each stream known -// on the SpdySession. This class provides interfaces for SpdySession to use. +// on the SpdySession. This class provides interfaces for SpdySession to use +// and base implementations for the interfaces. // Streams can be created either by the client or by the server. When they // are initiated by the client, both the SpdySession and client object (such as // a SpdyNetworkTransaction) will maintain a reference to the stream. When @@ -32,58 +32,9 @@ class SSLInfo; // until such a time as a client object requests a stream for the path. class SpdyStream : public base::RefCounted<SpdyStream> { public: - // Delegate handles protocol specific behavior of spdy stream. - class Delegate { - public: - Delegate() {} - - // Called when SYN frame has been sent. - // Returns true if no more data to be sent after SYN frame. - virtual bool OnSendHeadersComplete(int status) = 0; - - // Called when stream is ready to send data. - // Returns network error code. OK when it successfully sent data. - virtual int OnSendBody() = 0; - - // Called when data has been sent. |status| indicates network error - // or number of bytes has been sent. - // Returns true if no more data to be sent. - virtual bool OnSendBodyComplete(int status) = 0; - - // Called when SYN_REPLY received. |status| indicates network error. - // Returns network error code. - virtual int OnResponseReceived(const spdy::SpdyHeaderBlock& response, - base::Time response_time, - int status) = 0; - - // Called when data is received. - // Returns true if data is successfully processed. - virtual void OnDataReceived(const char* data, int length) = 0; - - // Called when SpdyStream is closed. - virtual void OnClose(int status) = 0; - - protected: - friend class base::RefCounted<Delegate>; - virtual ~Delegate() {} - - private: - DISALLOW_COPY_AND_ASSIGN(Delegate); - }; - // SpdyStream constructor SpdyStream(SpdySession* session, spdy::SpdyStreamId stream_id, bool pushed); - // Set new |delegate|. |delegate| must not be NULL. - // If it already received SYN_REPLY or data, OnResponseReceived() or - // OnDataReceived() will be called. - void SetDelegate(Delegate* delegate); - Delegate* GetDelegate() { return delegate_; } - - // Detach delegate from the stream. It will cancel the stream if it was not - // cancelled yet. It is safe to call multiple times. - void DetachDelegate(); - // Is this stream a pushed stream from the server. bool pushed() const { return pushed_; } @@ -100,8 +51,9 @@ class SpdyStream : public base::RefCounted<SpdyStream> { const BoundNetLog& net_log() const { return net_log_; } void set_net_log(const BoundNetLog& log) { net_log_ = log; } - const linked_ptr<spdy::SpdyHeaderBlock>& spdy_headers() const; - void set_spdy_headers(const linked_ptr<spdy::SpdyHeaderBlock>& headers); + const HttpResponseInfo* GetResponseInfo() const; + const HttpRequestInfo* GetRequestInfo() const; + void SetRequestInfo(const HttpRequestInfo& request); base::Time GetRequestTime() const; void SetRequestTime(base::Time t); @@ -109,7 +61,7 @@ class SpdyStream : public base::RefCounted<SpdyStream> { // received for this stream. |path| is the path of the URL for a server // initiated stream, otherwise is empty. // Returns a status code. - int OnResponseReceived(const spdy::SpdyHeaderBlock& response); + virtual int OnResponseReceived(const HttpResponseInfo& response) = 0; // Called by the SpdySession when response data has been received for this // stream. This callback may be called multiple times as data arrives @@ -118,43 +70,61 @@ class SpdyStream : public base::RefCounted<SpdyStream> { // from this buffer before returning from this callback. // |length| is the number of bytes received or an error. // A zero-length count does not indicate end-of-stream. - void OnDataReceived(const char* buffer, int bytes); + // Returns true on success and false on error. + virtual bool OnDataReceived(const char* buffer, int bytes) = 0; // Called by the SpdySession when a write has completed. This callback // will be called multiple times for each write which completes. Writes // include the SYN_STREAM write and also DATA frame writes. // |result| is the number of bytes written or a net error code. - void OnWriteComplete(int status); + virtual void OnWriteComplete(int status) = 0; // Called by the SpdySession when the request is finished. This callback // will always be called at the end of the request and signals to the // stream that the stream has no more network events. No further callbacks // to the stream will be made after this call. // |status| is an error code or OK. - void OnClose(int status); + virtual void OnClose(int status) = 0; - void Cancel(); + virtual void Cancel() = 0; bool cancelled() const { return cancelled_; } - // Interface for Spdy[Http|WebSocket]Stream to use. + void SetPushResponse(HttpResponseInfo* response_info); + + protected: + friend class base::RefCounted<SpdyStream>; + virtual ~SpdyStream(); + + int DoOnResponseReceived(const HttpResponseInfo& response); + bool DoOnDataReceived(const char* buffer,int bytes); + void DoOnWriteComplete(int status); + void DoOnClose(int status); - // Sends the request. - // For non push stream, it will send SYN_STREAM frame. - int DoSendRequest(bool has_upload_data); + void DoCancel(); + + // Sends the request. If |upload_data| is non-NULL, sends that in the + // request body. Note that the actual SYN_STREAM packet will have already + // been sent by this point. + // Note that SpdyStream takes ownership of |upload_data|. + // TODO(ukai): move out HTTP-specific thing to SpdyHttpStream. + int DoSendRequest(UploadDataStream* upload_data, + HttpResponseInfo* response_info); // Reads response headers. If the SpdyStream have already received // the response headers, return OK and response headers filled in - // |response| given in SendRequest. - // Otherwise, return ERR_IO_PENDING and OnResponseReceived() will be called. + // |response_info| given in SendRequest. + // Otherwise, return ERR_IO_PENDING. int DoReadResponseHeaders(); - // Sends DATA frame. - int WriteStreamData(IOBuffer* data, int length); - - bool GetSSLInfo(SSLInfo* ssl_info, bool* was_npn_negotiated); + const UploadDataStream* request_body_stream() const { + return request_body_stream_.get(); + } bool is_idle() const { return io_state_ == STATE_NONE; } bool response_complete() const { return response_complete_; } + void set_response_complete(bool response_complete) { + response_complete_ = response_complete; + } int response_status() const { return response_status_; } private: @@ -171,9 +141,6 @@ class SpdyStream : public base::RefCounted<SpdyStream> { STATE_DONE }; - friend class base::RefCounted<SpdyStream>; - virtual ~SpdyStream(); - // Try to make progress sending/receiving the request/response. int DoLoop(int result); @@ -199,18 +166,26 @@ class SpdyStream : public base::RefCounted<SpdyStream> { scoped_refptr<SpdySession> session_; - // The transaction should own the delegate. - SpdyStream::Delegate* delegate_; - // The request to send. - linked_ptr<spdy::SpdyHeaderBlock> request_; + HttpRequestInfo request_; // The time at which the request was made that resulted in this response. // For cached responses, this time could be "far" in the past. base::Time request_time_; - linked_ptr<spdy::SpdyHeaderBlock> response_; - base::Time response_time_; + // The push_response_ is the HTTP response data which is part of + // a server-initiated SYN_STREAM. If a client request comes in + // which matches the push stream, the data in push_response_ will + // be copied over to the response_ object owned by the caller + // of the request. + scoped_ptr<HttpResponseInfo> push_response_; + + // response_ is the HTTP response data object which is filled in + // when a SYN_REPLY comes in for the stream. It is not owned by this + // stream object. + HttpResponseInfo* response_; + + scoped_ptr<UploadDataStream> request_body_stream_; bool response_complete_; // TODO(mbelshe): fold this into the io_state. State io_state_; @@ -229,8 +204,6 @@ class SpdyStream : public base::RefCounted<SpdyStream> { int send_bytes_; int recv_bytes_; bool histograms_recorded_; - // Data received before delegate is attached. - std::vector<scoped_refptr<IOBufferWithSize> > pending_buffers_; DISALLOW_COPY_AND_ASSIGN(SpdyStream); }; |