| 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 // The timer may have a callback pointing back to us, so stop it just in case | 145 // The timer may have a callback pointing back to us, so stop it just in case |
| 146 // someone decides to run the event loop from their destructor. | 146 // someone decides to run the event loop from their destructor. |
| 147 timer_.Stop(); | 147 timer_.Stop(); |
| 148 } | 148 } |
| 149 | 149 |
| 150 void WebSocketChannel::SendAddChannelRequest( | 150 void WebSocketChannel::SendAddChannelRequest( |
| 151 const GURL& socket_url, | 151 const GURL& socket_url, |
| 152 const std::vector<std::string>& requested_subprotocols, | 152 const std::vector<std::string>& requested_subprotocols, |
| 153 const GURL& origin) { | 153 const GURL& origin) { |
| 154 // Delegate to the tested version. | 154 // Delegate to the tested version. |
| 155 SendAddChannelRequestWithFactory( | 155 SendAddChannelRequestWithSuppliedCreator( |
| 156 socket_url, | 156 socket_url, |
| 157 requested_subprotocols, | 157 requested_subprotocols, |
| 158 origin, | 158 origin, |
| 159 base::Bind(&WebSocketStream::CreateAndConnectStream)); | 159 base::Bind(&WebSocketStream::CreateAndConnectStream)); |
| 160 } | 160 } |
| 161 | 161 |
| 162 bool WebSocketChannel::InClosingState() const { | 162 bool WebSocketChannel::InClosingState() const { |
| 163 // The state RECV_CLOSED is not supported here, because it is only used in one | 163 // The state RECV_CLOSED is not supported here, because it is only used in one |
| 164 // code path and should not leak into the code in general. | 164 // code path and should not leak into the code in general. |
| 165 DCHECK_NE(RECV_CLOSED, state_) | 165 DCHECK_NE(RECV_CLOSED, state_) |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 return; | 246 return; |
| 247 } | 247 } |
| 248 AllowUnused(SendClose(code, IsStringUTF8(reason) ? reason : std::string())); | 248 AllowUnused(SendClose(code, IsStringUTF8(reason) ? reason : std::string())); |
| 249 // |this| may have been deleted. | 249 // |this| may have been deleted. |
| 250 } | 250 } |
| 251 | 251 |
| 252 void WebSocketChannel::SendAddChannelRequestForTesting( | 252 void WebSocketChannel::SendAddChannelRequestForTesting( |
| 253 const GURL& socket_url, | 253 const GURL& socket_url, |
| 254 const std::vector<std::string>& requested_subprotocols, | 254 const std::vector<std::string>& requested_subprotocols, |
| 255 const GURL& origin, | 255 const GURL& origin, |
| 256 const WebSocketStreamFactory& factory) { | 256 const WebSocketStreamCreator& creator) { |
| 257 SendAddChannelRequestWithFactory( | 257 SendAddChannelRequestWithSuppliedCreator( |
| 258 socket_url, requested_subprotocols, origin, factory); | 258 socket_url, requested_subprotocols, origin, creator); |
| 259 } | 259 } |
| 260 | 260 |
| 261 void WebSocketChannel::SetClosingHandshakeTimeoutForTesting( | 261 void WebSocketChannel::SetClosingHandshakeTimeoutForTesting( |
| 262 base::TimeDelta delay) { | 262 base::TimeDelta delay) { |
| 263 timeout_ = delay; | 263 timeout_ = delay; |
| 264 } | 264 } |
| 265 | 265 |
| 266 void WebSocketChannel::SendAddChannelRequestWithFactory( | 266 void WebSocketChannel::SendAddChannelRequestWithSuppliedCreator( |
| 267 const GURL& socket_url, | 267 const GURL& socket_url, |
| 268 const std::vector<std::string>& requested_subprotocols, | 268 const std::vector<std::string>& requested_subprotocols, |
| 269 const GURL& origin, | 269 const GURL& origin, |
| 270 const WebSocketStreamFactory& factory) { | 270 const WebSocketStreamCreator& creator) { |
| 271 DCHECK_EQ(FRESHLY_CONSTRUCTED, state_); | 271 DCHECK_EQ(FRESHLY_CONSTRUCTED, state_); |
| 272 socket_url_ = socket_url; | 272 socket_url_ = socket_url; |
| 273 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate( | 273 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate( |
| 274 new ConnectDelegate(this)); | 274 new ConnectDelegate(this)); |
| 275 stream_request_ = factory.Run(socket_url_, | 275 stream_request_ = creator.Run(socket_url_, |
| 276 requested_subprotocols, | 276 requested_subprotocols, |
| 277 origin, | 277 origin, |
| 278 url_request_context_, | 278 url_request_context_, |
| 279 BoundNetLog(), | 279 BoundNetLog(), |
| 280 connect_delegate.Pass()); | 280 connect_delegate.Pass()); |
| 281 state_ = CONNECTING; | 281 state_ = CONNECTING; |
| 282 } | 282 } |
| 283 | 283 |
| 284 void WebSocketChannel::OnConnectSuccess(scoped_ptr<WebSocketStream> stream) { | 284 void WebSocketChannel::OnConnectSuccess(scoped_ptr<WebSocketStream> stream) { |
| 285 DCHECK(stream); | 285 DCHECK(stream); |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 void WebSocketChannel::CloseTimeout() { | 704 void WebSocketChannel::CloseTimeout() { |
| 705 stream_->Close(); | 705 stream_->Close(); |
| 706 DCHECK_NE(CLOSED, state_); | 706 DCHECK_NE(CLOSED, state_); |
| 707 state_ = CLOSED; | 707 state_ = CLOSED; |
| 708 AllowUnused(event_interface_->OnDropChannel(kWebSocketErrorAbnormalClosure, | 708 AllowUnused(event_interface_->OnDropChannel(kWebSocketErrorAbnormalClosure, |
| 709 "Abnormal Closure")); | 709 "Abnormal Closure")); |
| 710 // |this| has been deleted. | 710 // |this| has been deleted. |
| 711 } | 711 } |
| 712 | 712 |
| 713 } // namespace net | 713 } // namespace net |
| OLD | NEW |