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

Side by Side Diff: net/spdy/spdy_deframer_visitor.cc

Issue 2801603003: Add SpdyString alias for std::string in net/spdy. (Closed)
Patch Set: 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_deframer_visitor.h ('k') | net/spdy/spdy_deframer_visitor_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/spdy/spdy_deframer_visitor.h" 5 #include "net/spdy/spdy_deframer_visitor.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <string.h>
9 8
10 #include <algorithm> 9 #include <algorithm>
11 #include <cstdint> 10 #include <cstdint>
12 #include <limits> 11 #include <limits>
13 12
14 #include "base/logging.h" 13 #include "base/logging.h"
15 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
16 #include "net/spdy/hpack/hpack_constants.h" 15 #include "net/spdy/hpack/hpack_constants.h"
17 #include "net/spdy/mock_spdy_framer_visitor.h" 16 #include "net/spdy/mock_spdy_framer_visitor.h"
18 #include "net/spdy/spdy_frame_builder.h" 17 #include "net/spdy/spdy_frame_builder.h"
19 #include "net/spdy/spdy_frame_reader.h" 18 #include "net/spdy/spdy_frame_reader.h"
20 #include "net/spdy/spdy_protocol.h" 19 #include "net/spdy/spdy_protocol.h"
21 #include "net/spdy/spdy_test_utils.h" 20 #include "net/spdy/spdy_test_utils.h"
22 21
23 using ::base::MakeUnique; 22 using ::base::MakeUnique;
24 using ::std::string;
25 using ::testing::AssertionFailure; 23 using ::testing::AssertionFailure;
26 using ::testing::AssertionResult; 24 using ::testing::AssertionResult;
27 using ::testing::AssertionSuccess; 25 using ::testing::AssertionSuccess;
28 26
29 namespace net { 27 namespace net {
30 namespace test { 28 namespace test {
31 29
32 // Specify whether to process headers as request or response in visitor-related 30 // Specify whether to process headers as request or response in visitor-related
33 // params. 31 // params.
34 enum class HeaderDirection { REQUEST, RESPONSE }; 32 enum class HeaderDirection { REQUEST, RESPONSE };
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 203
206 // Per-HPACK block state. Only valid while processing a HEADERS or 204 // Per-HPACK block state. Only valid while processing a HEADERS or
207 // PUSH_PROMISE frame, and its CONTINUATION frames. 205 // PUSH_PROMISE frame, and its CONTINUATION frames.
208 // Did the most recent HEADERS or PUSH_PROMISE include the END_STREAM flag? 206 // Did the most recent HEADERS or PUSH_PROMISE include the END_STREAM flag?
209 // Note that this does not necessarily indicate that the current frame is 207 // Note that this does not necessarily indicate that the current frame is
210 // the last frame for the stream (may be followed by CONTINUATION frames, 208 // the last frame for the stream (may be followed by CONTINUATION frames,
211 // may only half close). 209 // may only half close).
212 bool fin_ = false; 210 bool fin_ = false;
213 bool got_hpack_end_ = false; 211 bool got_hpack_end_ = false;
214 212
215 std::unique_ptr<string> data_; 213 std::unique_ptr<SpdyString> data_;
216 214
217 // Total length of the data frame. 215 // Total length of the data frame.
218 size_t data_len_ = 0; 216 size_t data_len_ = 0;
219 217
220 // Amount of skipped padding (i.e. total length of padding, including Pad 218 // Amount of skipped padding (i.e. total length of padding, including Pad
221 // Length field). 219 // Length field).
222 size_t padding_len_ = 0; 220 size_t padding_len_ = 0;
223 221
224 std::unique_ptr<string> goaway_description_; 222 std::unique_ptr<SpdyString> goaway_description_;
225 std::unique_ptr<StringPairVector> headers_; 223 std::unique_ptr<StringPairVector> headers_;
226 std::unique_ptr<SettingVector> settings_; 224 std::unique_ptr<SettingVector> settings_;
227 std::unique_ptr<TestHeadersHandler> headers_handler_; 225 std::unique_ptr<TestHeadersHandler> headers_handler_;
228 226
229 std::unique_ptr<SpdyGoAwayIR> goaway_ir_; 227 std::unique_ptr<SpdyGoAwayIR> goaway_ir_;
230 std::unique_ptr<SpdyHeadersIR> headers_ir_; 228 std::unique_ptr<SpdyHeadersIR> headers_ir_;
231 std::unique_ptr<SpdyPushPromiseIR> push_promise_ir_; 229 std::unique_ptr<SpdyPushPromiseIR> push_promise_ir_;
232 std::unique_ptr<SpdySettingsIR> settings_ir_; 230 std::unique_ptr<SpdySettingsIR> settings_ir_;
233 231
234 private: 232 private:
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 409
412 void SpdyTestDeframerImpl::OnAltSvc( 410 void SpdyTestDeframerImpl::OnAltSvc(
413 SpdyStreamId stream_id, 411 SpdyStreamId stream_id,
414 SpdyStringPiece origin, 412 SpdyStringPiece origin,
415 const SpdyAltSvcWireFormat::AlternativeServiceVector& altsvc_vector) { 413 const SpdyAltSvcWireFormat::AlternativeServiceVector& altsvc_vector) {
416 DVLOG(1) << "OnAltSvc stream_id: " << stream_id; 414 DVLOG(1) << "OnAltSvc stream_id: " << stream_id;
417 CHECK_EQ(frame_type_, UNSET) << " frame_type_=" 415 CHECK_EQ(frame_type_, UNSET) << " frame_type_="
418 << Http2FrameTypeToString(frame_type_); 416 << Http2FrameTypeToString(frame_type_);
419 CHECK_GT(stream_id, 0u); 417 CHECK_GT(stream_id, 0u);
420 auto ptr = MakeUnique<SpdyAltSvcIR>(stream_id); 418 auto ptr = MakeUnique<SpdyAltSvcIR>(stream_id);
421 ptr->set_origin(std::string(origin)); 419 ptr->set_origin(SpdyString(origin));
422 for (auto& altsvc : altsvc_vector) { 420 for (auto& altsvc : altsvc_vector) {
423 ptr->add_altsvc(altsvc); 421 ptr->add_altsvc(altsvc);
424 } 422 }
425 listener_->OnAltSvc(std::move(ptr)); 423 listener_->OnAltSvc(std::move(ptr));
426 } 424 }
427 425
428 // A CONTINUATION frame contains a Header Block Fragment, and immediately 426 // A CONTINUATION frame contains a Header Block Fragment, and immediately
429 // follows another frame that contains a Header Block Fragment (HEADERS, 427 // follows another frame that contains a Header Block Fragment (HEADERS,
430 // PUSH_PROMISE or CONTINUATION). The last such frame has the END flag set. 428 // PUSH_PROMISE or CONTINUATION). The last such frame has the END flag set.
431 // SpdyFramer ensures that the behavior is correct before calling the visitor. 429 // SpdyFramer ensures that the behavior is correct before calling the visitor.
(...skipping 18 matching lines...) Expand all
450 DVLOG(1) << "OnDataFrameHeader stream_id: " << stream_id; 448 DVLOG(1) << "OnDataFrameHeader stream_id: " << stream_id;
451 CHECK_EQ(frame_type_, UNSET) << " frame_type_=" 449 CHECK_EQ(frame_type_, UNSET) << " frame_type_="
452 << Http2FrameTypeToString(frame_type_); 450 << Http2FrameTypeToString(frame_type_);
453 CHECK_GT(stream_id, 0u); 451 CHECK_GT(stream_id, 0u);
454 CHECK_EQ(data_.get(), nullptr); 452 CHECK_EQ(data_.get(), nullptr);
455 frame_type_ = DATA; 453 frame_type_ = DATA;
456 454
457 stream_id_ = stream_id; 455 stream_id_ = stream_id;
458 fin_ = fin; 456 fin_ = fin;
459 data_len_ = length; 457 data_len_ = length;
460 data_.reset(new string()); 458 data_.reset(new SpdyString());
461 } 459 }
462 460
463 // The SpdyFramer will not process any more data at this point. 461 // The SpdyFramer will not process any more data at this point.
464 void SpdyTestDeframerImpl::OnError(SpdyFramer* framer) { 462 void SpdyTestDeframerImpl::OnError(SpdyFramer* framer) {
465 DVLOG(1) << "SpdyFramer detected an error in the stream: " 463 DVLOG(1) << "SpdyFramer detected an error in the stream: "
466 << SpdyFramer::SpdyFramerErrorToString(framer->spdy_framer_error()) 464 << SpdyFramer::SpdyFramerErrorToString(framer->spdy_framer_error())
467 << " frame_type_: " << Http2FrameTypeToString(frame_type_); 465 << " frame_type_: " << Http2FrameTypeToString(frame_type_);
468 listener_->OnError(framer, this); 466 listener_->OnError(framer, this);
469 } 467 }
470 468
471 // Received a GOAWAY frame from the peer. The last stream id it accepted from us 469 // Received a GOAWAY frame from the peer. The last stream id it accepted from us
472 // is |last_accepted_stream_id|. |status| is a protocol defined error code. 470 // is |last_accepted_stream_id|. |status| is a protocol defined error code.
473 // The frame may also contain data. After this OnGoAwayFrameData will be called 471 // The frame may also contain data. After this OnGoAwayFrameData will be called
474 // for any non-zero amount of data, and after that it will be called with len==0 472 // for any non-zero amount of data, and after that it will be called with len==0
475 // to indicate the end of the GOAWAY frame. 473 // to indicate the end of the GOAWAY frame.
476 void SpdyTestDeframerImpl::OnGoAway(SpdyStreamId last_good_stream_id, 474 void SpdyTestDeframerImpl::OnGoAway(SpdyStreamId last_good_stream_id,
477 SpdyErrorCode error_code) { 475 SpdyErrorCode error_code) {
478 DVLOG(1) << "OnGoAway last_good_stream_id: " << last_good_stream_id 476 DVLOG(1) << "OnGoAway last_good_stream_id: " << last_good_stream_id
479 << " error code: " << error_code; 477 << " error code: " << error_code;
480 CHECK_EQ(frame_type_, UNSET) << " frame_type_=" 478 CHECK_EQ(frame_type_, UNSET) << " frame_type_="
481 << Http2FrameTypeToString(frame_type_); 479 << Http2FrameTypeToString(frame_type_);
482 frame_type_ = GOAWAY; 480 frame_type_ = GOAWAY;
483 goaway_ir_ = MakeUnique<SpdyGoAwayIR>(last_good_stream_id, error_code, ""); 481 goaway_ir_ = MakeUnique<SpdyGoAwayIR>(last_good_stream_id, error_code, "");
484 goaway_description_.reset(new string()); 482 goaway_description_.reset(new SpdyString());
485 } 483 }
486 484
487 // If len==0 then we've reached the end of the GOAWAY frame. 485 // If len==0 then we've reached the end of the GOAWAY frame.
488 bool SpdyTestDeframerImpl::OnGoAwayFrameData(const char* goaway_data, 486 bool SpdyTestDeframerImpl::OnGoAwayFrameData(const char* goaway_data,
489 size_t len) { 487 size_t len) {
490 DVLOG(1) << "OnGoAwayFrameData"; 488 DVLOG(1) << "OnGoAwayFrameData";
491 CHECK_EQ(frame_type_, GOAWAY) << " frame_type_=" 489 CHECK_EQ(frame_type_, GOAWAY) << " frame_type_="
492 << Http2FrameTypeToString(frame_type_); 490 << Http2FrameTypeToString(frame_type_);
493 CHECK(goaway_description_); 491 CHECK(goaway_description_);
494 goaway_description_->append(goaway_data, len); 492 goaway_description_->append(goaway_data, len);
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 got_hpack_end_ = false; 735 got_hpack_end_ = false;
738 } 736 }
739 737
740 void SpdyTestDeframerImpl::OnHeader(SpdyStringPiece key, 738 void SpdyTestDeframerImpl::OnHeader(SpdyStringPiece key,
741 SpdyStringPiece value) { 739 SpdyStringPiece value) {
742 CHECK(frame_type_ == HEADERS || frame_type_ == CONTINUATION || 740 CHECK(frame_type_ == HEADERS || frame_type_ == CONTINUATION ||
743 frame_type_ == PUSH_PROMISE) 741 frame_type_ == PUSH_PROMISE)
744 << " frame_type_=" << Http2FrameTypeToString(frame_type_); 742 << " frame_type_=" << Http2FrameTypeToString(frame_type_);
745 CHECK(!got_hpack_end_); 743 CHECK(!got_hpack_end_);
746 CHECK(headers_); 744 CHECK(headers_);
747 headers_->emplace_back(std::string(key), std::string(value)); 745 headers_->emplace_back(SpdyString(key), SpdyString(value));
748 CHECK(headers_handler_); 746 CHECK(headers_handler_);
749 headers_handler_->OnHeader(key, value); 747 headers_handler_->OnHeader(key, value);
750 } 748 }
751 749
752 void SpdyTestDeframerImpl::OnHeaderBlockEnd(size_t header_bytes_parsed) { 750 void SpdyTestDeframerImpl::OnHeaderBlockEnd(size_t header_bytes_parsed) {
753 CHECK(headers_); 751 CHECK(headers_);
754 CHECK(frame_type_ == HEADERS || frame_type_ == CONTINUATION || 752 CHECK(frame_type_ == HEADERS || frame_type_ == CONTINUATION ||
755 frame_type_ == PUSH_PROMISE) 753 frame_type_ == PUSH_PROMISE)
756 << " frame_type_=" << Http2FrameTypeToString(frame_type_); 754 << " frame_type_=" << Http2FrameTypeToString(frame_type_);
757 CHECK(end_); 755 CHECK(end_);
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 // The SpdyFramer will not process any more data at this point. 1016 // The SpdyFramer will not process any more data at this point.
1019 void DeframerCallbackCollector::OnError(SpdyFramer* framer, 1017 void DeframerCallbackCollector::OnError(SpdyFramer* framer,
1020 SpdyTestDeframer* deframer) { 1018 SpdyTestDeframer* deframer) {
1021 CollectedFrame cf; 1019 CollectedFrame cf;
1022 cf.error_reported = true; 1020 cf.error_reported = true;
1023 collected_frames_->push_back(std::move(cf)); 1021 collected_frames_->push_back(std::move(cf));
1024 } 1022 }
1025 1023
1026 } // namespace test 1024 } // namespace test
1027 } // namespace net 1025 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_deframer_visitor.h ('k') | net/spdy/spdy_deframer_visitor_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698