Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / net / quic / test_tools / simple_quic_framer.cc
blob7784695d0353929cba4685e22771787feff9a1e2
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 #include "net/quic/test_tools/simple_quic_framer.h"
7 #include "base/stl_util.h"
8 #include "net/quic/crypto/quic_decrypter.h"
9 #include "net/quic/crypto/quic_encrypter.h"
11 using base::StringPiece;
12 using std::string;
13 using std::vector;
15 namespace net {
16 namespace test {
18 class SimpleFramerVisitor : public QuicFramerVisitorInterface {
19 public:
20 SimpleFramerVisitor()
21 : error_(QUIC_NO_ERROR) {
24 ~SimpleFramerVisitor() override { STLDeleteElements(&stream_data_); }
26 void OnError(QuicFramer* framer) override { error_ = framer->error(); }
28 bool OnProtocolVersionMismatch(QuicVersion version) override { return false; }
30 void OnPacket() override {}
31 void OnPublicResetPacket(const QuicPublicResetPacket& packet) override {
32 public_reset_packet_.reset(new QuicPublicResetPacket(packet));
34 void OnVersionNegotiationPacket(
35 const QuicVersionNegotiationPacket& packet) override {
36 version_negotiation_packet_.reset(
37 new QuicVersionNegotiationPacket(packet));
39 void OnRevivedPacket() override {}
41 bool OnUnauthenticatedPublicHeader(
42 const QuicPacketPublicHeader& header) override {
43 return true;
45 bool OnUnauthenticatedHeader(const QuicPacketHeader& header) override {
46 return true;
48 void OnDecryptedPacket(EncryptionLevel level) override {}
49 bool OnPacketHeader(const QuicPacketHeader& header) override {
50 has_header_ = true;
51 header_ = header;
52 return true;
55 void OnFecProtectedPayload(StringPiece payload) override {}
57 bool OnStreamFrame(const QuicStreamFrame& frame) override {
58 // Save a copy of the data so it is valid after the packet is processed.
59 string* string_data = new string();
60 frame.data.AppendToString(string_data);
61 stream_data_.push_back(string_data);
62 QuicStreamFrame stream_frame(frame);
63 // Make sure that the stream frame points to this data.
64 stream_frame.data = StringPiece(*string_data);
65 stream_frames_.push_back(stream_frame);
66 return true;
69 bool OnAckFrame(const QuicAckFrame& frame) override {
70 ack_frames_.push_back(frame);
71 return true;
74 bool OnStopWaitingFrame(const QuicStopWaitingFrame& frame) override {
75 stop_waiting_frames_.push_back(frame);
76 return true;
79 bool OnPingFrame(const QuicPingFrame& frame) override {
80 ping_frames_.push_back(frame);
81 return true;
84 void OnFecData(const QuicFecData& fec) override {
85 fec_data_ = fec;
86 fec_redundancy_ = fec_data_.redundancy.as_string();
87 fec_data_.redundancy = fec_redundancy_;
90 bool OnRstStreamFrame(const QuicRstStreamFrame& frame) override {
91 rst_stream_frames_.push_back(frame);
92 return true;
95 bool OnConnectionCloseFrame(const QuicConnectionCloseFrame& frame) override {
96 connection_close_frames_.push_back(frame);
97 return true;
100 bool OnGoAwayFrame(const QuicGoAwayFrame& frame) override {
101 goaway_frames_.push_back(frame);
102 return true;
105 bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override {
106 window_update_frames_.push_back(frame);
107 return true;
110 bool OnBlockedFrame(const QuicBlockedFrame& frame) override {
111 blocked_frames_.push_back(frame);
112 return true;
115 void OnPacketComplete() override {}
117 const QuicPacketHeader& header() const { return header_; }
118 const vector<QuicAckFrame>& ack_frames() const { return ack_frames_; }
119 const vector<QuicConnectionCloseFrame>& connection_close_frames() const {
120 return connection_close_frames_;
122 const vector<QuicGoAwayFrame>& goaway_frames() const {
123 return goaway_frames_;
125 const vector<QuicRstStreamFrame>& rst_stream_frames() const {
126 return rst_stream_frames_;
128 const vector<QuicStreamFrame>& stream_frames() const {
129 return stream_frames_;
131 const vector<QuicStopWaitingFrame>& stop_waiting_frames() const {
132 return stop_waiting_frames_;
134 const vector<QuicPingFrame>& ping_frames() const {
135 return ping_frames_;
137 const QuicFecData& fec_data() const {
138 return fec_data_;
140 const QuicVersionNegotiationPacket* version_negotiation_packet() const {
141 return version_negotiation_packet_.get();
144 private:
145 QuicErrorCode error_;
146 bool has_header_;
147 QuicPacketHeader header_;
148 QuicFecData fec_data_;
149 scoped_ptr<QuicVersionNegotiationPacket> version_negotiation_packet_;
150 scoped_ptr<QuicPublicResetPacket> public_reset_packet_;
151 string fec_redundancy_;
152 vector<QuicAckFrame> ack_frames_;
153 vector<QuicStopWaitingFrame> stop_waiting_frames_;
154 vector<QuicPingFrame> ping_frames_;
155 vector<QuicStreamFrame> stream_frames_;
156 vector<QuicRstStreamFrame> rst_stream_frames_;
157 vector<QuicGoAwayFrame> goaway_frames_;
158 vector<QuicConnectionCloseFrame> connection_close_frames_;
159 vector<QuicWindowUpdateFrame> window_update_frames_;
160 vector<QuicBlockedFrame> blocked_frames_;
161 vector<string*> stream_data_;
163 DISALLOW_COPY_AND_ASSIGN(SimpleFramerVisitor);
166 SimpleQuicFramer::SimpleQuicFramer()
167 : framer_(QuicSupportedVersions(),
168 QuicTime::Zero(),
169 Perspective::IS_SERVER) {
172 SimpleQuicFramer::SimpleQuicFramer(const QuicVersionVector& supported_versions)
173 : framer_(supported_versions, QuicTime::Zero(), Perspective::IS_SERVER) {
176 SimpleQuicFramer::~SimpleQuicFramer() {
179 bool SimpleQuicFramer::ProcessPacket(const QuicEncryptedPacket& packet) {
180 visitor_.reset(new SimpleFramerVisitor);
181 framer_.set_visitor(visitor_.get());
182 return framer_.ProcessPacket(packet);
185 void SimpleQuicFramer::Reset() {
186 visitor_.reset(new SimpleFramerVisitor);
190 const QuicPacketHeader& SimpleQuicFramer::header() const {
191 return visitor_->header();
194 const QuicFecData& SimpleQuicFramer::fec_data() const {
195 return visitor_->fec_data();
198 const QuicVersionNegotiationPacket*
199 SimpleQuicFramer::version_negotiation_packet() const {
200 return visitor_->version_negotiation_packet();
203 QuicFramer* SimpleQuicFramer::framer() {
204 return &framer_;
207 size_t SimpleQuicFramer::num_frames() const {
208 return ack_frames().size() +
209 goaway_frames().size() +
210 rst_stream_frames().size() +
211 stop_waiting_frames().size() +
212 stream_frames().size() +
213 ping_frames().size() +
214 connection_close_frames().size();
217 const vector<QuicAckFrame>& SimpleQuicFramer::ack_frames() const {
218 return visitor_->ack_frames();
221 const vector<QuicStopWaitingFrame>&
222 SimpleQuicFramer::stop_waiting_frames() const {
223 return visitor_->stop_waiting_frames();
226 const vector<QuicPingFrame>& SimpleQuicFramer::ping_frames() const {
227 return visitor_->ping_frames();
230 const vector<QuicStreamFrame>& SimpleQuicFramer::stream_frames() const {
231 return visitor_->stream_frames();
234 const vector<QuicRstStreamFrame>& SimpleQuicFramer::rst_stream_frames() const {
235 return visitor_->rst_stream_frames();
238 const vector<QuicGoAwayFrame>&
239 SimpleQuicFramer::goaway_frames() const {
240 return visitor_->goaway_frames();
243 const vector<QuicConnectionCloseFrame>&
244 SimpleQuicFramer::connection_close_frames() const {
245 return visitor_->connection_close_frames();
248 } // namespace test
249 } // namespace net