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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 if (event_interface_->OnFlowControl(send_quota_high_water_mark_) == | 305 if (event_interface_->OnFlowControl(send_quota_high_water_mark_) == |
306 CHANNEL_DELETED) | 306 CHANNEL_DELETED) |
307 return; | 307 return; |
308 | 308 |
309 // |stream_request_| is not used once the connection has succeeded. | 309 // |stream_request_| is not used once the connection has succeeded. |
310 stream_request_.reset(); | 310 stream_request_.reset(); |
311 AllowUnused(ReadFrames()); | 311 AllowUnused(ReadFrames()); |
312 // |this| may have been deleted. | 312 // |this| may have been deleted. |
313 } | 313 } |
314 | 314 |
315 void WebSocketChannel::OnConnectFailure(uint16 websocket_error) { | 315 void WebSocketChannel::OnConnectFailure(const std::string& message) { |
316 DCHECK_EQ(CONNECTING, state_); | 316 DCHECK_EQ(CONNECTING, state_); |
317 state_ = CLOSED; | 317 state_ = CLOSED; |
318 stream_request_.reset(); | 318 stream_request_.reset(); |
319 AllowUnused(event_interface_->OnAddChannelResponse(true, "")); | 319 AllowUnused(event_interface_->OnFailChannel(message)); |
320 // |this| has been deleted. | 320 // |this| has been deleted. |
321 } | 321 } |
322 | 322 |
323 ChannelState WebSocketChannel::WriteFrames() { | 323 ChannelState WebSocketChannel::WriteFrames() { |
324 int result = OK; | 324 int result = OK; |
325 do { | 325 do { |
326 // This use of base::Unretained is safe because this object owns the | 326 // This use of base::Unretained is safe because this object owns the |
327 // WebSocketStream and destroying it cancels all callbacks. | 327 // WebSocketStream and destroying it cancels all callbacks. |
328 result = stream_->WriteFrames( | 328 result = stream_->WriteFrames( |
329 data_being_sent_->frames(), | 329 data_being_sent_->frames(), |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 void WebSocketChannel::CloseTimeout() { | 712 void WebSocketChannel::CloseTimeout() { |
713 stream_->Close(); | 713 stream_->Close(); |
714 DCHECK_NE(CLOSED, state_); | 714 DCHECK_NE(CLOSED, state_); |
715 state_ = CLOSED; | 715 state_ = CLOSED; |
716 AllowUnused(event_interface_->OnDropChannel(kWebSocketErrorAbnormalClosure, | 716 AllowUnused(event_interface_->OnDropChannel(kWebSocketErrorAbnormalClosure, |
717 "Abnormal Closure")); | 717 "Abnormal Closure")); |
718 // |this| has been deleted. | 718 // |this| has been deleted. |
719 } | 719 } |
720 | 720 |
721 } // namespace net | 721 } // namespace net |
OLD | NEW |