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

Side by Side Diff: net/spdy/spdy_framer_decoder_adapter.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_framer.cc ('k') | net/spdy/spdy_framer_decoder_adapter.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) 2016 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_FRAMER_DECODER_ADAPTER_H_
6 #define NET_SPDY_SPDY_FRAMER_DECODER_ADAPTER_H_
7
8 #include <stddef.h>
9
10 #include <cstdint>
11 #include <memory>
12
13 #include "net/spdy/hpack/hpack_header_table.h"
14 #include "net/spdy/platform/api/spdy_string_piece.h"
15 #include "net/spdy/spdy_alt_svc_wire_format.h"
16 #include "net/spdy/spdy_framer.h"
17 #include "net/spdy/spdy_headers_handler_interface.h"
18 #include "net/spdy/spdy_protocol.h"
19
20 namespace net {
21
22 // Abstract base class for an HTTP/2 decoder to be called from SpdyFramer.
23 class SpdyFramerDecoderAdapter {
24 public:
25 SpdyFramerDecoderAdapter();
26 virtual ~SpdyFramerDecoderAdapter();
27
28 // Set callbacks to be called from the framer. A visitor must be set, or
29 // else the framer will likely crash. It is acceptable for the visitor
30 // to do nothing. If this is called multiple times, only the last visitor
31 // will be used.
32 virtual void set_visitor(SpdyFramerVisitorInterface* visitor);
33 SpdyFramerVisitorInterface* visitor() const { return visitor_; }
34
35 // Set extension callbacks to be called from the framer or decoder. Optional.
36 // If called multiple times, only the last visitor will be used.
37 virtual void set_extension_visitor(ExtensionVisitorInterface* visitor) = 0;
38
39 // Set debug callbacks to be called from the framer. The debug visitor is
40 // completely optional and need not be set in order for normal operation.
41 // If this is called multiple times, only the last visitor will be used.
42 virtual void set_debug_visitor(
43 SpdyFramerDebugVisitorInterface* debug_visitor);
44 SpdyFramerDebugVisitorInterface* debug_visitor() const {
45 return debug_visitor_;
46 }
47
48 // Set debug callbacks to be called from the HPACK decoder.
49 virtual void SetDecoderHeaderTableDebugVisitor(
50 std::unique_ptr<HpackHeaderTable::DebugVisitorInterface> visitor) = 0;
51
52 // Sets whether or not ProcessInput returns after finishing a frame, or
53 // continues processing additional frames. Normally ProcessInput processes
54 // all input, but this method enables the caller (and visitor) to work with
55 // a single frame at a time (or that portion of the frame which is provided
56 // as input). Reset() does not change the value of this flag.
57 virtual void set_process_single_input_frame(bool v);
58 bool process_single_input_frame() const {
59 return process_single_input_frame_;
60 }
61
62 // Decode the |len| bytes of encoded HTTP/2 starting at |*data|. Returns
63 // the number of bytes consumed. It is safe to pass more bytes in than
64 // may be consumed. Should process (or otherwise buffer) as much as
65 // available, unless process_single_input_frame is true.
66 virtual size_t ProcessInput(const char* data, size_t len) = 0;
67
68 // Reset the decoder (used just for tests at this time).
69 virtual void Reset() = 0;
70
71 // Current state of the decoder.
72 virtual SpdyFramer::SpdyState state() const = 0;
73
74 // Current error code (NO_ERROR if state != ERROR).
75 virtual SpdyFramer::SpdyFramerError spdy_framer_error() const = 0;
76
77 // Has any frame header looked like the start of an HTTP/1.1 (or earlier)
78 // response? Used to detect if a backend/server that we sent a request to
79 // has responded with an HTTP/1.1 (or earlier) response.
80 virtual bool probable_http_response() const = 0;
81
82 // Returns the estimate of dynamically allocated memory in bytes.
83 virtual size_t EstimateMemoryUsage() const = 0;
84
85 private:
86 SpdyFramerVisitorInterface* visitor_ = nullptr;
87 SpdyFramerDebugVisitorInterface* debug_visitor_ = nullptr;
88 bool process_single_input_frame_ = false;
89 };
90
91 // Create an instance of NestedSpdyFramerDecoder, which implements
92 // SpdyFramerDecoderAdapter, delegating to a SpdyFramer instance that will
93 // actually perform the decoding (when requested via ProcessInput). This allows
94 // us to test the SpdyFramerDecoderAdapter mechanism without changing the type
95 // of decoder that is used.
96 std::unique_ptr<SpdyFramerDecoderAdapter> CreateNestedSpdyFramerDecoder(
97 SpdyFramer* outer);
98
99 // SpdyFramerVisitorInterface::OnError needs the original SpdyFramer* to
100 // pass to the visitor (really a listener). This implementation takes care of
101 // that while passing along all other calls unmodified.
102 class SpdyFramerVisitorAdapter : public SpdyFramerVisitorInterface {
103 public:
104 SpdyFramerVisitorAdapter(SpdyFramerVisitorInterface* visitor,
105 SpdyFramer* framer)
106 : visitor_(visitor), framer_(framer) {}
107 ~SpdyFramerVisitorAdapter() override {}
108 // The visitor needs the original SpdyFramer, not the SpdyFramerDecoderAdapter
109 // instance.
110 void OnError(SpdyFramer* framer) override;
111 void OnCommonHeader(SpdyStreamId stream_id,
112 size_t length,
113 uint8_t type,
114 uint8_t flags) override;
115 void OnDataFrameHeader(SpdyStreamId stream_id,
116 size_t length,
117 bool fin) override;
118 void OnStreamFrameData(SpdyStreamId stream_id,
119 const char* data,
120 size_t len) override;
121 void OnStreamEnd(SpdyStreamId stream_id) override;
122 void OnStreamPadding(SpdyStreamId stream_id, size_t len) override;
123 SpdyHeadersHandlerInterface* OnHeaderFrameStart(
124 SpdyStreamId stream_id) override;
125 void OnHeaderFrameEnd(SpdyStreamId stream_id, bool end_headers) override;
126 void OnRstStream(SpdyStreamId stream_id, SpdyErrorCode error_code) override;
127 void OnSetting(SpdySettingsIds id, uint32_t value) override;
128 void OnPing(SpdyPingId unique_id, bool is_ack) override;
129 void OnSettings(bool clear_persisted) override;
130 void OnSettingsAck() override;
131 void OnSettingsEnd() override;
132 void OnGoAway(SpdyStreamId last_accepted_stream_id,
133 SpdyErrorCode error_code) override;
134 void OnHeaders(SpdyStreamId stream_id,
135 bool has_priority,
136 int weight,
137 SpdyStreamId parent_stream_id,
138 bool exclusive,
139 bool fin,
140 bool end) override;
141 void OnWindowUpdate(SpdyStreamId stream_id, int delta_window_size) override;
142 bool OnGoAwayFrameData(const char* goaway_data, size_t len) override;
143 void OnPushPromise(SpdyStreamId stream_id,
144 SpdyStreamId promised_stream_id,
145 bool end) override;
146 void OnContinuation(SpdyStreamId stream_id, bool end) override;
147 void OnPriority(SpdyStreamId stream_id,
148 SpdyStreamId parent_id,
149 int weight,
150 bool exclusive) override;
151 void OnAltSvc(SpdyStreamId stream_id,
152 SpdyStringPiece origin,
153 const SpdyAltSvcWireFormat::AlternativeServiceVector&
154 altsvc_vector) override;
155 bool OnUnknownFrame(SpdyStreamId stream_id, uint8_t frame_type) override;
156
157 protected:
158 SpdyFramerVisitorInterface* visitor() const { return visitor_; }
159 SpdyFramer* framer() const { return framer_; }
160
161 private:
162 SpdyFramerVisitorInterface* const visitor_;
163 SpdyFramer* const framer_;
164 };
165
166 } // namespace net
167
168 #endif // NET_SPDY_SPDY_FRAMER_DECODER_ADAPTER_H_
OLDNEW
« no previous file with comments | « net/spdy/spdy_framer.cc ('k') | net/spdy/spdy_framer_decoder_adapter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698