| 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_channel.h" | 5 #include "net/websockets/websocket_channel.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/basictypes.h" // for size_t | 9 #include "base/basictypes.h" // for size_t |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 class WebSocketChannel::ConnectDelegate | 105 class WebSocketChannel::ConnectDelegate |
| 106 : public WebSocketStream::ConnectDelegate { | 106 : public WebSocketStream::ConnectDelegate { |
| 107 public: | 107 public: |
| 108 explicit ConnectDelegate(WebSocketChannel* creator) : creator_(creator) {} | 108 explicit ConnectDelegate(WebSocketChannel* creator) : creator_(creator) {} |
| 109 | 109 |
| 110 virtual void OnSuccess(scoped_ptr<WebSocketStream> stream) OVERRIDE { | 110 virtual void OnSuccess(scoped_ptr<WebSocketStream> stream) OVERRIDE { |
| 111 creator_->OnConnectSuccess(stream.Pass()); | 111 creator_->OnConnectSuccess(stream.Pass()); |
| 112 // |this| may have been deleted. | 112 // |this| may have been deleted. |
| 113 } | 113 } |
| 114 | 114 |
| 115 virtual void OnFailure(uint16 websocket_error) OVERRIDE { | 115 virtual void OnFailure(const std::string& message) OVERRIDE { |
| 116 creator_->OnConnectFailure(websocket_error); | 116 creator_->OnConnectFailure(message); |
| 117 // |this| has been deleted. | 117 // |this| has been deleted. |
| 118 } | 118 } |
| 119 | 119 |
| 120 private: | 120 private: |
| 121 // A pointer to the WebSocketChannel that created this object. There is no | 121 // A pointer to the WebSocketChannel that created this object. There is no |
| 122 // danger of this pointer being stale, because deleting the WebSocketChannel | 122 // danger of this pointer being stale, because deleting the WebSocketChannel |
| 123 // cancels the connect process, deleting this object and preventing its | 123 // cancels the connect process, deleting this object and preventing its |
| 124 // callbacks from being called. | 124 // callbacks from being called. |
| 125 WebSocketChannel* const creator_; | 125 WebSocketChannel* const creator_; |
| 126 | 126 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 if (event_interface_->OnFlowControl(send_quota_high_water_mark_) == | 304 if (event_interface_->OnFlowControl(send_quota_high_water_mark_) == |
| 305 CHANNEL_DELETED) | 305 CHANNEL_DELETED) |
| 306 return; | 306 return; |
| 307 | 307 |
| 308 // |stream_request_| is not used once the connection has succeeded. | 308 // |stream_request_| is not used once the connection has succeeded. |
| 309 stream_request_.reset(); | 309 stream_request_.reset(); |
| 310 AllowUnused(ReadFrames()); | 310 AllowUnused(ReadFrames()); |
| 311 // |this| may have been deleted. | 311 // |this| may have been deleted. |
| 312 } | 312 } |
| 313 | 313 |
| 314 void WebSocketChannel::OnConnectFailure(uint16 websocket_error) { | 314 void WebSocketChannel::OnConnectFailure(const std::string& message) { |
| 315 DCHECK_EQ(CONNECTING, state_); | 315 DCHECK_EQ(CONNECTING, state_); |
| 316 state_ = CLOSED; | 316 state_ = CLOSED; |
| 317 stream_request_.reset(); | 317 stream_request_.reset(); |
| 318 AllowUnused(event_interface_->OnAddChannelResponse(true, "")); | 318 AllowUnused(event_interface_->OnFailChannel(message)); |
| 319 // |this| has been deleted. | 319 // |this| has been deleted. |
| 320 } | 320 } |
| 321 | 321 |
| 322 ChannelState WebSocketChannel::WriteFrames() { | 322 ChannelState WebSocketChannel::WriteFrames() { |
| 323 int result = OK; | 323 int result = OK; |
| 324 do { | 324 do { |
| 325 // This use of base::Unretained is safe because this object owns the | 325 // This use of base::Unretained is safe because this object owns the |
| 326 // WebSocketStream and destroying it cancels all callbacks. | 326 // WebSocketStream and destroying it cancels all callbacks. |
| 327 result = stream_->WriteFrames( | 327 result = stream_->WriteFrames( |
| 328 data_being_sent_->frames(), | 328 data_being_sent_->frames(), |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 void WebSocketChannel::CloseTimeout() { | 711 void WebSocketChannel::CloseTimeout() { |
| 712 stream_->Close(); | 712 stream_->Close(); |
| 713 DCHECK_NE(CLOSED, state_); | 713 DCHECK_NE(CLOSED, state_); |
| 714 state_ = CLOSED; | 714 state_ = CLOSED; |
| 715 AllowUnused(event_interface_->OnDropChannel(kWebSocketErrorAbnormalClosure, | 715 AllowUnused(event_interface_->OnDropChannel(kWebSocketErrorAbnormalClosure, |
| 716 "Abnormal Closure")); | 716 "Abnormal Closure")); |
| 717 // |this| has been deleted. | 717 // |this| has been deleted. |
| 718 } | 718 } |
| 719 | 719 |
| 720 } // namespace net | 720 } // namespace net |
| OLD | NEW |