| 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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 frames_.push_back(std::move(frame)); | 168 frames_.push_back(std::move(frame)); |
| 169 } | 169 } |
| 170 | 170 |
| 171 // Implementation of WebSocketStream::ConnectDelegate that simply forwards the | 171 // Implementation of WebSocketStream::ConnectDelegate that simply forwards the |
| 172 // calls on to the WebSocketChannel that created it. | 172 // calls on to the WebSocketChannel that created it. |
| 173 class WebSocketChannel::ConnectDelegate | 173 class WebSocketChannel::ConnectDelegate |
| 174 : public WebSocketStream::ConnectDelegate { | 174 : public WebSocketStream::ConnectDelegate { |
| 175 public: | 175 public: |
| 176 explicit ConnectDelegate(WebSocketChannel* creator) : creator_(creator) {} | 176 explicit ConnectDelegate(WebSocketChannel* creator) : creator_(creator) {} |
| 177 | 177 |
| 178 void OnCreateRequest(net::URLRequest* request) override { |
| 179 creator_->OnCreateURLRequest(request); |
| 180 } |
| 181 |
| 178 void OnSuccess(std::unique_ptr<WebSocketStream> stream) override { | 182 void OnSuccess(std::unique_ptr<WebSocketStream> stream) override { |
| 179 creator_->OnConnectSuccess(std::move(stream)); | 183 creator_->OnConnectSuccess(std::move(stream)); |
| 180 // |this| may have been deleted. | 184 // |this| may have been deleted. |
| 181 } | 185 } |
| 182 | 186 |
| 183 void OnFailure(const std::string& message) override { | 187 void OnFailure(const std::string& message) override { |
| 184 creator_->OnConnectFailure(message); | 188 creator_->OnConnectFailure(message); |
| 185 // |this| has been deleted. | 189 // |this| has been deleted. |
| 186 } | 190 } |
| 187 | 191 |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 std::unique_ptr<WebSocketHandshakeStreamCreateHelper> create_helper( | 600 std::unique_ptr<WebSocketHandshakeStreamCreateHelper> create_helper( |
| 597 new WebSocketHandshakeStreamCreateHelper(connect_delegate.get(), | 601 new WebSocketHandshakeStreamCreateHelper(connect_delegate.get(), |
| 598 requested_subprotocols)); | 602 requested_subprotocols)); |
| 599 stream_request_ = callback.Run(socket_url_, std::move(create_helper), origin, | 603 stream_request_ = callback.Run(socket_url_, std::move(create_helper), origin, |
| 600 first_party_for_cookies, additional_headers, | 604 first_party_for_cookies, additional_headers, |
| 601 url_request_context_, NetLogWithSource(), | 605 url_request_context_, NetLogWithSource(), |
| 602 std::move(connect_delegate)); | 606 std::move(connect_delegate)); |
| 603 SetState(CONNECTING); | 607 SetState(CONNECTING); |
| 604 } | 608 } |
| 605 | 609 |
| 610 void WebSocketChannel::OnCreateURLRequest(URLRequest* request) { |
| 611 event_interface_->OnCreateURLRequest(request); |
| 612 } |
| 613 |
| 606 void WebSocketChannel::OnConnectSuccess( | 614 void WebSocketChannel::OnConnectSuccess( |
| 607 std::unique_ptr<WebSocketStream> stream) { | 615 std::unique_ptr<WebSocketStream> stream) { |
| 608 DCHECK(stream); | 616 DCHECK(stream); |
| 609 DCHECK_EQ(CONNECTING, state_); | 617 DCHECK_EQ(CONNECTING, state_); |
| 610 | 618 |
| 611 stream_ = std::move(stream); | 619 stream_ = std::move(stream); |
| 612 | 620 |
| 613 SetState(CONNECTED); | 621 SetState(CONNECTED); |
| 614 | 622 |
| 615 if (event_interface_->OnAddChannelResponse(stream_->GetSubProtocol(), | 623 if (event_interface_->OnAddChannelResponse(stream_->GetSubProtocol(), |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1189 } | 1197 } |
| 1190 | 1198 |
| 1191 void WebSocketChannel::CloseTimeout() { | 1199 void WebSocketChannel::CloseTimeout() { |
| 1192 stream_->Close(); | 1200 stream_->Close(); |
| 1193 SetState(CLOSED); | 1201 SetState(CLOSED); |
| 1194 DoDropChannel(false, kWebSocketErrorAbnormalClosure, ""); | 1202 DoDropChannel(false, kWebSocketErrorAbnormalClosure, ""); |
| 1195 // |this| has been deleted. | 1203 // |this| has been deleted. |
| 1196 } | 1204 } |
| 1197 | 1205 |
| 1198 } // namespace net | 1206 } // namespace net |
| OLD | NEW |