Chromium Code Reviews| Index: net/websockets/websocket_basic_handshake_stream.cc |
| diff --git a/net/websockets/websocket_basic_handshake_stream.cc b/net/websockets/websocket_basic_handshake_stream.cc |
| index 2eee942478e92be827f9163c76c96a0d2ee9f947..0688ac88335197eaf5319fa1965a3690c5f6a3bd 100644 |
| --- a/net/websockets/websocket_basic_handshake_stream.cc |
| +++ b/net/websockets/websocket_basic_handshake_stream.cc |
| @@ -13,6 +13,7 @@ |
| #include "base/base64.h" |
| #include "base/basictypes.h" |
| #include "base/bind.h" |
| +#include "base/compiler_specific.h" |
| #include "base/containers/hash_tables.h" |
| #include "base/logging.h" |
| #include "base/metrics/histogram.h" |
| @@ -46,6 +47,34 @@ |
| namespace net { |
| +namespace { |
|
Adam Rice
2014/10/30 05:54:25
Please at a TODO to remove these once the bug is f
yhirano
2014/10/30 06:10:10
Done.
|
| + |
| +NOINLINE void RunCallbackWithOk(const CompletionCallback& callback, |
| + int result) { |
| + DCHECK_EQ(result, OK); |
| + callback.Run(OK); |
| +} |
| + |
| +NOINLINE void RunCallbackWithInvalidResponseCausedByRedirect( |
| + const CompletionCallback& callback, |
| + int result) { |
| + DCHECK_EQ(result, ERR_INVALID_RESPONSE); |
| + callback.Run(ERR_INVALID_RESPONSE); |
| +} |
| + |
| +NOINLINE void RunCallbackWithInvalidResponse( |
| + const CompletionCallback& callback, |
| + int result) { |
| + DCHECK_EQ(result, ERR_INVALID_RESPONSE); |
| + callback.Run(ERR_INVALID_RESPONSE); |
| +} |
| + |
| +NOINLINE void RunCallback(const CompletionCallback& callback, int result) { |
| + callback.Run(result); |
| +} |
| + |
| +} // namespace |
| + |
| // TODO(ricea): If more extensions are added, replace this with a more general |
| // mechanism. |
| struct WebSocketExtensionParams { |
| @@ -430,7 +459,8 @@ int WebSocketBasicHandshakeStream::ReadResponseHeaders( |
| callback)); |
| if (rv == ERR_IO_PENDING) |
| return rv; |
| - return ValidateResponse(rv); |
| + bool is_redirect = false; |
| + return ValidateResponse(rv, &is_redirect); |
| } |
| int WebSocketBasicHandshakeStream::ReadResponseBody( |
| @@ -535,7 +565,23 @@ void WebSocketBasicHandshakeStream::SetWebSocketKeyForTesting( |
| void WebSocketBasicHandshakeStream::ReadResponseHeadersCallback( |
| const CompletionCallback& callback, |
| int result) { |
| - callback.Run(ValidateResponse(result)); |
| + bool is_redirect = false; |
| + int rv = ValidateResponse(result, &is_redirect); |
| + |
| + switch (rv) { |
| + case OK: |
| + RunCallbackWithOk(callback, rv); |
| + break; |
| + case ERR_INVALID_RESPONSE: |
| + if (is_redirect) |
| + RunCallbackWithInvalidResponseCausedByRedirect(callback, rv); |
| + else |
| + RunCallbackWithInvalidResponse(callback, rv); |
| + break; |
| + default: |
| + RunCallback(callback, rv); |
| + break; |
| + } |
| } |
| void WebSocketBasicHandshakeStream::OnFinishOpeningHandshake() { |
| @@ -546,14 +592,17 @@ void WebSocketBasicHandshakeStream::OnFinishOpeningHandshake() { |
| http_response_info_->response_time); |
| } |
| -int WebSocketBasicHandshakeStream::ValidateResponse(int rv) { |
| +int WebSocketBasicHandshakeStream::ValidateResponse(int rv, |
| + bool* is_redirect) { |
| DCHECK(http_response_info_); |
| + *is_redirect = false; |
| // Most net errors happen during connection, so they are not seen by this |
| // method. The histogram for error codes is created in |
| // Delegate::OnResponseStarted in websocket_stream.cc instead. |
| if (rv >= 0) { |
| const HttpResponseHeaders* headers = http_response_info_->headers.get(); |
| const int response_code = headers->response_code(); |
| + *is_redirect = HttpResponseHeaders::IsRedirectResponseCode(response_code); |
| UMA_HISTOGRAM_SPARSE_SLOWLY("Net.WebSocket.ResponseCode", response_code); |
| switch (response_code) { |
| case HTTP_SWITCHING_PROTOCOLS: |