Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_HTTP_STREAM_H_ | 5 #ifndef NET_SPDY_SPDY_HTTP_STREAM_H_ |
| 6 #define NET_SPDY_SPDY_HTTP_STREAM_H_ | 6 #define NET_SPDY_SPDY_HTTP_STREAM_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <list> | 9 #include <list> |
| 10 #include <string> | |
| 10 | 11 |
| 11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 12 #include "base/ref_counted.h" | 13 #include "base/ref_counted.h" |
| 13 #include "base/task.h" | 14 #include "base/task.h" |
| 14 #include "net/base/completion_callback.h" | 15 #include "net/base/completion_callback.h" |
| 15 #include "net/base/net_log.h" | 16 #include "net/base/net_log.h" |
| 16 #include "net/http/http_request_info.h" | 17 #include "net/http/http_request_info.h" |
| 18 #include "net/http/http_stream.h" | |
| 17 #include "net/spdy/spdy_protocol.h" | 19 #include "net/spdy/spdy_protocol.h" |
| 18 #include "net/spdy/spdy_stream.h" | 20 #include "net/spdy/spdy_stream.h" |
| 19 | 21 |
| 20 namespace net { | 22 namespace net { |
| 21 | 23 |
| 22 class HttpResponseInfo; | 24 class HttpResponseInfo; |
| 23 class IOBuffer; | 25 class IOBuffer; |
| 24 class SpdySession; | 26 class SpdySession; |
| 25 class UploadData; | 27 class UploadData; |
| 26 class UploadDataStream; | 28 class UploadDataStream; |
| 27 | 29 |
| 28 // The SpdyHttpStream is a HTTP-specific type of stream known to a SpdySession. | 30 // The SpdyHttpStream is a HTTP-specific type of stream known to a SpdySession. |
| 29 class SpdyHttpStream : public SpdyStream::Delegate { | 31 class SpdyHttpStream : public SpdyStream::Delegate, public HttpStream { |
| 30 public: | 32 public: |
| 31 // SpdyHttpStream constructor | 33 // SpdyHttpStream constructor |
| 32 SpdyHttpStream(); | 34 explicit SpdyHttpStream(SpdySession* spdy_session); |
| 33 virtual ~SpdyHttpStream(); | 35 virtual ~SpdyHttpStream(); |
| 34 | 36 |
| 35 SpdyStream* stream() { return stream_.get(); } | 37 SpdyStream* stream() { return stream_.get(); } |
| 36 | 38 |
| 37 // Initialize stream. Must be called before calling InitializeRequest(). | 39 // =================================================== |
| 38 int InitializeStream(SpdySession* spdy_session, | 40 // HttpStream methods: |
| 39 const HttpRequestInfo& request_info, | |
| 40 const BoundNetLog& stream_net_log, | |
| 41 CompletionCallback* callback); | |
| 42 | 41 |
| 43 // Initialize request. Must be called before calling SendRequest(). | 42 // Initialize stream. Must be called before calling SendRequest(). |
| 44 // SpdyHttpStream takes ownership of |upload_data|. |upload_data| may be NULL. | 43 virtual int InitializeStream(const HttpRequestInfo* request_info, |
| 45 void InitializeRequest(base::Time request_time, | 44 const BoundNetLog& net_log, |
| 46 UploadDataStream* upload_data); | 45 CompletionCallback* callback); |
| 47 | |
| 48 const HttpResponseInfo* GetResponseInfo() const; | |
| 49 | |
| 50 // =================================================== | |
| 51 // Interface for [Http|Spdy]NetworkTransaction to use. | |
| 52 | 46 |
| 53 // Sends the request. | 47 // Sends the request. |
| 54 // |callback| is used when this completes asynchronously. | 48 // |callback| is used when this completes asynchronously. |
| 49 // SpdyHttpStream takes ownership of |upload_data|. |upload_data| may be NULL. | |
| 55 // The actual SYN_STREAM packet will be sent if the stream is non-pushed. | 50 // The actual SYN_STREAM packet will be sent if the stream is non-pushed. |
| 56 int SendRequest(HttpResponseInfo* response, | 51 virtual int SendRequest(const std::string& headers, |
|
vandebo (ex-Chrome)
2010/07/28 23:30:39
Here.
| |
| 57 CompletionCallback* callback); | 52 UploadDataStream* request_body, |
| 53 HttpResponseInfo* response, | |
| 54 CompletionCallback* callback); | |
| 55 | |
| 56 // Returns the number of bytes uploaded. | |
| 57 virtual uint64 GetUploadProgress() const; | |
| 58 | 58 |
| 59 // Reads the response headers. Returns a net error code. | 59 // Reads the response headers. Returns a net error code. |
| 60 int ReadResponseHeaders(CompletionCallback* callback); | 60 virtual int ReadResponseHeaders(CompletionCallback* callback); |
| 61 | |
| 62 virtual const HttpResponseInfo* GetResponseInfo() const; | |
| 61 | 63 |
| 62 // Reads the response body. Returns a net error code or the number of bytes | 64 // Reads the response body. Returns a net error code or the number of bytes |
| 63 // read. | 65 // read. |
| 64 int ReadResponseBody( | 66 virtual int ReadResponseBody( |
| 65 IOBuffer* buf, int buf_len, CompletionCallback* callback); | 67 IOBuffer* buf, int buf_len, CompletionCallback* callback); |
| 66 | 68 |
| 69 // Indicates if the response body has been completely read. | |
| 70 virtual bool IsResponseBodyComplete() const { | |
| 71 return stream_->response_complete(); | |
| 72 } | |
| 73 | |
| 74 // With SPDY the end of response is always detectable. | |
| 75 virtual bool CanFindEndOfResponse() const { return true; } | |
| 76 | |
| 77 // A SPDY stream never has more data after the FIN. | |
| 78 virtual bool IsMoreDataBuffered() const { return false; } | |
| 79 | |
| 80 // =================================================== | |
| 81 // SpdyStream::Delegate. | |
| 82 | |
| 67 // Cancels any callbacks from being invoked and deletes the stream. | 83 // Cancels any callbacks from being invoked and deletes the stream. |
| 68 void Cancel(); | 84 void Cancel(); |
| 69 | 85 |
| 70 // Returns the number of bytes uploaded. | |
| 71 uint64 GetUploadProgress() const; | |
| 72 | |
| 73 // =================================================== | |
| 74 // SpdyStream::Delegate. | |
| 75 | |
| 76 virtual bool OnSendHeadersComplete(int status); | 86 virtual bool OnSendHeadersComplete(int status); |
| 77 virtual int OnSendBody(); | 87 virtual int OnSendBody(); |
| 78 virtual bool OnSendBodyComplete(int status); | 88 virtual bool OnSendBodyComplete(int status); |
| 79 | 89 |
| 80 // Called by the SpdySession when a response (e.g. a SYN_REPLY) has been | 90 // Called by the SpdySession when a response (e.g. a SYN_REPLY) has been |
| 81 // received for this stream. | 91 // received for this stream. |
| 82 // SpdyHttpSession calls back |callback| set by SendRequest or | 92 // SpdyHttpSession calls back |callback| set by SendRequest or |
| 83 // ReadResponseHeaders. | 93 // ReadResponseHeaders. |
| 84 virtual int OnResponseReceived(const spdy::SpdyHeaderBlock& response, | 94 virtual int OnResponseReceived(const spdy::SpdyHeaderBlock& response, |
| 85 base::Time response_time, | 95 base::Time response_time, |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 111 | 121 |
| 112 // Returns true if the callback is invoked. | 122 // Returns true if the callback is invoked. |
| 113 bool DoBufferedReadCallback(); | 123 bool DoBufferedReadCallback(); |
| 114 bool ShouldWaitForMoreBufferedData() const; | 124 bool ShouldWaitForMoreBufferedData() const; |
| 115 | 125 |
| 116 ScopedRunnableMethodFactory<SpdyHttpStream> read_callback_factory_; | 126 ScopedRunnableMethodFactory<SpdyHttpStream> read_callback_factory_; |
| 117 scoped_refptr<SpdyStream> stream_; | 127 scoped_refptr<SpdyStream> stream_; |
| 118 scoped_refptr<SpdySession> spdy_session_; | 128 scoped_refptr<SpdySession> spdy_session_; |
| 119 | 129 |
| 120 // The request to send. | 130 // The request to send. |
| 121 HttpRequestInfo request_info_; | 131 const HttpRequestInfo* request_info_; |
| 122 | 132 |
| 123 scoped_ptr<UploadDataStream> request_body_stream_; | 133 scoped_ptr<UploadDataStream> request_body_stream_; |
| 124 | 134 |
| 125 // |response_info_| is the HTTP response data object which is filled in | 135 // |response_info_| is the HTTP response data object which is filled in |
| 126 // when a SYN_REPLY comes in for the stream. | 136 // when a SYN_REPLY comes in for the stream. |
| 127 // It is not owned by this stream object, or point to |push_response_info_|. | 137 // It is not owned by this stream object, or point to |push_response_info_|. |
| 128 HttpResponseInfo* response_info_; | 138 HttpResponseInfo* response_info_; |
| 129 | 139 |
| 130 scoped_ptr<HttpResponseInfo> push_response_info_; | 140 scoped_ptr<HttpResponseInfo> push_response_info_; |
| 131 | 141 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 146 // Has more data been received from the network during the wait for the | 156 // Has more data been received from the network during the wait for the |
| 147 // scheduled read callback. | 157 // scheduled read callback. |
| 148 bool more_read_data_pending_; | 158 bool more_read_data_pending_; |
| 149 | 159 |
| 150 DISALLOW_COPY_AND_ASSIGN(SpdyHttpStream); | 160 DISALLOW_COPY_AND_ASSIGN(SpdyHttpStream); |
| 151 }; | 161 }; |
| 152 | 162 |
| 153 } // namespace net | 163 } // namespace net |
| 154 | 164 |
| 155 #endif // NET_SPDY_SPDY_HTTP_STREAM_H_ | 165 #endif // NET_SPDY_SPDY_HTTP_STREAM_H_ |
| OLD | NEW |