Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Side by Side Diff: net/websockets/websocket_channel.cc

Issue 2315213002: Temporary: Detect WebSocket destruction order problem (Closed)
Patch Set: s/October 2017/October 2016/ Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http/http_network_session.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
28 #include "net/http/http_request_headers.h" 29 #include "net/http/http_request_headers.h"
29 #include "net/http/http_response_headers.h" 30 #include "net/http/http_response_headers.h"
31 #include "net/http/http_transaction_factory.h" // TODO(ricea): Remove
30 #include "net/http/http_util.h" 32 #include "net/http/http_util.h"
31 #include "net/log/net_log.h" 33 #include "net/log/net_log.h"
34 #include "net/url_request/url_request_context.h" // TODO(ricea): Remove
32 #include "net/websockets/websocket_errors.h" 35 #include "net/websockets/websocket_errors.h"
33 #include "net/websockets/websocket_event_interface.h" 36 #include "net/websockets/websocket_event_interface.h"
34 #include "net/websockets/websocket_frame.h" 37 #include "net/websockets/websocket_frame.h"
35 #include "net/websockets/websocket_handshake_request_info.h" 38 #include "net/websockets/websocket_handshake_request_info.h"
36 #include "net/websockets/websocket_handshake_response_info.h" 39 #include "net/websockets/websocket_handshake_response_info.h"
37 #include "net/websockets/websocket_handshake_stream_create_helper.h" 40 #include "net/websockets/websocket_handshake_stream_create_helper.h"
38 #include "net/websockets/websocket_mux.h" 41 #include "net/websockets/websocket_mux.h"
39 #include "net/websockets/websocket_stream.h" 42 #include "net/websockets/websocket_stream.h"
40 #include "url/origin.h" 43 #include "url/origin.h"
41 44
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 has_received_close_frame_(false), 323 has_received_close_frame_(false),
321 received_close_code_(0), 324 received_close_code_(0),
322 state_(FRESHLY_CONSTRUCTED), 325 state_(FRESHLY_CONSTRUCTED),
323 notification_sender_(new HandshakeNotificationSender(this)), 326 notification_sender_(new HandshakeNotificationSender(this)),
324 sending_text_message_(false), 327 sending_text_message_(false),
325 receiving_text_message_(false), 328 receiving_text_message_(false),
326 expecting_to_handle_continuation_(false), 329 expecting_to_handle_continuation_(false),
327 initial_frame_forwarded_(false) {} 330 initial_frame_forwarded_(false) {}
328 331
329 WebSocketChannel::~WebSocketChannel() { 332 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
330 // The stream may hold a pointer to read_frames_, and so it needs to be 341 // The stream may hold a pointer to read_frames_, and so it needs to be
331 // destroyed first. 342 // destroyed first.
332 stream_.reset(); 343 stream_.reset();
333 // The timer may have a callback pointing back to us, so stop it just in case 344 // The timer may have a callback pointing back to us, so stop it just in case
334 // someone decides to run the event loop from their destructor. 345 // someone decides to run the event loop from their destructor.
335 close_timer_.Stop(); 346 close_timer_.Stop();
336 } 347 }
337 348
338 void WebSocketChannel::SendAddChannelRequest( 349 void WebSocketChannel::SendAddChannelRequest(
339 const GURL& socket_url, 350 const GURL& socket_url,
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 SetState(CONNECTING); 602 SetState(CONNECTING);
592 } 603 }
593 604
594 void WebSocketChannel::OnConnectSuccess( 605 void WebSocketChannel::OnConnectSuccess(
595 std::unique_ptr<WebSocketStream> stream) { 606 std::unique_ptr<WebSocketStream> stream) {
596 DCHECK(stream); 607 DCHECK(stream);
597 DCHECK_EQ(CONNECTING, state_); 608 DCHECK_EQ(CONNECTING, state_);
598 609
599 stream_ = std::move(stream); 610 stream_ = std::move(stream);
600 611
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
601 SetState(CONNECTED); 618 SetState(CONNECTED);
602 619
603 if (event_interface_->OnAddChannelResponse(stream_->GetSubProtocol(), 620 if (event_interface_->OnAddChannelResponse(stream_->GetSubProtocol(),
604 stream_->GetExtensions()) == 621 stream_->GetExtensions()) ==
605 CHANNEL_DELETED) 622 CHANNEL_DELETED)
606 return; 623 return;
607 624
608 // TODO(ricea): Get flow control information from the WebSocketStream once we 625 // TODO(ricea): Get flow control information from the WebSocketStream once we
609 // have a multiplexing WebSocketStream. 626 // have a multiplexing WebSocketStream.
610 current_send_quota_ = send_quota_high_water_mark_; 627 current_send_quota_ = send_quota_high_water_mark_;
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 } 1198 }
1182 1199
1183 void WebSocketChannel::CloseTimeout() { 1200 void WebSocketChannel::CloseTimeout() {
1184 stream_->Close(); 1201 stream_->Close();
1185 SetState(CLOSED); 1202 SetState(CLOSED);
1186 DoDropChannel(false, kWebSocketErrorAbnormalClosure, ""); 1203 DoDropChannel(false, kWebSocketErrorAbnormalClosure, "");
1187 // |this| has been deleted. 1204 // |this| has been deleted.
1188 } 1205 }
1189 1206
1190 } // namespace net 1207 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_network_session.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698