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

Side by Side Diff: net/quic/crypto/crypto_framer.cc

Issue 921883003: Change QuicFramer so it accepts a QuicDataWriter rather than allocating (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Deprecate_flag_quic_use_std_cbrt
Patch Set: Created 5 years, 10 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 | « no previous file | net/quic/quic_data_writer.h » ('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) 2012 The Chromium Authors. All rights reserved. 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 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/quic/crypto/crypto_framer.h" 5 #include "net/quic/crypto/crypto_framer.h"
6 6
7 #include "net/quic/crypto/crypto_protocol.h" 7 #include "net/quic/crypto/crypto_protocol.h"
8 #include "net/quic/quic_data_reader.h" 8 #include "net/quic/quic_data_reader.h"
9 #include "net/quic/quic_data_writer.h" 9 #include "net/quic/quic_data_writer.h"
10 10
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 if (delta > overhead) { 99 if (delta > overhead) {
100 pad_length = delta - overhead; 100 pad_length = delta - overhead;
101 } 101 }
102 len += overhead + pad_length; 102 len += overhead + pad_length;
103 } 103 }
104 104
105 if (num_entries > kMaxEntries) { 105 if (num_entries > kMaxEntries) {
106 return nullptr; 106 return nullptr;
107 } 107 }
108 108
109 109 scoped_ptr<char[]> buffer(new char[len]);
110 QuicDataWriter writer(len); 110 QuicDataWriter writer(len, buffer.get());
111 if (!writer.WriteUInt32(message.tag())) { 111 if (!writer.WriteUInt32(message.tag())) {
112 DCHECK(false) << "Failed to write message tag."; 112 DCHECK(false) << "Failed to write message tag.";
113 return nullptr; 113 return nullptr;
114 } 114 }
115 if (!writer.WriteUInt16(static_cast<uint16>(num_entries))) { 115 if (!writer.WriteUInt16(static_cast<uint16>(num_entries))) {
116 DCHECK(false) << "Failed to write size."; 116 DCHECK(false) << "Failed to write size.";
117 return nullptr; 117 return nullptr;
118 } 118 }
119 if (!writer.WriteUInt16(0)) { 119 if (!writer.WriteUInt16(0)) {
120 DCHECK(false) << "Failed to write padding."; 120 DCHECK(false) << "Failed to write padding.";
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 } 174 }
175 } 175 }
176 176
177 if (need_pad_value) { 177 if (need_pad_value) {
178 if (!writer.WriteRepeatedByte('-', pad_length)) { 178 if (!writer.WriteRepeatedByte('-', pad_length)) {
179 DCHECK(false) << "Failed to write padding."; 179 DCHECK(false) << "Failed to write padding.";
180 return nullptr; 180 return nullptr;
181 } 181 }
182 } 182 }
183 183
184 return new QuicData(writer.take(), len, true); 184 return new QuicData(buffer.release(), len, true);
185 } 185 }
186 186
187 void CryptoFramer::Clear() { 187 void CryptoFramer::Clear() {
188 message_.Clear(); 188 message_.Clear();
189 tags_and_lengths_.clear(); 189 tags_and_lengths_.clear();
190 error_ = QUIC_NO_ERROR; 190 error_ = QUIC_NO_ERROR;
191 state_ = STATE_READING_TAG; 191 state_ = STATE_READING_TAG;
192 } 192 }
193 193
194 QuicErrorCode CryptoFramer::Process(StringPiece input) { 194 QuicErrorCode CryptoFramer::Process(StringPiece input) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 } 280 }
281 *end_offset += pad_length; 281 *end_offset += pad_length;
282 if (!writer->WriteUInt32(*end_offset)) { 282 if (!writer->WriteUInt32(*end_offset)) {
283 DCHECK(false) << "Failed to write end offset."; 283 DCHECK(false) << "Failed to write end offset.";
284 return false; 284 return false;
285 } 285 }
286 return true; 286 return true;
287 } 287 }
288 288
289 } // namespace net 289 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/quic/quic_data_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698