| 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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 // destroyed first. | 269 // destroyed first. |
| 270 stream_.reset(); | 270 stream_.reset(); |
| 271 // The timer may have a callback pointing back to us, so stop it just in case | 271 // The timer may have a callback pointing back to us, so stop it just in case |
| 272 // someone decides to run the event loop from their destructor. | 272 // someone decides to run the event loop from their destructor. |
| 273 timer_.Stop(); | 273 timer_.Stop(); |
| 274 } | 274 } |
| 275 | 275 |
| 276 void WebSocketChannel::SendAddChannelRequest( | 276 void WebSocketChannel::SendAddChannelRequest( |
| 277 const GURL& socket_url, | 277 const GURL& socket_url, |
| 278 const std::vector<std::string>& requested_subprotocols, | 278 const std::vector<std::string>& requested_subprotocols, |
| 279 const GURL& origin) { | 279 const std::string& origin) { |
| 280 // Delegate to the tested version. | 280 // Delegate to the tested version. |
| 281 SendAddChannelRequestWithSuppliedCreator( | 281 SendAddChannelRequestWithSuppliedCreator( |
| 282 socket_url, | 282 socket_url, |
| 283 requested_subprotocols, | 283 requested_subprotocols, |
| 284 origin, | 284 origin, |
| 285 base::Bind(&WebSocketStream::CreateAndConnectStream)); | 285 base::Bind(&WebSocketStream::CreateAndConnectStream)); |
| 286 } | 286 } |
| 287 | 287 |
| 288 bool WebSocketChannel::InClosingState() const { | 288 bool WebSocketChannel::InClosingState() const { |
| 289 // The state RECV_CLOSED is not supported here, because it is only used in one | 289 // The state RECV_CLOSED is not supported here, because it is only used in one |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 return; | 396 return; |
| 397 } | 397 } |
| 398 AllowUnused(SendClose( | 398 AllowUnused(SendClose( |
| 399 code, StreamingUtf8Validator::Validate(reason) ? reason : std::string())); | 399 code, StreamingUtf8Validator::Validate(reason) ? reason : std::string())); |
| 400 // |this| may have been deleted. | 400 // |this| may have been deleted. |
| 401 } | 401 } |
| 402 | 402 |
| 403 void WebSocketChannel::SendAddChannelRequestForTesting( | 403 void WebSocketChannel::SendAddChannelRequestForTesting( |
| 404 const GURL& socket_url, | 404 const GURL& socket_url, |
| 405 const std::vector<std::string>& requested_subprotocols, | 405 const std::vector<std::string>& requested_subprotocols, |
| 406 const GURL& origin, | 406 const std::string& origin, |
| 407 const WebSocketStreamCreator& creator) { | 407 const WebSocketStreamCreator& creator) { |
| 408 SendAddChannelRequestWithSuppliedCreator( | 408 SendAddChannelRequestWithSuppliedCreator( |
| 409 socket_url, requested_subprotocols, origin, creator); | 409 socket_url, requested_subprotocols, origin, creator); |
| 410 } | 410 } |
| 411 | 411 |
| 412 void WebSocketChannel::SetClosingHandshakeTimeoutForTesting( | 412 void WebSocketChannel::SetClosingHandshakeTimeoutForTesting( |
| 413 base::TimeDelta delay) { | 413 base::TimeDelta delay) { |
| 414 timeout_ = delay; | 414 timeout_ = delay; |
| 415 } | 415 } |
| 416 | 416 |
| 417 void WebSocketChannel::SendAddChannelRequestWithSuppliedCreator( | 417 void WebSocketChannel::SendAddChannelRequestWithSuppliedCreator( |
| 418 const GURL& socket_url, | 418 const GURL& socket_url, |
| 419 const std::vector<std::string>& requested_subprotocols, | 419 const std::vector<std::string>& requested_subprotocols, |
| 420 const GURL& origin, | 420 const std::string& origin, |
| 421 const WebSocketStreamCreator& creator) { | 421 const WebSocketStreamCreator& creator) { |
| 422 DCHECK_EQ(FRESHLY_CONSTRUCTED, state_); | 422 DCHECK_EQ(FRESHLY_CONSTRUCTED, state_); |
| 423 if (!socket_url.SchemeIsWSOrWSS()) { | 423 if (!socket_url.SchemeIsWSOrWSS()) { |
| 424 // TODO(ricea): Kill the renderer (this error should have been caught by | 424 // TODO(ricea): Kill the renderer (this error should have been caught by |
| 425 // Javascript). | 425 // Javascript). |
| 426 AllowUnused(event_interface_->OnAddChannelResponse(true, "", "")); | 426 AllowUnused(event_interface_->OnAddChannelResponse(true, "", "")); |
| 427 // |this| is deleted here. | 427 // |this| is deleted here. |
| 428 return; | 428 return; |
| 429 } | 429 } |
| 430 socket_url_ = socket_url; | 430 socket_url_ = socket_url; |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 | 942 |
| 943 void WebSocketChannel::CloseTimeout() { | 943 void WebSocketChannel::CloseTimeout() { |
| 944 stream_->Close(); | 944 stream_->Close(); |
| 945 DCHECK_NE(CLOSED, state_); | 945 DCHECK_NE(CLOSED, state_); |
| 946 state_ = CLOSED; | 946 state_ = CLOSED; |
| 947 AllowUnused(DoDropChannel(false, kWebSocketErrorAbnormalClosure, "")); | 947 AllowUnused(DoDropChannel(false, kWebSocketErrorAbnormalClosure, "")); |
| 948 // |this| has been deleted. | 948 // |this| has been deleted. |
| 949 } | 949 } |
| 950 | 950 |
| 951 } // namespace net | 951 } // namespace net |
| OLD | NEW |