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 <limits.h> // for INT_MAX | 7 #include <limits.h> // for INT_MAX |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 // destroyed first. | 330 // destroyed first. |
331 stream_.reset(); | 331 stream_.reset(); |
332 // The timer may have a callback pointing back to us, so stop it just in case | 332 // The timer may have a callback pointing back to us, so stop it just in case |
333 // someone decides to run the event loop from their destructor. | 333 // someone decides to run the event loop from their destructor. |
334 close_timer_.Stop(); | 334 close_timer_.Stop(); |
335 } | 335 } |
336 | 336 |
337 void WebSocketChannel::SendAddChannelRequest( | 337 void WebSocketChannel::SendAddChannelRequest( |
338 const GURL& socket_url, | 338 const GURL& socket_url, |
339 const std::vector<std::string>& requested_subprotocols, | 339 const std::vector<std::string>& requested_subprotocols, |
340 const url::Origin& origin) { | 340 const url::Origin& origin, |
| 341 const std::string& additional_headers) { |
341 // Delegate to the tested version. | 342 // Delegate to the tested version. |
342 SendAddChannelRequestWithSuppliedCreator( | 343 SendAddChannelRequestWithSuppliedCreator( |
343 socket_url, | 344 socket_url, requested_subprotocols, origin, additional_headers, |
344 requested_subprotocols, | |
345 origin, | |
346 base::Bind(&WebSocketStream::CreateAndConnectStream)); | 345 base::Bind(&WebSocketStream::CreateAndConnectStream)); |
347 } | 346 } |
348 | 347 |
349 void WebSocketChannel::SetState(State new_state) { | 348 void WebSocketChannel::SetState(State new_state) { |
350 DCHECK_NE(state_, new_state); | 349 DCHECK_NE(state_, new_state); |
351 | 350 |
352 if (new_state == CONNECTED) | 351 if (new_state == CONNECTED) |
353 established_on_ = base::TimeTicks::Now(); | 352 established_on_ = base::TimeTicks::Now(); |
354 if (state_ == CONNECTED && !established_on_.is_null()) { | 353 if (state_ == CONNECTED && !established_on_.is_null()) { |
355 UMA_HISTOGRAM_LONG_TIMES( | 354 UMA_HISTOGRAM_LONG_TIMES( |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 return CHANNEL_DELETED; | 537 return CHANNEL_DELETED; |
539 DCHECK_EQ(CONNECTED, state_); | 538 DCHECK_EQ(CONNECTED, state_); |
540 SetState(SEND_CLOSED); | 539 SetState(SEND_CLOSED); |
541 return CHANNEL_ALIVE; | 540 return CHANNEL_ALIVE; |
542 } | 541 } |
543 | 542 |
544 void WebSocketChannel::SendAddChannelRequestForTesting( | 543 void WebSocketChannel::SendAddChannelRequestForTesting( |
545 const GURL& socket_url, | 544 const GURL& socket_url, |
546 const std::vector<std::string>& requested_subprotocols, | 545 const std::vector<std::string>& requested_subprotocols, |
547 const url::Origin& origin, | 546 const url::Origin& origin, |
| 547 const std::string& additional_headers, |
548 const WebSocketStreamCreator& creator) { | 548 const WebSocketStreamCreator& creator) { |
549 SendAddChannelRequestWithSuppliedCreator( | 549 SendAddChannelRequestWithSuppliedCreator(socket_url, requested_subprotocols, |
550 socket_url, requested_subprotocols, origin, creator); | 550 origin, additional_headers, creator); |
551 } | 551 } |
552 | 552 |
553 void WebSocketChannel::SetClosingHandshakeTimeoutForTesting( | 553 void WebSocketChannel::SetClosingHandshakeTimeoutForTesting( |
554 base::TimeDelta delay) { | 554 base::TimeDelta delay) { |
555 closing_handshake_timeout_ = delay; | 555 closing_handshake_timeout_ = delay; |
556 } | 556 } |
557 | 557 |
558 void WebSocketChannel::SetUnderlyingConnectionCloseTimeoutForTesting( | 558 void WebSocketChannel::SetUnderlyingConnectionCloseTimeoutForTesting( |
559 base::TimeDelta delay) { | 559 base::TimeDelta delay) { |
560 underlying_connection_close_timeout_ = delay; | 560 underlying_connection_close_timeout_ = delay; |
561 } | 561 } |
562 | 562 |
563 void WebSocketChannel::SendAddChannelRequestWithSuppliedCreator( | 563 void WebSocketChannel::SendAddChannelRequestWithSuppliedCreator( |
564 const GURL& socket_url, | 564 const GURL& socket_url, |
565 const std::vector<std::string>& requested_subprotocols, | 565 const std::vector<std::string>& requested_subprotocols, |
566 const url::Origin& origin, | 566 const url::Origin& origin, |
| 567 const std::string& additional_headers, |
567 const WebSocketStreamCreator& creator) { | 568 const WebSocketStreamCreator& creator) { |
568 DCHECK_EQ(FRESHLY_CONSTRUCTED, state_); | 569 DCHECK_EQ(FRESHLY_CONSTRUCTED, state_); |
569 if (!socket_url.SchemeIsWSOrWSS()) { | 570 if (!socket_url.SchemeIsWSOrWSS()) { |
570 // TODO(ricea): Kill the renderer (this error should have been caught by | 571 // TODO(ricea): Kill the renderer (this error should have been caught by |
571 // Javascript). | 572 // Javascript). |
572 ignore_result(event_interface_->OnFailChannel("Invalid scheme")); | 573 ignore_result(event_interface_->OnFailChannel("Invalid scheme")); |
573 // |this| is deleted here. | 574 // |this| is deleted here. |
574 return; | 575 return; |
575 } | 576 } |
576 socket_url_ = socket_url; | 577 socket_url_ = socket_url; |
577 std::unique_ptr<WebSocketStream::ConnectDelegate> connect_delegate( | 578 std::unique_ptr<WebSocketStream::ConnectDelegate> connect_delegate( |
578 new ConnectDelegate(this)); | 579 new ConnectDelegate(this)); |
579 stream_request_ = creator.Run(socket_url_, requested_subprotocols, origin, | 580 stream_request_ = creator.Run(socket_url_, requested_subprotocols, origin, |
580 url_request_context_, BoundNetLog(), | 581 additional_headers, url_request_context_, |
581 std::move(connect_delegate)); | 582 BoundNetLog(), std::move(connect_delegate)); |
582 SetState(CONNECTING); | 583 SetState(CONNECTING); |
583 } | 584 } |
584 | 585 |
585 void WebSocketChannel::OnConnectSuccess( | 586 void WebSocketChannel::OnConnectSuccess( |
586 std::unique_ptr<WebSocketStream> stream) { | 587 std::unique_ptr<WebSocketStream> stream) { |
587 DCHECK(stream); | 588 DCHECK(stream); |
588 DCHECK_EQ(CONNECTING, state_); | 589 DCHECK_EQ(CONNECTING, state_); |
589 | 590 |
590 stream_ = std::move(stream); | 591 stream_ = std::move(stream); |
591 | 592 |
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1172 } | 1173 } |
1173 | 1174 |
1174 void WebSocketChannel::CloseTimeout() { | 1175 void WebSocketChannel::CloseTimeout() { |
1175 stream_->Close(); | 1176 stream_->Close(); |
1176 SetState(CLOSED); | 1177 SetState(CLOSED); |
1177 DoDropChannel(false, kWebSocketErrorAbnormalClosure, ""); | 1178 DoDropChannel(false, kWebSocketErrorAbnormalClosure, ""); |
1178 // |this| has been deleted. | 1179 // |this| has been deleted. |
1179 } | 1180 } |
1180 | 1181 |
1181 } // namespace net | 1182 } // namespace net |
OLD | NEW |