| 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 "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 } | 202 } |
| 203 | 203 |
| 204 WebrtcDataStreamAdapter::WebrtcDataStreamAdapter() : weak_factory_(this) {} | 204 WebrtcDataStreamAdapter::WebrtcDataStreamAdapter() : weak_factory_(this) {} |
| 205 | 205 |
| 206 WebrtcDataStreamAdapter::~WebrtcDataStreamAdapter() { | 206 WebrtcDataStreamAdapter::~WebrtcDataStreamAdapter() { |
| 207 DCHECK(pending_channels_.empty()); | 207 DCHECK(pending_channels_.empty()); |
| 208 } | 208 } |
| 209 | 209 |
| 210 void WebrtcDataStreamAdapter::Initialize( | 210 void WebrtcDataStreamAdapter::Initialize( |
| 211 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection, | 211 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection, |
| 212 bool is_server) { | 212 bool outgoing) { |
| 213 peer_connection_ = peer_connection; | 213 peer_connection_ = peer_connection; |
| 214 is_server_ = is_server; | 214 outgoing_ = outgoing; |
| 215 | 215 |
| 216 if (!is_server_) { | 216 if (outgoing_) { |
| 217 for (auto& channel : pending_channels_) { | 217 for (auto& channel : pending_channels_) { |
| 218 webrtc::DataChannelInit config; | 218 webrtc::DataChannelInit config; |
| 219 config.reliable = true; | 219 config.reliable = true; |
| 220 channel.second->Start( | 220 channel.second->Start( |
| 221 peer_connection_->CreateDataChannel(channel.first, &config)); | 221 peer_connection_->CreateDataChannel(channel.first, &config)); |
| 222 } | 222 } |
| 223 } | 223 } |
| 224 } | 224 } |
| 225 | 225 |
| 226 void WebrtcDataStreamAdapter::OnIncomingDataChannel( | 226 void WebrtcDataStreamAdapter::OnIncomingDataChannel( |
| 227 webrtc::DataChannelInterface* data_channel) { | 227 webrtc::DataChannelInterface* data_channel) { |
| 228 auto it = pending_channels_.find(data_channel->label()); | 228 auto it = pending_channels_.find(data_channel->label()); |
| 229 if (!is_server_ || it == pending_channels_.end()) { | 229 if (outgoing_ || it == pending_channels_.end()) { |
| 230 LOG(ERROR) << "Received unexpected data channel " << data_channel->label(); | 230 LOG(ERROR) << "Received unexpected data channel " << data_channel->label(); |
| 231 return; | 231 return; |
| 232 } | 232 } |
| 233 it->second->Start(data_channel); | 233 it->second->Start(data_channel); |
| 234 } | 234 } |
| 235 | 235 |
| 236 void WebrtcDataStreamAdapter::CreateChannel( | 236 void WebrtcDataStreamAdapter::CreateChannel( |
| 237 const std::string& name, | 237 const std::string& name, |
| 238 const ChannelCreatedCallback& callback) { | 238 const ChannelCreatedCallback& callback) { |
| 239 DCHECK(pending_channels_.find(name) == pending_channels_.end()); | 239 DCHECK(pending_channels_.find(name) == pending_channels_.end()); |
| 240 | 240 |
| 241 Channel* channel = | 241 Channel* channel = |
| 242 new Channel(base::Bind(&WebrtcDataStreamAdapter::OnChannelConnected, | 242 new Channel(base::Bind(&WebrtcDataStreamAdapter::OnChannelConnected, |
| 243 base::Unretained(this), callback)); | 243 base::Unretained(this), callback)); |
| 244 pending_channels_[name] = channel; | 244 pending_channels_[name] = channel; |
| 245 | 245 |
| 246 if (peer_connection_ && !is_server_) { | 246 if (peer_connection_ && outgoing_) { |
| 247 webrtc::DataChannelInit config; | 247 webrtc::DataChannelInit config; |
| 248 config.reliable = true; | 248 config.reliable = true; |
| 249 channel->Start(peer_connection_->CreateDataChannel(name, &config)); | 249 channel->Start(peer_connection_->CreateDataChannel(name, &config)); |
| 250 } | 250 } |
| 251 } | 251 } |
| 252 | 252 |
| 253 void WebrtcDataStreamAdapter::CancelChannelCreation(const std::string& name) { | 253 void WebrtcDataStreamAdapter::CancelChannelCreation(const std::string& name) { |
| 254 auto it = pending_channels_.find(name); | 254 auto it = pending_channels_.find(name); |
| 255 DCHECK(it != pending_channels_.end()); | 255 DCHECK(it != pending_channels_.end()); |
| 256 delete it->second; | 256 delete it->second; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 267 | 267 |
| 268 // The callback can delete the channel which also holds the callback | 268 // The callback can delete the channel which also holds the callback |
| 269 // object which may cause crash if the callback carries some arguments. Copy | 269 // object which may cause crash if the callback carries some arguments. Copy |
| 270 // the callback to stack to avoid this problem. | 270 // the callback to stack to avoid this problem. |
| 271 ChannelCreatedCallback callback = connected_callback; | 271 ChannelCreatedCallback callback = connected_callback; |
| 272 callback.Run(make_scoped_ptr(channel)); | 272 callback.Run(make_scoped_ptr(channel)); |
| 273 } | 273 } |
| 274 | 274 |
| 275 } // namespace protocol | 275 } // namespace protocol |
| 276 } // namespace remoting | 276 } // namespace remoting |
| OLD | NEW |