Update broken references to image assets
[chromium-blink-merge.git] / net / quic / quic_http_stream.h
bloba47e11a7f85caab741ec0eeac7867203a0170fed
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 <list>
10 #include "build/build_config.h"
12 // TODO(rtenneti): Temporary while investigating crbug.com/468529.
13 // Note base::Debug::StackTrace() is not supported in NACL
14 // builds so conditionally disabled it there.
15 #ifndef OS_NACL
16 #define TEMP_INSTRUMENTATION_468529
17 #endif
19 #ifdef TEMP_INSTRUMENTATION_468529
20 #include "base/debug/stack_trace.h"
21 #endif
22 #include "base/memory/weak_ptr.h"
23 #include "net/base/io_buffer.h"
24 #include "net/http/http_stream.h"
25 #include "net/quic/quic_chromium_client_session.h"
26 #include "net/quic/quic_reliable_client_stream.h"
28 namespace net {
30 namespace test {
31 class QuicHttpStreamPeer;
32 } // namespace test
34 // The QuicHttpStream is a QUIC-specific HttpStream subclass. It holds a
35 // non-owning pointer to a QuicReliableClientStream which it uses to
36 // send and receive data.
37 class NET_EXPORT_PRIVATE QuicHttpStream
38 : public QuicChromiumClientSession::Observer,
39 public QuicReliableClientStream::Delegate,
40 public HttpStream {
41 public:
42 explicit QuicHttpStream(
43 const base::WeakPtr<QuicChromiumClientSession>& session);
45 ~QuicHttpStream() override;
47 // HttpStream implementation.
48 int InitializeStream(const HttpRequestInfo* request_info,
49 RequestPriority priority,
50 const BoundNetLog& net_log,
51 const CompletionCallback& callback) override;
52 int SendRequest(const HttpRequestHeaders& request_headers,
53 HttpResponseInfo* response,
54 const CompletionCallback& callback) override;
55 UploadProgress GetUploadProgress() const override;
56 int ReadResponseHeaders(const CompletionCallback& callback) override;
57 int ReadResponseBody(IOBuffer* buf,
58 int buf_len,
59 const CompletionCallback& callback) override;
60 void Close(bool not_reusable) override;
61 HttpStream* RenewStreamForAuth() override;
62 bool IsResponseBodyComplete() const override;
63 bool CanFindEndOfResponse() const override;
64 bool IsConnectionReused() const override;
65 void SetConnectionReused() override;
66 bool IsConnectionReusable() const override;
67 int64 GetTotalReceivedBytes() const override;
68 bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override;
69 void GetSSLInfo(SSLInfo* ssl_info) override;
70 void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override;
71 bool IsSpdyHttpStream() const override;
72 void Drain(HttpNetworkSession* session) override;
73 void SetPriority(RequestPriority priority) override;
75 // QuicReliableClientStream::Delegate implementation
76 void OnHeadersAvailable(const SpdyHeaderBlock& headers) override;
77 void OnDataAvailable() override;
78 void OnClose(QuicErrorCode error) override;
79 void OnError(int error) override;
80 bool HasSendHeadersComplete() override;
82 // QuicChromiumClientSession::Observer implementation
83 void OnCryptoHandshakeConfirmed() override;
84 void OnSessionClosed(int error) override;
86 private:
87 friend class test::QuicHttpStreamPeer;
89 #ifdef TEMP_INSTRUMENTATION_468529
90 // TODO(rtenneti): Temporary while investigating crbug.com/468529
91 enum Liveness {
92 ALIVE = 0xCA11AB13,
93 DEAD = 0xDEADBEEF,
95 #endif
97 enum State {
98 STATE_NONE,
99 STATE_SEND_HEADERS,
100 STATE_SEND_HEADERS_COMPLETE,
101 STATE_READ_REQUEST_BODY,
102 STATE_READ_REQUEST_BODY_COMPLETE,
103 STATE_SEND_BODY,
104 STATE_SEND_BODY_COMPLETE,
105 STATE_OPEN,
108 void OnStreamReady(int rv);
109 void OnIOComplete(int rv);
110 void DoCallback(int rv);
112 int DoLoop(int);
113 int DoSendHeaders();
114 int DoSendHeadersComplete(int rv);
115 int DoReadRequestBody();
116 int DoReadRequestBodyComplete(int rv);
117 int DoSendBody();
118 int DoSendBodyComplete(int rv);
119 int DoReadResponseHeaders();
120 int DoReadResponseHeadersComplete(int rv);
122 int ProcessResponseHeaders(const SpdyHeaderBlock& headers);
124 int ReadAvailableData(IOBuffer* buf, int buf_len);
126 SpdyMajorVersion GetSpdyVersion();
128 // TODO(rtenneti): Temporary while investigating crbug.com/468529
129 void CrashIfInvalid() const;
131 State next_state_;
133 base::WeakPtr<QuicChromiumClientSession> session_;
134 int session_error_; // Error code from the connection shutdown.
135 bool was_handshake_confirmed_; // True if the crypto handshake succeeded.
136 QuicChromiumClientSession::StreamRequest stream_request_;
137 QuicReliableClientStream* stream_; // Non-owning.
139 // The following three fields are all owned by the caller and must
140 // outlive this object, according to the HttpStream contract.
142 // The request to send.
143 const HttpRequestInfo* request_info_;
144 // The request body to send, if any, owned by the caller.
145 UploadDataStream* request_body_stream_;
146 // Time the request was issued.
147 base::Time request_time_;
148 // The priority of the request.
149 RequestPriority priority_;
150 // |response_info_| is the HTTP response data object which is filled in
151 // when a the response headers are read. It is not owned by this stream.
152 HttpResponseInfo* response_info_;
153 // Because response data is buffered, also buffer the response status if the
154 // stream is explicitly closed via OnError or OnClose with an error.
155 // Once all buffered data has been returned, this will be used as the final
156 // response.
157 int response_status_;
159 // Serialized request headers.
160 SpdyHeaderBlock request_headers_;
162 bool response_headers_received_;
164 // Serialized HTTP request.
165 std::string request_;
167 // Number of bytes received when the stream was closed.
168 int64 closed_stream_received_bytes_;
170 // The caller's callback to be used for asynchronous operations.
171 CompletionCallback callback_;
173 // Caller provided buffer for the ReadResponseBody() response.
174 scoped_refptr<IOBuffer> user_buffer_;
175 int user_buffer_len_;
177 // Temporary buffer used to read the request body from UploadDataStream.
178 scoped_refptr<IOBufferWithSize> raw_request_body_buf_;
179 // Wraps raw_request_body_buf_ to read the remaining data progressively.
180 scoped_refptr<DrainableIOBuffer> request_body_buf_;
182 BoundNetLog stream_net_log_;
184 #ifdef TEMP_INSTRUMENTATION_468529
185 // TODO(rtenneti): Temporary while investigating crbug.com/468529
186 Liveness liveness_ = ALIVE;
187 base::debug::StackTrace stack_trace_;
188 #endif
190 base::WeakPtrFactory<QuicHttpStream> weak_factory_;
192 DISALLOW_COPY_AND_ASSIGN(QuicHttpStream);
195 } // namespace net
197 #endif // NET_QUIC_QUIC_HTTP_STREAM_H_