Re-land: C++ readability review
[chromium-blink-merge.git] / net / spdy / spdy_http_stream.h
blob333454bb4196e8efaddccc920b02a85e960b13a4
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_SPDY_SPDY_HTTP_STREAM_H_
6 #define NET_SPDY_SPDY_HTTP_STREAM_H_
8 #include <list>
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.h"
13 #include "net/base/completion_callback.h"
14 #include "net/http/http_stream.h"
15 #include "net/log/net_log.h"
16 #include "net/spdy/spdy_read_queue.h"
17 #include "net/spdy/spdy_session.h"
18 #include "net/spdy/spdy_stream.h"
20 namespace net {
22 class DrainableIOBuffer;
23 struct HttpRequestInfo;
24 class HttpResponseInfo;
25 class IOBuffer;
26 class SpdySession;
27 class UploadDataStream;
29 // The SpdyHttpStream is a HTTP-specific type of stream known to a SpdySession.
30 class NET_EXPORT_PRIVATE SpdyHttpStream : public SpdyStream::Delegate,
31 public HttpStream {
32 public:
33 // |spdy_session| must not be NULL.
34 SpdyHttpStream(const base::WeakPtr<SpdySession>& spdy_session, bool direct);
35 ~SpdyHttpStream() override;
37 SpdyStream* stream() { return stream_.get(); }
39 // Cancels any callbacks from being invoked and deletes the stream.
40 void Cancel();
42 // HttpStream implementation.
44 int InitializeStream(const HttpRequestInfo* request_info,
45 RequestPriority priority,
46 const BoundNetLog& net_log,
47 const CompletionCallback& callback) override;
49 int SendRequest(const HttpRequestHeaders& headers,
50 HttpResponseInfo* response,
51 const CompletionCallback& callback) override;
52 UploadProgress GetUploadProgress() const override;
53 int ReadResponseHeaders(const CompletionCallback& callback) override;
54 int ReadResponseBody(IOBuffer* buf,
55 int buf_len,
56 const CompletionCallback& callback) override;
57 void Close(bool not_reusable) override;
58 HttpStream* RenewStreamForAuth() override;
59 bool IsResponseBodyComplete() const override;
60 bool CanFindEndOfResponse() const override;
62 // Must not be called if a NULL SpdySession was pssed into the
63 // constructor.
64 bool IsConnectionReused() const override;
66 void SetConnectionReused() override;
67 bool IsConnectionReusable() const override;
68 int64 GetTotalReceivedBytes() const override;
69 bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override;
70 void GetSSLInfo(SSLInfo* ssl_info) override;
71 void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override;
72 bool IsSpdyHttpStream() const override;
73 void Drain(HttpNetworkSession* session) override;
74 void SetPriority(RequestPriority priority) override;
76 // SpdyStream::Delegate implementation.
77 void OnRequestHeadersSent() override;
78 SpdyResponseHeadersStatus OnResponseHeadersUpdated(
79 const SpdyHeaderBlock& response_headers) override;
80 void OnDataReceived(scoped_ptr<SpdyBuffer> buffer) override;
81 void OnDataSent() override;
82 void OnClose(int status) override;
84 private:
85 // Must be called only when |request_info_| is non-NULL.
86 bool HasUploadData() const;
88 void OnStreamCreated(const CompletionCallback& callback, int rv);
90 // Reads the remaining data (whether chunked or not) from the
91 // request body stream and sends it if there's any. The read and
92 // subsequent sending may happen asynchronously. Must be called only
93 // when HasUploadData() is true.
94 void ReadAndSendRequestBodyData();
96 // Called when data has just been read from the request body stream;
97 // does the actual sending of data.
98 void OnRequestBodyReadCompleted(int status);
100 // Call the user callback.
101 void DoCallback(int rv);
103 void ScheduleBufferedReadCallback();
105 // Returns true if the callback is invoked.
106 bool DoBufferedReadCallback();
107 bool ShouldWaitForMoreBufferedData() const;
109 const base::WeakPtr<SpdySession> spdy_session_;
110 bool is_reused_;
111 SpdyStreamRequest stream_request_;
112 base::WeakPtr<SpdyStream> stream_;
114 bool stream_closed_;
116 // Set only when |stream_closed_| is true.
117 int closed_stream_status_;
118 SpdyStreamId closed_stream_id_;
119 bool closed_stream_has_load_timing_info_;
120 LoadTimingInfo closed_stream_load_timing_info_;
121 int64 closed_stream_received_bytes_;
123 // The request to send.
124 const HttpRequestInfo* request_info_;
126 // |response_info_| is the HTTP response data object which is filled in
127 // when a SYN_REPLY comes in for the stream.
128 // It is not owned by this stream object, or point to |push_response_info_|.
129 HttpResponseInfo* response_info_;
131 scoped_ptr<HttpResponseInfo> push_response_info_;
133 // We don't use SpdyStream's |response_header_status_| as we
134 // sometimes call back into our delegate before it is updated.
135 SpdyResponseHeadersStatus response_headers_status_;
137 // We buffer the response body as it arrives asynchronously from the stream.
138 SpdyReadQueue response_body_queue_;
140 CompletionCallback callback_;
142 // User provided buffer for the ReadResponseBody() response.
143 scoped_refptr<IOBuffer> user_buffer_;
144 int user_buffer_len_;
146 // Temporary buffer used to read the request body from UploadDataStream.
147 scoped_refptr<IOBufferWithSize> request_body_buf_;
148 int request_body_buf_size_;
150 // Is there a scheduled read callback pending.
151 bool buffered_read_callback_pending_;
152 // Has more data been received from the network during the wait for the
153 // scheduled read callback.
154 bool more_read_data_pending_;
156 // Is this spdy stream direct to the origin server (or to a proxy).
157 bool direct_;
159 base::WeakPtrFactory<SpdyHttpStream> weak_factory_;
161 DISALLOW_COPY_AND_ASSIGN(SpdyHttpStream);
164 } // namespace net
166 #endif // NET_SPDY_SPDY_HTTP_STREAM_H_