summaryrefslogtreecommitdiffstats
path: root/net/websockets
diff options
context:
space:
mode:
authortyoshino@chromium.org <tyoshino@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-19 05:55:13 +0000
committertyoshino@chromium.org <tyoshino@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-19 05:55:13 +0000
commitc4432939ffbacd0b7aedded5ecb604a366c2310e (patch)
treeff4f0ca47c7add267d8df8735a54fe4d6c04f845 /net/websockets
parent945af5d4222904b49163594cd72ffe3c4ba99dbb (diff)
downloadchromium_src-c4432939ffbacd0b7aedded5ecb604a366c2310e.zip
chromium_src-c4432939ffbacd0b7aedded5ecb604a366c2310e.tar.gz
chromium_src-c4432939ffbacd0b7aedded5ecb604a366c2310e.tar.bz2
Reduce a variable and indentation in WebSocketChannel::ParseClose()
BUG=none Review URL: https://codereview.chromium.org/195733014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@257856 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/websockets')
-rw-r--r--net/websockets/websocket_channel.cc48
1 files changed, 24 insertions, 24 deletions
diff --git a/net/websockets/websocket_channel.cc b/net/websockets/websocket_channel.cc
index 953d4f7..e8122b6 100644
--- a/net/websockets/websocket_channel.cc
+++ b/net/websockets/websocket_channel.cc
@@ -904,26 +904,28 @@ bool WebSocketChannel::ParseClose(const scoped_refptr<IOBuffer>& buffer,
uint16* code,
std::string* reason,
std::string* message) {
- bool parsed_ok = true;
reason->clear();
if (size < kWebSocketCloseCodeLength) {
- *code = kWebSocketErrorNoStatusReceived;
- if (size != 0) {
- DVLOG(1) << "Close frame with payload size " << size << " received "
- << "(the first byte is " << std::hex
- << static_cast<int>(buffer->data()[0]) << ")";
- parsed_ok = false;
- *code = kWebSocketErrorProtocolError;
- *message =
- "Received a broken close frame containing an invalid size body.";
+ if (size == 0U) {
+ *code = kWebSocketErrorNoStatusReceived;
+ return true;
}
- return parsed_ok;
+
+ DVLOG(1) << "Close frame with payload size " << size << " received "
+ << "(the first byte is " << std::hex
+ << static_cast<int>(buffer->data()[0]) << ")";
+ *code = kWebSocketErrorProtocolError;
+ *message =
+ "Received a broken close frame containing an invalid size body.";
+ return false;
}
+
const char* data = buffer->data();
uint16 unchecked_code = 0;
base::ReadBigEndian(data, &unchecked_code);
COMPILE_ASSERT(sizeof(unchecked_code) == kWebSocketCloseCodeLength,
they_should_both_be_two_bytes);
+
switch (unchecked_code) {
case kWebSocketErrorNoStatusReceived:
case kWebSocketErrorAbnormalClosure:
@@ -931,25 +933,23 @@ bool WebSocketChannel::ParseClose(const scoped_refptr<IOBuffer>& buffer,
*code = kWebSocketErrorProtocolError;
*message =
"Received a broken close frame containing a reserved status code.";
- parsed_ok = false;
- break;
+ return false;
default:
*code = unchecked_code;
break;
}
- if (parsed_ok) {
- std::string text(data + kWebSocketCloseCodeLength, data + size);
- if (StreamingUtf8Validator::Validate(text)) {
- reason->swap(text);
- } else {
- *code = kWebSocketErrorProtocolError;
- *reason = "Invalid UTF-8 in Close frame";
- *message = "Received a broken close frame containing invalid UTF-8.";
- parsed_ok = false;
- }
+
+ std::string text(data + kWebSocketCloseCodeLength, data + size);
+ if (StreamingUtf8Validator::Validate(text)) {
+ reason->swap(text);
+ return true;
}
- return parsed_ok;
+
+ *code = kWebSocketErrorProtocolError;
+ *reason = "Invalid UTF-8 in Close frame";
+ *message = "Received a broken close frame containing invalid UTF-8.";
+ return false;
}
ChannelState WebSocketChannel::DoDropChannel(bool was_clean,