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()) { | |
tyoshino (SeeGerritForStatus)
2014/01/09 05:52:05
how about listing all cases so that -Wswitch-enum
yhirano
2014/01/09 06:04:19
Done.
| |
78 case URLRequestStatus::CANCELED: | |
79 failure_message = "WebSocket opening handshake was canceled"; | |
80 break; | |
81 case URLRequestStatus::FAILED: | |
82 failure_message = | |
83 std::string("Error in connection establishment: ") + | |
84 ErrorToString(url_request_.status().error()); | |
85 break; | |
86 default: | |
87 break; | |
88 } | |
89 } | |
90 connect_delegate_->OnFailure(failure_message); | |
74 } | 91 } |
75 | 92 |
76 private: | 93 private: |
77 // |delegate_| needs to be declared before |url_request_| so that it gets | 94 // |delegate_| needs to be declared before |url_request_| so that it gets |
78 // initialised first. | 95 // initialised first. |
79 scoped_ptr<Delegate> delegate_; | 96 scoped_ptr<Delegate> delegate_; |
80 | 97 |
81 // Deleting the StreamRequestImpl object deletes this URLRequest object, | 98 // Deleting the StreamRequestImpl object deletes this URLRequest object, |
82 // cancelling the whole connection. | 99 // cancelling the whole connection. |
83 URLRequest url_request_; | 100 URLRequest url_request_; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) { | 207 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) { |
191 return CreateAndConnectStreamWithCreateHelper(socket_url, | 208 return CreateAndConnectStreamWithCreateHelper(socket_url, |
192 create_helper.Pass(), | 209 create_helper.Pass(), |
193 origin, | 210 origin, |
194 url_request_context, | 211 url_request_context, |
195 net_log, | 212 net_log, |
196 connect_delegate.Pass()); | 213 connect_delegate.Pass()); |
197 } | 214 } |
198 | 215 |
199 } // namespace net | 216 } // namespace net |
OLD | NEW |