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

Unified Diff: net/spdy/spdy_framer.cc

Issue 202113002: Syntactic-only changes to use protocol_version() over spdy_version_ in SpdyFramer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/spdy/spdy_framer.cc
diff --git a/net/spdy/spdy_framer.cc b/net/spdy/spdy_framer.cc
index 2e2d340edbc22762f7e3b220a01e1c5ca5b0f1e9..970899da2694eef4e957a0aa43f5a5907bf57c6c 100644
--- a/net/spdy/spdy_framer.cc
+++ b/net/spdy/spdy_framer.cc
@@ -187,7 +187,7 @@ size_t SpdyFramer::GetControlFrameHeaderSize() const {
size_t SpdyFramer::GetSynStreamMinimumSize() const {
// Size, in bytes, of a SYN_STREAM frame not including the variable-length
// name-value block.
- if (spdy_version_ < 4) {
+ if (protocol_version() <= SPDY3) {
// Calculated as:
// control frame header + 2 * 4 (stream IDs) + 1 (priority)
// + 1 (unused, was credential slot)
@@ -203,14 +203,14 @@ size_t SpdyFramer::GetSynReplyMinimumSize() const {
// Size, in bytes, of a SYN_REPLY frame not including the variable-length
// name-value block.
size_t size = GetControlFrameHeaderSize();
- if (spdy_version_ < 4) {
+ if (protocol_version() <= SPDY3) {
// Calculated as:
// control frame header + 4 (stream IDs)
size += 4;
}
// In SPDY 2, there were 2 unused bytes before payload.
- if (protocol_version() < 3) {
+ if (protocol_version() < SPDY3) {
size += 2;
}
@@ -219,7 +219,7 @@ size_t SpdyFramer::GetSynReplyMinimumSize() const {
size_t SpdyFramer::GetRstStreamMinimumSize() const {
// Size, in bytes, of a RST_STREAM frame.
- if (spdy_version_ < 4) {
+ if (protocol_version() <= SPDY3) {
// Calculated as:
// control frame header + 4 (stream id) + 4 (status code)
return GetControlFrameHeaderSize() + 8;
@@ -234,7 +234,7 @@ size_t SpdyFramer::GetSettingsMinimumSize() const {
// Size, in bytes, of a SETTINGS frame not including the IDs and values
// from the variable-length value block. Calculated as:
// control frame header + 4 (number of ID/value pairs)
- if (spdy_version_ < 4) {
+ if (protocol_version() <= SPDY3) {
return GetControlFrameHeaderSize() + 4;
} else {
return GetControlFrameHeaderSize();
@@ -243,7 +243,7 @@ size_t SpdyFramer::GetSettingsMinimumSize() const {
size_t SpdyFramer::GetPingSize() const {
// Size, in bytes, of this PING frame.
- if (spdy_version_ < 4) {
+ if (protocol_version() <= SPDY3) {
// Calculated as:
// control frame header + 4 (id)
return GetControlFrameHeaderSize() + 4;
@@ -274,14 +274,14 @@ size_t SpdyFramer::GetHeadersMinimumSize() const {
// Size, in bytes, of a HEADERS frame not including the variable-length
// name-value block.
size_t size = GetControlFrameHeaderSize();
- if (spdy_version_ < 4) {
+ if (protocol_version() <= SPDY3) {
// Calculated as:
// control frame header + 4 (stream IDs)
size += 4;
}
// In SPDY 2, there were 2 unused bytes before payload.
- if (protocol_version() < 3) {
+ if (protocol_version() <= SPDY2) {
size += 2;
}
@@ -290,7 +290,7 @@ size_t SpdyFramer::GetHeadersMinimumSize() const {
size_t SpdyFramer::GetWindowUpdateSize() const {
// Size, in bytes, of a WINDOW_UPDATE frame.
- if (spdy_version_ < 4) {
+ if (protocol_version() <= SPDY3) {
// Calculated as:
// control frame header + 4 (stream id) + 4 (delta)
return GetControlFrameHeaderSize() + 8;
@@ -326,7 +326,7 @@ size_t SpdyFramer::GetFrameMinimumSize() const {
}
size_t SpdyFramer::GetFrameMaximumSize() const {
- if (protocol_version() < 4) {
+ if (protocol_version() <= SPDY3) {
// 24-bit length field plus eight-byte frame header.
return ((1<<24) - 1) + 8;
} else {
@@ -531,7 +531,7 @@ size_t SpdyFramer::ProcessInput(const char* data, size_t len) {
case SPDY_CONTROL_FRAME_HEADER_BLOCK: {
int bytes_read = ProcessControlFrameHeaderBlock(
- data, len, spdy_version_ >= 4 ? true : false);
+ data, len, protocol_version() > SPDY3);
len -= bytes_read;
data += bytes_read;
break;
@@ -634,7 +634,7 @@ size_t SpdyFramer::ProcessCommonHeader(const char* data, size_t len) {
// ProcessControlFrameHeader() will set current_frame_type_ to the
// correct value if this is a valid control frame.
current_frame_type_ = DATA;
- if (protocol_version() < 4) {
+ if (protocol_version() <= SPDY3) {
bool successful_read = reader->ReadUInt16(&version);
DCHECK(successful_read);
is_control_frame = (version & kControlFlagMask) != 0;
@@ -725,14 +725,14 @@ size_t SpdyFramer::ProcessCommonHeader(const char* data, size_t len) {
// if we're here, then we have the common header all received.
if (!is_control_frame) {
- if (protocol_version() >= 4) {
+ if (protocol_version() > SPDY3) {
// Catch bogus tests sending oversized DATA frames.
DCHECK_GE(GetFrameMaximumSize(), current_frame_length_)
<< "DATA frame too large for SPDY >= 4.";
}
uint8 valid_data_flags = 0;
- if (protocol_version() >= 4) {
+ if (protocol_version() > SPDY3) {
valid_data_flags = DATA_FLAG_FIN | DATA_FLAG_END_SEGMENT |
DATA_FLAG_PAD_LOW | DATA_FLAG_PAD_HIGH;
} else {
@@ -756,11 +756,11 @@ size_t SpdyFramer::ProcessCommonHeader(const char* data, size_t len) {
CHANGE_STATE(SPDY_AUTO_RESET);
}
}
- } else if (version != spdy_version_) {
+ } else if (version != protocol_version()) {
// We check version before we check validity: version can never be
// 'invalid', it can only be unsupported.
DVLOG(1) << "Unsupported SPDY version " << version
- << " (expected " << spdy_version_ << ")";
+ << " (expected " << protocol_version() << ")";
set_error(SPDY_UNSUPPORTED_VERSION);
} else {
ProcessControlFrameHeader(control_frame_type_field);
@@ -774,7 +774,7 @@ void SpdyFramer::ProcessControlFrameHeader(uint16 control_frame_type_field) {
DCHECK_LE(GetControlFrameHeaderSize(), current_frame_buffer_length_);
// Early detection of deprecated frames that we ignore.
- if (protocol_version() < SPDY4) {
+ if (protocol_version() <= SPDY3) {
if (control_frame_type_field == NOOP) {
current_frame_type_ = NOOP;
DVLOG(1) << "NOOP control frame found. Ignoring.";
@@ -784,7 +784,7 @@ void SpdyFramer::ProcessControlFrameHeader(uint16 control_frame_type_field) {
if (control_frame_type_field == CREDENTIAL) {
current_frame_type_ = CREDENTIAL;
- DCHECK_EQ(3, protocol_version());
+ DCHECK_EQ(SPDY3, protocol_version());
DVLOG(1) << "CREDENTIAL control frame found. Ignoring.";
CHANGE_STATE(SPDY_IGNORE_REMAINING_PAYLOAD);
return;
@@ -824,9 +824,9 @@ void SpdyFramer::ProcessControlFrameHeader(uint16 control_frame_type_field) {
// For SPDY version 4 and up, the RST_STREAM frame may include optional
// opaque data, so we only have a lower limit on the frame size.
if ((current_frame_length_ != GetRstStreamMinimumSize() &&
- protocol_version() < 4) ||
+ protocol_version() <= SPDY3) ||
(current_frame_length_ < GetRstStreamMinimumSize() &&
- protocol_version() >= 4)) {
+ protocol_version() > SPDY3)) {
set_error(SPDY_INVALID_CONTROL_FRAME);
} else if (current_frame_flags_ != 0) {
set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS);
@@ -836,23 +836,23 @@ void SpdyFramer::ProcessControlFrameHeader(uint16 control_frame_type_field) {
{
// Make sure that we have an integral number of 8-byte key/value pairs,
// plus a 4-byte length field in SPDY3 and below.
- size_t values_prefix_size = (protocol_version() < 4 ? 4 : 0);
+ size_t values_prefix_size = (protocol_version() <= SPDY3 ? 4 : 0);
// Size of each key/value pair in bytes.
- size_t setting_size = (protocol_version() < 4 ? 8 : 5);
+ size_t setting_size = (protocol_version() <= SPDY3 ? 8 : 5);
if (current_frame_length_ < GetSettingsMinimumSize() ||
(current_frame_length_ - GetControlFrameHeaderSize())
% setting_size != values_prefix_size) {
DLOG(WARNING) << "Invalid length for SETTINGS frame: "
<< current_frame_length_;
set_error(SPDY_INVALID_CONTROL_FRAME);
- } else if (protocol_version() < 4 &&
+ } else if (protocol_version() <= SPDY3 &&
current_frame_flags_ &
~SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS) {
set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS);
- } else if (protocol_version() >= 4 &&
+ } else if (protocol_version() > SPDY3 &&
current_frame_flags_ & ~SETTINGS_FLAG_ACK) {
set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS);
- } else if (protocol_version() >= 4 &&
+ } else if (protocol_version() > SPDY3 &&
current_frame_flags_ & SETTINGS_FLAG_ACK &&
current_frame_length_ > GetSettingsMinimumSize()) {
set_error(SPDY_INVALID_CONTROL_FRAME);
@@ -862,7 +862,7 @@ void SpdyFramer::ProcessControlFrameHeader(uint16 control_frame_type_field) {
case PING:
if (current_frame_length_ != GetPingSize()) {
set_error(SPDY_INVALID_CONTROL_FRAME);
- } else if ((protocol_version() < 4 && current_frame_flags_ != 0) ||
+ } else if ((protocol_version() <= SPDY3 && current_frame_flags_ != 0) ||
(current_frame_flags_ & ~PING_FLAG_ACK)) {
set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS);
}
@@ -874,9 +874,9 @@ void SpdyFramer::ProcessControlFrameHeader(uint16 control_frame_type_field) {
// be appended to the GOAWAY frame, thus there is only a minimal length
// restriction.
if ((current_frame_length_ != GetGoAwayMinimumSize() &&
- protocol_version() < 4) ||
+ protocol_version() <= SPDY3) ||
(current_frame_length_ < GetGoAwayMinimumSize() &&
- protocol_version() >= 4)) {
+ protocol_version() > SPDY3)) {
set_error(SPDY_INVALID_CONTROL_FRAME);
} else if (current_frame_flags_ != 0) {
set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS);
@@ -886,16 +886,16 @@ void SpdyFramer::ProcessControlFrameHeader(uint16 control_frame_type_field) {
case HEADERS:
{
size_t min_size = GetHeadersMinimumSize();
- if (spdy_version_ > 3 &&
+ if (protocol_version() > SPDY3 &&
(current_frame_flags_ & HEADERS_FLAG_PRIORITY)) {
min_size += 4;
}
if (current_frame_length_ < min_size) {
set_error(SPDY_INVALID_CONTROL_FRAME);
- } else if (spdy_version_ < 4 &&
+ } else if (protocol_version() <= SPDY3 &&
current_frame_flags_ & ~CONTROL_FLAG_FIN) {
set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS);
- } else if (spdy_version_ >= 4 && current_frame_flags_ &
+ } else if (protocol_version() > SPDY3 && current_frame_flags_ &
~(CONTROL_FLAG_FIN | HEADERS_FLAG_PRIORITY |
HEADERS_FLAG_END_HEADERS)) {
set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS);
@@ -919,9 +919,9 @@ void SpdyFramer::ProcessControlFrameHeader(uint16 control_frame_type_field) {
case PUSH_PROMISE:
if (current_frame_length_ < GetPushPromiseMinimumSize()) {
set_error(SPDY_INVALID_CONTROL_FRAME);
- } else if (spdy_version_ < 4 && current_frame_flags_ != 0) {
+ } else if (protocol_version() <= SPDY3 && current_frame_flags_ != 0) {
set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS);
- } else if (spdy_version_ >= 4 && current_frame_flags_ &
+ } else if (protocol_version() > SPDY3 && current_frame_flags_ &
~PUSH_PROMISE_FLAG_END_PUSH_PROMISE) {
set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS);
}
@@ -983,7 +983,8 @@ void SpdyFramer::ProcessControlFrameHeader(uint16 control_frame_type_field) {
break;
case HEADERS:
frame_size_without_variable_data = GetHeadersMinimumSize();
- if (spdy_version_ > 3 && current_frame_flags_ & HEADERS_FLAG_PRIORITY) {
+ if (protocol_version() > SPDY3 &&
+ current_frame_flags_ & HEADERS_FLAG_PRIORITY) {
frame_size_without_variable_data += 4; // priority
}
break;
@@ -1268,12 +1269,10 @@ size_t SpdyFramer::ProcessControlFrameBeforeHeaderBlock(const char* data,
switch (current_frame_type_) {
case SYN_STREAM:
{
- DCHECK_GT(4, spdy_version_);
+ DCHECK_GE(SPDY3, protocol_version());
bool successful_read = true;
- if (spdy_version_ < 4) {
- successful_read = reader.ReadUInt31(&current_frame_stream_id_);
- DCHECK(successful_read);
- }
+ successful_read = reader.ReadUInt31(&current_frame_stream_id_);
+ DCHECK(successful_read);
if (current_frame_stream_id_ == 0) {
set_error(SPDY_INVALID_CONTROL_FRAME);
break;
@@ -1286,7 +1285,7 @@ size_t SpdyFramer::ProcessControlFrameBeforeHeaderBlock(const char* data,
SpdyPriority priority = 0;
successful_read = reader.ReadUInt8(&priority);
DCHECK(successful_read);
- if (protocol_version() < 3) {
+ if (protocol_version() <= SPDY2) {
priority = priority >> 6;
} else {
priority = priority >> 5;
@@ -1312,7 +1311,8 @@ size_t SpdyFramer::ProcessControlFrameBeforeHeaderBlock(const char* data,
CHANGE_STATE(SPDY_CONTROL_FRAME_HEADER_BLOCK);
break;
case SETTINGS:
- if (spdy_version_ >= 4 && current_frame_flags_ & SETTINGS_FLAG_ACK) {
+ if (protocol_version() > SPDY3 &&
+ current_frame_flags_ & SETTINGS_FLAG_ACK) {
visitor_->OnSettingsAck();
CHANGE_STATE(SPDY_AUTO_RESET);
} else {
@@ -1325,11 +1325,11 @@ size_t SpdyFramer::ProcessControlFrameBeforeHeaderBlock(const char* data,
case HEADERS:
// SYN_REPLY and HEADERS are the same, save for the visitor call.
{
- if (spdy_version_ > 3) {
+ if (protocol_version() > SPDY3) {
DCHECK_EQ(HEADERS, current_frame_type_);
}
bool successful_read = true;
- if (spdy_version_ < 4) {
+ if (protocol_version() <= SPDY3) {
successful_read = reader.ReadUInt31(&current_frame_stream_id_);
DCHECK(successful_read);
}
@@ -1337,11 +1337,11 @@ size_t SpdyFramer::ProcessControlFrameBeforeHeaderBlock(const char* data,
set_error(SPDY_INVALID_CONTROL_FRAME);
break;
}
- if (protocol_version() < 3) {
+ if (protocol_version() <= SPDY2) {
// SPDY 2 had two unused bytes here. Seek past them.
reader.Seek(2);
}
- if (spdy_version_ > 3 &&
+ if (protocol_version() > SPDY3 &&
!(current_frame_flags_ & HEADERS_FLAG_END_HEADERS) &&
current_frame_type_ == HEADERS) {
expect_continuation_ = current_frame_stream_id_;
@@ -1350,7 +1350,7 @@ size_t SpdyFramer::ProcessControlFrameBeforeHeaderBlock(const char* data,
const bool has_priority =
(current_frame_flags_ & HEADERS_FLAG_PRIORITY) != 0;
uint32 priority = 0;
- if (protocol_version() > 3 && has_priority) {
+ if (protocol_version() > SPDY3 && has_priority) {
successful_read = reader.ReadUInt31(&priority);
DCHECK(successful_read);
}
@@ -1358,7 +1358,7 @@ size_t SpdyFramer::ProcessControlFrameBeforeHeaderBlock(const char* data,
if (debug_visitor_) {
// SPDY 4 reports HEADERS with PRIORITY as SYN_STREAM.
SpdyFrameType reported_type = current_frame_type_;
- if (protocol_version() > 3 && has_priority) {
+ if (protocol_version() > SPDY3 && has_priority) {
reported_type = SYN_STREAM;
}
debug_visitor_->OnReceiveCompressedFrame(
@@ -1370,7 +1370,7 @@ size_t SpdyFramer::ProcessControlFrameBeforeHeaderBlock(const char* data,
visitor_->OnSynReply(
current_frame_stream_id_,
(current_frame_flags_ & CONTROL_FLAG_FIN) != 0);
- } else if (spdy_version_ > 3 &&
+ } else if (protocol_version() > SPDY3 &&
current_frame_flags_ & HEADERS_FLAG_PRIORITY) {
// SPDY 4+ is missing SYN_STREAM. Simulate it so that API changes
// can be made independent of wire changes.
@@ -1391,7 +1391,7 @@ size_t SpdyFramer::ProcessControlFrameBeforeHeaderBlock(const char* data,
break;
case PUSH_PROMISE:
{
- DCHECK_LE(4, protocol_version());
+ DCHECK_LT(SPDY3, protocol_version());
if (current_frame_stream_id_ == 0) {
set_error(SPDY_INVALID_CONTROL_FRAME);
break;
@@ -1480,7 +1480,7 @@ size_t SpdyFramer::ProcessControlFrameHeaderBlock(const char* data,
processed_successfully = false;
}
} else if (process_bytes > 0) {
- if (enable_compression_ && spdy_version_ < 4) {
+ if (enable_compression_ && protocol_version() <= SPDY3) {
processed_successfully = IncrementallyDecompressControlFrameHeaderData(
current_frame_stream_id_, data, process_bytes);
} else {
@@ -1537,7 +1537,7 @@ size_t SpdyFramer::ProcessSettingsFramePayload(const char* data,
size_t unprocessed_bytes = std::min(data_len, remaining_data_length_);
size_t processed_bytes = 0;
- size_t setting_size = spdy_version_ < 4 ? 8 : 5;
+ size_t setting_size = protocol_version() <= SPDY3 ? 8 : 5;
// Loop over our incoming data.
while (unprocessed_bytes > 0) {
@@ -1587,8 +1587,8 @@ size_t SpdyFramer::ProcessSettingsFramePayload(const char* data,
}
void SpdyFramer::DeliverHpackBlockAsSpdy3Block() {
- DCHECK_GE(spdy_version_, SPDY4);
- DCHECK_EQ(remaining_data_length_, 0u);
+ DCHECK_LT(SPDY3, protocol_version());
+ DCHECK_EQ(0u, remaining_data_length_);
const SpdyNameValueBlock& block = hpack_decoder_.decoded_block();
if (block.empty()) {
@@ -1613,10 +1613,10 @@ bool SpdyFramer::ProcessSetting(const char* data) {
// Extract fields.
// Maintain behavior of old SPDY 2 bug with byte ordering of flags/id.
- if (spdy_version_ < 4) {
+ if (protocol_version() <= SPDY3) {
const uint32 id_and_flags_wire = *(reinterpret_cast<const uint32*>(data));
SettingsFlagsAndId id_and_flags =
- SettingsFlagsAndId::FromWireFormat(spdy_version_, id_and_flags_wire);
+ SettingsFlagsAndId::FromWireFormat(protocol_version(), id_and_flags_wire);
id = static_cast<SpdySettingsIds>(id_and_flags.id());
flags = id_and_flags.flags();
value = ntohl(*(reinterpret_cast<const uint32*>(data + 4)));
@@ -1641,7 +1641,7 @@ bool SpdyFramer::ProcessSetting(const char* data) {
return false;
}
- if (spdy_version_ < 4) {
+ if (protocol_version() <= SPDY3) {
// Detect duplicates.
if (static_cast<uint32>(id) <= settings_scratch_.last_setting_id) {
DLOG(WARNING) << "Duplicate entry or invalid ordering for id " << id
@@ -1680,10 +1680,10 @@ size_t SpdyFramer::ProcessControlFramePayload(const char* data, size_t len) {
switch (current_frame_type_) {
case PING: {
SpdyPingId id = 0;
- bool is_ack =
- spdy_version_ >= 4 && (current_frame_flags_ & PING_FLAG_ACK);
+ bool is_ack = protocol_version() > SPDY3 &&
+ (current_frame_flags_ & PING_FLAG_ACK);
bool successful_read = true;
- if (spdy_version_ < 4) {
+ if (protocol_version() <= SPDY3) {
uint32 id32 = 0;
successful_read = reader.ReadUInt32(&id32);
id = id32;
@@ -1698,7 +1698,7 @@ size_t SpdyFramer::ProcessControlFramePayload(const char* data, size_t len) {
case WINDOW_UPDATE: {
uint32 delta_window_size = 0;
bool successful_read = true;
- if (spdy_version_ < 4) {
+ if (protocol_version() <= SPDY3) {
successful_read = reader.ReadUInt31(&current_frame_stream_id_);
DCHECK(successful_read);
}
@@ -1710,7 +1710,7 @@ size_t SpdyFramer::ProcessControlFramePayload(const char* data, size_t len) {
}
break;
case BLOCKED: {
- DCHECK_LE(4, protocol_version());
+ DCHECK_LT(SPDY3, protocol_version());
DCHECK(reader.IsDoneReading());
visitor_->OnBlocked(current_frame_stream_id_);
}
@@ -1754,7 +1754,7 @@ size_t SpdyFramer::ProcessGoAwayFramePayload(const char* data, size_t len) {
// In SPDYv3 and up, frames also specify a status code - parse it out.
SpdyGoAwayStatus status = GOAWAY_OK;
- if (spdy_version_ >= 3) {
+ if (protocol_version() >= SPDY3) {
uint32 status_raw = GOAWAY_OK;
successful_read = reader.ReadUInt32(&status_raw);
DCHECK(successful_read);
@@ -1815,7 +1815,7 @@ size_t SpdyFramer::ProcessRstStreamFramePayload(const char* data, size_t len) {
SpdyFrameReader reader(current_frame_buffer_.get(),
current_frame_buffer_length_);
reader.Seek(GetControlFrameHeaderSize()); // Seek past frame header.
- if (protocol_version() < 4) {
+ if (protocol_version() <= SPDY3) {
bool successful_read = reader.ReadUInt31(&current_frame_stream_id_);
DCHECK(successful_read);
}
@@ -1967,7 +1967,7 @@ size_t SpdyFramer::ParseHeaderBlockInBuffer(const char* header_data,
// Read number of headers.
uint32 num_headers;
- if (spdy_version_ < 3) {
+ if (protocol_version() <= SPDY2) {
uint16 temp;
if (!reader.ReadUInt16(&temp)) {
DVLOG(1) << "Unable to read number of headers.";
@@ -1986,7 +1986,7 @@ size_t SpdyFramer::ParseHeaderBlockInBuffer(const char* header_data,
base::StringPiece temp;
// Read header name.
- if ((spdy_version_ < 3) ? !reader.ReadStringPiece16(&temp)
+ if ((protocol_version() <= SPDY2) ? !reader.ReadStringPiece16(&temp)
: !reader.ReadStringPiece32(&temp)) {
DVLOG(1) << "Unable to read header name (" << index + 1 << " of "
<< num_headers << ").";
@@ -1995,7 +1995,7 @@ size_t SpdyFramer::ParseHeaderBlockInBuffer(const char* header_data,
std::string name = temp.as_string();
// Read header value.
- if ((spdy_version_ < 3) ? !reader.ReadStringPiece16(&temp)
+ if ((protocol_version() <= SPDY2) ? !reader.ReadStringPiece16(&temp)
: !reader.ReadStringPiece32(&temp)) {
DVLOG(1) << "Unable to read header value (" << index + 1 << " of "
<< num_headers << ").";
@@ -2022,7 +2022,7 @@ SpdySerializedFrame* SpdyFramer::SerializeData(const SpdyDataIR& datair) const {
flags = DATA_FLAG_FIN;
}
- if (protocol_version() >= 4) {
+ if (protocol_version() > SPDY3) {
int num_padding_fields = 0;
if (datair.pad_low()) {
flags |= DATA_FLAG_PAD_LOW;
@@ -2069,7 +2069,7 @@ SpdySerializedFrame* SpdyFramer::SerializeDataFrameHeader(
if (data.fin()) {
flags = DATA_FLAG_FIN;
}
- if (protocol_version() >= 4) {
+ if (protocol_version() > SPDY3) {
if (data.pad_low()) {
flags |= DATA_FLAG_PAD_LOW;
}
@@ -2097,7 +2097,7 @@ SpdySerializedFrame* SpdyFramer::SerializeSynStream(
}
// In SPDY >= 4, SYN_STREAM frames are HEADERS frames, but for now
// we never expect to have to overflow into a CONTINUATION frame.
- if (spdy_version_ >= 4) {
+ if (protocol_version() > SPDY3) {
flags |= HEADERS_FLAG_PRIORITY;
flags |= HEADERS_FLAG_END_HEADERS;
}
@@ -2113,7 +2113,7 @@ SpdySerializedFrame* SpdyFramer::SerializeSynStream(
size_t size = GetSynStreamMinimumSize();
string hpack_encoding;
- if (spdy_version_ >= 4) {
+ if (protocol_version() > SPDY3) {
hpack_encoder_.EncodeHeaderSet(syn_stream.name_value_block(),
&hpack_encoding);
size += hpack_encoding.size();
@@ -2122,11 +2122,11 @@ SpdySerializedFrame* SpdyFramer::SerializeSynStream(
}
SpdyFrameBuilder builder(size);
- if (spdy_version_ < 4) {
+ if (protocol_version() <= SPDY3) {
builder.WriteControlFrameHeader(*this, SYN_STREAM, flags);
builder.WriteUInt32(syn_stream.stream_id());
builder.WriteUInt32(syn_stream.associated_to_stream_id());
- builder.WriteUInt8(priority << ((spdy_version_ < 3) ? 6 : 5));
+ builder.WriteUInt8(priority << ((protocol_version() <= SPDY2) ? 6 : 5));
builder.WriteUInt8(0); // Unused byte where credential slot used to be.
} else {
builder.WriteFramePrefix(*this,
@@ -2136,14 +2136,15 @@ SpdySerializedFrame* SpdyFramer::SerializeSynStream(
builder.WriteUInt32(priority);
}
DCHECK_EQ(GetSynStreamMinimumSize(), builder.length());
- if (spdy_version_ >= 4) {
+ if (protocol_version() > SPDY3) {
builder.WriteBytes(&hpack_encoding[0], hpack_encoding.size());
} else {
SerializeNameValueBlock(&builder, syn_stream);
}
if (debug_visitor_) {
- const size_t payload_len = spdy_version_ >= 4 ? hpack_encoding.size() :
+ const size_t payload_len = protocol_version() > SPDY3 ?
+ hpack_encoding.size() :
GetSerializedLength(protocol_version(),
&(syn_stream.name_value_block()));
// SPDY 4 reports this compression as a SYN_STREAM compression.
@@ -2164,7 +2165,7 @@ SpdySerializedFrame* SpdyFramer::SerializeSynReply(
}
// In SPDY >= 4, SYN_REPLY frames are HEADERS frames, but for now
// we never expect to have to overflow into a CONTINUATION frame.
- if (spdy_version_ >= 4) {
+ if (protocol_version() > SPDY3) {
flags |= HEADERS_FLAG_END_HEADERS;
}
@@ -2172,7 +2173,7 @@ SpdySerializedFrame* SpdyFramer::SerializeSynReply(
size_t size = GetSynReplyMinimumSize();
string hpack_encoding;
- if (spdy_version_ >= 4) {
+ if (protocol_version() > SPDY3) {
hpack_encoder_.EncodeHeaderSet(syn_reply.name_value_block(),
&hpack_encoding);
size += hpack_encoding.size();
@@ -2181,7 +2182,7 @@ SpdySerializedFrame* SpdyFramer::SerializeSynReply(
}
SpdyFrameBuilder builder(size);
- if (spdy_version_ < 4) {
+ if (protocol_version() <= SPDY3) {
builder.WriteControlFrameHeader(*this, SYN_REPLY, flags);
builder.WriteUInt32(syn_reply.stream_id());
} else {
@@ -2190,18 +2191,19 @@ SpdySerializedFrame* SpdyFramer::SerializeSynReply(
flags,
syn_reply.stream_id());
}
- if (protocol_version() < 3) {
+ if (protocol_version() < SPDY3) {
builder.WriteUInt16(0); // Unused.
}
DCHECK_EQ(GetSynReplyMinimumSize(), builder.length());
- if (spdy_version_ >= 4) {
+ if (protocol_version() > SPDY3) {
builder.WriteBytes(&hpack_encoding[0], hpack_encoding.size());
} else {
SerializeNameValueBlock(&builder, syn_reply);
}
if (debug_visitor_) {
- const size_t payload_len = spdy_version_ >= 4 ? hpack_encoding.size() :
+ const size_t payload_len = protocol_version() > SPDY3 ?
+ hpack_encoding.size() :
GetSerializedLength(protocol_version(),
&(syn_reply.name_value_block()));
debug_visitor_->OnSendCompressedFrame(syn_reply.stream_id(),
@@ -2221,13 +2223,13 @@ SpdySerializedFrame* SpdyFramer::SerializeRstStream(
// commented but left in place to simplify future patching.
// Compute the output buffer size, taking opaque data into account.
uint16 expected_length = GetRstStreamMinimumSize();
- if (protocol_version() >= 4) {
+ if (protocol_version() > SPDY3) {
expected_length += rst_stream.description().size();
}
SpdyFrameBuilder builder(expected_length);
// Serialize the RST_STREAM frame.
- if (protocol_version() < 4) {
+ if (protocol_version() <= SPDY3) {
builder.WriteControlFrameHeader(*this, RST_STREAM, 0);
builder.WriteUInt32(rst_stream.stream_id());
} else {
@@ -2237,7 +2239,7 @@ SpdySerializedFrame* SpdyFramer::SerializeRstStream(
builder.WriteUInt32(rst_stream.status());
// In SPDY4 and up, RST_STREAM frames may also specify opaque data.
- if (protocol_version() >= 4 && rst_stream.description().size() > 0) {
+ if (protocol_version() > SPDY3 && rst_stream.description().size() > 0) {
builder.WriteBytes(rst_stream.description().data(),
rst_stream.description().size());
}
@@ -2250,7 +2252,7 @@ SpdySerializedFrame* SpdyFramer::SerializeSettings(
const SpdySettingsIR& settings) const {
uint8 flags = 0;
- if (spdy_version_ < 4) {
+ if (protocol_version() <= SPDY3) {
if (settings.clear_settings()) {
flags |= SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS;
}
@@ -2261,30 +2263,30 @@ SpdySerializedFrame* SpdyFramer::SerializeSettings(
}
const SpdySettingsIR::ValueMap* values = &(settings.values());
- size_t setting_size = (protocol_version() < 4 ? 8 : 5);
+ size_t setting_size = (protocol_version() <= SPDY3 ? 8 : 5);
// Size, in bytes, of this SETTINGS frame.
const size_t size = GetSettingsMinimumSize() +
(values->size() * setting_size);
SpdyFrameBuilder builder(size);
- if (spdy_version_ < 4) {
+ if (protocol_version() <= SPDY3) {
builder.WriteControlFrameHeader(*this, SETTINGS, flags);
} else {
builder.WriteFramePrefix(*this, SETTINGS, flags, 0);
}
// If this is an ACK, payload should be empty.
- if (spdy_version_ >= 4 && settings.is_ack()) {
+ if (protocol_version() > SPDY3 && settings.is_ack()) {
return builder.take();
}
- if (spdy_version_ < 4) {
+ if (protocol_version() <= SPDY3) {
builder.WriteUInt32(values->size());
}
DCHECK_EQ(GetSettingsMinimumSize(), builder.length());
for (SpdySettingsIR::ValueMap::const_iterator it = values->begin();
it != values->end();
++it) {
- if (spdy_version_ < 4) {
+ if (protocol_version() <= SPDY3) {
uint8 setting_flags = 0;
if (it->second.persist_value) {
setting_flags |= SETTINGS_FLAG_PLEASE_PERSIST;
@@ -2305,7 +2307,7 @@ SpdySerializedFrame* SpdyFramer::SerializeSettings(
}
SpdyFrame* SpdyFramer::SerializeBlocked(const SpdyBlockedIR& blocked) const {
- DCHECK_LE(4, protocol_version());
+ DCHECK_LT(SPDY3, protocol_version());
SpdyFrameBuilder builder(GetBlockedSize());
builder.WriteFramePrefix(*this, BLOCKED, kNoFlags, blocked.stream_id());
return builder.take();
@@ -2313,7 +2315,7 @@ SpdyFrame* SpdyFramer::SerializeBlocked(const SpdyBlockedIR& blocked) const {
SpdySerializedFrame* SpdyFramer::SerializePing(const SpdyPingIR& ping) const {
SpdyFrameBuilder builder(GetPingSize());
- if (spdy_version_ < 4) {
+ if (protocol_version() <= SPDY3) {
builder.WriteControlFrameHeader(*this, PING, kNoFlags);
builder.WriteUInt32(static_cast<uint32>(ping.id()));
} else {
@@ -2333,13 +2335,13 @@ SpdySerializedFrame* SpdyFramer::SerializeGoAway(
// Compute the output buffer size, take opaque data into account.
uint16 expected_length = GetGoAwayMinimumSize();
- if (protocol_version() >= 4) {
+ if (protocol_version() > SPDY3) {
expected_length += goaway.description().size();
}
SpdyFrameBuilder builder(expected_length);
// Serialize the GOAWAY frame.
- if (spdy_version_ < 4) {
+ if (protocol_version() <= SPDY3) {
builder.WriteControlFrameHeader(*this, GOAWAY, kNoFlags);
} else {
builder.WriteFramePrefix(*this, GOAWAY, 0, 0);
@@ -2349,12 +2351,12 @@ SpdySerializedFrame* SpdyFramer::SerializeGoAway(
builder.WriteUInt32(goaway.last_good_stream_id());
// In SPDY3 and up, GOAWAY frames also specify the error status code.
- if (protocol_version() >= 3) {
+ if (protocol_version() >= SPDY3) {
builder.WriteUInt32(goaway.status());
}
// In SPDY4 and up, GOAWAY frames may also specify opaque data.
- if ((protocol_version() >= 4) && (goaway.description().size() > 0)) {
+ if ((protocol_version() > SPDY3) && (goaway.description().size() > 0)) {
builder.WriteBytes(goaway.description().data(),
goaway.description().size());
}
@@ -2369,7 +2371,7 @@ SpdySerializedFrame* SpdyFramer::SerializeHeaders(
if (headers.fin()) {
flags |= CONTROL_FLAG_FIN;
}
- if (spdy_version_ >= 4) {
+ if (protocol_version() > SPDY3) {
if (headers.end_headers()) {
flags |= HEADERS_FLAG_END_HEADERS;
}
@@ -2391,7 +2393,7 @@ SpdySerializedFrame* SpdyFramer::SerializeHeaders(
}
string hpack_encoding;
- if (spdy_version_ >= 4) {
+ if (protocol_version() > SPDY3) {
hpack_encoder_.EncodeHeaderSet(headers.name_value_block(), &hpack_encoding);
size += hpack_encoding.size();
} else {
@@ -2399,7 +2401,7 @@ SpdySerializedFrame* SpdyFramer::SerializeHeaders(
}
SpdyFrameBuilder builder(size);
- if (spdy_version_ < 4) {
+ if (protocol_version() <= SPDY3) {
builder.WriteControlFrameHeader(*this, HEADERS, flags);
builder.WriteUInt32(headers.stream_id());
} else {
@@ -2411,19 +2413,20 @@ SpdySerializedFrame* SpdyFramer::SerializeHeaders(
builder.WriteUInt32(priority);
}
}
- if (protocol_version() < 3) {
+ if (protocol_version() <= SPDY2) {
builder.WriteUInt16(0); // Unused.
}
DCHECK_EQ(GetHeadersMinimumSize(), builder.length());
- if (spdy_version_ >= 4) {
+ if (protocol_version() > SPDY3) {
builder.WriteBytes(&hpack_encoding[0], hpack_encoding.size());
} else {
SerializeNameValueBlock(&builder, headers);
}
if (debug_visitor_) {
- const size_t payload_len = spdy_version_ >= 4 ? hpack_encoding.size() :
+ const size_t payload_len = protocol_version() > SPDY3 ?
+ hpack_encoding.size() :
GetSerializedLength(protocol_version(),
&(headers.name_value_block()));
debug_visitor_->OnSendCompressedFrame(headers.stream_id(),
@@ -2438,7 +2441,7 @@ SpdySerializedFrame* SpdyFramer::SerializeHeaders(
SpdySerializedFrame* SpdyFramer::SerializeWindowUpdate(
const SpdyWindowUpdateIR& window_update) const {
SpdyFrameBuilder builder(GetWindowUpdateSize());
- if (spdy_version_ < 4) {
+ if (protocol_version() <= SPDY3) {
builder.WriteControlFrameHeader(*this, WINDOW_UPDATE, kNoFlags);
builder.WriteUInt32(window_update.stream_id());
} else {
@@ -2454,7 +2457,7 @@ SpdySerializedFrame* SpdyFramer::SerializeWindowUpdate(
SpdyFrame* SpdyFramer::SerializePushPromise(
const SpdyPushPromiseIR& push_promise) {
- DCHECK_LE(4, protocol_version());
+ DCHECK_LT(SPDY3, protocol_version());
uint8 flags = 0;
if (push_promise.end_push_promise()) {
flags |= PUSH_PROMISE_FLAG_END_PUSH_PROMISE;
@@ -2463,7 +2466,7 @@ SpdyFrame* SpdyFramer::SerializePushPromise(
size_t size = GetPushPromiseMinimumSize();
string hpack_encoding;
- if (spdy_version_ >= 4) {
+ if (protocol_version() > SPDY3) {
hpack_encoder_.EncodeHeaderSet(push_promise.name_value_block(),
&hpack_encoding);
size += hpack_encoding.size();
@@ -2477,14 +2480,15 @@ SpdyFrame* SpdyFramer::SerializePushPromise(
builder.WriteUInt32(push_promise.promised_stream_id());
DCHECK_EQ(GetPushPromiseMinimumSize(), builder.length());
- if (spdy_version_ >= 4) {
+ if (protocol_version() > SPDY3) {
builder.WriteBytes(&hpack_encoding[0], hpack_encoding.size());
} else {
SerializeNameValueBlock(&builder, push_promise);
}
if (debug_visitor_) {
- const size_t payload_len = spdy_version_ >= 4 ? hpack_encoding.size() :
+ const size_t payload_len = protocol_version() > SPDY3 ?
+ hpack_encoding.size() :
GetSerializedLength(protocol_version(),
&(push_promise.name_value_block()));
debug_visitor_->OnSendCompressedFrame(push_promise.stream_id(),
@@ -2499,7 +2503,7 @@ SpdyFrame* SpdyFramer::SerializePushPromise(
// new one. Figure out whether it makes sense to keep SerializeContinuation().
SpdyFrame* SpdyFramer::SerializeContinuation(
const SpdyContinuationIR& continuation) {
- CHECK_GE(spdy_version_, 4);
+ CHECK_LT(SPDY3, protocol_version());
uint8 flags = 0;
if (continuation.end_headers()) {
flags |= HEADERS_FLAG_END_HEADERS;
@@ -2591,7 +2595,7 @@ SpdySerializedFrame* SpdyFramer::SerializeFrame(const SpdyFrameIR& frame) {
}
size_t SpdyFramer::GetSerializedLength(const SpdyHeaderBlock& headers) {
- CHECK_LT(spdy_version_, 4);
+ CHECK_GE(SPDY3, protocol_version());
const size_t uncompressed_length =
GetSerializedLength(protocol_version(), &headers);
if (!enable_compression_) {
@@ -2631,10 +2635,10 @@ z_stream* SpdyFramer::GetHeaderCompressor() {
kCompressorMemLevel,
Z_DEFAULT_STRATEGY);
if (success == Z_OK) {
- const char* dictionary = (spdy_version_ < 3) ? kV2Dictionary
- : kV3Dictionary;
- const int dictionary_size = (spdy_version_ < 3) ? kV2DictionarySize
- : kV3DictionarySize;
+ const char* dictionary = (protocol_version() <= SPDY2) ?
+ kV2Dictionary : kV3Dictionary;
+ const int dictionary_size = (protocol_version() <= SPDY2) ?
+ kV2DictionarySize : kV3DictionarySize;
success = deflateSetDictionary(header_compressor_.get(),
reinterpret_cast<const Bytef*>(dictionary),
dictionary_size);
@@ -2694,13 +2698,13 @@ bool SpdyFramer::IncrementallyDecompressControlFrameHeaderData(
int rv = inflate(decomp, Z_SYNC_FLUSH);
if (rv == Z_NEED_DICT) {
- const char* dictionary = (spdy_version_ < 3) ? kV2Dictionary
- : kV3Dictionary;
- const int dictionary_size = (spdy_version_ < 3) ? kV2DictionarySize
- : kV3DictionarySize;
+ const char* dictionary = (protocol_version() <= SPDY2) ? kV2Dictionary
+ : kV3Dictionary;
+ const int dictionary_size = (protocol_version() <= SPDY2) ?
+ kV2DictionarySize : kV3DictionarySize;
const DictionaryIds& ids = g_dictionary_ids.Get();
- const uLong dictionary_id = (spdy_version_ < 3) ? ids.v2_dictionary_id
- : ids.v3_dictionary_id;
+ const uLong dictionary_id = (protocol_version() <= SPDY2) ?
+ ids.v2_dictionary_id : ids.v3_dictionary_id;
// Need to try again with the right dictionary.
if (decomp->adler == dictionary_id) {
rv = inflateSetDictionary(decomp,
@@ -2758,7 +2762,7 @@ void SpdyFramer::SerializeNameValueBlockWithoutCompression(
SpdyFrameBuilder* builder,
const SpdyNameValueBlock& name_value_block) const {
// Serialize number of headers.
- if (protocol_version() < 3) {
+ if (protocol_version() <= SPDY2) {
builder->WriteUInt16(name_value_block.size());
} else {
builder->WriteUInt32(name_value_block.size());
@@ -2768,7 +2772,7 @@ void SpdyFramer::SerializeNameValueBlockWithoutCompression(
for (SpdyHeaderBlock::const_iterator it = name_value_block.begin();
it != name_value_block.end();
++it) {
- if (protocol_version() < 3) {
+ if (protocol_version() <= SPDY2) {
builder->WriteString(it->first);
builder->WriteString(it->second);
} else {
@@ -2781,7 +2785,7 @@ void SpdyFramer::SerializeNameValueBlockWithoutCompression(
void SpdyFramer::SerializeNameValueBlock(
SpdyFrameBuilder* builder,
const SpdyFrameWithNameValueBlockIR& frame) {
- CHECK_LT(spdy_version_, 4);
+ CHECK_GE(SPDY3, protocol_version());
if (!enable_compression_) {
return SerializeNameValueBlockWithoutCompression(builder,
frame.name_value_block());
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698