diff options
author | ukai@chromium.org <ukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-18 07:16:26 +0000 |
---|---|---|
committer | ukai@chromium.org <ukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-18 07:16:26 +0000 |
commit | f3b61f9de846be52ecd105039c4d548e3053234c (patch) | |
tree | d2033c37b675f77c1e883bc075d1e82d5e6084b8 /net/spdy/spdy_stream.h | |
parent | 89a3da9808c7f1b0b5481ce1d6b1c45cdcc01040 (diff) | |
download | chromium_src-f3b61f9de846be52ecd105039c4d548e3053234c.zip chromium_src-f3b61f9de846be52ecd105039c4d548e3053234c.tar.gz chromium_src-f3b61f9de846be52ecd105039c4d548e3053234c.tar.bz2 |
Refactor SpdyStream to get HTTP specific out of the interface and members.
Add SpdyStream::Delegate interface and SpdyHttpStream implements SpdyStream::Delegate.
SpdyHeaderBlock<->HTTP request/response conversion functions moved
from spdy_session.cc to spdy_http_stream.cc.
All interface between SpdySession and SpdyStream uses SpdyHeaderBlock
instead of HttpRequestInfo,HttpResponseInfo.
BUG=42320
TEST=none
Review URL: http://codereview.chromium.org/2667002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50215 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/spdy/spdy_stream.h')
-rw-r--r-- | net/spdy/spdy_stream.h | 137 |
1 files changed, 82 insertions, 55 deletions
diff --git a/net/spdy/spdy_stream.h b/net/spdy/spdy_stream.h index 1792cf1..919bca8 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/http/http_request_info.h" +#include "net/spdy/spdy_framer.h" #include "net/spdy/spdy_protocol.h" namespace net { -class HttpResponseInfo; class SpdySession; -class UploadDataStream; +class SSLInfo; // The SpdyStream is used by the SpdySession to represent each stream known -// on the SpdySession. This class provides interfaces for SpdySession to use -// and base implementations for the interfaces. +// on the SpdySession. This class provides interfaces for SpdySession to use. // 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,9 +32,58 @@ class UploadDataStream; // 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_; } @@ -51,9 +100,8 @@ 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 HttpResponseInfo* GetResponseInfo() const; - const HttpRequestInfo* GetRequestInfo() const; - void SetRequestInfo(const HttpRequestInfo& request); + const linked_ptr<spdy::SpdyHeaderBlock>& spdy_headers() const; + void set_spdy_headers(const linked_ptr<spdy::SpdyHeaderBlock>& headers); base::Time GetRequestTime() const; void SetRequestTime(base::Time t); @@ -61,7 +109,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. - virtual int OnResponseReceived(const HttpResponseInfo& response) = 0; + int OnResponseReceived(const spdy::SpdyHeaderBlock& response); // Called by the SpdySession when response data has been received for this // stream. This callback may be called multiple times as data arrives @@ -70,61 +118,43 @@ 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. - // Returns true on success and false on error. - virtual bool OnDataReceived(const char* buffer, int bytes) = 0; + void OnDataReceived(const char* buffer, int bytes); // 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. - virtual void OnWriteComplete(int status) = 0; + void OnWriteComplete(int status); // 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. - virtual void OnClose(int status) = 0; + void OnClose(int status); - virtual void Cancel() = 0; + void Cancel(); bool cancelled() const { return cancelled_; } - 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); + // Interface for Spdy[Http|WebSocket]Stream to use. - 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); + // Sends the request. + // For non push stream, it will send SYN_STREAM frame. + int DoSendRequest(bool has_upload_data); // Reads response headers. If the SpdyStream have already received // the response headers, return OK and response headers filled in - // |response_info| given in SendRequest. - // Otherwise, return ERR_IO_PENDING. + // |response| given in SendRequest. + // Otherwise, return ERR_IO_PENDING and OnResponseReceived() will be called. int DoReadResponseHeaders(); - const UploadDataStream* request_body_stream() const { - return request_body_stream_.get(); - } + // Sends DATA frame. + int WriteStreamData(IOBuffer* data, int length); + + bool GetSSLInfo(SSLInfo* ssl_info, bool* was_npn_negotiated); 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: @@ -141,6 +171,9 @@ 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); @@ -166,26 +199,18 @@ class SpdyStream : public base::RefCounted<SpdyStream> { scoped_refptr<SpdySession> session_; + // The transaction should own the delegate. + SpdyStream::Delegate* delegate_; + // The request to send. - HttpRequestInfo request_; + linked_ptr<spdy::SpdyHeaderBlock> 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_; - // 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_; + linked_ptr<spdy::SpdyHeaderBlock> response_; + base::Time response_time_; bool response_complete_; // TODO(mbelshe): fold this into the io_state. State io_state_; @@ -204,6 +229,8 @@ 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); }; |