| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/websockets/websocket_stream.h" | 5 #include "net/websockets/websocket_stream.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "net/http/http_request_headers.h" | 9 #include "net/http/http_request_headers.h" |
| 10 #include "net/http/http_status_code.h" | 10 #include "net/http/http_status_code.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 // and so terminates the handshake if it is incomplete. | 63 // and so terminates the handshake if it is incomplete. |
| 64 virtual ~StreamRequestImpl() {} | 64 virtual ~StreamRequestImpl() {} |
| 65 | 65 |
| 66 URLRequest* url_request() { return &url_request_; } | 66 URLRequest* url_request() { return &url_request_; } |
| 67 | 67 |
| 68 void PerformUpgrade() { | 68 void PerformUpgrade() { |
| 69 connect_delegate_->OnSuccess(create_helper_->stream()->Upgrade()); | 69 connect_delegate_->OnSuccess(create_helper_->stream()->Upgrade()); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void ReportFailure() { | 72 void ReportFailure() { |
| 73 connect_delegate_->OnFailure(kWebSocketErrorAbnormalClosure); | 73 std::string failure_message; |
| 74 if (create_helper_->stream()) { |
| 75 failure_message = create_helper_->stream()->GetFailureMessage(); |
| 76 } else { |
| 77 switch (url_request_.status().status()) { |
| 78 case URLRequestStatus::SUCCESS: |
| 79 case URLRequestStatus::IO_PENDING: |
| 80 break; |
| 81 case URLRequestStatus::CANCELED: |
| 82 failure_message = "WebSocket opening handshake was canceled"; |
| 83 break; |
| 84 case URLRequestStatus::FAILED: |
| 85 failure_message = |
| 86 std::string("Error in connection establishment: ") + |
| 87 ErrorToString(url_request_.status().error()); |
| 88 break; |
| 89 } |
| 90 } |
| 91 connect_delegate_->OnFailure(failure_message); |
| 74 } | 92 } |
| 75 | 93 |
| 76 private: | 94 private: |
| 77 // |delegate_| needs to be declared before |url_request_| so that it gets | 95 // |delegate_| needs to be declared before |url_request_| so that it gets |
| 78 // initialised first. | 96 // initialised first. |
| 79 scoped_ptr<Delegate> delegate_; | 97 scoped_ptr<Delegate> delegate_; |
| 80 | 98 |
| 81 // Deleting the StreamRequestImpl object deletes this URLRequest object, | 99 // Deleting the StreamRequestImpl object deletes this URLRequest object, |
| 82 // cancelling the whole connection. | 100 // cancelling the whole connection. |
| 83 URLRequest url_request_; | 101 URLRequest url_request_; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) { | 208 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) { |
| 191 return CreateAndConnectStreamWithCreateHelper(socket_url, | 209 return CreateAndConnectStreamWithCreateHelper(socket_url, |
| 192 create_helper.Pass(), | 210 create_helper.Pass(), |
| 193 origin, | 211 origin, |
| 194 url_request_context, | 212 url_request_context, |
| 195 net_log, | 213 net_log, |
| 196 connect_delegate.Pass()); | 214 connect_delegate.Pass()); |
| 197 } | 215 } |
| 198 | 216 |
| 199 } // namespace net | 217 } // namespace net |
| OLD | NEW |