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