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

Side by Side Diff: remoting/protocol/webrtc_data_stream_adapter.cc

Issue 2172153005: Ensure that connection can be closed in response to a data message. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Pass all tests Created 4 years, 4 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 | « remoting/protocol/connection_unittest.cc ('k') | remoting/protocol/webrtc_transport.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "remoting/protocol/webrtc_data_stream_adapter.h" 5 #include "remoting/protocol/webrtc_data_stream_adapter.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/callback_helpers.h" 11 #include "base/callback_helpers.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
16 #include "net/base/net_errors.h" 16 #include "net/base/net_errors.h"
17 #include "remoting/base/compound_buffer.h" 17 #include "remoting/base/compound_buffer.h"
18 #include "remoting/protocol/message_serialization.h" 18 #include "remoting/protocol/message_serialization.h"
19 19
20 namespace remoting { 20 namespace remoting {
21 namespace protocol { 21 namespace protocol {
22 22
23 WebrtcDataStreamAdapter::WebrtcDataStreamAdapter( 23 WebrtcDataStreamAdapter::WebrtcDataStreamAdapter(
24 rtc::scoped_refptr<webrtc::DataChannelInterface> channel) 24 rtc::scoped_refptr<webrtc::DataChannelInterface> channel)
25 : channel_(channel) { 25 : channel_(channel.get()) {
26 channel_->RegisterObserver(this); 26 channel_->RegisterObserver(this);
27 DCHECK_EQ(channel_->state(), webrtc::DataChannelInterface::kConnecting); 27 DCHECK_EQ(channel_->state(), webrtc::DataChannelInterface::kConnecting);
28 } 28 }
29 29
30 WebrtcDataStreamAdapter::~WebrtcDataStreamAdapter() { 30 WebrtcDataStreamAdapter::~WebrtcDataStreamAdapter() {
31 if (channel_) { 31 if (channel_) {
32 channel_->UnregisterObserver(); 32 channel_->UnregisterObserver();
33 channel_->Close(); 33 channel_->Close();
34
35 // Destroy |channel_| asynchronously as it may be on stack.
36 channel_->AddRef();
37 base::ThreadTaskRunnerHandle::Get()->ReleaseSoon(FROM_HERE, channel_.get());
38 channel_ = nullptr;
34 } 39 }
35 } 40 }
36 41
37 void WebrtcDataStreamAdapter::Start(EventHandler* event_handler) { 42 void WebrtcDataStreamAdapter::Start(EventHandler* event_handler) {
38 DCHECK(!event_handler_); 43 DCHECK(!event_handler_);
39 DCHECK(event_handler); 44 DCHECK(event_handler);
40 45
41 event_handler_ = event_handler; 46 event_handler_ = event_handler;
42 } 47 }
43 48
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 94
90 std::unique_ptr<CompoundBuffer> buffer(new CompoundBuffer()); 95 std::unique_ptr<CompoundBuffer> buffer(new CompoundBuffer());
91 buffer->AppendCopyOf(reinterpret_cast<const char*>(rtc_buffer.data.data()), 96 buffer->AppendCopyOf(reinterpret_cast<const char*>(rtc_buffer.data.data()),
92 rtc_buffer.data.size()); 97 rtc_buffer.data.size());
93 buffer->Lock(); 98 buffer->Lock();
94 event_handler_->OnMessageReceived(std::move(buffer)); 99 event_handler_->OnMessageReceived(std::move(buffer));
95 } 100 }
96 101
97 } // namespace protocol 102 } // namespace protocol
98 } // namespace remoting 103 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/connection_unittest.cc ('k') | remoting/protocol/webrtc_transport.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698