| 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> |
| 11 #include <deque> | 11 #include <deque> |
| 12 #include <utility> | 12 #include <utility> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/big_endian.h" | 15 #include "base/big_endian.h" |
| 16 #include "base/bind.h" | 16 #include "base/bind.h" |
| 17 #include "base/location.h" | 17 #include "base/location.h" |
| 18 #include "base/macros.h" | 18 #include "base/macros.h" |
| 19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
| 20 #include "base/memory/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
| 21 #include "base/metrics/histogram_macros.h" | 21 #include "base/metrics/histogram_macros.h" |
| 22 #include "base/numerics/safe_conversions.h" | 22 #include "base/numerics/safe_conversions.h" |
| 23 #include "base/single_thread_task_runner.h" | 23 #include "base/single_thread_task_runner.h" |
| 24 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
| 25 #include "base/threading/thread_task_runner_handle.h" | 25 #include "base/threading/thread_task_runner_handle.h" |
| 26 #include "base/time/time.h" | 26 #include "base/time/time.h" |
| 27 #include "net/base/io_buffer.h" | 27 #include "net/base/io_buffer.h" |
| 28 #include "net/http/http_network_session.h" // TODO(ricea): Remove | |
| 29 #include "net/http/http_request_headers.h" | 28 #include "net/http/http_request_headers.h" |
| 30 #include "net/http/http_response_headers.h" | 29 #include "net/http/http_response_headers.h" |
| 31 #include "net/http/http_transaction_factory.h" // TODO(ricea): Remove | |
| 32 #include "net/http/http_util.h" | 30 #include "net/http/http_util.h" |
| 33 #include "net/log/net_log.h" | 31 #include "net/log/net_log.h" |
| 34 #include "net/url_request/url_request_context.h" // TODO(ricea): Remove | |
| 35 #include "net/websockets/websocket_errors.h" | 32 #include "net/websockets/websocket_errors.h" |
| 36 #include "net/websockets/websocket_event_interface.h" | 33 #include "net/websockets/websocket_event_interface.h" |
| 37 #include "net/websockets/websocket_frame.h" | 34 #include "net/websockets/websocket_frame.h" |
| 38 #include "net/websockets/websocket_handshake_request_info.h" | 35 #include "net/websockets/websocket_handshake_request_info.h" |
| 39 #include "net/websockets/websocket_handshake_response_info.h" | 36 #include "net/websockets/websocket_handshake_response_info.h" |
| 40 #include "net/websockets/websocket_handshake_stream_create_helper.h" | 37 #include "net/websockets/websocket_handshake_stream_create_helper.h" |
| 41 #include "net/websockets/websocket_mux.h" | 38 #include "net/websockets/websocket_mux.h" |
| 42 #include "net/websockets/websocket_stream.h" | 39 #include "net/websockets/websocket_stream.h" |
| 43 #include "url/origin.h" | 40 #include "url/origin.h" |
| 44 | 41 |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 has_received_close_frame_(false), | 320 has_received_close_frame_(false), |
| 324 received_close_code_(0), | 321 received_close_code_(0), |
| 325 state_(FRESHLY_CONSTRUCTED), | 322 state_(FRESHLY_CONSTRUCTED), |
| 326 notification_sender_(new HandshakeNotificationSender(this)), | 323 notification_sender_(new HandshakeNotificationSender(this)), |
| 327 sending_text_message_(false), | 324 sending_text_message_(false), |
| 328 receiving_text_message_(false), | 325 receiving_text_message_(false), |
| 329 expecting_to_handle_continuation_(false), | 326 expecting_to_handle_continuation_(false), |
| 330 initial_frame_forwarded_(false) {} | 327 initial_frame_forwarded_(false) {} |
| 331 | 328 |
| 332 WebSocketChannel::~WebSocketChannel() { | 329 WebSocketChannel::~WebSocketChannel() { |
| 333 // TODO(ricea): Remove this by October 2016. See bug 641013. | |
| 334 if (stream_) { | |
| 335 HttpTransactionFactory* http_transaction_factory = | |
| 336 url_request_context_->http_transaction_factory(); | |
| 337 if (http_transaction_factory) | |
| 338 http_transaction_factory->GetSession()->DecrementActiveWebSockets(); | |
| 339 } | |
| 340 | |
| 341 // The stream may hold a pointer to read_frames_, and so it needs to be | 330 // The stream may hold a pointer to read_frames_, and so it needs to be |
| 342 // destroyed first. | 331 // destroyed first. |
| 343 stream_.reset(); | 332 stream_.reset(); |
| 344 // The timer may have a callback pointing back to us, so stop it just in case | 333 // The timer may have a callback pointing back to us, so stop it just in case |
| 345 // someone decides to run the event loop from their destructor. | 334 // someone decides to run the event loop from their destructor. |
| 346 close_timer_.Stop(); | 335 close_timer_.Stop(); |
| 347 } | 336 } |
| 348 | 337 |
| 349 void WebSocketChannel::SendAddChannelRequest( | 338 void WebSocketChannel::SendAddChannelRequest( |
| 350 const GURL& socket_url, | 339 const GURL& socket_url, |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 SetState(CONNECTING); | 591 SetState(CONNECTING); |
| 603 } | 592 } |
| 604 | 593 |
| 605 void WebSocketChannel::OnConnectSuccess( | 594 void WebSocketChannel::OnConnectSuccess( |
| 606 std::unique_ptr<WebSocketStream> stream) { | 595 std::unique_ptr<WebSocketStream> stream) { |
| 607 DCHECK(stream); | 596 DCHECK(stream); |
| 608 DCHECK_EQ(CONNECTING, state_); | 597 DCHECK_EQ(CONNECTING, state_); |
| 609 | 598 |
| 610 stream_ = std::move(stream); | 599 stream_ = std::move(stream); |
| 611 | 600 |
| 612 // TODO(ricea): Remove this before October 2016. | |
| 613 HttpTransactionFactory* http_transaction_factory = | |
| 614 url_request_context_->http_transaction_factory(); | |
| 615 if (http_transaction_factory) | |
| 616 http_transaction_factory->GetSession()->IncrementActiveWebSockets(); | |
| 617 | |
| 618 SetState(CONNECTED); | 601 SetState(CONNECTED); |
| 619 | 602 |
| 620 if (event_interface_->OnAddChannelResponse(stream_->GetSubProtocol(), | 603 if (event_interface_->OnAddChannelResponse(stream_->GetSubProtocol(), |
| 621 stream_->GetExtensions()) == | 604 stream_->GetExtensions()) == |
| 622 CHANNEL_DELETED) | 605 CHANNEL_DELETED) |
| 623 return; | 606 return; |
| 624 | 607 |
| 625 // TODO(ricea): Get flow control information from the WebSocketStream once we | 608 // TODO(ricea): Get flow control information from the WebSocketStream once we |
| 626 // have a multiplexing WebSocketStream. | 609 // have a multiplexing WebSocketStream. |
| 627 current_send_quota_ = send_quota_high_water_mark_; | 610 current_send_quota_ = send_quota_high_water_mark_; |
| (...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1198 } | 1181 } |
| 1199 | 1182 |
| 1200 void WebSocketChannel::CloseTimeout() { | 1183 void WebSocketChannel::CloseTimeout() { |
| 1201 stream_->Close(); | 1184 stream_->Close(); |
| 1202 SetState(CLOSED); | 1185 SetState(CLOSED); |
| 1203 DoDropChannel(false, kWebSocketErrorAbnormalClosure, ""); | 1186 DoDropChannel(false, kWebSocketErrorAbnormalClosure, ""); |
| 1204 // |this| has been deleted. | 1187 // |this| has been deleted. |
| 1205 } | 1188 } |
| 1206 | 1189 |
| 1207 } // namespace net | 1190 } // namespace net |
| OLD | NEW |