Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: net/spdy/spdy_http_stream.h

Issue 2832973003: Split net/spdy into core and chromium subdirectories. (Closed)
Patch Set: Fix some more build rules. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/spdy/spdy_headers_handler_interface.h ('k') | net/spdy/spdy_http_stream.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #ifndef NET_SPDY_SPDY_HTTP_STREAM_H_
6 #define NET_SPDY_SPDY_HTTP_STREAM_H_
7
8 #include <stdint.h>
9
10 #include <list>
11
12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h"
15 #include "net/base/completion_callback.h"
16 #include "net/base/net_export.h"
17 #include "net/log/net_log_source.h"
18 #include "net/spdy/multiplexed_http_stream.h"
19 #include "net/spdy/spdy_read_queue.h"
20 #include "net/spdy/spdy_session.h"
21 #include "net/spdy/spdy_stream.h"
22
23 namespace net {
24
25 struct HttpRequestInfo;
26 class HttpResponseInfo;
27 class IOBuffer;
28 class SpdySession;
29 class UploadDataStream;
30
31 // The SpdyHttpStream is a HTTP-specific type of stream known to a SpdySession.
32 class NET_EXPORT_PRIVATE SpdyHttpStream : public SpdyStream::Delegate,
33 public MultiplexedHttpStream {
34 public:
35 static const size_t kRequestBodyBufferSize;
36 // |spdy_session| must not be NULL.
37 SpdyHttpStream(const base::WeakPtr<SpdySession>& spdy_session,
38 bool direct,
39 NetLogSource source_dependency);
40 ~SpdyHttpStream() override;
41
42 SpdyStream* stream() { return stream_; }
43
44 // Cancels any callbacks from being invoked and deletes the stream.
45 void Cancel();
46
47 // HttpStream implementation.
48
49 int InitializeStream(const HttpRequestInfo* request_info,
50 RequestPriority priority,
51 const NetLogWithSource& net_log,
52 const CompletionCallback& callback) override;
53
54 int SendRequest(const HttpRequestHeaders& headers,
55 HttpResponseInfo* response,
56 const CompletionCallback& callback) override;
57 int ReadResponseHeaders(const CompletionCallback& callback) override;
58 int ReadResponseBody(IOBuffer* buf,
59 int buf_len,
60 const CompletionCallback& callback) override;
61 void Close(bool not_reusable) override;
62 bool IsResponseBodyComplete() const override;
63
64 // Must not be called if a NULL SpdySession was pssed into the
65 // constructor.
66 bool IsConnectionReused() const override;
67
68 // Total number of bytes received over the network of SPDY data, headers, and
69 // push_promise frames associated with this stream, including the size of
70 // frame headers, after SSL decryption and not including proxy overhead.
71 int64_t GetTotalReceivedBytes() const override;
72 // Total number of bytes sent over the network of SPDY frames associated with
73 // this stream, including the size of frame headers, before SSL encryption and
74 // not including proxy overhead. Note that some SPDY frames such as pings are
75 // not associated with any stream, and are not included in this value.
76 int64_t GetTotalSentBytes() const override;
77 bool GetAlternativeService(
78 AlternativeService* alternative_service) const override;
79 bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override;
80 bool GetRemoteEndpoint(IPEndPoint* endpoint) override;
81 void PopulateNetErrorDetails(NetErrorDetails* details) override;
82 void SetPriority(RequestPriority priority) override;
83
84 // SpdyStream::Delegate implementation.
85 void OnHeadersSent() override;
86 void OnHeadersReceived(const SpdyHeaderBlock& response_headers) override;
87 void OnDataReceived(std::unique_ptr<SpdyBuffer> buffer) override;
88 void OnDataSent() override;
89 void OnTrailers(const SpdyHeaderBlock& trailers) override;
90 void OnClose(int status) override;
91 NetLogSource source_dependency() const override;
92
93 private:
94 // Helper function used to initialize private members and to set delegate on
95 // stream when stream is created.
96 void InitializeStreamHelper();
97
98 // Helper function used for resetting stream from inside the stream.
99 void ResetStreamInternal();
100
101 // Must be called only when |request_info_| is non-NULL.
102 bool HasUploadData() const;
103
104 void OnStreamCreated(const CompletionCallback& callback, int rv);
105
106 // Reads the remaining data (whether chunked or not) from the
107 // request body stream and sends it if there's any. The read and
108 // subsequent sending may happen asynchronously. Must be called only
109 // when HasUploadData() is true.
110 void ReadAndSendRequestBodyData();
111
112 // Called when data has just been read from the request body stream;
113 // does the actual sending of data.
114 void OnRequestBodyReadCompleted(int status);
115
116 // Call the user callback associated with sending the request.
117 void DoRequestCallback(int rv);
118
119 // Method to PostTask for calling request callback asynchronously.
120 void MaybeDoRequestCallback(int rv);
121
122 // Post the request callback if not null.
123 // This is necessary because the request callback might destroy |stream_|,
124 // which does not support that.
125 void MaybePostRequestCallback(int rv);
126
127 // Call the user callback associated with reading the response.
128 void DoResponseCallback(int rv);
129
130 void ScheduleBufferedReadCallback();
131 void DoBufferedReadCallback();
132 bool ShouldWaitForMoreBufferedData() const;
133
134 const base::WeakPtr<SpdySession> spdy_session_;
135 bool is_reused_;
136 SpdyStreamRequest stream_request_;
137 const NetLogSource source_dependency_;
138
139 // |stream_| is owned by SpdySession.
140 // Before InitializeStream() is called, stream_ == nullptr.
141 // After InitializeStream() is called but before OnClose() is called,
142 // |*stream_| is guaranteed to be valid.
143 // After OnClose() is called, stream_ == nullptr.
144 SpdyStream* stream_;
145
146 // False before OnClose() is called, true after.
147 bool stream_closed_;
148
149 // Set only when |stream_closed_| is true.
150 int closed_stream_status_;
151 SpdyStreamId closed_stream_id_;
152 bool closed_stream_has_load_timing_info_;
153 LoadTimingInfo closed_stream_load_timing_info_;
154 // After |stream_| has been closed, this keeps track of the total number of
155 // bytes received over the network for |stream_| while it was open.
156 int64_t closed_stream_received_bytes_;
157 // After |stream_| has been closed, this keeps track of the total number of
158 // bytes sent over the network for |stream_| while it was open.
159 int64_t closed_stream_sent_bytes_;
160
161 // The request to send.
162 // Set to null when response body is starting to be read. This is to allow
163 // the stream to be shared for reading and to possibly outlive request_info_'s
164 // owner.
165 const HttpRequestInfo* request_info_;
166
167 // |response_info_| is the HTTP response data object which is filled in
168 // when a response HEADERS comes in for the stream.
169 // It is not owned by this stream object, or point to |push_response_info_|.
170 HttpResponseInfo* response_info_;
171
172 std::unique_ptr<HttpResponseInfo> push_response_info_;
173
174 bool response_headers_complete_;
175
176 // We buffer the response body as it arrives asynchronously from the stream.
177 SpdyReadQueue response_body_queue_;
178
179 CompletionCallback request_callback_;
180 CompletionCallback response_callback_;
181
182 // User provided buffer for the ReadResponseBody() response.
183 scoped_refptr<IOBuffer> user_buffer_;
184 int user_buffer_len_;
185
186 // Temporary buffer used to read the request body from UploadDataStream.
187 scoped_refptr<IOBufferWithSize> request_body_buf_;
188 int request_body_buf_size_;
189
190 // Is there a scheduled read callback pending.
191 bool buffered_read_callback_pending_;
192 // Has more data been received from the network during the wait for the
193 // scheduled read callback.
194 bool more_read_data_pending_;
195
196 // Is this spdy stream direct to the origin server (or to a proxy).
197 bool direct_;
198
199 bool was_alpn_negotiated_;
200
201 base::WeakPtrFactory<SpdyHttpStream> weak_factory_;
202
203 DISALLOW_COPY_AND_ASSIGN(SpdyHttpStream);
204 };
205
206 } // namespace net
207
208 #endif // NET_SPDY_SPDY_HTTP_STREAM_H_
OLDNEW
« no previous file with comments | « net/spdy/spdy_headers_handler_interface.h ('k') | net/spdy/spdy_http_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698