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

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

Issue 2515143002: Removing SPDY3 from the code base. (Closed)
Patch Set: Addressed a failure on windows. Created 4 years, 1 month 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
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/spdy/spdy_frame_builder.h" 5 #include "net/spdy/spdy_frame_builder.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "net/spdy/spdy_bug_tracker.h" 10 #include "net/spdy/spdy_bug_tracker.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 return false; 56 return false;
57 } 57 }
58 58
59 length_ += length; 59 length_ += length;
60 return true; 60 return true;
61 } 61 }
62 62
63 bool SpdyFrameBuilder::WriteControlFrameHeader(const SpdyFramer& framer, 63 bool SpdyFrameBuilder::WriteControlFrameHeader(const SpdyFramer& framer,
64 SpdyFrameType type, 64 SpdyFrameType type,
65 uint8_t flags) { 65 uint8_t flags) {
66 DCHECK_EQ(SPDY3, version_); 66 DCHECK(false);
67 DCHECK(SpdyConstants::IsValidFrameType( 67 DCHECK(SpdyConstants::IsValidFrameType(
68 version_, SpdyConstants::SerializeFrameType(version_, type))); 68 version_, SpdyConstants::SerializeFrameType(version_, type)));
69 bool success = true; 69 bool success = true;
70 FlagsAndLength flags_length = 70 FlagsAndLength flags_length =
71 CreateFlagsAndLength(flags, capacity_ - framer.GetFrameHeaderSize()); 71 CreateFlagsAndLength(flags, capacity_ - framer.GetFrameHeaderSize());
72 success &= WriteUInt16(kControlFlagMask | kSpdy3Version); 72 success &= WriteUInt16(kControlFlagMask | kSpdy3Version);
73 success &= WriteUInt16( 73 success &= WriteUInt16(
74 SpdyConstants::SerializeFrameType(framer.protocol_version(), type)); 74 SpdyConstants::SerializeFrameType(framer.protocol_version(), type));
75 success &= WriteBytes(&flags_length, sizeof(flags_length)); 75 success &= WriteBytes(&flags_length, sizeof(flags_length));
76 DCHECK_EQ(framer.GetFrameHeaderSize(), length()); 76 DCHECK_EQ(framer.GetFrameHeaderSize(), length());
77 return success; 77 return success;
78 } 78 }
79 79
80 bool SpdyFrameBuilder::WriteDataFrameHeader(const SpdyFramer& framer, 80 bool SpdyFrameBuilder::WriteDataFrameHeader(const SpdyFramer& framer,
81 SpdyStreamId stream_id, 81 SpdyStreamId stream_id,
82 uint8_t flags) { 82 uint8_t flags) {
83 if (version_ == HTTP2) { 83 return BeginNewFrame(framer, DATA, flags, stream_id);
84 return BeginNewFrame(framer, DATA, flags, stream_id);
85 }
86 DCHECK_EQ(0u, stream_id & ~kStreamIdMask);
87 bool success = true;
88 success &= WriteUInt32(stream_id);
89 size_t length_field = capacity_ - framer.GetDataFrameMinimumSize();
90 DCHECK_EQ(0u, length_field & ~static_cast<size_t>(kLengthMask));
91 FlagsAndLength flags_length;
92 flags_length.length = base::HostToNet32(static_cast<uint32_t>(length_field));
93 DCHECK_EQ(0, flags & ~kDataFlagsMask);
94 flags_length.flags[0] = flags;
95 success &= WriteBytes(&flags_length, sizeof(flags_length));
96 DCHECK_EQ(framer.GetDataFrameMinimumSize(), length());
97 return success;
98 } 84 }
99 85
100 bool SpdyFrameBuilder::BeginNewFrame(const SpdyFramer& framer, 86 bool SpdyFrameBuilder::BeginNewFrame(const SpdyFramer& framer,
101 SpdyFrameType type, 87 SpdyFrameType type,
102 uint8_t flags, 88 uint8_t flags,
103 SpdyStreamId stream_id) { 89 SpdyStreamId stream_id) {
104 DCHECK(SpdyConstants::IsValidFrameType( 90 DCHECK(SpdyConstants::IsValidFrameType(
105 version_, SpdyConstants::SerializeFrameType(version_, type))); 91 version_, SpdyConstants::SerializeFrameType(version_, type)));
106 DCHECK_EQ(0u, stream_id & ~kStreamIdMask); 92 DCHECK_EQ(0u, stream_id & ~kStreamIdMask);
107 DCHECK_EQ(HTTP2, framer.protocol_version()); 93 DCHECK_EQ(HTTP2, framer.protocol_version());
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 Seek(data_len); 148 Seek(data_len);
163 return true; 149 return true;
164 } 150 }
165 151
166 bool SpdyFrameBuilder::RewriteLength(const SpdyFramer& framer) { 152 bool SpdyFrameBuilder::RewriteLength(const SpdyFramer& framer) {
167 return OverwriteLength(framer, length_ - framer.GetFrameHeaderSize()); 153 return OverwriteLength(framer, length_ - framer.GetFrameHeaderSize());
168 } 154 }
169 155
170 bool SpdyFrameBuilder::OverwriteLength(const SpdyFramer& framer, 156 bool SpdyFrameBuilder::OverwriteLength(const SpdyFramer& framer,
171 size_t length) { 157 size_t length) {
172 if (version_ == SPDY3) { 158 DCHECK_GE(framer.GetFrameMaximumSize(), length);
173 DCHECK_GE(framer.GetFrameMaximumSize() - framer.GetFrameMinimumSize(),
174 length);
175 } else {
176 DCHECK_GE(framer.GetFrameMaximumSize(), length);
177 }
178 bool success = false; 159 bool success = false;
179 const size_t old_length = length_; 160 const size_t old_length = length_;
180 161
181 if (version_ == SPDY3) { 162 length_ = 0;
182 FlagsAndLength flags_length = CreateFlagsAndLength( 163 success = WriteUInt24(length);
183 0, // We're not writing over the flags value anyway.
184 length);
185
186 // Write into the correct location by temporarily faking the offset.
187 length_ = 5; // Offset at which the length field occurs.
188 success = WriteBytes(reinterpret_cast<char*>(&flags_length) + 1,
189 sizeof(flags_length) - 1);
190 } else {
191 length_ = 0;
192 success = WriteUInt24(length);
193 }
194 164
195 length_ = old_length; 165 length_ = old_length;
196 return success; 166 return success;
197 } 167 }
198 168
199 bool SpdyFrameBuilder::OverwriteFlags(const SpdyFramer& framer, uint8_t flags) { 169 bool SpdyFrameBuilder::OverwriteFlags(const SpdyFramer& framer, uint8_t flags) {
200 DCHECK_EQ(HTTP2, framer.protocol_version()); 170 DCHECK_EQ(HTTP2, framer.protocol_version());
201 bool success = false; 171 bool success = false;
202 const size_t old_length = length_; 172 const size_t old_length = length_;
203 // Flags are the fifth octet in the frame prefix. 173 // Flags are the fifth octet in the frame prefix.
(...skipping 11 matching lines...) Expand all
215 185
216 if (offset_ + length_ + length > capacity_) { 186 if (offset_ + length_ + length > capacity_) {
217 DCHECK(false); 187 DCHECK(false);
218 return false; 188 return false;
219 } 189 }
220 190
221 return true; 191 return true;
222 } 192 }
223 193
224 } // namespace net 194 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698