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

Side by Side Diff: net/spdy/buffered_spdy_framer.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/bidirectional_stream_spdy_impl_unittest.cc ('k') | net/spdy/buffered_spdy_framer.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_BUFFERED_SPDY_FRAMER_H_
6 #define NET_SPDY_BUFFERED_SPDY_FRAMER_H_
7
8 #include <stddef.h>
9 #include <stdint.h>
10
11 #include <memory>
12
13 #include "base/macros.h"
14 #include "net/base/net_export.h"
15 #include "net/spdy/header_coalescer.h"
16 #include "net/spdy/platform/api/spdy_string.h"
17 #include "net/spdy/platform/api/spdy_string_piece.h"
18 #include "net/spdy/spdy_alt_svc_wire_format.h"
19 #include "net/spdy/spdy_framer.h"
20 #include "net/spdy/spdy_header_block.h"
21 #include "net/spdy/spdy_protocol.h"
22
23 namespace net {
24
25 class NET_EXPORT_PRIVATE BufferedSpdyFramerVisitorInterface {
26 public:
27 BufferedSpdyFramerVisitorInterface() {}
28
29 // Called if an error is detected in the SpdySerializedFrame protocol.
30 virtual void OnError(SpdyFramer::SpdyFramerError spdy_framer_error) = 0;
31
32 // Called if an error is detected in a HTTP2 stream.
33 virtual void OnStreamError(SpdyStreamId stream_id,
34 const SpdyString& description) = 0;
35
36 // Called after all the header data for HEADERS control frame is received.
37 virtual void OnHeaders(SpdyStreamId stream_id,
38 bool has_priority,
39 int weight,
40 SpdyStreamId parent_stream_id,
41 bool exclusive,
42 bool fin,
43 SpdyHeaderBlock headers) = 0;
44
45 // Called when a data frame header is received.
46 virtual void OnDataFrameHeader(SpdyStreamId stream_id,
47 size_t length,
48 bool fin) = 0;
49
50 // Called when data is received.
51 // |stream_id| The stream receiving data.
52 // |data| A buffer containing the data received.
53 // |len| The length of the data buffer (at most 2^16 - 1 - 8).
54 virtual void OnStreamFrameData(SpdyStreamId stream_id,
55 const char* data,
56 size_t len) = 0;
57
58 // Called when the other side has finished sending data on this stream.
59 // |stream_id| The stream that was receivin data.
60 virtual void OnStreamEnd(SpdyStreamId stream_id) = 0;
61
62 // Called when padding is received (padding length field or padding octets).
63 // |stream_id| The stream receiving data.
64 // |len| The number of padding octets.
65 virtual void OnStreamPadding(SpdyStreamId stream_id, size_t len) = 0;
66
67 // Called when a SETTINGS frame is received.
68 virtual void OnSettings() = 0;
69
70 // Called when an individual setting within a SETTINGS frame has been parsed
71 // and validated.
72 virtual void OnSetting(SpdySettingsIds id, uint32_t value) = 0;
73
74 // Called when a SETTINGS frame is received with the ACK flag set.
75 virtual void OnSettingsAck() {}
76
77 // Called at the completion of parsing SETTINGS id and value tuples.
78 virtual void OnSettingsEnd() {}
79
80 // Called when a PING frame has been parsed.
81 virtual void OnPing(SpdyPingId unique_id, bool is_ack) = 0;
82
83 // Called when a RST_STREAM frame has been parsed.
84 virtual void OnRstStream(SpdyStreamId stream_id,
85 SpdyErrorCode error_code) = 0;
86
87 // Called when a GOAWAY frame has been parsed.
88 virtual void OnGoAway(SpdyStreamId last_accepted_stream_id,
89 SpdyErrorCode error_code,
90 SpdyStringPiece debug_data) = 0;
91
92 // Called when a WINDOW_UPDATE frame has been parsed.
93 virtual void OnWindowUpdate(SpdyStreamId stream_id,
94 int delta_window_size) = 0;
95
96 // Called when a PUSH_PROMISE frame has been parsed.
97 virtual void OnPushPromise(SpdyStreamId stream_id,
98 SpdyStreamId promised_stream_id,
99 SpdyHeaderBlock headers) = 0;
100
101 // Called when an ALTSVC frame has been parsed.
102 virtual void OnAltSvc(
103 SpdyStreamId stream_id,
104 SpdyStringPiece origin,
105 const SpdyAltSvcWireFormat::AlternativeServiceVector& altsvc_vector) = 0;
106
107 // Called when a frame type we don't recognize is received.
108 // Return true if this appears to be a valid extension frame, false otherwise.
109 // We distinguish between extension frames and nonsense by checking
110 // whether the stream id is valid.
111 virtual bool OnUnknownFrame(SpdyStreamId stream_id, uint8_t frame_type) = 0;
112
113 protected:
114 virtual ~BufferedSpdyFramerVisitorInterface() {}
115
116 private:
117 DISALLOW_COPY_AND_ASSIGN(BufferedSpdyFramerVisitorInterface);
118 };
119
120 class NET_EXPORT_PRIVATE BufferedSpdyFramer
121 : public SpdyFramerVisitorInterface {
122 public:
123 BufferedSpdyFramer();
124 ~BufferedSpdyFramer() override;
125
126 // Sets callbacks to be called from the buffered spdy framer. A visitor must
127 // be set, or else the framer will likely crash. It is acceptable for the
128 // visitor to do nothing. If this is called multiple times, only the last
129 // visitor will be used.
130 void set_visitor(BufferedSpdyFramerVisitorInterface* visitor);
131
132 // Set debug callbacks to be called from the framer. The debug visitor is
133 // completely optional and need not be set in order for normal operation.
134 // If this is called multiple times, only the last visitor will be used.
135 void set_debug_visitor(SpdyFramerDebugVisitorInterface* debug_visitor);
136
137 // SpdyFramerVisitorInterface
138 void OnError(SpdyFramer* spdy_framer) override;
139 void OnHeaders(SpdyStreamId stream_id,
140 bool has_priority,
141 int weight,
142 SpdyStreamId parent_stream_id,
143 bool exclusive,
144 bool fin,
145 bool end) override;
146 void OnStreamFrameData(SpdyStreamId stream_id,
147 const char* data,
148 size_t len) override;
149 void OnStreamEnd(SpdyStreamId stream_id) override;
150 void OnStreamPadding(SpdyStreamId stream_id, size_t len) override;
151 SpdyHeadersHandlerInterface* OnHeaderFrameStart(
152 SpdyStreamId stream_id) override;
153 void OnHeaderFrameEnd(SpdyStreamId stream_id, bool end_headers) override;
154 void OnSettings(bool clear_persisted) override;
155 void OnSetting(SpdySettingsIds id, uint32_t value) override;
156 void OnSettingsAck() override;
157 void OnSettingsEnd() override;
158 void OnPing(SpdyPingId unique_id, bool is_ack) override;
159 void OnRstStream(SpdyStreamId stream_id, SpdyErrorCode error_code) override;
160 void OnGoAway(SpdyStreamId last_accepted_stream_id,
161 SpdyErrorCode error_code) override;
162 bool OnGoAwayFrameData(const char* goaway_data, size_t len) override;
163 void OnWindowUpdate(SpdyStreamId stream_id, int delta_window_size) override;
164 void OnPushPromise(SpdyStreamId stream_id,
165 SpdyStreamId promised_stream_id,
166 bool end) override;
167 void OnAltSvc(SpdyStreamId stream_id,
168 SpdyStringPiece origin,
169 const SpdyAltSvcWireFormat::AlternativeServiceVector&
170 altsvc_vector) override;
171 void OnDataFrameHeader(SpdyStreamId stream_id,
172 size_t length,
173 bool fin) override;
174 void OnContinuation(SpdyStreamId stream_id, bool end) override;
175 bool OnUnknownFrame(SpdyStreamId stream_id, uint8_t frame_type) override;
176
177 // SpdyFramer methods.
178 size_t ProcessInput(const char* data, size_t len);
179 void UpdateHeaderDecoderTableSize(uint32_t value);
180 void Reset();
181 SpdyFramer::SpdyFramerError spdy_framer_error() const;
182 SpdyFramer::SpdyState state() const;
183 bool MessageFullyRead();
184 bool HasError();
185 std::unique_ptr<SpdySerializedFrame> CreateRstStream(
186 SpdyStreamId stream_id,
187 SpdyErrorCode error_code) const;
188 std::unique_ptr<SpdySerializedFrame> CreateSettings(
189 const SettingsMap& values) const;
190 std::unique_ptr<SpdySerializedFrame> CreatePingFrame(SpdyPingId unique_id,
191 bool is_ack) const;
192 std::unique_ptr<SpdySerializedFrame> CreateWindowUpdate(
193 SpdyStreamId stream_id,
194 uint32_t delta_window_size) const;
195 std::unique_ptr<SpdySerializedFrame> CreateDataFrame(SpdyStreamId stream_id,
196 const char* data,
197 uint32_t len,
198 SpdyDataFlags flags);
199 std::unique_ptr<SpdySerializedFrame> CreatePriority(
200 SpdyStreamId stream_id,
201 SpdyStreamId dependency_id,
202 int weight,
203 bool exclusive) const;
204
205 // Serialize a frame of unknown type.
206 SpdySerializedFrame SerializeFrame(const SpdyFrameIR& frame) {
207 return spdy_framer_.SerializeFrame(frame);
208 }
209
210 SpdyPriority GetHighestPriority() const;
211
212 size_t GetDataFrameMinimumSize() const {
213 return spdy_framer_.GetDataFrameMinimumSize();
214 }
215
216 size_t GetFrameHeaderSize() const {
217 return spdy_framer_.GetFrameHeaderSize();
218 }
219
220 size_t GetFrameMinimumSize() const {
221 return spdy_framer_.GetFrameMinimumSize();
222 }
223
224 size_t GetFrameMaximumSize() const {
225 return spdy_framer_.GetFrameMaximumSize();
226 }
227
228 size_t GetDataFrameMaximumPayload() const {
229 return spdy_framer_.GetDataFrameMaximumPayload();
230 }
231
232 int frames_received() const { return frames_received_; }
233
234 // Returns the estimate of dynamically allocated memory in bytes.
235 size_t EstimateMemoryUsage() const;
236
237 private:
238 SpdyFramer spdy_framer_;
239 BufferedSpdyFramerVisitorInterface* visitor_;
240
241 int frames_received_;
242
243 // Collection of fields from control frames that we need to
244 // buffer up from the spdy framer.
245 struct ControlFrameFields {
246 SpdyFrameType type;
247 SpdyStreamId stream_id;
248 SpdyStreamId associated_stream_id;
249 SpdyStreamId promised_stream_id;
250 bool has_priority;
251 SpdyPriority priority;
252 int weight;
253 SpdyStreamId parent_stream_id;
254 bool exclusive;
255 bool fin;
256 bool unidirectional;
257 };
258 std::unique_ptr<ControlFrameFields> control_frame_fields_;
259
260 // Collection of fields of a GOAWAY frame that this class needs to buffer.
261 struct GoAwayFields {
262 SpdyStreamId last_accepted_stream_id;
263 SpdyErrorCode error_code;
264 SpdyString debug_data;
265
266 // Returns the estimate of dynamically allocated memory in bytes.
267 size_t EstimateMemoryUsage() const;
268 };
269 std::unique_ptr<GoAwayFields> goaway_fields_;
270
271 std::unique_ptr<HeaderCoalescer> coalescer_;
272
273 DISALLOW_COPY_AND_ASSIGN(BufferedSpdyFramer);
274 };
275
276 } // namespace net
277
278 #endif // NET_SPDY_BUFFERED_SPDY_FRAMER_H_
OLDNEW
« no previous file with comments | « net/spdy/bidirectional_stream_spdy_impl_unittest.cc ('k') | net/spdy/buffered_spdy_framer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698