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

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

Issue 138273017: Added new callbacks to SpdyHeadersHandlerInterface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase onto upstream change. Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « net/spdy/spdy_headers_block_parser.h ('k') | net/spdy/spdy_headers_block_parser_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 (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2014 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_headers_block_parser.h" 5 #include "net/spdy/spdy_headers_block_parser.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/sys_byteorder.h" 9 #include "base/sys_byteorder.h"
10 10
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 std::vector<char> SpdyHeadersBlockParserReader::Remainder() { 58 std::vector<char> SpdyHeadersBlockParserReader::Remainder() {
59 std::vector<char> remainder(Available(), '\0'); 59 std::vector<char> remainder(Available(), '\0');
60 if (remainder.size()) { 60 if (remainder.size()) {
61 ReadN(remainder.size(), &remainder[0]); 61 ReadN(remainder.size(), &remainder[0]);
62 } 62 }
63 DCHECK_EQ(0u, Available()); 63 DCHECK_EQ(0u, Available());
64 return remainder; 64 return remainder;
65 } 65 }
66 66
67 SpdyHeadersBlockParser::SpdyHeadersBlockParser(KeyValueHandler* handler) : 67 SpdyHeadersBlockParser::SpdyHeadersBlockParser(
68 state_(READING_HEADER_BLOCK_LEN), 68 SpdyHeadersHandlerInterface* handler) : state_(READING_HEADER_BLOCK_LEN),
69 remaining_key_value_pairs_for_frame_(0), 69 remaining_key_value_pairs_for_frame_(0), next_field_len_(0),
70 next_field_len_(0),
71 handler_(handler) { 70 handler_(handler) {
72 } 71 }
73 72
74 SpdyHeadersBlockParser::~SpdyHeadersBlockParser() {} 73 SpdyHeadersBlockParser::~SpdyHeadersBlockParser() {}
75 74
76 bool SpdyHeadersBlockParser::ParseUInt32(Reader* reader, 75 bool SpdyHeadersBlockParser::ParseUInt32(Reader* reader,
77 uint32_t* parsed_value) { 76 uint32_t* parsed_value) {
78 // Are there enough bytes available? 77 // Are there enough bytes available?
79 if (reader->Available() < sizeof(uint32_t)) { 78 if (reader->Available() < sizeof(uint32_t)) {
80 return false; 79 return false;
(...skipping 24 matching lines...) Expand all
105 base::StringPiece prefix; 104 base::StringPiece prefix;
106 if (headers_block_prefix_.size()) { 105 if (headers_block_prefix_.size()) {
107 prefix.set(&headers_block_prefix_[0], headers_block_prefix_.size()); 106 prefix.set(&headers_block_prefix_[0], headers_block_prefix_.size());
108 } 107 }
109 Reader reader(prefix, base::StringPiece(headers_data, len)); 108 Reader reader(prefix, base::StringPiece(headers_data, len));
110 109
111 // If we didn't parse out yet the number of key-value pairs in this 110 // If we didn't parse out yet the number of key-value pairs in this
112 // headers block, try to do it now (succeeds if we received enough bytes). 111 // headers block, try to do it now (succeeds if we received enough bytes).
113 if (state_ == READING_HEADER_BLOCK_LEN) { 112 if (state_ == READING_HEADER_BLOCK_LEN) {
114 if (ParseUInt32(&reader, &remaining_key_value_pairs_for_frame_)) { 113 if (ParseUInt32(&reader, &remaining_key_value_pairs_for_frame_)) {
114 handler_->OnHeaderBlock(remaining_key_value_pairs_for_frame_);
115 state_ = READING_KEY_LEN; 115 state_ = READING_KEY_LEN;
116 } else { 116 } else {
117 headers_block_prefix_ = reader.Remainder(); 117 headers_block_prefix_ = reader.Remainder();
118 return; 118 return;
119 } 119 }
120 } 120 }
121 121
122 // Parse out and handle the key-value pairs. 122 // Parse out and handle the key-value pairs.
123 while (remaining_key_value_pairs_for_frame_ > 0) { 123 while (remaining_key_value_pairs_for_frame_ > 0) {
124 // Parse the key-value length, in case we don't already have it. 124 // Parse the key-value length, in case we don't already have it.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 // Did not receive enough bytes. 167 // Did not receive enough bytes.
168 break; 168 break;
169 } 169 }
170 } 170 }
171 171
172 // Unread suffix becomes the prefix upon next invocation. 172 // Unread suffix becomes the prefix upon next invocation.
173 headers_block_prefix_ = reader.Remainder(); 173 headers_block_prefix_ = reader.Remainder();
174 174
175 // Did we finish handling the current block? 175 // Did we finish handling the current block?
176 if (remaining_key_value_pairs_for_frame_ == 0) { 176 if (remaining_key_value_pairs_for_frame_ == 0) {
177 handler_->OnHeaderBlockEnd();
177 Reset(); 178 Reset();
178 } 179 }
179 } 180 }
180 181
181 } // namespace net 182 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_headers_block_parser.h ('k') | net/spdy/spdy_headers_block_parser_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698