Roll src/third_party/WebKit eac3800:0237a66 (svn 202606:202607)
[chromium-blink-merge.git] / net / quic / quic_http_stream.h
blobdf88bf8d5dc4c94be8279cda53b16ff013313291
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
3 // found in the LICENSE file.
5 #ifndef NET_QUIC_QUIC_HTTP_STREAM_H_
6 #define NET_QUIC_QUIC_HTTP_STREAM_H_
8 #include <stdint.h>
10 #include <list>
12 #include "base/memory/weak_ptr.h"
13 #include "net/base/io_buffer.h"
14 #include "net/http/http_stream.h"
15 #include "net/quic/quic_chromium_client_session.h"
16 #include "net/quic/quic_reliable_client_stream.h"
18 namespace net {
20 namespace test {
21 class QuicHttpStreamPeer;
22 } // namespace test
24 // The QuicHttpStream is a QUIC-specific HttpStream subclass. It holds a
25 // non-owning pointer to a QuicReliableClientStream which it uses to
26 // send and receive data.
27 class NET_EXPORT_PRIVATE QuicHttpStream
28 : public QuicChromiumClientSession::Observer,
29 public QuicReliableClientStream::Delegate,
30 public HttpStream {
31 public:
32 explicit QuicHttpStream(
33 const base::WeakPtr<QuicChromiumClientSession>& session);
35 ~QuicHttpStream() override;
37 // HttpStream implementation.
38 int InitializeStream(const HttpRequestInfo* request_info,
39 RequestPriority priority,
40 const BoundNetLog& net_log,
41 const CompletionCallback& callback) override;
42 int SendRequest(const HttpRequestHeaders& request_headers,
43 HttpResponseInfo* response,
44 const CompletionCallback& callback) override;
45 UploadProgress GetUploadProgress() const override;
46 int ReadResponseHeaders(const CompletionCallback& callback) override;
47 int ReadResponseBody(IOBuffer* buf,
48 int buf_len,
49 const CompletionCallback& callback) override;
50 void Close(bool not_reusable) override;
51 HttpStream* RenewStreamForAuth() override;
52 bool IsResponseBodyComplete() const override;
53 bool IsConnectionReused() const override;
54 void SetConnectionReused() override;
55 bool CanReuseConnection() const override;
56 int64 GetTotalReceivedBytes() const override;
57 int64_t GetTotalSentBytes() const override;
58 bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override;
59 void GetSSLInfo(SSLInfo* ssl_info) override;
60 void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override;
61 void Drain(HttpNetworkSession* session) override;
62 void SetPriority(RequestPriority priority) override;
64 // QuicReliableClientStream::Delegate implementation
65 void OnHeadersAvailable(const SpdyHeaderBlock& headers) override;
66 void OnDataAvailable() override;
67 void OnClose(QuicErrorCode error) override;
68 void OnError(int error) override;
69 bool HasSendHeadersComplete() override;
71 // QuicChromiumClientSession::Observer implementation
72 void OnCryptoHandshakeConfirmed() override;
73 void OnSessionClosed(int error) override;
75 private:
76 friend class test::QuicHttpStreamPeer;
78 enum State {
79 STATE_NONE,
80 STATE_SEND_HEADERS,
81 STATE_SEND_HEADERS_COMPLETE,
82 STATE_READ_REQUEST_BODY,
83 STATE_READ_REQUEST_BODY_COMPLETE,
84 STATE_SEND_BODY,
85 STATE_SEND_BODY_COMPLETE,
86 STATE_OPEN,
89 void OnStreamReady(int rv);
90 void OnIOComplete(int rv);
91 void DoCallback(int rv);
93 int DoLoop(int);
94 int DoSendHeaders();
95 int DoSendHeadersComplete(int rv);
96 int DoReadRequestBody();
97 int DoReadRequestBodyComplete(int rv);
98 int DoSendBody();
99 int DoSendBodyComplete(int rv);
100 int DoReadResponseHeaders();
101 int DoReadResponseHeadersComplete(int rv);
103 int ProcessResponseHeaders(const SpdyHeaderBlock& headers);
105 int ReadAvailableData(IOBuffer* buf, int buf_len);
107 SpdyMajorVersion GetSpdyVersion();
109 void ResetStream();
111 State next_state_;
113 base::WeakPtr<QuicChromiumClientSession> session_;
114 int session_error_; // Error code from the connection shutdown.
115 bool was_handshake_confirmed_; // True if the crypto handshake succeeded.
116 QuicChromiumClientSession::StreamRequest stream_request_;
117 QuicReliableClientStream* stream_; // Non-owning.
119 // The following three fields are all owned by the caller and must
120 // outlive this object, according to the HttpStream contract.
122 // The request to send.
123 const HttpRequestInfo* request_info_;
124 // The request body to send, if any, owned by the caller.
125 UploadDataStream* request_body_stream_;
126 // Time the request was issued.
127 base::Time request_time_;
128 // The priority of the request.
129 RequestPriority priority_;
130 // |response_info_| is the HTTP response data object which is filled in
131 // when a the response headers are read. It is not owned by this stream.
132 HttpResponseInfo* response_info_;
133 // Because response data is buffered, also buffer the response status if the
134 // stream is explicitly closed via OnError or OnClose with an error.
135 // Once all buffered data has been returned, this will be used as the final
136 // response.
137 int response_status_;
139 // Serialized request headers.
140 SpdyHeaderBlock request_headers_;
142 bool response_headers_received_;
144 // Serialized HTTP request.
145 std::string request_;
147 // Number of bytes received when the stream was closed.
148 int64 closed_stream_received_bytes_;
149 // Number of bytes sent when the stream was closed.
150 int64_t closed_stream_sent_bytes_;
152 // The caller's callback to be used for asynchronous operations.
153 CompletionCallback callback_;
155 // Caller provided buffer for the ReadResponseBody() response.
156 scoped_refptr<IOBuffer> user_buffer_;
157 int user_buffer_len_;
159 // Temporary buffer used to read the request body from UploadDataStream.
160 scoped_refptr<IOBufferWithSize> raw_request_body_buf_;
161 // Wraps raw_request_body_buf_ to read the remaining data progressively.
162 scoped_refptr<DrainableIOBuffer> request_body_buf_;
164 BoundNetLog stream_net_log_;
166 base::WeakPtrFactory<QuicHttpStream> weak_factory_;
168 DISALLOW_COPY_AND_ASSIGN(QuicHttpStream);
171 } // namespace net
173 #endif // NET_QUIC_QUIC_HTTP_STREAM_H_