| OLD | NEW |
| 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/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
| 15 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 16 #include "remoting/base/compound_buffer.h" | 17 #include "remoting/base/compound_buffer.h" |
| 17 #include "remoting/protocol/message_pipe.h" | 18 #include "remoting/protocol/message_pipe.h" |
| 18 #include "remoting/protocol/message_serialization.h" | 19 #include "remoting/protocol/message_serialization.h" |
| 19 | 20 |
| 20 namespace remoting { | 21 namespace remoting { |
| 21 namespace protocol { | 22 namespace protocol { |
| 22 | 23 |
| 23 class WebrtcDataStreamAdapter::Channel : public MessagePipe, | 24 class WebrtcDataStreamAdapter::Channel : public MessagePipe, |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 state_ = State::CLOSED; | 138 state_ = State::CLOSED; |
| 138 | 139 |
| 139 // Notify the adapter about the error asychronously. | 140 // Notify the adapter about the error asychronously. |
| 140 base::ThreadTaskRunnerHandle::Get()->PostTask( | 141 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 141 FROM_HERE, | 142 FROM_HERE, |
| 142 base::Bind(&WebrtcDataStreamAdapter::OnChannelError, adapter_)); | 143 base::Bind(&WebrtcDataStreamAdapter::OnChannelError, adapter_)); |
| 143 } | 144 } |
| 144 | 145 |
| 145 void WebrtcDataStreamAdapter::Channel::OnMessage( | 146 void WebrtcDataStreamAdapter::Channel::OnMessage( |
| 146 const webrtc::DataBuffer& rtc_buffer) { | 147 const webrtc::DataBuffer& rtc_buffer) { |
| 147 scoped_ptr<CompoundBuffer> buffer(new CompoundBuffer()); | 148 std::unique_ptr<CompoundBuffer> buffer(new CompoundBuffer()); |
| 148 buffer->AppendCopyOf(reinterpret_cast<const char*>(rtc_buffer.data.data()), | 149 buffer->AppendCopyOf(reinterpret_cast<const char*>(rtc_buffer.data.data()), |
| 149 rtc_buffer.data.size()); | 150 rtc_buffer.data.size()); |
| 150 buffer->Lock(); | 151 buffer->Lock(); |
| 151 message_received_callback_.Run(std::move(buffer)); | 152 message_received_callback_.Run(std::move(buffer)); |
| 152 } | 153 } |
| 153 | 154 |
| 154 struct WebrtcDataStreamAdapter::PendingChannel { | 155 struct WebrtcDataStreamAdapter::PendingChannel { |
| 155 PendingChannel() {} | 156 PendingChannel() {} |
| 156 PendingChannel(scoped_ptr<Channel> channel, | 157 PendingChannel(std::unique_ptr<Channel> channel, |
| 157 const ChannelCreatedCallback& connected_callback) | 158 const ChannelCreatedCallback& connected_callback) |
| 158 : channel(std::move(channel)), connected_callback(connected_callback) {} | 159 : channel(std::move(channel)), connected_callback(connected_callback) {} |
| 159 PendingChannel(PendingChannel&& other) | 160 PendingChannel(PendingChannel&& other) |
| 160 : channel(std::move(other.channel)), | 161 : channel(std::move(other.channel)), |
| 161 connected_callback(std::move(other.connected_callback)) {} | 162 connected_callback(std::move(other.connected_callback)) {} |
| 162 PendingChannel& operator=(PendingChannel&& other) { | 163 PendingChannel& operator=(PendingChannel&& other) { |
| 163 channel = std::move(other.channel); | 164 channel = std::move(other.channel); |
| 164 connected_callback = std::move(other.connected_callback); | 165 connected_callback = std::move(other.connected_callback); |
| 165 return *this; | 166 return *this; |
| 166 } | 167 } |
| 167 | 168 |
| 168 scoped_ptr<Channel> channel; | 169 std::unique_ptr<Channel> channel; |
| 169 ChannelCreatedCallback connected_callback; | 170 ChannelCreatedCallback connected_callback; |
| 170 }; | 171 }; |
| 171 | 172 |
| 172 WebrtcDataStreamAdapter::WebrtcDataStreamAdapter( | 173 WebrtcDataStreamAdapter::WebrtcDataStreamAdapter( |
| 173 bool outgoing, | 174 bool outgoing, |
| 174 const ErrorCallback& error_callback) | 175 const ErrorCallback& error_callback) |
| 175 : outgoing_(outgoing), | 176 : outgoing_(outgoing), |
| 176 error_callback_(error_callback), | 177 error_callback_(error_callback), |
| 177 weak_factory_(this) {} | 178 weak_factory_(this) {} |
| 178 | 179 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 197 it->second.channel->Start(data_channel); | 198 it->second.channel->Start(data_channel); |
| 198 } | 199 } |
| 199 | 200 |
| 200 void WebrtcDataStreamAdapter::CreateChannel( | 201 void WebrtcDataStreamAdapter::CreateChannel( |
| 201 const std::string& name, | 202 const std::string& name, |
| 202 const ChannelCreatedCallback& callback) { | 203 const ChannelCreatedCallback& callback) { |
| 203 DCHECK(peer_connection_); | 204 DCHECK(peer_connection_); |
| 204 DCHECK(pending_channels_.find(name) == pending_channels_.end()); | 205 DCHECK(pending_channels_.find(name) == pending_channels_.end()); |
| 205 | 206 |
| 206 Channel* channel = new Channel(weak_factory_.GetWeakPtr()); | 207 Channel* channel = new Channel(weak_factory_.GetWeakPtr()); |
| 207 pending_channels_[name] = PendingChannel(make_scoped_ptr(channel), callback); | 208 pending_channels_[name] = PendingChannel(base::WrapUnique(channel), callback); |
| 208 | 209 |
| 209 if (outgoing_) { | 210 if (outgoing_) { |
| 210 webrtc::DataChannelInit config; | 211 webrtc::DataChannelInit config; |
| 211 config.reliable = true; | 212 config.reliable = true; |
| 212 channel->Start(peer_connection_->CreateDataChannel(name, &config)); | 213 channel->Start(peer_connection_->CreateDataChannel(name, &config)); |
| 213 } | 214 } |
| 214 } | 215 } |
| 215 | 216 |
| 216 void WebrtcDataStreamAdapter::CancelChannelCreation(const std::string& name) { | 217 void WebrtcDataStreamAdapter::CancelChannelCreation(const std::string& name) { |
| 217 auto it = pending_channels_.find(name); | 218 auto it = pending_channels_.find(name); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 229 // |connected_callback|. | 230 // |connected_callback|. |
| 230 pending_channel.connected_callback.Run(std::move(pending_channel.channel)); | 231 pending_channel.connected_callback.Run(std::move(pending_channel.channel)); |
| 231 } | 232 } |
| 232 | 233 |
| 233 void WebrtcDataStreamAdapter::OnChannelError() { | 234 void WebrtcDataStreamAdapter::OnChannelError() { |
| 234 error_callback_.Run(CHANNEL_CONNECTION_ERROR); | 235 error_callback_.Run(CHANNEL_CONNECTION_ERROR); |
| 235 } | 236 } |
| 236 | 237 |
| 237 } // namespace protocol | 238 } // namespace protocol |
| 238 } // namespace remoting | 239 } // namespace remoting |
| OLD | NEW |