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_
12 #include "build/build_config.h"
14 // TODO(rtenneti): Temporary while investigating crbug.com/468529.
15 // Note base::Debug::StackTrace() is not supported in NACL
16 // builds so conditionally disabled it there.
18 #define TEMP_INSTRUMENTATION_468529
21 #ifdef TEMP_INSTRUMENTATION_468529
22 #include "base/debug/stack_trace.h"
24 #include "base/memory/weak_ptr.h"
25 #include "net/base/io_buffer.h"
26 #include "net/http/http_stream.h"
27 #include "net/quic/quic_chromium_client_session.h"
28 #include "net/quic/quic_reliable_client_stream.h"
33 class QuicHttpStreamPeer
;
36 // The QuicHttpStream is a QUIC-specific HttpStream subclass. It holds a
37 // non-owning pointer to a QuicReliableClientStream which it uses to
38 // send and receive data.
39 class NET_EXPORT_PRIVATE QuicHttpStream
40 : public QuicChromiumClientSession::Observer
,
41 public QuicReliableClientStream::Delegate
,
44 explicit QuicHttpStream(
45 const base::WeakPtr
<QuicChromiumClientSession
>& session
);
47 ~QuicHttpStream() override
;
49 // HttpStream implementation.
50 int InitializeStream(const HttpRequestInfo
* request_info
,
51 RequestPriority priority
,
52 const BoundNetLog
& net_log
,
53 const CompletionCallback
& callback
) override
;
54 int SendRequest(const HttpRequestHeaders
& request_headers
,
55 HttpResponseInfo
* response
,
56 const CompletionCallback
& callback
) override
;
57 UploadProgress
GetUploadProgress() const override
;
58 int ReadResponseHeaders(const CompletionCallback
& callback
) override
;
59 int ReadResponseBody(IOBuffer
* buf
,
61 const CompletionCallback
& callback
) override
;
62 void Close(bool not_reusable
) override
;
63 HttpStream
* RenewStreamForAuth() override
;
64 bool IsResponseBodyComplete() const override
;
65 bool IsConnectionReused() const override
;
66 void SetConnectionReused() override
;
67 bool CanReuseConnection() const override
;
68 int64
GetTotalReceivedBytes() const override
;
69 int64_t GetTotalSentBytes() const override
;
70 bool GetLoadTimingInfo(LoadTimingInfo
* load_timing_info
) const override
;
71 void GetSSLInfo(SSLInfo
* ssl_info
) override
;
72 void GetSSLCertRequestInfo(SSLCertRequestInfo
* cert_request_info
) override
;
73 void Drain(HttpNetworkSession
* session
) override
;
74 void SetPriority(RequestPriority priority
) override
;
76 // QuicReliableClientStream::Delegate implementation
77 void OnHeadersAvailable(const SpdyHeaderBlock
& headers
) override
;
78 void OnDataAvailable() override
;
79 void OnClose(QuicErrorCode error
) override
;
80 void OnError(int error
) override
;
81 bool HasSendHeadersComplete() override
;
83 // QuicChromiumClientSession::Observer implementation
84 void OnCryptoHandshakeConfirmed() override
;
85 void OnSessionClosed(int error
) override
;
88 friend class test::QuicHttpStreamPeer
;
90 #ifdef TEMP_INSTRUMENTATION_468529
91 // TODO(rtenneti): Temporary while investigating crbug.com/468529
101 STATE_SEND_HEADERS_COMPLETE
,
102 STATE_READ_REQUEST_BODY
,
103 STATE_READ_REQUEST_BODY_COMPLETE
,
105 STATE_SEND_BODY_COMPLETE
,
109 void OnStreamReady(int rv
);
110 void OnIOComplete(int rv
);
111 void DoCallback(int rv
);
115 int DoSendHeadersComplete(int rv
);
116 int DoReadRequestBody();
117 int DoReadRequestBodyComplete(int rv
);
119 int DoSendBodyComplete(int rv
);
120 int DoReadResponseHeaders();
121 int DoReadResponseHeadersComplete(int rv
);
123 int ProcessResponseHeaders(const SpdyHeaderBlock
& headers
);
125 int ReadAvailableData(IOBuffer
* buf
, int buf_len
);
127 SpdyMajorVersion
GetSpdyVersion();
131 // TODO(rtenneti): Temporary while investigating crbug.com/468529
132 void CrashIfInvalid() const;
136 base::WeakPtr
<QuicChromiumClientSession
> session_
;
137 int session_error_
; // Error code from the connection shutdown.
138 bool was_handshake_confirmed_
; // True if the crypto handshake succeeded.
139 QuicChromiumClientSession::StreamRequest stream_request_
;
140 QuicReliableClientStream
* stream_
; // Non-owning.
142 // The following three fields are all owned by the caller and must
143 // outlive this object, according to the HttpStream contract.
145 // The request to send.
146 const HttpRequestInfo
* request_info_
;
147 // The request body to send, if any, owned by the caller.
148 UploadDataStream
* request_body_stream_
;
149 // Time the request was issued.
150 base::Time request_time_
;
151 // The priority of the request.
152 RequestPriority priority_
;
153 // |response_info_| is the HTTP response data object which is filled in
154 // when a the response headers are read. It is not owned by this stream.
155 HttpResponseInfo
* response_info_
;
156 // Because response data is buffered, also buffer the response status if the
157 // stream is explicitly closed via OnError or OnClose with an error.
158 // Once all buffered data has been returned, this will be used as the final
160 int response_status_
;
162 // Serialized request headers.
163 SpdyHeaderBlock request_headers_
;
165 bool response_headers_received_
;
167 // Serialized HTTP request.
168 std::string request_
;
170 // Number of bytes received when the stream was closed.
171 int64 closed_stream_received_bytes_
;
172 // Number of bytes sent when the stream was closed.
173 int64_t closed_stream_sent_bytes_
;
175 // The caller's callback to be used for asynchronous operations.
176 CompletionCallback callback_
;
178 // Caller provided buffer for the ReadResponseBody() response.
179 scoped_refptr
<IOBuffer
> user_buffer_
;
180 int user_buffer_len_
;
182 // Temporary buffer used to read the request body from UploadDataStream.
183 scoped_refptr
<IOBufferWithSize
> raw_request_body_buf_
;
184 // Wraps raw_request_body_buf_ to read the remaining data progressively.
185 scoped_refptr
<DrainableIOBuffer
> request_body_buf_
;
187 BoundNetLog stream_net_log_
;
189 #ifdef TEMP_INSTRUMENTATION_468529
190 // TODO(rtenneti): Temporary while investigating crbug.com/468529
191 Liveness liveness_
= ALIVE
;
192 base::debug::StackTrace stack_trace_
;
195 base::WeakPtrFactory
<QuicHttpStream
> weak_factory_
;
197 DISALLOW_COPY_AND_ASSIGN(QuicHttpStream
);
202 #endif // NET_QUIC_QUIC_HTTP_STREAM_H_